| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| 11 | 11 |
| 12 #include "vm/assembler.h" | 12 #include "vm/assembler.h" |
| 13 #include "vm/ast_printer.h" | 13 #include "vm/ast_printer.h" |
| 14 #include "vm/code_generator.h" | |
| 15 #include "vm/compiler.h" | 14 #include "vm/compiler.h" |
| 16 #include "vm/dart_api_impl.h" | 15 #include "vm/dart_api_impl.h" |
| 17 #include "vm/disassembler.h" | 16 #include "vm/disassembler.h" |
| 18 #include "vm/longjump.h" | |
| 19 #include "vm/parser.h" | 17 #include "vm/parser.h" |
| 20 #include "vm/virtual_memory.h" | 18 #include "vm/virtual_memory.h" |
| 21 | 19 |
| 22 | 20 |
| 23 namespace dart { | 21 namespace dart { |
| 24 | 22 |
| 25 DECLARE_FLAG(bool, disassemble); | 23 DECLARE_FLAG(bool, disassemble); |
| 26 | 24 |
| 27 | 25 |
| 28 TestCaseBase* TestCaseBase::first_ = NULL; | 26 TestCaseBase* TestCaseBase::first_ = NULL; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); | 165 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); |
| 168 const Array& functions = Array::Handle(Array::New(1)); | 166 const Array& functions = Array::Handle(Array::New(1)); |
| 169 functions.SetAt(0, function_); | 167 functions.SetAt(0, function_); |
| 170 cls.SetFunctions(functions); | 168 cls.SetFunctions(functions); |
| 171 Library& lib = Library::Handle(Library::CoreLibrary()); | 169 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 172 lib.AddClass(cls); | 170 lib.AddClass(cls); |
| 173 } | 171 } |
| 174 | 172 |
| 175 | 173 |
| 176 void CodeGenTest::Compile() { | 174 void CodeGenTest::Compile() { |
| 177 Assembler assembler; | |
| 178 ParsedFunction parsed_function(function_); | 175 ParsedFunction parsed_function(function_); |
| 179 parsed_function.SetNodeSequence(node_sequence_); | 176 parsed_function.SetNodeSequence(node_sequence_); |
| 180 parsed_function.set_instantiator(NULL); | 177 parsed_function.set_instantiator(NULL); |
| 181 parsed_function.set_default_parameter_values(default_parameter_values_); | 178 parsed_function.set_default_parameter_values(default_parameter_values_); |
| 182 parsed_function.AllocateVariables(); | 179 parsed_function.AllocateVariables(); |
| 183 bool retval; | 180 const Error& error = |
| 184 Isolate* isolate = Isolate::Current(); | 181 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
| 185 EXPECT(isolate != NULL); | 182 EXPECT(error.IsNull()); |
| 186 LongJump* base = isolate->long_jump_base(); | |
| 187 LongJump jump; | |
| 188 isolate->set_long_jump_base(&jump); | |
| 189 if (setjmp(*jump.Set()) == 0) { | |
| 190 CodeGenerator code_gen(&assembler, parsed_function); | |
| 191 code_gen.GenerateCode(); | |
| 192 const char* function_fullname = function_.ToFullyQualifiedCString(); | |
| 193 const Code& code = | |
| 194 Code::Handle(Code::FinalizeCode(function_fullname, &assembler)); | |
| 195 if (FLAG_disassemble) { | |
| 196 OS::Print("Code for function '%s' {\n", function_fullname); | |
| 197 const Instructions& instructions = | |
| 198 Instructions::Handle(code.instructions()); | |
| 199 uword start = instructions.EntryPoint(); | |
| 200 Disassembler::Disassemble(start, start + assembler.CodeSize()); | |
| 201 OS::Print("}\n"); | |
| 202 } | |
| 203 function_.SetCode(code); | |
| 204 retval = true; | |
| 205 } else { | |
| 206 retval = false; | |
| 207 } | |
| 208 EXPECT(retval); | |
| 209 isolate->set_long_jump_base(base); | |
| 210 } | 183 } |
| 211 | 184 |
| 212 | 185 |
| 213 bool CompilerTest::TestCompileScript(const Library& library, | 186 bool CompilerTest::TestCompileScript(const Library& library, |
| 214 const Script& script) { | 187 const Script& script) { |
| 215 Isolate* isolate = Isolate::Current(); | 188 Isolate* isolate = Isolate::Current(); |
| 216 ASSERT(isolate != NULL); | 189 ASSERT(isolate != NULL); |
| 217 const Error& error = Error::Handle(Compiler::Compile(library, script)); | 190 const Error& error = Error::Handle(Compiler::Compile(library, script)); |
| 218 return error.IsNull(); | 191 return error.IsNull(); |
| 219 } | 192 } |
| 220 | 193 |
| 221 | 194 |
| 222 bool CompilerTest::TestCompileFunction(const Function& function) { | 195 bool CompilerTest::TestCompileFunction(const Function& function) { |
| 223 Isolate* isolate = Isolate::Current(); | 196 Isolate* isolate = Isolate::Current(); |
| 224 ASSERT(isolate != NULL); | 197 ASSERT(isolate != NULL); |
| 225 ASSERT(ClassFinalizer::AllClassesFinalized()); | 198 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 226 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 199 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
| 227 return error.IsNull(); | 200 return error.IsNull(); |
| 228 } | 201 } |
| 229 | 202 |
| 230 } // namespace dart | 203 } // namespace dart |
| OLD | NEW |