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 main() { | 5 main() { |
6 print(""" | 6 print(""" |
7 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 7 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file |
8 // for details. All rights reserved. Use of this source code is governed by a | 8 // for details. All rights reserved. Use of this source code is governed by a |
9 // BSD-style license that can be found in the LICENSE.md file. | 9 // BSD-style license that can be found in the LICENSE.md file. |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 break; | 35 break; |
36 case "I": | 36 case "I": |
37 String field = "uint32Argument$i"; | 37 String field = "uint32Argument$i"; |
38 fields.add(field); | 38 fields.add(field); |
39 encode.add(" ..addUint32($field)\n"); | 39 encode.add(" ..addUint32($field)\n"); |
40 break; | 40 break; |
41 default: | 41 default: |
42 throw "Unknown format: $code"; | 42 throw "Unknown format: $code"; |
43 } | 43 } |
44 } | 44 } |
| 45 |
| 46 String toStringExpression = formatString; |
| 47 if (!fields.isEmpty) { |
| 48 List<String> parts = formatString.split("%d"); |
| 49 StringBuffer buffer = new StringBuffer(); |
| 50 Iterator iterator = fields.iterator; |
| 51 for (String part in parts) { |
| 52 buffer.write(part); |
| 53 if (iterator.moveNext()) { |
| 54 buffer.write(r'${'); |
| 55 buffer.write(iterator.current); |
| 56 buffer.write('}'); |
| 57 } |
| 58 } |
| 59 toStringExpression = '$buffer'; |
| 60 } |
| 61 |
45 print(""" | 62 print(""" |
46 | 63 |
47 class $name extends Bytecode { | 64 class $name extends Bytecode { |
48 ${ | 65 ${ |
49 fields.map((a) => ' final int $a;\n').join('') | 66 fields.map((a) => ' final int $a;\n').join('') |
50 } const $name(${fields.map((a) => 'this.$a').join(', ')}) | 67 } const $name(${fields.map((a) => 'this.$a').join(', ')}) |
51 : super(); | 68 : super(); |
52 | 69 |
53 Opcode get opcode => Opcode.$name; | 70 Opcode get opcode => Opcode.$name; |
54 | 71 |
55 String get name => '$name'; | 72 String get name => '$name'; |
56 | 73 |
57 String get format => '$format'; | 74 String get format => '$format'; |
58 | 75 |
59 int get size => $size; | 76 int get size => $size; |
60 | 77 |
61 int get stackPointerDifference => $spDiff; | 78 int get stackPointerDifference => $spDiff; |
62 | 79 |
63 String get formatString => '$formatString'; | 80 String get formatString => '$formatString'; |
64 | 81 |
65 void addTo(Sink<List<int>> sink) { | 82 void addTo(Sink<List<int>> sink) { |
66 buffer | 83 buffer |
67 ..addUint8(opcode.index) | 84 ..addUint8(opcode.index) |
68 ${ | 85 ${ |
69 encode.join("") | 86 encode.join("") |
70 } ..sendOn(sink); | 87 } ..sendOn(sink); |
71 } | 88 } |
| 89 |
| 90 String toString() => '$toStringExpression'; |
72 }"""); | 91 }"""); |
73 }); | 92 }); |
74 } | 93 } |
75 | 94 |
76 void doBytecodes(V(String name, String format, int size, spDiff, | 95 void doBytecodes(V(String name, String format, int size, spDiff, |
77 String formatString)) { | 96 String formatString)) { |
78 // Code below was copied from src/shared/bytecodes.h. | 97 // Code below was copied from src/shared/bytecodes.h. |
79 var kVarDiff = "VAR_DIFF"; | 98 var kVarDiff = "VAR_DIFF"; |
80 /* Name Format Size SP-diff format-string */ | 99 /* Name Format Size SP-diff format-string */ |
81 V("LoadLocal0", "", 1, 1, "load local 0"); | 100 V("LoadLocal0", "", 1, 1, "load local 0"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 V("Identical", "", 1, -1, "identical"); | 188 V("Identical", "", 1, -1, "identical"); |
170 V("IdenticalNonNumeric", "", 1, -1, "identical non numeric"); | 189 V("IdenticalNonNumeric", "", 1, -1, "identical non numeric"); |
171 | 190 |
172 V("EnterNoSuchMethod", "", 1, 3, "enter noSuchMethod"); | 191 V("EnterNoSuchMethod", "", 1, 3, "enter noSuchMethod"); |
173 V("ExitNoSuchMethod", "", 1, -1, "exit noSuchMethod"); | 192 V("ExitNoSuchMethod", "", 1, -1, "exit noSuchMethod"); |
174 | 193 |
175 V("FrameSize", "B", 2, kVarDiff, "frame size %d"); | 194 V("FrameSize", "B", 2, kVarDiff, "frame size %d"); |
176 | 195 |
177 V("MethodEnd", "I", 5, 0, "method end %d"); | 196 V("MethodEnd", "I", 5, 0, "method end %d"); |
178 } | 197 } |
OLD | NEW |