Commit 7358e198 authored by whesse@chromium.org's avatar whesse@chromium.org

X64 implementation: Test Compiler::Compile by compiling and running a function.

Review URL: http://codereview.chromium.org/126191

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2178 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fb03c841
......@@ -30,6 +30,8 @@
#include "macro-assembler.h"
#include "register-allocator-inl.h"
#include "codegen.h"
// TEST
#include "compiler.h"
namespace v8 {
namespace internal {
......@@ -97,43 +99,48 @@ void CodeGenerator::DeclareGlobals(Handle<FixedArray> a) {
}
void CodeGenerator::TestCodeGenerator() {
// Generate code.
ZoneScope zone_scope(DELETE_ON_EXIT);
const int initial_buffer_size = 4 * KB;
CodeGenerator cgen(initial_buffer_size, NULL, false);
CodeGeneratorScope scope(&cgen);
Scope dummy_scope;
cgen.scope_ = &dummy_scope;
cgen.GenCode(NULL);
CodeDesc desc;
cgen.masm()->GetCode(&desc);
// Compile a function from a string, and run it.
Handle<JSFunction> test_function = Compiler::Compile(
Factory::NewStringFromAscii(CStrVector("42")),
Factory::NewStringFromAscii(CStrVector("CodeGeneratorTestScript")),
0,
0,
NULL,
NULL);
Code* code_object = test_function->code(); // Local for debugging ease.
USE(code_object);
// Create a dummy function and context.
Handle<JSFunction> bridge =
Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value());
Handle<Context> context =
Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
test_function = Factory::NewFunctionFromBoilerplate(
test_function,
context);
bool pending_exceptions;
Handle<Object> result =
Execution::Call(test_function,
Handle<Object>::cast(test_function),
0,
NULL,
&pending_exceptions);
CHECK(result->IsSmi());
CHECK_EQ(42, Smi::cast(*result)->value());
}
void CodeGenerator::GenCode(FunctionLiteral* function) {
if (function != NULL) {
CodeForFunctionPosition(function);
// ASSERT(scope_ == NULL);
// scope_ = function->scope();
__ int3(); // UNIMPLEMENTED
} else {
// GenCode Implementation under construction. Run by TestCodeGenerator
// with a == NULL.
// Everything guarded by if (function) should be run, unguarded,
// once testing is over.
// Record the position for debugging purposes.
if (function) {
CodeForFunctionPosition(function);
}
// ZoneList<Statement*>* body = fun->body();
// Initialize state.
// While testing, scope is set in cgen before calling GenCode().
if (function) {
ASSERT(scope_ == NULL);
scope_ = function->scope();
}
ASSERT(allocator_ == NULL);
RegisterAllocator register_allocator(this);
allocator_ = &register_allocator;
......@@ -142,7 +149,7 @@ void CodeGenerator::GenCode(FunctionLiteral* function) {
set_in_spilled_code(false);
// Adjust for function-level loop nesting.
// loop_nesting_ += fun->loop_nesting();
loop_nesting_ += function->loop_nesting();
JumpTarget::set_compiling_deferred_code(false);
......@@ -169,12 +176,42 @@ void CodeGenerator::GenCode(FunctionLiteral* function) {
allocator_->Initialize();
frame_->Enter();
__ movq(rax, Immediate(0x2a));
__ Ret();
Result return_register = allocator_->Allocate(rax);
__ movq(return_register.reg(), Immediate(0x54)); // Smi 42
GenerateReturnSequence(&return_register);
}
}
void CodeGenerator::GenerateReturnSequence(Result* return_value) {
// The return value is a live (but not currently reference counted)
// reference to rax. This is safe because the current frame does not
// contain a reference to rax (it is prepared for the return by spilling
// all registers).
if (FLAG_trace) {
frame_->Push(return_value);
// *return_value = frame_->CallRuntime(Runtime::kTraceExit, 1);
}
return_value->ToRegister(rax);
// Add a label for checking the size of the code used for returning.
Label check_exit_codesize;
masm_->bind(&check_exit_codesize);
// Leave the frame and return popping the arguments and the
// receiver.
frame_->Exit();
masm_->ret((scope_->num_parameters() + 1) * kPointerSize);
DeleteFrame();
// Check that the size of the code used for returning matches what is
// expected by the debugger.
// ASSERT_EQ(Debug::kIa32JSReturnSequenceLength,
// masm_->SizeOfCodeGeneratedSince(&check_exit_codesize));
}
void CodeGenerator::GenerateFastCaseSwitchJumpTable(SwitchStatement* a,
int b,
int c,
......
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