public void Call(IAsm a) { Var func = a.getVar(); String funcsig = genDataTypeSig(a.getVar()); /* gen type info */ VarList x = func.getParams(); /* get any params */ String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(MyC.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(MyC.MAXSTR); sb.Append("\tcall "); sb.Append(funcsig); sb.Append("("); sb.Append(paramsig); sb.Append(")\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void FieldDef(IAsm a) { Var e = a.getVar(); /* get the field var ptr */ 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: Console.WriteLine("?Unhandled field def type\n"); Environment.Exit(1); break; } StringBuilder sb = new StringBuilder(MyC.MAXSTR); sb.Append(prefix); /* copy the prefix */ sb.Append(genDataTypeSig(e)); /* gen type info, rets updated dp */ sb.Append(" "); sb.Append(e.getName()); /* copy the variable name */ sb.Append("\r\n"); io.Out(sb.ToString()); }
public void FuncBegin(IAsm a) { Var func = a.getVar(); Type funcsig = genDataTypeSig(a.getVar()); /* gen return type info */ VarList paramlist = func.getParams(); /* get any params */ Type[] paramTypes = null; // in case no params 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); // save the method ref /* * set the argument symbol info */ for (int i = 0; i < paramlist.Length(); i++) { emethod.DefineParameter(i + 1, 0, paramlist.FindByIndex(i).getName()); } il = emethod.GetILGenerator(); // create new il generator if (func.getName().Equals("main")) /* special entry point for main */ { appbuild.SetEntryPoint(emethod); } // emodule.SetUserEntryPoint(emethod); /* * must also re-init the label hashtable for each function */ labelhash = new Hashtable(); localsdone = false; }
public void Load(IAsm a) { StringBuilder sb = new StringBuilder(MyC.MAXSTR); Var e = a.getVar(); if (e == null) { Console.WriteLine("?Load instruction with no variable ptr"); Environment.Exit(1); } switch (e.getClassId()) { case Tok.T_STATIC: { sb.Append("\tldsfld "); sb.Append(genFieldRef(e)); sb.Append("\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//"); 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//"); sb.Append(a.getICount()); sb.Append(", "); sb.Append(e.getName()); sb.Append("\r\n"); break; default: Console.Write("?Instruction load of unknown class ("); Console.Write(e.getClassId()); Console.WriteLine(")"); Environment.Exit(1); break; } io.Out(sb.ToString()); }
public void Store(IAsm a) { Var e = a.getVar(); int id = e.getClassId(); if (e == null) { Io.ICE("Store instruction with no variable ptr"); } if (e.getLocalToken() != null) { // LocalToken lt = (LocalToken) e.getLocalToken(); 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 FuncBegin(IAsm a) { Var func = a.getVar(); String funcsig = genDataTypeSig(a.getVar()); /* gen type info */ VarList x = func.getParams(); /* get any params */ String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(MyC.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(MyC.MAXSTR); sb.Append("\t.method "); 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().Equals("main")) /* special entry point for main */ { io.Out("\t.entrypoint\r\n"); } }
public void FieldDef(IAsm a) { Var e = a.getVar(); /* get the field var ptr */ FieldAttributes attr = FieldAttributes.Private; /* default attributes is 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); // returns token e.setFieldBuilder((Object)f); // store token for later usage }
public void Call(IAsm a) { Var func = a.getVar(); Object o = func.getMethodBuilder(); // get previous declared reference if (o == null) { Io.ICE("No previous extern for (" + func.getName() + ")"); } MethodBuilder mb = (MethodBuilder)o; // il.Emit(OpCodes.Ldc_I4_0); // push 0 for the "this" ptr // VarList x = func.getParams(); /* get any params */ // if (x.Length() > 0) // { // int max = x.Length(); // for (int i = 0; i < max; i++) // { // Var e = x.FindByIndex(i); // genLoad(e); // } // } il.Emit(OpCodes.Call, mb); // call the MethodBuilder }
public void Call(IAsm a) { Var func = a.getVar(); String funcsig = genDataTypeSig(a.getVar()); /* gen type info */ VarList x = func.getParams(); /* get any params */ String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(MyC.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(MyC.MAXSTR); sb.Append("\tcall "); sb.Append(funcsig); sb.Append("("); sb.Append(paramsig); sb.Append(")\t//"); sb.Append(a.getICount()); sb.Append("\r\n"); io.Out(sb.ToString()); }
public void FuncBegin(IAsm a) { Var func = a.getVar(); String funcsig = genDataTypeSig(a.getVar()); /* gen type info */ VarList x = func.getParams(); /* get any params */ String paramsig = ""; if (x.Length() > 0) { int max = x.Length(); StringBuilder t = new StringBuilder(MyC.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(MyC.MAXSTR); sb.Append("\t.method "); 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().Equals("main")) /* special entry point for main */ io.Out("\t.entrypoint\r\n"); }
public void Call(IAsm a) { Var func = a.getVar(); Object o = func.getMethodBuilder(); // get previous declared reference if (o == null) Io.ICE("No previous extern for (" + func.getName() + ")"); MethodBuilder mb = (MethodBuilder) o; // il.Emit(OpCodes.Ldc_I4_0); // push 0 for the "this" ptr // VarList x = func.getParams(); /* get any params */ // if (x.Length() > 0) // { // int max = x.Length(); // for (int i = 0; i < max; i++) // { // Var e = x.FindByIndex(i); // genLoad(e); // } // } il.Emit(OpCodes.Call, mb); // call the MethodBuilder }
public void FuncBegin(IAsm a) { Var func = a.getVar(); Type funcsig = genDataTypeSig(a.getVar()); /* gen return type info */ VarList paramlist = func.getParams(); /* get any params */ Type[] paramTypes = null; // in case no params 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); // save the method ref /* * set the argument symbol info */ for (int i = 0; i < paramlist.Length(); i++) emethod.DefineParameter(i+1, 0, paramlist.FindByIndex(i).getName()); il = emethod.GetILGenerator(); // create new il generator if (func.getName().Equals("main")) /* special entry point for main */ appbuild.SetEntryPoint(emethod); // emodule.SetUserEntryPoint(emethod); /* * must also re-init the label hashtable for each function */ labelhash = new Hashtable(); localsdone = false; }
public void Store(IAsm a) { Var e = a.getVar(); int id = e.getClassId(); if (e == null) Io.ICE("Store instruction with no variable ptr"); if (e.getLocalToken() != null) { // LocalToken lt = (LocalToken) e.getLocalToken(); 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 Load(IAsm a) { Var e = a.getVar(); genLoad(e); }
public void FieldDef(IAsm a) { Var e = a.getVar(); /* get the field var ptr */ FieldAttributes attr = FieldAttributes.Private; /* default attributes is 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); // returns token e.setFieldBuilder((Object) f); // store token for later usage }