本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例5: SetEntryPointForConsoleApplicationPortable
public static void SetEntryPointForConsoleApplicationPortable(AssemblyBuilder assemblyBuilder, MethodInfo entryMethod)
{
assemblyBuilder.SetEntryPoint(entryMethod, PEFileKinds.ConsoleApplication);
}
示例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);
}
示例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);
}
示例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);
}