Chromium Code Reviews| 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 SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 | 6 |
| 7 final JavaScriptBackend backend; | 7 final JavaScriptBackend backend; |
| 8 | 8 |
| 9 SsaCodeGeneratorTask(JavaScriptBackend backend) | 9 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 10 : this.backend = backend, | 10 : this.backend = backend, |
| 11 super(backend.compiler); | 11 super(backend.compiler); |
| 12 String get name => 'SSA code generator'; | 12 String get name => 'SSA code generator'; |
| 13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; | 13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; |
| 14 | 14 |
| 15 | 15 |
| 16 js.Fun buildJavaScriptFunction(FunctionElement element, | 16 js.Fun buildJavaScriptFunction(FunctionElement element, |
|
ahe
2012/09/18 11:25:54
Yay! Fun with js!
| |
| 17 List<js.Parameter> parameters, | 17 List<js.Parameter> parameters, |
| 18 js.Block body) { | 18 js.Block body) { |
| 19 FunctionExpression expression = element.cachedNode; | 19 FunctionExpression expression = |
| 20 element.implementation.parseNode(backend.compiler); | |
| 20 js.Fun result = new js.Fun(parameters, body); | 21 js.Fun result = new js.Fun(parameters, body); |
| 21 // TODO(johnniwinther): remove the 'element.patch' hack. | 22 // TODO(johnniwinther): remove the 'element.patch' hack. |
| 22 Element sourceElement = element.patch == null ? element : element.patch; | 23 Element sourceElement = element.patch == null ? element : element.patch; |
| 23 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file; | 24 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file; |
| 24 // TODO(podivilov): find the right sourceFile here and remove offset checks | 25 // TODO(podivilov): find the right sourceFile here and remove offset checks |
| 25 // below. | 26 // below. |
| 26 if (expression.getBeginToken().charOffset < sourceFile.text.length) { | 27 if (expression.getBeginToken().charOffset < sourceFile.text.length) { |
| 27 result.sourcePosition = new SourceFileLocation( | 28 result.sourcePosition = new SourceFileLocation( |
| 28 sourceFile, expression.getBeginToken()); | 29 sourceFile, expression.getBeginToken()); |
| 29 } | 30 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 HTypeMap types = context.types; | 66 HTypeMap types = context.types; |
| 66 graph.exit.predecessors.forEach((block) { | 67 graph.exit.predecessors.forEach((block) { |
| 67 assert(block.last is HGoto || block.last is HReturn); | 68 assert(block.last is HGoto || block.last is HReturn); |
| 68 if (block.last is HReturn) { | 69 if (block.last is HReturn) { |
| 69 backend.registerReturnType(work.element, types[block.last.inputs[0]]); | 70 backend.registerReturnType(work.element, types[block.last.inputs[0]]); |
| 70 } else { | 71 } else { |
| 71 backend.registerReturnType(work.element, HType.NULL); | 72 backend.registerReturnType(work.element, HType.NULL); |
| 72 } | 73 } |
| 73 }); | 74 }); |
| 74 compiler.tracer.traceGraph("codegen", graph); | 75 compiler.tracer.traceGraph("codegen", graph); |
| 75 Map<Element, String> parameterNames = getParameterNames(work); | 76 Map<Element, String> parameterNames = getParameterNames(work); |
|
ahe
2012/09/18 11:25:54
Eliminate getParameterNames?
Johnni Winther
2012/09/20 08:12:23
It's used elsewhere.
| |
| 76 parameterNames.forEach((element, name) { | 77 work.element.computeSignature(compiler).forEachParameter((element) { |
| 77 compiler.enqueuer.codegen.addToWorkList(element); | 78 compiler.enqueuer.codegen.addToWorkList(element); |
| 78 }); | 79 }); |
| 79 List<js.Parameter> parameters = <js.Parameter>[]; | 80 List<js.Parameter> parameters = <js.Parameter>[]; |
| 80 parameterNames.forEach((element, name) { | 81 parameterNames.forEach((element, name) { |
| 81 parameters.add(new js.Parameter(name)); | 82 parameters.add(new js.Parameter(name)); |
| 82 }); | 83 }); |
| 83 addTypeParameters(work.element, parameters, parameterNames); | 84 addTypeParameters(work.element, parameters, parameterNames); |
| 84 String parametersString = Strings.join(parameterNames.getValues(), ", "); | 85 String parametersString = Strings.join(parameterNames.getValues(), ", "); |
| 85 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( | 86 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( |
| 86 backend, work, parameters, parameterNames); | 87 backend, work, parameters, parameterNames); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 if (codegen.setup != null) body.statements.add(codegen.setup); | 150 if (codegen.setup != null) body.statements.add(codegen.setup); |
| 150 body.statements.add(codegen.body); | 151 body.statements.add(codegen.body); |
| 151 js.Fun fun = | 152 js.Fun fun = |
| 152 buildJavaScriptFunction(work.element, codegen.newParameters, body); | 153 buildJavaScriptFunction(work.element, codegen.newParameters, body); |
| 153 return prettyPrint(fun); | 154 return prettyPrint(fun); |
| 154 }); | 155 }); |
| 155 } | 156 } |
| 156 | 157 |
| 157 Map<Element, String> getParameterNames(WorkItem work) { | 158 Map<Element, String> getParameterNames(WorkItem work) { |
| 158 Map<Element, String> parameterNames = new LinkedHashMap<Element, String>(); | 159 Map<Element, String> parameterNames = new LinkedHashMap<Element, String>(); |
| 159 FunctionElement function = work.element; | 160 FunctionElement function = work.element.implementation; |
| 160 | 161 |
| 161 // The dom/html libraries have inline JS code that reference | 162 // The dom/html libraries have inline JS code that reference |
| 162 // parameter names directly. Long-term such code will be rejected. | 163 // parameter names directly. Long-term such code will be rejected. |
| 163 // Now, just don't mangle the parameter name. | 164 // Now, just don't mangle the parameter name. |
| 164 function.computeSignature(compiler).forEachParameter((Element element) { | 165 function.computeSignature(compiler).forEachParameter((Element element) { |
| 165 parameterNames[element] = function.isNative() | 166 parameterNames[element] = function.isNative() |
| 166 ? element.name.slowToString() | 167 ? element.name.slowToString() |
| 167 : JsNames.getValid('${element.name.slowToString()}'); | 168 : JsNames.getValid('${element.name.slowToString()}'); |
| 168 }); | 169 }); |
| 169 return parameterNames; | 170 return parameterNames; |
| (...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2982 if (leftType.canBeNull() && rightType.canBeNull()) { | 2983 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2983 if (left.isConstantNull() || right.isConstantNull() || | 2984 if (left.isConstantNull() || right.isConstantNull() || |
| 2984 (leftType.isPrimitive() && leftType == rightType)) { | 2985 (leftType.isPrimitive() && leftType == rightType)) { |
| 2985 return '=='; | 2986 return '=='; |
| 2986 } | 2987 } |
| 2987 return null; | 2988 return null; |
| 2988 } else { | 2989 } else { |
| 2989 return '==='; | 2990 return '==='; |
| 2990 } | 2991 } |
| 2991 } | 2992 } |
| OLD | NEW |