tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ABIArgGenerator.h (2040B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef jit_ABIArgGenerator_h
      8 #define jit_ABIArgGenerator_h
      9 
     10 #include "mozilla/Assertions.h"
     11 
     12 #include <stdint.h>
     13 
     14 #include "jit/ABIFunctionType.h"
     15 #include "jit/Assembler.h"
     16 #include "jit/IonTypes.h"
     17 #include "jit/RegisterSets.h"
     18 #include "wasm/WasmFrame.h"
     19 
     20 namespace js::jit {
     21 
     22 static inline MIRType ToMIRType(MIRType t) { return t; }
     23 
     24 static inline MIRType ToMIRType(ABIType argType) {
     25  switch (argType) {
     26    case ABIType::General:
     27      return MIRType::Pointer;
     28    case ABIType::Float64:
     29      return MIRType::Double;
     30    case ABIType::Float32:
     31      return MIRType::Float32;
     32    case ABIType::Int32:
     33      return MIRType::Int32;
     34    case ABIType::Int64:
     35      return MIRType::Int64;
     36    case ABIType::Void:
     37      return MIRType::None;
     38    default:
     39      break;
     40  }
     41  MOZ_CRASH("unexpected argType");
     42 }
     43 
     44 template <class VecT>
     45 class ABIArgIter {
     46  ABIArgGenerator gen_;
     47  const VecT& types_;
     48  unsigned i_;
     49 
     50  void settle() {
     51    if (!done()) gen_.next(ToMIRType(types_[i_]));
     52  }
     53 
     54 public:
     55  ABIArgIter(const VecT& types, ABIKind kind)
     56      : gen_(kind), types_(types), i_(0) {
     57    settle();
     58  }
     59  void operator++(int) {
     60    MOZ_ASSERT(!done());
     61    i_++;
     62    settle();
     63  }
     64  bool done() const { return i_ == types_.length(); }
     65 
     66  ABIArg* operator->() {
     67    MOZ_ASSERT(!done());
     68    return &gen_.current();
     69  }
     70  ABIArg& operator*() {
     71    MOZ_ASSERT(!done());
     72    return gen_.current();
     73  }
     74 
     75  unsigned index() const {
     76    MOZ_ASSERT(!done());
     77    return i_;
     78  }
     79  MIRType mirType() const {
     80    MOZ_ASSERT(!done());
     81    return ToMIRType(types_[i_]);
     82  }
     83  uint32_t stackBytesConsumedSoFar() const {
     84    return gen_.stackBytesConsumedSoFar();
     85  }
     86 };
     87 
     88 }  // namespace js::jit
     89 
     90 #endif /* jit_ABIArgGenerator_h */