@@ -54,44 +54,46 @@ namespace semantic_actions_util {
54
54
}
55
55
56
56
void appendToCode (string code) {
57
- outputCode.push_back (code);
57
+ outputCode.push_back (" Label_ " + std::to_string (nextInstructionIndex) + " : \n " + code);
58
58
nextInstructionIndex++;
59
59
}
60
60
61
61
void backpatch (unordered_set<int > list, int instruction_index) {
62
62
for (auto index : list) {
63
63
outputCode[index] = outputCode[index].substr (0 , outputCode[index].size ()-1 );
64
- outputCode[index] += to_string (instruction_index);
64
+ outputCode[index] += " Label_ " + to_string (instruction_index);
65
65
}
66
66
}
67
67
68
68
void defineVariable (string name, int varType) {
69
69
declareVariable (name, varType);
70
70
if (varType == INT_TYPE) {
71
- appendToCode (" iconst_0\n istore_" + to_string (currentVariableIndex -1 ));
71
+ appendToCode (" iconst_0" );
72
+ appendToCode (" istore_" + to_string (currentVariableIndex -1 ));
72
73
} else if (varType == FLOAT_TYPE) {
73
- appendToCode (" fconst_0\n fstore_" + to_string (currentVariableIndex -1 ));
74
+ appendToCode (" fconst_0" );
75
+ appendToCode (" fstore_" + to_string (currentVariableIndex -1 ));
74
76
}
75
77
76
78
}
77
79
78
80
void generateHeader () {
79
81
// TO-DO get file name
80
82
// appendToCode(".source " + outfileName);
81
- appendToCode (" .class public java_class\n .super java/lang/Object\n " );
82
- appendToCode (" .method public <init>()V" );
83
- appendToCode (" aload_0" );
84
- appendToCode (" invokenonvirtual java/lang/Object/<init>()V" );
85
- appendToCode (" return" );
86
- appendToCode (" .end method\n " );
87
- appendToCode (" .method public static main([Ljava/lang/String;)V" );
88
- appendToCode (" .limit locals 100\n .limit stack 100" );
89
- appendToCode (" .line 1" );
83
+ outputCode. push_back (" .class public java_class\n .super java/lang/Object\n " );
84
+ outputCode. push_back (" .method public <init>()V" );
85
+ outputCode. push_back (" aload_0" );
86
+ outputCode. push_back (" invokenonvirtual java/lang/Object/<init>()V" );
87
+ outputCode. push_back (" return" );
88
+ outputCode. push_back (" .end method\n " );
89
+ outputCode. push_back (" .method public static main([Ljava/lang/String;)V" );
90
+ outputCode. push_back (" .limit locals 100\n .limit stack 100" );
91
+ outputCode. push_back (" .line 1" );
90
92
}
91
93
92
94
void generateFooter () {
93
- appendToCode (" return" );
94
- appendToCode (" .end method" );
95
+ outputCode. push_back (" return" );
96
+ outputCode. push_back (" .end method" );
95
97
}
96
98
97
99
unordered_set<int > makeList (int instruction_index) {
0 commit comments