public void Load(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); Var e = a.getVar(); if (e == null) { io.Abort("PL0402: load instruction with no variable ptr"); } switch (e.getClassId()) { case Tok.T_STATIC: sb.Append("\tldsfld "); sb.Append(genFieldRef(e)); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; case Tok.T_AUTO: case Tok.T_DEFCLASS: sb.Append("\tldloc "); sb.Append(e.getIndex()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; case Tok.T_PARAM: sb.Append("\tldarg "); sb.Append(e.getIndex()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; default: io.Abort("PL0403: instruction load of unknown class (" + e.getClassId() + ")"); break; } io.Out(sb.ToString()); }
public void LoadConst(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); int value = Convert.ToInt32(a.getInsn()); sb.Append("\tldc.i4"); if (value > 127 || value < -128) { sb.Append(" "); } else if (value > 8 || value < -1) { sb.Append(".s "); } else { sb.Append("."); } sb.Append(a.getInsn()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void Ret(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append("\tret\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void Branch(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append("\t"); sb.Append(a.getInsn()); sb.Append(" "); sb.Append(a.getLabel()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void Call(IAsm a) { Var func = a.getVar(); LibFunc lfunc; String funcsig = genDataTypeSig(a.getVar()); VarList x = func.getParams(); String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(Io.MAXSTR); for (int i = 0; i < max; i++) { Var e = x.FindByIndex(i); t.Append(genDataTypeSig(e)); if (i < max - 1) { t.Append(","); } } paramsig = t.ToString(); } StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append("\tcall "); sb.Append(funcsig); sb.Append(" "); lfunc = lib.lookup_func(a.getVar().getName()); if (lfunc != null) { sb.Append(lfunc.nameFull); } else { sb.Append(io.GetClassname()); sb.Append("::"); sb.Append(func.getName()); sb.Append("("); sb.Append(paramsig); sb.Append(")"); } sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
void NextInsn(int incr) { int ncount = 0; if (iroot == null) { icur = iroot = new IAsm(); } else { ncount = icur.getICount() + incr; icur.setNext(new IAsm()); icur = icur.getNext(); } icur.setICount(ncount); }
public void Call(IAsm a) { Var func = a.getVar(); LibFunc lfunc; String funcsig = genDataTypeSig(a.getVar()); VarList x = func.getParams(); String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(Io.MAXSTR); for (int i = 0; i < max; i++) { Var e = x.FindByIndex(i); t.Append(genDataTypeSig(e)); if (i < max-1) t.Append(","); } paramsig = t.ToString(); } StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append("\tcall "); sb.Append(funcsig); sb.Append(" "); lfunc = lib.lookup_func(a.getVar().getName()); if (lfunc != null) { sb.Append(lfunc.nameFull); } else { sb.Append(io.GetClassname()); sb.Append("::"); sb.Append(func.getName()); sb.Append("("); sb.Append(paramsig); sb.Append(")"); } sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void Store(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); Var e = a.getVar(); if (e == null) { io.Abort("PL0404: store instruction with no variable ptr"); } switch (e.getClassId()) { case Tok.T_STATIC: sb.Append("\tstsfld "); sb.Append(genFieldRef(e)); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; case Tok.T_AUTO: case Tok.T_DEFCLASS: sb.Append("\tstloc "); sb.Append(e.getIndex()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; case Tok.T_PARAM: sb.Append("\tstarg "); sb.Append(e.getIndex()); sb.Append("\t\t\t\t\t//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; default: io.Abort("PL0405: instruction load of unknown class (" + e.getClassId() + ")"); break; } io.Out(sb.ToString()); }