当前位置: 首页>>代码示例>>C#>>正文


C# MethodBuilder.GetILGenerator方法代码示例

本文整理汇总了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>();
    }
开发者ID:jbolton209,项目名称:GFNHacking,代码行数:20,代码来源:CodeGen.cs

示例2: Create

		internal static CodeEmitter Create(MethodBuilder mb)
		{
			return new CodeEmitter(mb.GetILGenerator(), mb.DeclaringType);
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:4,代码来源:CodeEmitter.cs

示例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");
    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:38,代码来源:codegen.cs

示例4: Create

		internal static CodeEmitter Create(MethodBuilder mb)
		{
			return new CodeEmitter(mb.GetILGenerator());
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:4,代码来源:CodeEmitter.cs

示例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;
    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:22,代码来源:codegen.cs


注:本文中的MethodBuilder.GetILGenerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。