| 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 class WorkItem { | 5 class WorkItem { |
| 6 final Element element; | 6 final Element element; |
| 7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
| 8 Function run; | 8 Function run; |
| 9 Map<int, BailoutInfo> bailouts = null; | 9 Map<int, BailoutInfo> bailouts = null; |
| 10 bool allowSpeculativeOptimization = true; | 10 bool allowSpeculativeOptimization = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Queue<WorkItem> worklist; | 40 Queue<WorkItem> worklist; |
| 41 Universe universe; | 41 Universe universe; |
| 42 String assembledCode; | 42 String assembledCode; |
| 43 Namer namer; | 43 Namer namer; |
| 44 Types types; | 44 Types types; |
| 45 final String currentDirectory; | 45 final String currentDirectory; |
| 46 | 46 |
| 47 CompilerTask measuredTask; | 47 CompilerTask measuredTask; |
| 48 Element _currentElement; | 48 Element _currentElement; |
| 49 LibraryElement coreLibrary; | 49 LibraryElement coreLibrary; |
| 50 LibraryElement coreImplLibrary; |
| 51 LibraryElement jsHelperLibrary; |
| 50 LibraryElement mainApp; | 52 LibraryElement mainApp; |
| 51 | 53 |
| 52 Element get currentElement() => _currentElement; | 54 Element get currentElement() => _currentElement; |
| 53 withCurrentElement(Element element, f()) { | 55 withCurrentElement(Element element, f()) { |
| 54 Element old = currentElement; | 56 Element old = currentElement; |
| 55 _currentElement = element; | 57 _currentElement = element; |
| 56 try { | 58 try { |
| 57 return f(); | 59 return f(); |
| 58 } finally { | 60 } finally { |
| 59 _currentElement = old; | 61 _currentElement = old; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // writes directly into a file. | 138 // writes directly into a file. |
| 137 if (GENERATE_SSA_TRACE) { | 139 if (GENERATE_SSA_TRACE) { |
| 138 print("------------------"); | 140 print("------------------"); |
| 139 print(new HTracer.singleton()); | 141 print(new HTracer.singleton()); |
| 140 print("------------------"); | 142 print("------------------"); |
| 141 } | 143 } |
| 142 log('compilation succeeded'); | 144 log('compilation succeeded'); |
| 143 return true; | 145 return true; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void scanCoreLibrary() { | 148 LibraryElement scanBuiltinLibrary(String filename) { |
| 147 String fileName = io.join([legDirectory, 'lib', 'core.dart']); | 149 String fileName = io.join([legDirectory, 'lib', filename]); |
| 148 Uri cwd = new Uri(scheme: 'file', path: currentDirectory); | 150 Uri cwd = new Uri(scheme: 'file', path: currentDirectory); |
| 149 Uri uri = cwd.resolve(fileName); | 151 Uri uri = cwd.resolve(fileName); |
| 150 Script script = readScript(uri); | 152 LibraryElement library = scanner.loadLibrary(uri, null); |
| 151 coreLibrary = new LibraryElement(script); | |
| 152 withCurrentElement(coreLibrary, () => scanner.scan(currentElement)); | |
| 153 // Make our special function a foreign kind. | 153 // Make our special function a foreign kind. |
| 154 coreLibrary.define(new ForeignElement( | 154 // TODO(ahe): We should only add these elements to one library. |
| 155 const SourceString('JS'), coreLibrary), this); | 155 library.define(new ForeignElement( |
| 156 coreLibrary.define(new ForeignElement( | 156 const SourceString('JS'), library), this); |
| 157 const SourceString('UNINTERCEPTED'), coreLibrary), this); | 157 library.define(new ForeignElement( |
| 158 coreLibrary.define(new ForeignElement( | 158 const SourceString('UNINTERCEPTED'), library), this); |
| 159 const SourceString('JS_HAS_EQUALS'), coreLibrary), this); | 159 library.define(new ForeignElement( |
| 160 const SourceString('JS_HAS_EQUALS'), library), this); |
| 161 return library; |
| 162 } |
| 163 |
| 164 void scanBuiltinLibraries() { |
| 165 coreLibrary = scanBuiltinLibrary('core.dart'); |
| 166 coreImplLibrary = scanBuiltinLibrary('coreimpl.dart'); |
| 167 jsHelperLibrary = scanBuiltinLibrary('js_helper.dart'); |
| 160 // TODO(ngeoffray): Lazily add this method. | 168 // TODO(ngeoffray): Lazily add this method. |
| 161 universe.invokedNames[NO_SUCH_METHOD] = | 169 universe.invokedNames[NO_SUCH_METHOD] = |
| 162 new Set<Invocation>.from(<Invocation>[new Invocation(2)]); | 170 new Set<Invocation>.from(<Invocation>[new Invocation(2)]); |
| 163 } | 171 } |
| 164 | 172 |
| 165 void enqueueInvokedInstanceMethods() { | 173 void enqueueInvokedInstanceMethods() { |
| 166 // TODO(floitsch): find a more efficient way of doing this. | 174 // TODO(floitsch): find a more efficient way of doing this. |
| 167 // Run through the classes and see if we need to compile methods. | 175 // Run through the classes and see if we need to compile methods. |
| 168 for (ClassElement classElement in universe.instantiatedClasses) { | 176 for (ClassElement classElement in universe.instantiatedClasses) { |
| 169 for (ClassElement currentClass = classElement; | 177 for (ClassElement currentClass = classElement; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 if (universe.invokedSetters.contains(member.name)) { | 200 if (universe.invokedSetters.contains(member.name)) { |
| 193 addToWorklist(member); | 201 addToWorklist(member); |
| 194 } | 202 } |
| 195 } | 203 } |
| 196 } | 204 } |
| 197 } | 205 } |
| 198 } | 206 } |
| 199 } | 207 } |
| 200 | 208 |
| 201 void runCompiler(Script script) { | 209 void runCompiler(Script script) { |
| 202 scanCoreLibrary(); | 210 scanBuiltinLibraries(); |
| 203 mainApp = new LibraryElement(script); | 211 mainApp = new LibraryElement(script); |
| 204 Element element; | 212 Element element; |
| 205 withCurrentElement(mainApp, () { | 213 withCurrentElement(mainApp, () { |
| 206 scanner.scan(currentElement); | 214 scanner.scan(currentElement); |
| 207 element = mainApp.find(MAIN); | 215 element = mainApp.find(MAIN); |
| 208 if (element === null) cancel('Could not find $MAIN'); | 216 if (element === null) cancel('Could not find $MAIN'); |
| 209 }); | 217 }); |
| 210 worklist.add(new WorkItem.toCompile(element)); | 218 worklist.add(new WorkItem.toCompile(element)); |
| 211 do { | 219 do { |
| 212 while (!worklist.isEmpty()) { | 220 while (!worklist.isEmpty()) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 reportWarning(Node node, var message) {} | 314 reportWarning(Node node, var message) {} |
| 307 reportError(Node node, var message) {} | 315 reportError(Node node, var message) {} |
| 308 | 316 |
| 309 Script readScript(Uri uri) { | 317 Script readScript(Uri uri) { |
| 310 unimplemented('Compiler.readScript'); | 318 unimplemented('Compiler.readScript'); |
| 311 } | 319 } |
| 312 | 320 |
| 313 String get legDirectory() { | 321 String get legDirectory() { |
| 314 unimplemented('Compiler.legDirectory'); | 322 unimplemented('Compiler.legDirectory'); |
| 315 } | 323 } |
| 324 |
| 325 Element findHelper(SourceString name) => jsHelperLibrary.find(name); |
| 316 } | 326 } |
| 317 | 327 |
| 318 class CompilerTask { | 328 class CompilerTask { |
| 319 final Compiler compiler; | 329 final Compiler compiler; |
| 320 final Stopwatch watch; | 330 final Stopwatch watch; |
| 321 | 331 |
| 322 CompilerTask(this.compiler) : watch = new Stopwatch(); | 332 CompilerTask(this.compiler) : watch = new Stopwatch(); |
| 323 | 333 |
| 324 String get name() => 'Unknown task'; | 334 String get name() => 'Unknown task'; |
| 325 int get timing() => watch.elapsedInMs(); | 335 int get timing() => watch.elapsedInMs(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 340 | 350 |
| 341 class CompilerCancelledException implements Exception { | 351 class CompilerCancelledException implements Exception { |
| 342 final String reason; | 352 final String reason; |
| 343 CompilerCancelledException(this.reason); | 353 CompilerCancelledException(this.reason); |
| 344 | 354 |
| 345 String toString() { | 355 String toString() { |
| 346 String banner = 'compiler cancelled'; | 356 String banner = 'compiler cancelled'; |
| 347 return (reason !== null) ? '$banner: $reason' : '$banner'; | 357 return (reason !== null) ? '$banner: $reason' : '$banner'; |
| 348 } | 358 } |
| 349 } | 359 } |
| OLD | NEW |