static void Review(ICCode line, Generals g) { if (line is ICLabel) { var l = line as ICLabel; if (l.LHead[0] != '_') { f = l.LFull; size = g.FVarSize[f]; } } if (line is ICAssignStrToVar) { ((ICAssignStrToVar)line).R = "string" + g.StrCount[((ICAssignStrToVar)line).R]; } if (line is ICPopParams) { pcount = 0; } if (line is ICPushParams) { ++pcount; ((ICPushParams)line).Set(pcount, size); } if (line is ICAssignStrToMem) { ((ICAssignStrToMem)line).R = "string" + g.StrCount[((ICAssignStrToMem)line).R]; } if (line is ICCallLabel) { ((ICCallLabel)line).Set(size); } if (line is ICCallAddress) { ((ICCallAddress)line).Set(size); } }
public static string Generate(List <ICCode> lines) { var data = new List <string>(); Generals g = new Generals(lines); foreach (var item in g.StrCount) { data.Add("string" + item.Value + ": .asciiz \"" + (item.Key[0] == '"' ? item.Key.Substring(1, item.Key.Length - 2) : item.Key) + "\""); } foreach (var item in g.Inherit) { var tmp = "_class." + item.Key + ": .word string" + g.StrCount[item.Key] + ", "; var parent = item.Value; while (parent != "Object") { tmp += "string" + g.StrCount[parent] + ", "; parent = g.Inherit[parent]; } tmp += "string" + g.StrCount["Object"] + ", 0"; data.Add(tmp); } var s = Data(data); s += Calls(); foreach (var item in lines) { Review(item, g); foreach (var line in item.Generate()) { s += line + NEWLINE; } } s += FINISH; return(s); }