tor-browser

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

ABIFunctionType.h (1882B)


      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_ABIFunctionType_h
      8 #define jit_ABIFunctionType_h
      9 
     10 #include <initializer_list>
     11 #include <stdint.h>
     12 
     13 #include "jit/ABIFunctionTypeGenerated.h"
     14 
     15 namespace js {
     16 namespace jit {
     17 
     18 enum class ABIKind {
     19  // The system ABI for calling native functions.
     20  System,
     21  // The wasm ABI for calling wasm functions. See "The WASM ABIs" in WasmFrame.h
     22  // for more information.
     23  Wasm,
     24 };
     25 
     26 enum class ABIType {
     27  // A pointer sized integer
     28  General = 0x1,
     29  // A 32-bit integer
     30  Int32 = 0x2,
     31  // A 64-bit integer
     32  Int64 = 0x3,
     33  // A 32-bit floating point number
     34  Float32 = 0x4,
     35  // A 64-bit floating point number
     36  Float64 = 0x5,
     37  // No result
     38  Void = 0x6,
     39 };
     40 
     41 const size_t ABITypeArgShift = 0x3;
     42 const size_t ABITypeArgMask = (1 << ABITypeArgShift) - 1;
     43 
     44 namespace detail {
     45 
     46 static constexpr uint64_t MakeABIFunctionType(
     47    ABIType ret, std::initializer_list<ABIType> args) {
     48  uint64_t abiType = 0;
     49  for (auto arg : args) {
     50    abiType <<= ABITypeArgShift;
     51    abiType |= (uint64_t)arg;
     52  }
     53  abiType <<= ABITypeArgShift;
     54  abiType |= (uint64_t)ret;
     55  return abiType;
     56 }
     57 
     58 }  // namespace detail
     59 
     60 enum ABIFunctionType : uint64_t {
     61  // The enum must be explicitly typed to avoid UB: some validly constructed
     62  // members are larger than any explicitly declared members.
     63  ABI_FUNCTION_TYPE_ENUM
     64 };
     65 
     66 static constexpr ABIFunctionType MakeABIFunctionType(
     67    ABIType ret, std::initializer_list<ABIType> args) {
     68  return ABIFunctionType(detail::MakeABIFunctionType(ret, args));
     69 }
     70 
     71 }  // namespace jit
     72 }  // namespace js
     73 
     74 #endif /* jit_ABIFunctionType_h */