@@ -426,7 +426,7 @@ void StringEntry::code_def(ostream& s, int stringclasstag)
426
426
<< WORD << (DEFAULT_OBJFIELDS + STRING_SLOTS + (len+4 )/4 ) << endl // size
427
427
<< WORD;
428
428
429
- emit_disptable_ref (Str, s);
429
+ emit_disptable_ref (Str, s);
430
430
431
431
s << endl; // dispatch table
432
432
s << WORD; lensym->code_ref (s); s << endl; // string length
@@ -468,7 +468,7 @@ void IntEntry::code_def(ostream &s, int intclasstag)
468
468
<< WORD << (DEFAULT_OBJFIELDS + INT_SLOTS) << endl // object size
469
469
<< WORD;
470
470
471
- emit_disptable_ref (Int, s);
471
+ emit_disptable_ref (Int, s);
472
472
473
473
s << endl; // dispatch table
474
474
s << WORD << str << endl; // integer value
@@ -512,7 +512,7 @@ void BoolConst::code_def(ostream& s, int boolclasstag)
512
512
<< WORD << (DEFAULT_OBJFIELDS + BOOL_SLOTS) << endl // object size
513
513
<< WORD;
514
514
515
- emit_disptable_ref (Bool, s);
515
+ emit_disptable_ref (Bool, s);
516
516
517
517
s << endl; // dispatch table
518
518
s << WORD << val << endl; // value (0 or 1)
@@ -969,7 +969,7 @@ void CgenNode::codeDispatchTable(ostream& str) const {
969
969
for (std::map<Symbol, Method>::const_iterator iter = method_map_.begin ();
970
970
iter != method_map_.end ();
971
971
++iter){
972
- Method m = iter->second ;
972
+ Method m = iter->second ;
973
973
str << WORD;
974
974
emit_method_ref (m->getNative (), m->getName (), str);
975
975
str << endl;
@@ -1184,7 +1184,7 @@ int newLabel(){
1184
1184
// such code should be posted on pornhub instead of github. :)
1185
1185
//
1186
1186
void assign_class::code (ostream &s) {
1187
- // Eval expression
1187
+ // Eval expression
1188
1188
expr->code (s);
1189
1189
// Get the location(in terms of register).
1190
1190
ObjectLocation* obj_loc = env.lookup (name);
@@ -1195,104 +1195,104 @@ void assign_class::code(ostream &s) {
1195
1195
// An helper function for dispatch
1196
1196
// type_name is of use only when it's non-static dispatch
1197
1197
void dispatch_common (Expression& expr, Symbol * type_name, Symbol& name, Expressions& actual,
1198
- char * filename, int line_num, bool is_static_dispatch, ostream &s){
1199
- if (cgen_debug) s << " # dispatch_common called" << endl;
1198
+ char * filename, int line_num, bool is_static_dispatch, ostream &s){
1199
+ if (cgen_debug) s << " # dispatch_common called" << endl;
1200
1200
1201
1201
1202
1202
if (cgen_debug) s << " # creating new label" << endl;
1203
- // create new label
1204
- int label_exec = newLabel ();
1205
-
1206
- // deal with all args and push to stack (a1-aN)
1207
- for (int i = 0 ; i < actual->len (); i++){
1208
- Expression arg = actual->nth (i);
1209
- // eval the arg and push to stack
1210
- arg->code (s);
1211
- emit_push (ACC,s);
1212
- }
1213
-
1214
- // the first parameter is the object itself
1215
- if (cgen_debug) s << " # generating code for object_id: " << expr->get_type () << endl;
1216
- if (expr->get_type () == SELF_TYPE) {
1217
- // move s0 to a0 (as the first parameter)
1218
- emit_move (ACC, SELF, s);
1219
- }
1220
- else {
1221
- // eval the attr name, the attr get loaded to $a0 automatically
1222
- expr->code (s);
1223
- }
1224
-
1225
- if (cgen_debug) s << " # abort on error" << endl;
1226
- // Abort
1227
- // if a0 is $0, abort and call dispatch_abort
1228
- emit_bne (ACC,ZERO,label_exec,s);
1229
- // load filename
1230
- StringEntry * fname = stringtable.lookup_string (filename);
1231
- emit_partial_load_address (ACC,s);
1232
- fname->code_ref (s);
1233
- s << endl;
1234
- // T1 is the line number
1235
- emit_load_imm (T1,line_num,s);
1236
- emit_jal (" _dispatch_abort" ,s);
1237
-
1238
- if (cgen_debug) s << " # exec dispatched table" << endl;
1239
- // Valid: preceed to exec
1240
- emit_label_def (label_exec,s);
1241
-
1242
- // get the dispatch table of object at $a0
1243
- if (is_static_dispatch){
1244
- emit_partial_load_address (T1,s);
1245
- emit_disptable_ref (*type_name,s);
1246
- s << endl;
1247
- }
1248
- else {
1249
- emit_load (T1, 2 , ACC, s);
1250
- }
1251
-
1252
- // get the function offset
1253
- int func_offset = 0 ;
1254
-
1255
- std::map<Symbol, Method> method_map;
1256
- // get the dispatch table for object
1257
- if (is_static_dispatch){
1258
- method_map = class_map[*type_name]->getMethodMap ();
1259
- }
1260
- else {
1261
- Symbol object_name = expr->get_type ();
1262
- if (object_name == SELF_TYPE) {
1263
- method_map = cur_class->getMethodMap ();
1264
- } else {
1265
- method_map = class_map[object_name]->getMethodMap ();
1266
- }
1267
- }
1268
-
1269
- // search for the target function in the dispatch table
1270
- for (std::map<Symbol, Method>::const_iterator iter = method_map.begin ();
1271
- iter != method_map.end ();
1272
- ++iter){
1273
- if (iter->first == name){
1274
- break ;
1275
- }
1276
- func_offset ++;
1277
- }
1278
- emit_load (T1,func_offset,T1,s);
1279
-
1280
- // jalr
1281
- emit_jalr (T1,s);
1203
+ // create new label
1204
+ int label_exec = newLabel ();
1205
+
1206
+ // deal with all args and push to stack (a1-aN)
1207
+ for (int i = 0 ; i < actual->len (); i++){
1208
+ Expression arg = actual->nth (i);
1209
+ // eval the arg and push to stack
1210
+ arg->code (s);
1211
+ emit_push (ACC,s);
1212
+ }
1213
+
1214
+ // the first parameter is the object itself
1215
+ if (cgen_debug) s << " # generating code for object_id: " << expr->get_type () << endl;
1216
+ if (expr->get_type () == SELF_TYPE) {
1217
+ // move s0 to a0 (as the first parameter)
1218
+ emit_move (ACC, SELF, s);
1219
+ }
1220
+ else {
1221
+ // eval the attr name, the attr get loaded to $a0 automatically
1222
+ expr->code (s);
1223
+ }
1224
+
1225
+ if (cgen_debug) s << " # abort on error" << endl;
1226
+ // Abort
1227
+ // if a0 is $0, abort and call dispatch_abort
1228
+ emit_bne (ACC,ZERO,label_exec,s);
1229
+ // load filename
1230
+ StringEntry * fname = stringtable.lookup_string (filename);
1231
+ emit_partial_load_address (ACC,s);
1232
+ fname->code_ref (s);
1233
+ s << endl;
1234
+ // T1 is the line number
1235
+ emit_load_imm (T1,line_num,s);
1236
+ emit_jal (" _dispatch_abort" ,s);
1237
+
1238
+ if (cgen_debug) s << " # exec dispatched table" << endl;
1239
+ // Valid: preceed to exec
1240
+ emit_label_def (label_exec,s);
1241
+
1242
+ // get the dispatch table of object at $a0
1243
+ if (is_static_dispatch){
1244
+ emit_partial_load_address (T1,s);
1245
+ emit_disptable_ref (*type_name,s);
1246
+ s << endl;
1247
+ }
1248
+ else {
1249
+ emit_load (T1, 2 , ACC, s);
1250
+ }
1251
+
1252
+ // get the function offset
1253
+ int func_offset = 0 ;
1254
+
1255
+ std::map<Symbol, Method> method_map;
1256
+ // get the dispatch table for object
1257
+ if (is_static_dispatch){
1258
+ method_map = class_map[*type_name]->getMethodMap ();
1259
+ }
1260
+ else {
1261
+ Symbol object_name = expr->get_type ();
1262
+ if (object_name == SELF_TYPE) {
1263
+ method_map = cur_class->getMethodMap ();
1264
+ } else {
1265
+ method_map = class_map[object_name]->getMethodMap ();
1266
+ }
1267
+ }
1268
+
1269
+ // search for the target function in the dispatch table
1270
+ for (std::map<Symbol, Method>::const_iterator iter = method_map.begin ();
1271
+ iter != method_map.end ();
1272
+ ++iter){
1273
+ if (iter->first == name){
1274
+ break ;
1275
+ }
1276
+ func_offset ++;
1277
+ }
1278
+ emit_load (T1,func_offset,T1,s);
1279
+
1280
+ // jalr
1281
+ emit_jalr (T1,s);
1282
1282
}
1283
1283
1284
1284
void static_dispatch_class::code (ostream &s) {
1285
1285
if (cgen_debug) s << " # static_dispatch called" << endl;
1286
1286
1287
- char * filename = cur_class->get_filename ()->get_string ();
1288
- dispatch_common (expr, &type_name,name,actual,filename,this ->get_line_number (),true ,s);
1287
+ char * filename = cur_class->get_filename ()->get_string ();
1288
+ dispatch_common (expr, &type_name,name,actual,filename,this ->get_line_number (),true ,s);
1289
1289
}
1290
1290
1291
1291
void dispatch_class::code (ostream &s) {
1292
- if (cgen_debug) s << " # dispatch called" << endl;
1292
+ if (cgen_debug) s << " # dispatch called" << endl;
1293
1293
1294
- char * filename = cur_class->get_filename ()->get_string ();
1295
- dispatch_common (expr,NULL ,name,actual,filename,this ->get_line_number (),false ,s);
1294
+ char * filename = cur_class->get_filename ()->get_string ();
1295
+ dispatch_common (expr,NULL ,name,actual,filename,this ->get_line_number (),false ,s);
1296
1296
1297
1297
}
1298
1298
@@ -1476,13 +1476,13 @@ void divide_class::code(ostream &s) {
1476
1476
// Negate.
1477
1477
void neg_class::code (ostream &s) {
1478
1478
// eval e1: get int object
1479
- e1 ->code (s);
1479
+ e1 ->code (s);
1480
1480
emit_copy (s);
1481
1481
// load value of int object
1482
- emit_load (T1, 3 , ACC, s);
1483
- emit_neg (T1, T1, s);
1484
- // store value back
1485
- emit_store_int (T1, ACC, s);
1482
+ emit_load (T1, 3 , ACC, s);
1483
+ emit_neg (T1, T1, s);
1484
+ // store value back
1485
+ emit_store_int (T1, ACC, s);
1486
1486
}
1487
1487
1488
1488
// Not
@@ -1502,9 +1502,9 @@ void lessThanCommon(Expression e1, Expression e2, ostream& s, const bool eq){
1502
1502
// eval e1, e2 and store to t1 t2
1503
1503
arith_common (e1 , e2 , s);
1504
1504
if (eq){
1505
- emit_bleq (T1, T2, label_isles, s);
1505
+ emit_bleq (T1, T2, label_isles, s);
1506
1506
} else {
1507
- emit_blt (T1, T2, label_isles, s);
1507
+ emit_blt (T1, T2, label_isles, s);
1508
1508
}
1509
1509
// Else branch.
1510
1510
emit_load_bool (ACC, falsebool, s);
@@ -1622,7 +1622,7 @@ void object_class::code(ostream &s) {
1622
1622
ObjectLocation * loc = env.lookup (name);
1623
1623
1624
1624
// move the attr to a0
1625
- emit_load (ACC,loc->getOffset (), loc->getReg (), s);
1625
+ emit_load (ACC,loc->getOffset (), loc->getReg (), s);
1626
1626
}
1627
1627
1628
1628
0 commit comments