Commit 6447b78f authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[interpreter] Adds interpreter cctests.

BUG=v8:4280
LOG=N

Review URL: https://codereview.chromium.org/1269683002

Cr-Commit-Position: refs/heads/master@{#30087}
parent d0bbd542
...@@ -53,6 +53,7 @@ void Interpreter::Initialize(bool create_heap_objects) { ...@@ -53,6 +53,7 @@ void Interpreter::Initialize(bool create_heap_objects) {
// Load literal '0' into the accumulator. // Load literal '0' into the accumulator.
void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -61,6 +62,7 @@ void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) { ...@@ -61,6 +62,7 @@ void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) {
// Load an 8-bit integer literal into the accumulator as a Smi. // Load an 8-bit integer literal into the accumulator as a Smi.
void Interpreter::DoLdaSmi8(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaSmi8(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement 8-bit integer to SMI promotion. // TODO(rmcilroy) Implement 8-bit integer to SMI promotion.
__ Dispatch();
} }
...@@ -69,6 +71,7 @@ void Interpreter::DoLdaSmi8(compiler::InterpreterAssembler* assembler) { ...@@ -69,6 +71,7 @@ void Interpreter::DoLdaSmi8(compiler::InterpreterAssembler* assembler) {
// Load Undefined into the accumulator. // Load Undefined into the accumulator.
void Interpreter::DoLdaUndefined(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaUndefined(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -77,6 +80,7 @@ void Interpreter::DoLdaUndefined(compiler::InterpreterAssembler* assembler) { ...@@ -77,6 +80,7 @@ void Interpreter::DoLdaUndefined(compiler::InterpreterAssembler* assembler) {
// Load Null into the accumulator. // Load Null into the accumulator.
void Interpreter::DoLdaNull(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaNull(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -85,6 +89,7 @@ void Interpreter::DoLdaNull(compiler::InterpreterAssembler* assembler) { ...@@ -85,6 +89,7 @@ void Interpreter::DoLdaNull(compiler::InterpreterAssembler* assembler) {
// Load TheHole into the accumulator. // Load TheHole into the accumulator.
void Interpreter::DoLdaTheHole(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaTheHole(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -93,6 +98,7 @@ void Interpreter::DoLdaTheHole(compiler::InterpreterAssembler* assembler) { ...@@ -93,6 +98,7 @@ void Interpreter::DoLdaTheHole(compiler::InterpreterAssembler* assembler) {
// Load True into the accumulator. // Load True into the accumulator.
void Interpreter::DoLdaTrue(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaTrue(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -101,6 +107,7 @@ void Interpreter::DoLdaTrue(compiler::InterpreterAssembler* assembler) { ...@@ -101,6 +107,7 @@ void Interpreter::DoLdaTrue(compiler::InterpreterAssembler* assembler) {
// Load False into the accumulator. // Load False into the accumulator.
void Interpreter::DoLdaFalse(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdaFalse(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -109,6 +116,7 @@ void Interpreter::DoLdaFalse(compiler::InterpreterAssembler* assembler) { ...@@ -109,6 +116,7 @@ void Interpreter::DoLdaFalse(compiler::InterpreterAssembler* assembler) {
// Load accumulator with value from register <src>. // Load accumulator with value from register <src>.
void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) { void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -117,6 +125,7 @@ void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) { ...@@ -117,6 +125,7 @@ void Interpreter::DoLdar(compiler::InterpreterAssembler* assembler) {
// Store accumulator to register <dst>. // Store accumulator to register <dst>.
void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) { void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -125,6 +134,7 @@ void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) { ...@@ -125,6 +134,7 @@ void Interpreter::DoStar(compiler::InterpreterAssembler* assembler) {
// Add register <src> to accumulator. // Add register <src> to accumulator.
void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) { void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -133,6 +143,7 @@ void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) { ...@@ -133,6 +143,7 @@ void Interpreter::DoAdd(compiler::InterpreterAssembler* assembler) {
// Subtract register <src> from accumulator. // Subtract register <src> from accumulator.
void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) { void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
...@@ -141,6 +152,7 @@ void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) { ...@@ -141,6 +152,7 @@ void Interpreter::DoSub(compiler::InterpreterAssembler* assembler) {
// Multiply accumulator by register <src>. // Multiply accumulator by register <src>.
void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) { void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement add register to accumulator. // TODO(rmcilroy) Implement add register to accumulator.
__ Dispatch();
} }
...@@ -149,6 +161,7 @@ void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) { ...@@ -149,6 +161,7 @@ void Interpreter::DoMul(compiler::InterpreterAssembler* assembler) {
// Divide register <src> by accumulator. // Divide register <src> by accumulator.
void Interpreter::DoDiv(compiler::InterpreterAssembler* assembler) { void Interpreter::DoDiv(compiler::InterpreterAssembler* assembler) {
// TODO(rmcilroy) Implement. // TODO(rmcilroy) Implement.
__ Dispatch();
} }
......
...@@ -1138,6 +1138,8 @@ class Isolate { ...@@ -1138,6 +1138,8 @@ class Isolate {
void RegisterCancelableTask(Cancelable* task); void RegisterCancelableTask(Cancelable* task);
void RemoveCancelableTask(Cancelable* task); void RemoveCancelableTask(Cancelable* task);
interpreter::Interpreter* interpreter() const { return interpreter_; }
protected: protected:
explicit Isolate(bool enable_serializer); explicit Isolate(bool enable_serializer);
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
'compiler/test-run-variables.cc', 'compiler/test-run-variables.cc',
'compiler/test-simplified-lowering.cc', 'compiler/test-simplified-lowering.cc',
'cctest.cc', 'cctest.cc',
'interpreter/test-interpreter.cc',
'gay-fixed.cc', 'gay-fixed.cc',
'gay-precision.cc', 'gay-precision.cc',
'gay-shortest.cc', 'gay-shortest.cc',
......
// Copyright 2015 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/bytecode-array-builder.h"
#include "src/interpreter/interpreter.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
class InterpreterCallable {
public:
InterpreterCallable(Isolate* isolate, Handle<JSFunction> function)
: isolate_(isolate), function_(function) {}
virtual ~InterpreterCallable() {}
MaybeHandle<Object> operator()() {
return Execution::Call(isolate_, function_,
isolate_->factory()->undefined_value(), 0, nullptr,
false);
}
private:
Isolate* isolate_;
Handle<JSFunction> function_;
};
class InterpreterTester {
public:
InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode)
: isolate_(isolate), function_(GetBytecodeFunction(isolate, bytecode)) {
i::FLAG_ignition = true;
Handle<FixedArray> empty_array = isolate->factory()->empty_fixed_array();
Handle<FixedArray> interpreter_table =
isolate->factory()->interpreter_table();
if (interpreter_table.is_identical_to(empty_array)) {
// Ensure handler table is generated.
isolate->interpreter()->Initialize(true);
}
}
virtual ~InterpreterTester() {}
InterpreterCallable GetCallable() {
return InterpreterCallable(isolate_, function_);
}
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;
}
DISALLOW_COPY_AND_ASSIGN(InterpreterTester);
};
} // namespace internal
} // namespace v8
using namespace v8::internal;
using namespace v8::internal::interpreter;
TEST(TestInterpreterReturn) {
InitializedHandleScope handles;
Handle<Object> undefined_value =
handles.main_isolate()->factory()->undefined_value();
BytecodeArrayBuilder builder(handles.main_isolate());
// TODO(rmcilroy) set to 0 once BytecodeArray update to allow zero size
// register file.
builder.set_locals_count(1);
builder.Return();
Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
InterpreterTester tester(handles.main_isolate(), bytecode_array);
InterpreterCallable callable(tester.GetCallable());
Handle<Object> return_val = callable().ToHandleChecked();
CHECK(return_val.is_identical_to(undefined_value));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment