Reviewers: oth,
Message:
Orion: This is the CL I mentioned which would be really nice to have a
BytecodeEmitter for :).
Description:
[interpreter] Adds interpreter cctests.
BUG=v8:4280
LOG=N
Please review this at https://codereview.chromium.org/1269683002/
Base URL:
ssh://rmcilroy.lon.corp.google.com///usr/local/google/code/v8_full/v8@interpreter_builtins
Affected files (+79, -0 lines):
M src/isolate.h
M test/cctest/cctest.gyp
A test/cctest/interpreter/test-interpreter.cc
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index
585c5b8bf2f5f54bb3013bdcdff0538c12318c64..820a3e40927c2982237c55088e2c357d5c301228
100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -1139,6 +1139,8 @@ class Isolate {
FutexWaitListNode* futex_wait_list_node() { return
&futex_wait_list_node_; }
+ interpreter::Interpreter* interpreter() const { return interpreter_; }
+
void RegisterCancelableTask(CancelableTask* task);
void RemoveCancelableTask(CancelableTask* task);
Index: test/cctest/cctest.gyp
diff --git a/test/cctest/cctest.gyp b/test/cctest/cctest.gyp
index
de1ad4f57af2a71992c0ff486be74523caafb349..4375d58f4e164d6d113acedfa1f1dfd82fd8f164
100644
--- a/test/cctest/cctest.gyp
+++ b/test/cctest/cctest.gyp
@@ -82,6 +82,7 @@
'compiler/test-run-variables.cc',
'compiler/test-simplified-lowering.cc',
'cctest.cc',
+ 'interpreter/test-interpreter.cc',
'gay-fixed.cc',
'gay-precision.cc',
'gay-shortest.cc',
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc
b/test/cctest/interpreter/test-interpreter.cc
new file mode 100644
index
0000000000000000000000000000000000000000..0c869389788ed2570a098c93890c9fdd667c1ae2
--- /dev/null
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -0,0 +1,76 @@
+// 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.
+
+#include "src/v8.h"
+
+#include "src/execution.h"
+#include "src/handles.h"
+#include "src/interpreter/interpreter.h"
+#include "test/cctest/cctest.h"
+
+namespace v8 {
+namespace internal {
+
+class InterpreterTester {
+ public:
+ InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode)
+ : isolate_(isolate), function_(GetBytecodeFunction(isolate,
bytecode)) {
+ i::FLAG_ignition = true;
+ // TODO(rmcilroy): don't regenerate if it's already generated.
+ isolate_->interpreter()->Initialize(isolate_);
+ }
+ virtual ~InterpreterTester() {}
+
+ MaybeHandle<Object> Call() {
+ Handle<Object> args[] = {};
+ return Execution::Call(isolate_, function_,
+ isolate_->factory()->undefined_value(), 0, args,
+ false);
+ }
+
+ private:
+ Isolate* isolate_;
+ Handle<JSFunction> function_;
+
+ static Handle<JSFunction> GetBytecodeFunction(
+ Isolate* isolate, Handle<BytecodeArray> bytecode_array) {
+ Handle<JSFunction> function = v8::Utils::OpenHandle(
+ *v8::Handle<v8::Function>::Cast(CompileRun("(function(){})")));
+
function->ReplaceCode(*isolate->builtins()->InterpreterEntryTrampoline());
+ function->shared()->set_function_data(*bytecode_array);
+ return function;
+ }
+};
+
+} // namespace internal
+} // namespace v8
+
+using namespace v8::internal;
+
+TEST(TestInterpreterReturn) {
+ InitializedHandleScope handles;
+ Handle<Object> undefined_value =
+ handles.main_isolate()->factory()->undefined_value();
+ // TODO(rmcilroy): Use a proper bytecode builder for this.
+ uint8_t raw_bytecodes[1] = {1};
+ Handle<BytecodeArray> bytecode_array =
+ handles.main_isolate()->factory()->NewBytecodeArray(1, raw_bytecodes,
+ kPointerSize);
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ Handle<Object> return_val = tester.Call().ToHandleChecked();
+ CHECK(return_val.is_identical_to(undefined_value));
+}
+
+
+TEST(TestInterpreterLiteral0) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Use a proper bytecode builder for this.
+ uint8_t raw_bytecodes[3] = {0, 0, 1};
+ Handle<BytecodeArray> bytecode_array =
+ handles.main_isolate()->factory()->NewBytecodeArray(3, raw_bytecodes,
+ kPointerSize);
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ Handle<Object> return_val = tester.Call().ToHandleChecked();
+ CHECK_EQ(*return_val, i::Smi::FromInt(0));
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.