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


C# AssemblyBuilder.SetEntryPoint方法代码示例

本文整理汇总了C#中System.Reflection.Emit.AssemblyBuilder.SetEntryPoint方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyBuilder.SetEntryPoint方法的具体用法?C# AssemblyBuilder.SetEntryPoint怎么用?C# AssemblyBuilder.SetEntryPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.AssemblyBuilder的用法示例。


在下文中一共展示了AssemblyBuilder.SetEntryPoint方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CodeGen

        public CodeGen(ParseTreeNode stmt, string moduleName)
        {
            if (Path.GetFileName(moduleName) != moduleName)
            {
                throw new System.Exception("can only output into current directory!");
            }

            AssemblyName name = new AssemblyName(Path.GetFileNameWithoutExtension(moduleName));

            asmb = System.AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save);

            ModuleBuilder modb = asmb.DefineDynamicModule(moduleName);

            //mainProgram = modb.DefineType("Program");

            //var mainArgs = new List<Tuple<string, Type>>();
            //var mainProgramDef = new FunctionDefinition
            //(
            //    mainProgram.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes),
            //    new List<FunctionDefinition.Argument>()
            //);

            SymbolTable symbolTable = new SymbolTable(modb.DefineType("__Program"));

            symbolTable.AddFunctionHeader("__Main", MethodAttributes.Static, null, new FunctionDefinition.Argument[]{});

            //symbolTable.functionTable.AddHeader("Main", mainProgramDef);

            stmt = PreGenerate(stmt, symbolTable);
            stmt = ImportList(stmt, symbolTable);

            // CodeGenerator
            var il = symbolTable.functionTable["__Main"].GetILGenerator();

            // Go Compile!
            this.GenStmt(stmt, il, symbolTable);

            //il.Emit(OpCodes.Ldstr, "Press any key to exit the program...");
            //il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
            //il.Emit(OpCodes.Call, typeof(System.Console).GetMethod("ReadKey", new Type[] { }));

            il.Emit(OpCodes.Ret);
            //mainProgram.CreateType();
            modb.CreateGlobalFunctions();
            asmb.SetEntryPoint(symbolTable.functionTable["__Main"].methodDefinition);

            symbolTable.typeTable.types[0].typeBuilder.CreateType();

            asmb.Save(moduleName);
            foreach (var symbol in symbolTable.Locals)
            {
                Console.WriteLine("{0}: {1}", symbol.Key, symbol.Value);
            }
            symbolTable = null;
            il = null;
        }
开发者ID:mirhagk,项目名称:IronTuring,代码行数:56,代码来源:CodeGen.cs

示例2: BuildLi

        public void BuildLi(List<CodeBlock> CodeBlocks, string asmname)
        {
            //setup
            asm = AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName(asmname), AssemblyBuilderAccess.Save);
            ModuleBuilder mod = asm.DefineDynamicModule("TestOutput.exe",
               asmname +".exe");
            TypeBuilder type = mod.DefineType("Program", TypeAttributes.Class);
            MethodBuilder main = type.DefineMethod("Main",
               MethodAttributes.Public | MethodAttributes.Static);
            ILGenerator il = main.GetILGenerator();
            //actual il code

            foreach (var block in CodeBlocks)
            {
                if (block.name == "ClassCode")
                {
                    foreach (IAst node in block.Nodes)
                    {
                        if (node is ObjCallStmt)
                        {
                            ObjCallStmt nd = node as ObjCallStmt;
                            il.Emit(OpCodes.Ldstr, (nd.Paramaters[0] as EcString).Value as string);
                        }

                    }

                    break;
                }

            }

            /*  il.Emit(OpCodes.Ldstr, "Hello world!");
            il.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine",
                BindingFlags.Public | BindingFlags.Static,
                null, new Type[] { typeof(String) }, null));*/
            il.Emit(OpCodes.Ret);

            //done
            type.CreateType();
            asm.SetEntryPoint(main);
        }
开发者ID:Myvar,项目名称:Eclang,代码行数:42,代码来源:Compiler.cs

示例3: GetTypeBuilder

        public static TypeBuilder GetTypeBuilder(string fileName, ModuleBuilder mb, AssemblyBuilder ab)
        {
            StreamReader file = new StreamReader(fileName);
            TypeBuilder tb = mb.DefineType( fileName.Substring(0,fileName.Length-3).Replace(@"\", "."), TypeAttributes.Public);
            var code = file.ReadToEnd();
            var esprima = new Esprima.NET.Esprima();
            var node = esprima.parse(code, new Options());

            foreach (var fcuntionDef in node.body.Where(x => x.type == "FunctionDeclaration"))
            {
                var argumentNames = [email protected](x => typeof(Object)).ToArray();
                MethodBuilder metb = tb.DefineMethod(fcuntionDef.id.name, MethodAttributes.Public | MethodAttributes.Static, null, argumentNames);
                ab.SetEntryPoint(metb);
                ILGenerator il = metb.GetILGenerator();
                il.EmitWriteLine("Hello World");
                il.Emit(OpCodes.Ret);
                il.Emit(OpCodes.Ret);
            }
            tb.CreateType();
            return tb;
        }
开发者ID:alfredoaguirre,项目名称:Esprima.Net,代码行数:21,代码来源:Class1.cs

示例4: BrainfuckApp

        public BrainfuckApp(string name)
        {
            Name = name;
            _asBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName { Name = "Brainfuck app" }, AssemblyBuilderAccess.Save);
            _modBuilder = _asBuilder.DefineDynamicModule("bf", name + ".exe");
            _typeBuilder = _modBuilder.DefineType("Program", TypeAttributes.Public);
            _methBuilder = _typeBuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static);
            _asBuilder.SetEntryPoint(_methBuilder);
            _il = _methBuilder.GetILGenerator();

            _il.DeclareLocal(typeof(int));
            _il.DeclareLocal(typeof(int[]));

            // Initialize idx to 0
            _il.Emit(OpCodes.Ldc_I4_0);
            _il.Emit(OpCodes.Stloc_0);

            // Initialize cell with 30000 fields of int
            _il.Emit(OpCodes.Ldc_I4, 30000);
            _il.Emit(OpCodes.Newarr, typeof(int));
            _il.Emit(OpCodes.Stloc_1);
        }
