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::kRegularFunction, | 145 Function::New(function_name, RawFunction::kRegularFunction, |
145 true, false, 0)); | 146 true, false, 0)); |
146 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); | 147 const Code& code = Code::Handle(Code::FinalizeCode(function, assembler_)); |
147 if (FLAG_disassemble) { | 148 if (FLAG_disassemble) { |
148 OS::Print("Code for test '%s' {\n", name_); | 149 OS::Print("Code for test '%s' {\n", name_); |
149 const Instructions& instructions = | 150 const Instructions& instructions = |
150 Instructions::Handle(code.instructions()); | 151 Instructions::Handle(code.instructions()); |
151 uword start = instructions.EntryPoint(); | 152 uword start = instructions.EntryPoint(); |
152 Disassembler::Disassemble(start, start + assembler_->CodeSize()); | 153 Disassembler::Disassemble(start, start + assembler_->CodeSize()); |
153 OS::Print("}\n"); | 154 OS::Print("}\n"); |
154 } | 155 } |
155 const Instructions& instructions = Instructions::Handle(code.instructions()); | 156 const Instructions& instructions = Instructions::Handle(code.instructions()); |
156 return instructions.EntryPoint(); | 157 return instructions.EntryPoint(); |
157 } | 158 } |
158 | 159 |
159 | 160 |
160 CodeGenTest::CodeGenTest(const char* name) | 161 CodeGenTest::CodeGenTest(const char* name) |
161 : function_(Function::ZoneHandle()), | 162 : function_(Function::ZoneHandle()), |
162 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, | 163 node_sequence_(new SequenceNode(Scanner::kDummyTokenIndex, |
163 new LocalScope(NULL, 0, 0))), | 164 new LocalScope(NULL, 0, 0))), |
164 default_parameter_values_(Array::ZoneHandle()) { | 165 default_parameter_values_(Array::ZoneHandle()) { |
165 ASSERT(name != NULL); | 166 ASSERT(name != NULL); |
166 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); | 167 const String& function_name = String::ZoneHandle(Symbols::New(name)); |
167 function_ = Function::New( | 168 function_ = Function::New( |
168 function_name, RawFunction::kRegularFunction, true, false, 0); | 169 function_name, RawFunction::kRegularFunction, true, false, 0); |
169 function_.set_result_type(Type::Handle(Type::DynamicType())); | 170 function_.set_result_type(Type::Handle(Type::DynamicType())); |
170 // Add function to a class and that class to the class dictionary so that | 171 // Add function to a class and that class to the class dictionary so that |
171 // frame walking can be used. | 172 // frame walking can be used. |
172 Class& cls = Class::ZoneHandle(); | 173 Class& cls = Class::ZoneHandle(); |
173 const Script& script = Script::Handle(); | 174 const Script& script = Script::Handle(); |
174 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); | 175 cls = Class::New(function_name, script, Scanner::kDummyTokenIndex); |
175 const Array& functions = Array::Handle(Array::New(1)); | 176 const Array& functions = Array::Handle(Array::New(1)); |
176 functions.SetAt(0, function_); | 177 functions.SetAt(0, function_); |
(...skipping 16 matching lines...) Expand all Loading... |
193 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); | 194 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
194 EXPECT(error.IsNull()); | 195 EXPECT(error.IsNull()); |
195 } | 196 } |
196 | 197 |
197 | 198 |
198 LocalVariable* CodeGenTest::CreateTempConstVariable(const char* name_part) { | 199 LocalVariable* CodeGenTest::CreateTempConstVariable(const char* name_part) { |
199 char name[64]; | 200 char name[64]; |
200 OS::SNPrint(name, 64, ":%s", name_part); | 201 OS::SNPrint(name, 64, ":%s", name_part); |
201 LocalVariable* temp = | 202 LocalVariable* temp = |
202 new LocalVariable(0, | 203 new LocalVariable(0, |
203 String::ZoneHandle(String::NewSymbol(name)), | 204 String::ZoneHandle(Symbols::New(name)), |
204 Type::ZoneHandle(Type::DynamicType())); | 205 Type::ZoneHandle(Type::DynamicType())); |
205 temp->set_is_final(); | 206 temp->set_is_final(); |
206 node_sequence_->scope()->AddVariable(temp); | 207 node_sequence_->scope()->AddVariable(temp); |
207 return temp; | 208 return temp; |
208 } | 209 } |
209 | 210 |
210 | 211 |
211 bool CompilerTest::TestCompileScript(const Library& library, | 212 bool CompilerTest::TestCompileScript(const Library& library, |
212 const Script& script) { | 213 const Script& script) { |
213 Isolate* isolate = Isolate::Current(); | 214 Isolate* isolate = Isolate::Current(); |
214 ASSERT(isolate != NULL); | 215 ASSERT(isolate != NULL); |
215 const Error& error = Error::Handle(Compiler::Compile(library, script)); | 216 const Error& error = Error::Handle(Compiler::Compile(library, script)); |
216 return error.IsNull(); | 217 return error.IsNull(); |
217 } | 218 } |
218 | 219 |
219 | 220 |
220 bool CompilerTest::TestCompileFunction(const Function& function) { | 221 bool CompilerTest::TestCompileFunction(const Function& function) { |
221 Isolate* isolate = Isolate::Current(); | 222 Isolate* isolate = Isolate::Current(); |
222 ASSERT(isolate != NULL); | 223 ASSERT(isolate != NULL); |
223 ASSERT(ClassFinalizer::AllClassesFinalized()); | 224 ASSERT(ClassFinalizer::AllClassesFinalized()); |
224 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 225 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
225 return error.IsNull(); | 226 return error.IsNull(); |
226 } | 227 } |
227 | 228 |
228 } // namespace dart | 229 } // namespace dart |
OLD | NEW |