Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library fletchc.codegen_visitor; | 5 library fletchc.codegen_visitor; |
| 6 | 6 |
| 7 import 'package:compiler/src/resolution/semantic_visitor.dart' show | 7 import 'package:compiler/src/resolution/semantic_visitor.dart' show |
| 8 SemanticSendVisitor, | 8 SemanticSendVisitor, |
| 9 SemanticVisitor; | 9 SemanticVisitor; |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 import 'package:compiler/src/universe/universe.dart'; | 30 import 'package:compiler/src/universe/universe.dart'; |
| 31 import 'package:compiler/src/util/util.dart' show Spannable; | 31 import 'package:compiler/src/util/util.dart' show Spannable; |
| 32 import 'package:compiler/src/dart_types.dart'; | 32 import 'package:compiler/src/dart_types.dart'; |
| 33 | 33 |
| 34 import 'fletch_context.dart'; | 34 import 'fletch_context.dart'; |
| 35 | 35 |
| 36 import 'fletch_backend.dart'; | 36 import 'fletch_backend.dart'; |
| 37 | 37 |
| 38 import 'fletch_constants.dart' show | 38 import 'fletch_constants.dart' show |
| 39 CompiledFunctionConstant, | 39 CompiledFunctionConstant, |
| 40 FletchClassConstant; | 40 FletchClassConstant, |
| 41 FletchClassInstanceConstant; | |
| 41 | 42 |
| 42 import '../bytecodes.dart' show | 43 import '../bytecodes.dart' show |
| 43 Bytecode; | 44 Bytecode; |
| 44 | 45 |
| 45 import 'compiled_function.dart' show | 46 import 'compiled_function.dart' show |
| 46 CompiledFunction; | 47 CompiledFunction; |
| 47 | 48 |
| 48 import 'fletch_selector.dart'; | 49 import 'fletch_selector.dart'; |
| 49 | 50 |
| 50 import 'closure_environment.dart'; | 51 import 'closure_environment.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } | 183 } |
| 183 | 184 |
| 184 int allocateConstantFromNode(Node node, {TreeElements elements}) { | 185 int allocateConstantFromNode(Node node, {TreeElements elements}) { |
| 185 ConstantExpression expression = compileConstant( | 186 ConstantExpression expression = compileConstant( |
| 186 node, | 187 node, |
| 187 elements: elements, | 188 elements: elements, |
| 188 isConst: false); | 189 isConst: false); |
| 189 return compiledFunction.allocateConstant(expression.value); | 190 return compiledFunction.allocateConstant(expression.value); |
| 190 } | 191 } |
| 191 | 192 |
| 193 int allocateConstantClassInstance(int classId) { | |
| 194 var constant = new FletchClassInstanceConstant(classId); | |
| 195 context.markConstantUsed(constant); | |
|
ahe
2015/04/07 15:00:11
Why isn't this called for other constants?
Anders Johnsen
2015/04/08 06:32:14
It is, through "compileConstant".
| |
| 196 return compiledFunction.allocateConstant(constant); | |
| 197 } | |
| 198 | |
| 192 int allocateStringConstant(String string) { | 199 int allocateStringConstant(String string) { |
| 193 return compiledFunction.allocateConstant( | 200 return compiledFunction.allocateConstant( |
| 194 context.backend.constantSystem.createString( | 201 context.backend.constantSystem.createString( |
| 195 new DartString.literal(string))); | 202 new DartString.literal(string))); |
| 196 } | 203 } |
| 197 | 204 |
| 198 ClosureInfo get closureInfo => closureEnvironment.closures[element]; | 205 ClosureInfo get closureInfo => closureEnvironment.closures[element]; |
| 199 | 206 |
| 200 LocalValue createLocalValueFor( | 207 LocalValue createLocalValueFor( |
| 201 LocalElement element, | 208 LocalElement element, |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 } | 715 } |
| 709 builder.identical(); | 716 builder.identical(); |
| 710 } | 717 } |
| 711 | 718 |
| 712 void handleStaticFunctionGet(MethodElement function) { | 719 void handleStaticFunctionGet(MethodElement function) { |
| 713 registry.registerStaticInvocation(function); | 720 registry.registerStaticInvocation(function); |
| 714 CompiledFunction compiledFunctionTarget = | 721 CompiledFunction compiledFunctionTarget = |
| 715 context.backend.createCompiledFunction(function, null, null); | 722 context.backend.createCompiledFunction(function, null, null); |
| 716 CompiledClass compiledClass = context.backend.createTearoffClass( | 723 CompiledClass compiledClass = context.backend.createTearoffClass( |
| 717 compiledFunctionTarget); | 724 compiledFunctionTarget); |
| 718 int classConstant = compiledFunction.allocateConstantFromClass( | 725 if (compiledClass.fields == 0) { |
|
ahe
2015/04/08 08:04:18
Why is it the number of fields that determine if y
Anders Johnsen
2015/04/08 08:37:57
Because the field is not a constant - it can only
| |
| 719 compiledClass.id); | 726 int constId = allocateConstantClassInstance(compiledClass.id); |
| 720 builder.allocate(classConstant, compiledClass.fields); | 727 builder.loadConst(constId); |
| 728 } else { | |
| 729 int classConstant = compiledFunction.allocateConstantFromClass( | |
| 730 compiledClass.id); | |
| 731 builder.allocate(classConstant, compiledClass.fields); | |
| 732 } | |
| 721 } | 733 } |
| 722 | 734 |
| 723 void visitTopLevelFunctionGet( | 735 void visitTopLevelFunctionGet( |
| 724 Send node, | 736 Send node, |
| 725 MethodElement function, | 737 MethodElement function, |
| 726 _) { | 738 _) { |
| 727 handleStaticFunctionGet(function); | 739 handleStaticFunctionGet(function); |
| 728 applyVisitState(); | 740 applyVisitState(); |
| 729 } | 741 } |
| 730 | 742 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 if (isTrue) { | 1093 if (isTrue) { |
| 1082 builder.loadLiteralTrue(); | 1094 builder.loadLiteralTrue(); |
| 1083 } else { | 1095 } else { |
| 1084 builder.loadLiteralFalse(); | 1096 builder.loadLiteralFalse(); |
| 1085 } | 1097 } |
| 1086 } else if (visitState == VisitState.Test) { | 1098 } else if (visitState == VisitState.Test) { |
| 1087 builder.branch(isTrue ? trueLabel : falseLabel); | 1099 builder.branch(isTrue ? trueLabel : falseLabel); |
| 1088 } | 1100 } |
| 1089 } | 1101 } |
| 1090 | 1102 |
| 1103 void visitLiteralInt(LiteralInt node) { | |
| 1104 if (visitState == VisitState.Value) { | |
| 1105 int value = node.value; | |
| 1106 if (value >= 0x3FFFFFFF) { | |
|
ahe
2015/04/07 15:03:30
0x3FFFFFFF should probably be a named constant wit
Anders Johnsen
2015/04/08 06:32:13
literal ints are never negative.
ahe
2015/04/08 08:04:18
Assert that?
Anders Johnsen
2015/04/08 08:37:57
Done.
| |
| 1107 int constId = allocateConstantFromNode(node); | |
| 1108 builder.loadConst(constId); | |
| 1109 } else { | |
| 1110 builder.loadLiteral(value); | |
| 1111 } | |
| 1112 } else if (visitState == VisitState.Test) { | |
| 1113 builder.branch(falseLabel); | |
| 1114 } | |
| 1115 } | |
| 1116 | |
| 1091 void visitLiteral(Literal node) { | 1117 void visitLiteral(Literal node) { |
| 1092 if (visitState == VisitState.Value) { | 1118 if (visitState == VisitState.Value) { |
| 1093 builder.loadConst(allocateConstantFromNode(node)); | 1119 builder.loadConst(allocateConstantFromNode(node)); |
| 1094 } else if (visitState == VisitState.Test) { | 1120 } else if (visitState == VisitState.Test) { |
| 1095 builder.branch(falseLabel); | 1121 builder.branch(falseLabel); |
| 1096 } | 1122 } |
| 1097 } | 1123 } |
| 1098 | 1124 |
| 1099 void visitLiteralList(LiteralList node) { | 1125 void visitLiteralList(LiteralList node) { |
| 1100 if (node.isConst) { | 1126 if (node.isConst) { |
| (...skipping 2169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3270 | 3296 |
| 3271 void errorUnresolvedSuperIndex( | 3297 void errorUnresolvedSuperIndex( |
| 3272 Send node, | 3298 Send node, |
| 3273 Element element, | 3299 Element element, |
| 3274 Node index, | 3300 Node index, |
| 3275 _) { | 3301 _) { |
| 3276 generateUnimplementedError( | 3302 generateUnimplementedError( |
| 3277 node, "[errorUnresolvedSuperIndex] isn't implemented."); | 3303 node, "[errorUnresolvedSuperIndex] isn't implemented."); |
| 3278 } | 3304 } |
| 3279 } | 3305 } |
| OLD | NEW |