本文整理汇总了C#中MethodBuilder.GetILGenerator方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder.GetILGenerator方法的具体用法?C# MethodBuilder.GetILGenerator怎么用?C# MethodBuilder.GetILGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodBuilder
的用法示例。
在下文中一共展示了MethodBuilder.GetILGenerator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeGen
public CodeGen(Stmt stmt, string moduleName)
{
if (string.IsNullOrEmpty(moduleName)) throw new ArgumentException("must have a module name", "moduleName");
_stmt = stmt;
_moduleName = moduleName;
if (Path.GetFileName(moduleName) != moduleName) throw new Exception("can only output into current directory!");
var filename = Path.GetFileNameWithoutExtension(moduleName);
var asmName = new AssemblyName(filename);
_asmb = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Save);
_modb = _asmb.DefineDynamicModule(moduleName);
_typeBuilder = _modb.DefineType("Foo");
_methb = _typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void),
Type.EmptyTypes);
_il = _methb.GetILGenerator();
SymbolTable = new Dictionary<string, LocalBuilder>();
}
示例2: Create
internal static CodeEmitter Create(MethodBuilder mb)
{
return new CodeEmitter(mb.GetILGenerator(), mb.DeclaringType);
}
示例3: Generate
public void Generate(String filename)
{
AppDomain ad = Thread.GetDomain(); //AppDomain.CreateDomain("First", null, null);
AssemblyName an = new AssemblyName();
an.Name = filename + ".exe"; //AssemblyName.CreateSimpleName(filename + ".exe", "LispExe", "Lisp Executable", "default_alias");
AssemblyBuilder ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder mb = ab.DefineDynamicModule(filename + ".exe", filename + ".exe");
MethodBuilder methodb;
//DescriptorInfo di = new DescriptorInfo(0);
tb = mb.DefineType(filename);
//di.SetReturnType(typeof(void));
//di.MethodAttributes = MethodAttributes.Static | MethodAttributes.Public;
methodb = tb.DefineMethod("Main", MethodAttributes.Static | MethodAttributes.Public, typeof(void), null);
il = methodb.GetILGenerator();
do{
expr.Head.Visit(this);
if (expr.Head is FunctionDef)
GenerateDefStub(((FunctionDef)expr.Head).Name);
else if (expr.Head is GlobalVarDef)
GenerateDefStub(((GlobalVarDef)expr.Head).Name);
else if (expr.Head.ExpType == typeof(int))
GenerateNumericExpStub();
else if (expr.Head.ExpType == typeof(bool))
GenerateBoolExpStub();
else if (expr.Head.ExpType == typeof(CList))
GenerateListExpStub();
expr = expr.Tail;
}while(expr != null);
il.Emit(OpCodes.Ret);
tb.CreateType();
ab.SetEntryPoint((mb.GetType(filename)).GetMethod("Main"));
ab.Save(filename + ".exe");
}
示例4: Create
internal static CodeEmitter Create(MethodBuilder mb)
{
return new CodeEmitter(mb.GetILGenerator());
}
示例5: FunctionDef
public void FunctionDef(FunctionDef e)
{
Type[] param = new Type[e.Count];
DoVars = new Hashtable();
for (int i = 0; i < e.Count; i++){
param[i] = (Type)e.Params[i];
}
//DescriptorInfo di = new DescriptorInfo(param);
//di.SetReturnType(e.ExpType);
//di.MethodAttributes = MethodAttributes.Static | MethodAttributes.Public;
methodb = tb.DefineMethod(e.Name, MethodAttributes.Static | MethodAttributes.Public, e.ExpType, param);
Functions.Add(e.Name, methodb);
ILGenerator ilmain = il;
il = methodb.GetILGenerator();
e.Body.Visit(this);
il.Emit(OpCodes.Ret);
il = ilmain;
}