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

Unified Diff: runtime/vm/unit_test.h

Issue 1283733003: VM: Refactor assembler test that rely on the constant pool. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Added comments, fixed that pass in Thread Created 5 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 | « runtime/vm/assembler_x64_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/unit_test.h
diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h
index b74d4479472ad331928968dd000a5d39889bd6e8..9c6682e812b92a62fcd54e0122028bb9d2275e14 100644
--- a/runtime/vm/unit_test.h
+++ b/runtime/vm/unit_test.h
@@ -323,6 +323,26 @@ class TestIsolateScope {
};
+template<typename T> struct is_void {
+ static const bool value = false;
+};
+
+
+template<> struct is_void<void> {
+ static const bool value = true;
+};
+
+
+template<typename T> struct is_double {
+ static const bool value = false;
+};
+
+
+template<> struct is_double<double> {
+ static const bool value = true;
+};
+
+
class AssemblerTest {
public:
AssemblerTest(const char* name, Assembler* assembler)
@@ -338,16 +358,87 @@ class AssemblerTest {
const Code& code() const { return code_; }
- uword entry() const { return entry_; }
+ uword entry() const { return code_.EntryPoint(); }
+
+ // Invoke is used to call assembler test functions using the ABI calling
+ // convention.
+ // ResultType is the return type of the assembler test function.
+ // ArgNType is the type of the Nth argument.
+#if defined(USING_SIMULATOR)
+
+#if defined(ARCH_IS_64_BIT)
+ // TODO(fschneider): Make Invoke<> more general and work on 32-bit platforms.
+ // Since Simulator::Call always return a int64_t, bit_cast does not work
+ // on 32-bit platforms when returning an int32_t. Since template functions
+ // don't support partial specialization, we'd need to introduce a helper
+ // class to support 32-bit return types.
+ template<typename ResultType> ResultType Invoke() {
+ const bool fp_return = is_double<ResultType>::value;
+ const bool fp_args = false;
+ return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
+ bit_cast<intptr_t, uword>(entry()), 0, 0, 0, 0, fp_return, fp_args));
+ }
+ template<typename ResultType, typename Arg1Type>
+ ResultType Invoke(Arg1Type arg1) {
+ const bool fp_return = is_double<ResultType>::value;
+ const bool fp_args = is_double<Arg1Type>::value;
+ // TODO(fschneider): Support double arguments for simulator calls.
+ COMPILE_ASSERT(!fp_args);
+ return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
+ bit_cast<intptr_t, uword>(entry()),
+ reinterpret_cast<intptr_t>(arg1),
+ 0, 0, 0, fp_return, fp_args));
+ }
+#endif // ARCH_IS_64_BIT
+
+ template<typename ResultType,
+ typename Arg1Type,
+ typename Arg2Type,
+ typename Arg3Type>
+ ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
+ // TODO(fschneider): Support double arguments for simulator calls.
+ COMPILE_ASSERT(is_void<ResultType>::value);
+ COMPILE_ASSERT(!is_double<Arg1Type>::value);
+ COMPILE_ASSERT(!is_double<Arg2Type>::value);
+ COMPILE_ASSERT(!is_double<Arg3Type>::value);
+ const bool fp_args = false;
+ const bool fp_return = false;
+ Simulator::Current()->Call(
+ bit_cast<intptr_t, uword>(entry()),
+ reinterpret_cast<intptr_t>(arg1),
+ reinterpret_cast<intptr_t>(arg2),
+ reinterpret_cast<intptr_t>(arg3),
+ 0, fp_return, fp_args);
+ }
+#else
+ template<typename ResultType> ResultType Invoke() {
+ typedef ResultType (*FunctionType) ();
+ return reinterpret_cast<FunctionType>(entry())();
+ }
+
+ template<typename ResultType, typename Arg1Type>
+ ResultType Invoke(Arg1Type arg1) {
+ typedef ResultType (*FunctionType) (Arg1Type);
+ return reinterpret_cast<FunctionType>(entry())(arg1);
+ }
+
+ template<typename ResultType,
+ typename Arg1Type,
+ typename Arg2Type,
+ typename Arg3Type>
+ ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
+ typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type);
+ return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3);
+ }
+#endif // USING_SIMULATOR
- // Assemble test and set code_ and entry_.
+ // Assemble test and set code_.
void Assemble();
private:
const char* name_;
Assembler* assembler_;
Code& code_;
- uword entry_;
DISALLOW_COPY_AND_ASSIGN(AssemblerTest);
};
« no previous file with comments | « runtime/vm/assembler_x64_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698