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/compiler.h" | 14 #include "vm/compiler.h" |
15 #include "vm/dart_api_impl.h" | 15 #include "vm/dart_api_impl.h" |
16 #include "vm/disassembler.h" | 16 #include "vm/disassembler.h" |
17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
| 18 #include "vm/symbols.h" |
18 #include "vm/virtual_memory.h" | 19 #include "vm/virtual_memory.h" |
19 | 20 |
20 | 21 |
21 namespace dart { | 22 namespace dart { |
22 | 23 |
23 DECLARE_FLAG(bool, disassemble); | 24 DECLARE_FLAG(bool, disassemble); |
24 | 25 |
25 | 26 |
26 TestCaseBase* TestCaseBase::first_ = NULL; | 27 TestCaseBase* TestCaseBase::first_ = NULL; |
27 TestCaseBase* TestCaseBase::tail_ = NULL; | 28 TestCaseBase* TestCaseBase::tail_ = NULL; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Dart_Handle library, | 133 Dart_Handle library, |
133 Dart_Handle url) { | 134 Dart_Handle url) { |
134 if (tag == kCanonicalizeUrl) { | 135 if (tag == kCanonicalizeUrl) { |
135 return url; | 136 return url; |
136 } | 137 } |
137 return Api::Success(Isolate::Current()); | 138 return Api::Success(Isolate::Current()); |
138 } | 139 } |
139 | 140 |
140 | 141 |
141 uword AssemblerTest::Assemble() { | 142 uword AssemblerTest::Assemble() { |
142 const String& function_name = String::ZoneHandle(String::NewSymbol(name_)); | 143 const String& function_name = String::ZoneHandle(Symbols::New(name_)); |
143 Function& function = Function::ZoneHandle( | 144 Function& function = Function::ZoneHandle( |
144 Function::New(function_name, RawFunction::kFunction, true, false, 0)); | 145 Function::New(function_name, RawFunction::kFunction, true, false, 0)); |
145 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); | 146 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); |
146 if (FLAG_disassemble) { | 147 if (FLAG_disassemble) { |
147 OS::Print("Code for test '%s' {\n", name_); | 148 OS::Print("Code for test '%s' {\n", name_); |
148 const Instructions& instructions = | 149 const Instructions& instructions = |
149 Instructions::Handle(code.instructions()); | 150 Instructions::Handle(code.instructions()); |
150 uword start = instructions.EntryPoint(); | 151 uword start = instructions.EntryPoint(); |
151 Disassembler::Disassemble(start, start + assembler_->CodeSize()); | 152 Disassembler::Disassemble(start, start + assembler_->CodeSize()); |
152 OS::Print("}\n"); | 153 OS::Print("}\n"); |
153 } | 154 } |
154 const Instructions& instructions = Instructions::Handle(code.instructions()); | 155 const Instructions& instructions = Instructions::Handle(code.instructions()); |
155 return instructions.EntryPoint(); | 156 return instructions.EntryPoint(); |
156 } | 157 } |
157 | 158 |
158 | 159 |
159 CodeGenTest::CodeGenTest(const char* name) | 160 CodeGenTest::CodeGenTest(const char* name) |
160 : function_(Function::ZoneHandle()), | 161 : function_(Function::ZoneHandle()), |
161 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, | 162 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, |
162 new LocalScope(NULL, 0, 0))), | 163 new LocalScope(NULL, 0, 0))), |
163 default_parameter_values_(Array::ZoneHandle()) { | 164 default_parameter_values_(Array::ZoneHandle()) { |
164 ASSERT(name != NULL); | 165 ASSERT(name != NULL); |
165 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | 166 const String& function_name = String::ZoneHandle(Symbols::New(name)); |
166 function_ = Function::New( | 167 function_ = Function::New( |
167 function_name, RawFunction::kFunction, true, false, 0); | 168 function_name, RawFunction::kFunction, true, false, 0); |
168 function_.set_result_type(Type::Handle(Type::DynamicType())); | 169 function_.set_result_type(Type::Handle(Type::DynamicType())); |
169 // Add function to a class and that class to the class dictionary so that | 170 // Add function to a class and that class to the class dictionary so that |
170 // frame walking can be used. | 171 // frame walking can be used. |
171 Class& cls = Class::ZoneHandle(); | 172 Class& cls = Class::ZoneHandle(); |
172 const Script& script = Script::Handle(); | 173 const Script& script = Script::Handle(); |
173 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); | 174 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); |
174 const Array& functions = Array::Handle(Array::New(1)); | 175 const Array& functions = Array::Handle(Array::New(1)); |
175 functions.SetAt(0, function_); | 176 functions.SetAt(0, function_); |
(...skipping 16 matching lines...) Expand all Loading... |
192 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); | 193 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
193 EXPECT(error.IsNull()); | 194 EXPECT(error.IsNull()); |
194 } | 195 } |
195 | 196 |
196 | 197 |
197 LocalVariable* CodeGenTest::CreateTempConstVariable(const char* name_part) { | 198 LocalVariable* CodeGenTest::CreateTempConstVariable(const char* name_part) { |
198 char name[64]; | 199 char name[64]; |
199 OS::SNPrint(name, 64, ":%s", name_part); | 200 OS::SNPrint(name, 64, ":%s", name_part); |
200 LocalVariable* temp = | 201 LocalVariable* temp = |
201 new LocalVariable(0, | 202 new LocalVariable(0, |
202 String::ZoneHandle(String::NewSymbol(name)), | 203 String::ZoneHandle(Symbols::New(name)), |
203 Type::ZoneHandle(Type::DynamicType())); | 204 Type::ZoneHandle(Type::DynamicType())); |
204 temp->set_is_final(); | 205 temp->set_is_final(); |
205 node_sequence_->scope()->AddVariable(temp); | 206 node_sequence_->scope()->AddVariable(temp); |
206 return temp; | 207 return temp; |
207 } | 208 } |
208 | 209 |
209 | 210 |
210 bool CompilerTest::TestCompileScript(const Library& library, | 211 bool CompilerTest::TestCompileScript(const Library& library, |
211 const Script& script) { | 212 const Script& script) { |
212 Isolate* isolate = Isolate::Current(); | 213 Isolate* isolate = Isolate::Current(); |
213 ASSERT(isolate != NULL); | 214 ASSERT(isolate != NULL); |
214 const Error& error = Error::Handle(Compiler::Compile(library, script)); | 215 const Error& error = Error::Handle(Compiler::Compile(library, script)); |
215 return error.IsNull(); | 216 return error.IsNull(); |
216 } | 217 } |
217 | 218 |
218 | 219 |
219 bool CompilerTest::TestCompileFunction(const Function& function) { | 220 bool CompilerTest::TestCompileFunction(const Function& function) { |
220 Isolate* isolate = Isolate::Current(); | 221 Isolate* isolate = Isolate::Current(); |
221 ASSERT(isolate != NULL); | 222 ASSERT(isolate != NULL); |
222 ASSERT(ClassFinalizer::AllClassesFinalized()); | 223 ASSERT(ClassFinalizer::AllClassesFinalized()); |
223 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 224 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
224 return error.IsNull(); | 225 return error.IsNull(); |
225 } | 226 } |
226 | 227 |
227 } // namespace dart | 228 } // namespace dart |
OLD | NEW |