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 FieldDef(IAsm a) { Var e = a.getVar(); String prefix = ""; switch (e.getClassId()) { case Tok.T_STATIC: prefix = "\t.field "; break; case Tok.T_AUTO: case Tok.T_DEFCLASS: prefix = "\t.field "; break; default: io.Abort("PL0407: unhandled field def type"); break; } StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append(prefix); sb.Append(genDataTypeSig(e)); sb.Append(" "); sb.Append(e.getName()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void LoadConst(IAsm a) { int value = Convert.ToInt32(a.getInsn()); if (value > 127 || value < -128) { il.Emit(OpCodes.Ldc_I4, value); } else if (value > 8 || value < -1) { il.Emit(OpCodes.Ldc_I4_S, Convert.ToSByte(value)); } else if (value == -1) { il.Emit(OpCodes.Ldc_I4_M1); } else { Object o = opcodehash["ldc.i4." + a.getInsn()]; if (o == null) { io.ICE("could not find opcode for (ldc.i4." + a.getInsn() + ")"); } il.Emit((OpCode)o); } }
public void Label(IAsm a) { StringBuilder sb = new StringBuilder(Io.MAXSTR); sb.Append(a.getLabel()); sb.Append(":\r\n"); io.Out(sb.ToString()); }
public void Branch(IAsm a) { Object o = opcodehash[a.getInsn()]; if (o == null) io.ICE("instruction branch opcode (" + a.getInsn() + ") not found in hash"); il.Emit((OpCode) o, (Label) getILLabel(a)); }
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 Insn(IAsm a) { Object o = opcodehash[a.getInsn()]; if (o == null) { io.ICE("instruction opcode (" + a.getInsn() + ") not found in hash"); } il.Emit((OpCode)o); }
public void Branch(IAsm a) { Object o = opcodehash[a.getInsn()]; if (o == null) { io.ICE("instruction branch opcode (" + a.getInsn() + ") not found in hash"); } il.Emit((OpCode)o, (Label)getILLabel(a)); }
private Object getILLabel(IAsm a) { String s = a.getLabel(); Object l = labelhash[s]; if (l == null) { l = (Object)il.DefineLabel(); labelhash[s] = l; } return(l); }
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()); }
public void Call(IAsm a) { Var func = a.getVar(); Object o = func.getMethodBuilder(); LibFunc lfunc = lib.lookup_func(a.getVar().getName()); if (lfunc != null) { il.Emit(OpCodes.Call, lfunc.methodInfo); } else { if (o == null) io.ICE("no previous extern for (" + func.getName() + ")"); MethodBuilder mb = (MethodBuilder) o; il.Emit(OpCodes.Call, mb); } }
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 FieldDef(IAsm a) { Var e = a.getVar(); FieldAttributes attr = FieldAttributes.Private; if (e.getClassId() == Tok.T_STATIC) { attr |= FieldAttributes.Static; } Type t = genDataTypeSig(e); /* gen type info */ FieldBuilder f = eclass.DefineField(e.getName(), t, attr); e.setFieldBuilder((Object)f); }
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 Call(IAsm a) { Var func = a.getVar(); Object o = func.getMethodBuilder(); LibFunc lfunc = lib.lookup_func(a.getVar().getName()); if (lfunc != null) { il.Emit(OpCodes.Call, lfunc.methodInfo); } else { if (o == null) { io.ICE("no previous extern for (" + func.getName() + ")"); } MethodBuilder mb = (MethodBuilder)o; il.Emit(OpCodes.Call, mb); } }
public void FuncBegin(IAsm a) { Var func = a.getVar(); 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("\t.method public "); sb.Append("static "); sb.Append(funcsig); sb.Append(" "); sb.Append(func.getName()); sb.Append("("); sb.Append(paramsig); sb.Append(") {\r\n"); io.Out(sb.ToString()); if (func.getName().ToLower().Equals("main")) { io.Out("\t.entrypoint\r\n"); } }
public void FuncBegin(IAsm a) { Var func = a.getVar(); Type funcsig = genDataTypeSig(a.getVar()); VarList paramlist = func.getParams(); Type[] paramTypes = null; if (paramlist.Length() > 0) { int max = paramlist.Length(); paramTypes = new Type[max]; for (int i = 0; i < max; i++) { Var e = paramlist.FindByIndex(i); paramTypes[i] = genDataTypeSig(e); } } emethod = eclass.DefineMethod(func.getName(), MethodAttributes.Static | MethodAttributes.Public, funcsig, paramTypes); func.setMethodBuilder(emethod); for (int i = 0; i < paramlist.Length(); i++) { emethod.DefineParameter(i + 1, 0, paramlist.FindByIndex(i).getName()); } il = emethod.GetILGenerator(); if (func.getName().ToLower().Equals("main")) { appbuild.SetEntryPoint(emethod); } // emodule.SetUserEntryPoint(emethod); labelhash = new Hashtable(); }
private bool IsNextNonInsnGen(IAsm a) { IAsm cur = a.getNext(); if (cur == null) { return(true); } int type = cur.getIType(); while (type == IAsm.I_LABEL) { cur = cur.getNext(); type = cur.getIType(); } if (type == IAsm.I_COMMENT) { return(true); } return(false); }
public void setNext(IAsm n) { next = n; }
public void LoadConst(IAsm a) { int value = Convert.ToInt32(a.getInsn()); if (value > 127 || value < -128) { il.Emit(OpCodes.Ldc_I4, value); } else if (value > 8 || value < -1) { il.Emit(OpCodes.Ldc_I4_S, Convert.ToSByte(value)); } else if (value == -1) { il.Emit(OpCodes.Ldc_I4_M1); } else { Object o = opcodehash["ldc.i4."+a.getInsn()]; if (o == null) io.ICE("could not find opcode for (ldc.i4." + a.getInsn() + ")"); il.Emit((OpCode) o); } }
public void Load(IAsm a) { Var e = a.getVar(); genLoad(e); }
public void Store(IAsm a) { if (a.getVar() == null) { io.ICE("store instruction with no variable ptr"); } Var e = localvars.FindByName(a.getVar().getName()); if (e == null) { e = a.getVar(); } int id = e.getClassId(); if (e.getLocalToken() != null) { LocalBuilder lt = (LocalBuilder)e.getLocalToken(); il.Emit(OpCodes.Stloc, lt); } else { if (e.getFieldBuilder() != null) { FieldBuilder fb = (FieldBuilder)e.getFieldBuilder(); if (id == Tok.T_STATIC) { il.Emit(OpCodes.Stsfld, fb); } else { il.Emit(OpCodes.Stfld, fb); } } else { int index = e.getIndex(); if (id == Tok.T_PARAM) { if (index <= 256) { il.Emit(OpCodes.Starg_S, index); } else { il.Emit(OpCodes.Starg, index); } } else { if (id == Tok.T_AUTO || id == Tok.T_DEFCLASS) { il.Emit(OpCodes.Stloc, index); } else { io.ICE("instruction load of unknown class (" + e.getClassId() + ")"); } } } } }
public void LIST() { IAsm a = iroot; IAsm p; Asm x = new Asm(io, lib); while (a != null) { switch (a.getIType()) { case IAsm.I_INSN: x.Insn(a); break; case IAsm.I_LABEL: x.Label(a); break; case IAsm.I_BRANCH: x.Branch(a); break; case IAsm.I_INSN_STORE: x.Store(a); break; case IAsm.I_INSN_LOAD: x.Load(a); break; case IAsm.I_INSN_LOAD_CONST: x.LoadConst(a); break; case IAsm.I_FUNC_BEGIN: x.FuncBegin(a); break; case IAsm.I_FUNC_END: x.FuncEnd(); break; case IAsm.I_CALL: x.Call(a); break; case IAsm.I_RET: x.Ret(a); break; case IAsm.I_COMMENT: break; case IAsm.I_FIELD: x.FieldDef(a); break; case IAsm.I_LOCALDEF: x.LocalVars(localvars); break; default: io.Abort("PL0302: unhandled instruction type " + a.getIType()); break; } p = a; a = a.getNext(); } }
public void FieldDef(IAsm a) { Var e = a.getVar(); FieldAttributes attr = FieldAttributes.Private; if (e.getClassId() == Tok.T_STATIC) attr |= FieldAttributes.Static; Type t = genDataTypeSig(e); /* gen type info */ FieldBuilder f = eclass.DefineField(e.getName(), t, attr); e.setFieldBuilder((Object) f); }
public void Ret(IAsm a) { il.Emit(OpCodes.Ret); }
public void Finish() { iroot = icur = null; }
public void FuncBegin(IAsm a) { Var func = a.getVar(); 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("\t.method public "); sb.Append("static "); sb.Append(funcsig); sb.Append(" "); sb.Append(func.getName()); sb.Append("("); sb.Append(paramsig); sb.Append(") {\r\n"); io.Out(sb.ToString()); if (func.getName().ToLower().Equals("main")) io.Out("\t.entrypoint\r\n"); }
public void Store(IAsm a) { if (a.getVar() == null) io.ICE("store instruction with no variable ptr"); Var e = localvars.FindByName(a.getVar().getName()); if (e == null) e = a.getVar(); int id = e.getClassId(); if (e.getLocalToken() != null) { LocalBuilder lt = (LocalBuilder) e.getLocalToken(); il.Emit(OpCodes.Stloc, lt); } else { if (e.getFieldBuilder() != null) { FieldBuilder fb = (FieldBuilder) e.getFieldBuilder(); if (id == Tok.T_STATIC) il.Emit(OpCodes.Stsfld, fb); else il.Emit(OpCodes.Stfld, fb); } else { int index = e.getIndex(); if (id == Tok.T_PARAM) { if (index <= 256) il.Emit(OpCodes.Starg_S, index); else il.Emit(OpCodes.Starg, index); } else { if (id == Tok.T_AUTO || id == Tok.T_DEFCLASS) il.Emit(OpCodes.Stloc, index); else io.ICE("instruction load of unknown class (" + e.getClassId()+")"); } } } }
private Object getILLabel(IAsm a) { String s = a.getLabel(); Object l = labelhash[s]; if (l == null) { l = (Object) il.DefineLabel(); labelhash[s] = l; } return l; }
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()); }
private bool IsNextNonInsnGen(IAsm a) { IAsm cur = a.getNext(); if (cur == null) return true; int type = cur.getIType(); while (type == IAsm.I_LABEL) { cur = cur.getNext(); type = cur.getIType(); } if (type == IAsm.I_COMMENT) return true; return false; }
public void FuncBegin(IAsm a) { Var func = a.getVar(); Type funcsig = genDataTypeSig(a.getVar()); VarList paramlist = func.getParams(); Type[] paramTypes = null; if (paramlist.Length() > 0) { int max = paramlist.Length(); paramTypes = new Type[max]; for (int i = 0; i < max; i++) { Var e = paramlist.FindByIndex(i); paramTypes[i] = genDataTypeSig(e); } } emethod = eclass.DefineMethod(func.getName(), MethodAttributes.Static|MethodAttributes.Public, funcsig, paramTypes); func.setMethodBuilder(emethod); for (int i = 0; i < paramlist.Length(); i++) emethod.DefineParameter(i+1, 0, paramlist.FindByIndex(i).getName()); il = emethod.GetILGenerator(); if (func.getName().ToLower().Equals("main")) appbuild.SetEntryPoint(emethod); // emodule.SetUserEntryPoint(emethod); labelhash = new Hashtable(); }
public void Label(IAsm a) { il.MarkLabel((Label)getILLabel(a)); }
public void Insn(IAsm a) { Object o = opcodehash[a.getInsn()]; if (o == null) io.ICE("instruction opcode (" + a.getInsn() + ") not found in hash"); il.Emit((OpCode) o); }
public void Label(IAsm a) { il.MarkLabel((Label) getILLabel(a)); }