// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_COMPILER_C_SIGNATURE_H_ #define V8_COMPILER_C_SIGNATURE_H_ #include "src/compiler/machine-type.h" namespace v8 { namespace internal { namespace compiler { template inline MachineType MachineTypeForC() { CHECK(false); // Instantiated with invalid type. return kMachNone; } template <> inline MachineType MachineTypeForC() { return kMachNone; } template <> inline MachineType MachineTypeForC() { return kMachInt8; } template <> inline MachineType MachineTypeForC() { return kMachUint8; } template <> inline MachineType MachineTypeForC() { return kMachInt16; } template <> inline MachineType MachineTypeForC() { return kMachUint16; } template <> inline MachineType MachineTypeForC() { return kMachInt32; } template <> inline MachineType MachineTypeForC() { return kMachUint32; } template <> inline MachineType MachineTypeForC() { return kMachInt64; } template <> inline MachineType MachineTypeForC() { return kMachUint64; } template <> inline MachineType MachineTypeForC() { return kMachFloat64; } template <> inline MachineType MachineTypeForC() { return kMachAnyTagged; } template class CSignatureOf : public MachineSignature { protected: MachineType storage_[1 + kParamCount]; CSignatureOf() : MachineSignature(MachineTypeForC() != kMachNone ? 1 : 0, kParamCount, reinterpret_cast(&storage_)) { if (return_count_ == 1) storage_[0] = MachineTypeForC(); } void Set(int index, MachineType type) { DCHECK(index >= 0 && index < kParamCount); reps_[return_count_ + index] = type; } }; // Helper classes for instantiating Signature objects to be callable from C. template class CSignature0 : public CSignatureOf { public: CSignature0() : CSignatureOf() {} }; template class CSignature1 : public CSignatureOf { public: CSignature1() : CSignatureOf() { this->Set(0, MachineTypeForC()); } }; template class CSignature2 : public CSignatureOf { public: CSignature2() : CSignatureOf() { this->Set(0, MachineTypeForC()); this->Set(1, MachineTypeForC()); } }; template class CSignature3 : public CSignatureOf { public: CSignature3() : CSignatureOf() { this->Set(0, MachineTypeForC()); this->Set(1, MachineTypeForC()); this->Set(2, MachineTypeForC()); } }; static const CSignature2 int32_int32_to_int32; static const CSignature2 uint32_uint32_to_uint32; static const CSignature2 float64_float64_to_float64; } } } // namespace v8::internal::compiler #endif // V8_COMPILER_C_SIGNATURE_H_