开发者ID:pollyzoid,项目名称:bfnet,代码行数:22,代码来源:BrainfuckApp.cs

示例5: SetEntryPointForConsoleApplicationPortable

 public static void SetEntryPointForConsoleApplicationPortable(AssemblyBuilder assemblyBuilder, MethodInfo entryMethod)
 {
     assemblyBuilder.SetEntryPoint(entryMethod, PEFileKinds.ConsoleApplication);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:4,代码来源:AssemblyBuilderExtensions.cs

示例6: AddEntryPoint

        private static void AddEntryPoint(AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder)
        {
            var typeBuilder = moduleBuilder.DefineType(
                 Guid.NewGuid().ToString("N"), TypeAttributes.Class | TypeAttributes.Public,
                 typeof(object));

            var methodBuilder = typeBuilder.DefineMethod("Main",
                MethodAttributes.HideBySig | MethodAttributes.Static | MethodAttributes.Public,
                typeof(void), new Type[] { typeof(string[]) });

            var methodGenerator = methodBuilder.GetILGenerator();
            methodGenerator.EmitWriteLine("go!");
            methodGenerator.Emit(OpCodes.Ret);

            typeBuilder.CreateType();

            assemblyBuilder.SetEntryPoint(methodBuilder);
        }
开发者ID:JasonBock,项目名称:AssemblyVerifier,代码行数:18,代码来源:DynamicVerificationTests.cs

示例7: GenerateExe

        public void GenerateExe()
        {
            string AssemblyName = "TestAssembly";
            string ClassName = "TestClass";
            string ExeName = ClassName + ".exe";

            // 获得应用程序域,用于创建程序集。
            domain = Thread.GetDomain();

            // 创建程序集名称。
            name = new AssemblyName();
            name.Name = AssemblyName;

            // 创建程序集。
            asmbuilder = domain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);

            // 创建模块。
            modbuilder = asmbuilder.DefineDynamicModule(ExeName);

            // 创建类型。
            typbuilder = modbuilder.DefineType(ClassName);

            // 创建全局变量(类的静态变量)
            fld = typbuilder.DefineField("haha", typeof(int), FieldAttributes.Static);

            // 创建静态方法Add:public static int Add(int,int)
            addBuilder = typbuilder.DefineMethod("Add", MethodAttributes.Public | MethodAttributes.Static, typeof(int), new Type[] { typeof(int), typeof(int) });

            // 创建静态方法Add:public static int Fact(int)
            factBuilder = typbuilder.DefineMethod("Fact", MethodAttributes.Public | MethodAttributes.Static, typeof(int), new Type[] { typeof(int) });

            // 创建静态方法Main:public static void Main(string[])
            mainBuilder = typbuilder.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(string[]) });

            // Add方法的代码生成器
            iladd = addBuilder.GetILGenerator();

            // 产生Add方法的代码
            GenerateCodeForAdd();

            // Fact方法的代码生成器
            ilfact = factBuilder.GetILGenerator();

            // 产生Fact方法的代码
            GenerateCodeForFact();

            // Main方法的代码生成器
            ilmain = mainBuilder.GetILGenerator();

            // 产生Main方法的代码。
            GenerateCodeForMain();

            // 类里所有东西都已经定义好了,现在要创建这个类。
            typbuilder.CreateType();

            // 设置入口点。
            asmbuilder.SetEntryPoint((modbuilder.GetType(ClassName)).GetMethod("Main"));

            // 保存到EXE文件。
            asmbuilder.Save(ExeName);
        }
开发者ID:lewischeng-ms,项目名称:misc,代码行数:61,代码来源:codegen.cs

示例8: SaveAssembly

        private void SaveAssembly(
      string fullyQualifiedModuleName,
      AssemblyBuilder assemblyBuilder,
      TypeBuilder typeBuilder)
        {
            Type NireType = typeBuilder.CreateType();

              NireType.GetMethod("Main").Invoke(null, new string[] {null});

              // set the entry point for the application and save it
              assemblyBuilder.SetEntryPoint(this.methodbuilder, PEFileKinds.ConsoleApplication);
              assemblyBuilder.Save(fullyQualifiedModuleName);
        }
开发者ID:donreamey,项目名称:NireLang,代码行数:13,代码来源:GenerateIL.cs


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