Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: test/cctest/compiler/c-signature.h

Issue 515173002: Add MachineSignature, which is an encapsulation of the machine types for parameters and return valu… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/compiler/codegen-tester.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/c-signature.h
diff --git a/test/cctest/compiler/c-signature.h b/test/cctest/compiler/c-signature.h
new file mode 100644
index 0000000000000000000000000000000000000000..5d161dbe7ae3eed5bcd9601a9d7a81bbdb1fbf55
--- /dev/null
+++ b/test/cctest/compiler/c-signature.h
@@ -0,0 +1,133 @@
+// 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 <typename T>
+inline MachineType MachineTypeForC() {
+ CHECK(false); // Instantiated with invalid type.
+ return kMachNone;
+}
+
+template <>
+inline MachineType MachineTypeForC<void>() {
+ return kMachNone;
+}
+
+template <>
+inline MachineType MachineTypeForC<int8_t>() {
+ return kMachInt8;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint8_t>() {
+ return kMachUint8;
+}
+
+template <>
+inline MachineType MachineTypeForC<int16_t>() {
+ return kMachInt16;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint16_t>() {
+ return kMachUint16;
+}
+
+template <>
+inline MachineType MachineTypeForC<int32_t>() {
+ return kMachInt32;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint32_t>() {
+ return kMachUint32;
+}
+
+template <>
+inline MachineType MachineTypeForC<int64_t>() {
+ return kMachInt64;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint64_t>() {
+ return kMachUint64;
+}
+
+template <>
+inline MachineType MachineTypeForC<double>() {
+ return kMachFloat64;
+}
+
+template <>
+inline MachineType MachineTypeForC<Object*>() {
+ return kMachAnyTagged;
+}
+
+template <typename Ret, uint16_t kParamCount>
+class CSignatureOf : public MachineSignature {
+ protected:
+ MachineType storage_[1 + kParamCount];
+
+ CSignatureOf()
+ : MachineSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0,
+ kParamCount,
+ reinterpret_cast<MachineType*>(&storage_)) {
+ if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>();
+ }
+ 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 <typename Ret>
+class CSignature0 : public CSignatureOf<Ret, 0> {
+ public:
+ CSignature0() : CSignatureOf<Ret, 0>() {}
+};
+
+template <typename Ret, typename P1>
+class CSignature1 : public CSignatureOf<Ret, 1> {
+ public:
+ CSignature1() : CSignatureOf<Ret, 1>() {
+ this->Set(0, MachineTypeForC<P1>());
+ }
+};
+
+template <typename Ret, typename P1, typename P2>
+class CSignature2 : public CSignatureOf<Ret, 2> {
+ public:
+ CSignature2() : CSignatureOf<Ret, 2>() {
+ this->Set(0, MachineTypeForC<P1>());
+ this->Set(1, MachineTypeForC<P2>());
+ }
+};
+
+template <typename Ret, typename P1, typename P2, typename P3>
+class CSignature3 : public CSignatureOf<Ret, 3> {
+ public:
+ CSignature3() : CSignatureOf<Ret, 3>() {
+ this->Set(0, MachineTypeForC<P1>());
+ this->Set(1, MachineTypeForC<P2>());
+ this->Set(2, MachineTypeForC<P3>());
+ }
+};
+
+static const CSignature2<int32_t, int32_t, int32_t> int32_int32_to_int32;
+static const CSignature2<uint32_t, uint32_t, uint32_t> uint32_uint32_to_uint32;
+static const CSignature2<double, double, double> float64_float64_to_float64;
+}
+}
+} // namespace v8::internal::compiler
+
+#endif // V8_COMPILER_C_SIGNATURE_H_
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/compiler/codegen-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698