Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/js_backend/backend.dart (revision 18239) |
| +++ sdk/lib/_internal/compiler/implementation/js_backend/backend.dart (working copy) |
| @@ -621,6 +621,19 @@ |
| SsaCodeGeneratorTask generator; |
| CodeEmitterTask emitter; |
| + /** |
| + * The generated code as a js AST for compiled methods. |
|
karlklose
2013/02/08 11:44:53
'js' -> 'JavaScript' or 'JS'
|
| + */ |
| + Map<Element, js.Expression> get generatedCode { |
| + return compiler.enqueuer.codegen.generatedCode; |
| + } |
| + |
| + /** |
| + * The generated code as a js AST for compiled bailout methods. |
|
karlklose
2013/02/08 11:44:53
ditto.
|
| + */ |
| + final Map<Element, js.Expression> generatedBailoutCode = |
| + new Map<Element, js.Expression>(); |
| + |
| ClassElement jsStringClass; |
| ClassElement jsArrayClass; |
| ClassElement jsNumberClass; |
| @@ -928,7 +941,8 @@ |
| } |
| void codegen(CodegenWorkItem work) { |
| - if (work.element.kind.category == ElementCategory.VARIABLE) { |
| + Element element = work.element; |
| + if (element.kind.category == ElementCategory.VARIABLE) { |
| Constant initialValue = compiler.constantHandler.compileWorkItem(work); |
| if (initialValue != null) { |
| return; |
| @@ -946,13 +960,13 @@ |
| if (work.allowSpeculativeOptimization |
| && optimizer.trySpeculativeOptimizations(work, graph)) { |
| js.Expression code = generator.generateBailoutMethod(work, graph); |
| - compiler.codegenWorld.addBailoutCode(work, code); |
| + generatedBailoutCode[element] = code; |
| optimizer.prepareForSpeculativeOptimizations(work, graph); |
| optimizer.optimize(work, graph, true); |
| } |
| js.Expression code = generator.generateCode(work, graph); |
| - compiler.codegenWorld.addGeneratedCode(work, code); |
| - invalidateAfterCodegen.forEach(compiler.enqueuer.codegen.eagerRecompile); |
| + generatedCode[element] = code; |
| + invalidateAfterCodegen.forEach(eagerRecompile); |
| invalidateAfterCodegen.clear(); |
| } |
| @@ -964,6 +978,16 @@ |
| return new native.NativeCodegenEnqueuer(world, compiler, emitter); |
| } |
| + /** |
| + * Unit test hook that returns code of an element as a String. |
| + * |
| + * Invariant: [element] must be a declaration element. |
| + */ |
| + String assembleCode(Element element) { |
| + assert(invariant(element, element.isDeclaration)); |
| + return js.prettyPrint(generatedCode[element], compiler).getText(); |
| + } |
| + |
| void assembleProgram() { |
| emitter.assembleProgram(); |
| } |
| @@ -1222,4 +1246,17 @@ |
| Element getGetRuntimeTypeInfo() { |
| return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); |
| } |
| + |
| + /** |
| + * Remove [element] from the set of generated code, and put it back |
| + * into the worklist. |
| + * |
| + * Invariant: [element] must be a declaration element. |
| + */ |
| + void eagerRecompile(Element element) { |
| + assert(invariant(element, element.isDeclaration)); |
| + generatedCode.remove(element); |
| + generatedBailoutCode.remove(element); |
| + compiler.enqueuer.codegen.addToWorkList(element); |
| + } |
| } |