public CodeGenerator(string fileName) { typecount = 0; funccount = 0; string clearname = Path.GetFileNameWithoutExtension(fileName); EXEFileName = clearname + ".exe"; ScopedGenerators = new Stack <ILGenerator>(); AssemblyName assemName = new AssemblyName("TigerProgram"); ILAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, AssemblyBuilderAccess.RunAndSave, Path.GetDirectoryName(fileName)); ILModule = ILAssembly.DefineDynamicModule(clearname, EXEFileName); BuiltInFunctiontoBuilder = new Dictionary <string, MethodBuilder>(); //Creating the Standard Library StandardLibrary = ILModule.DefineType("StandardLibrary", TypeAttributes.Public | TypeAttributes.Class); GenerateCodeForBuiltInFunctions(); StandardLibrary.CreateType(); //Creating the Program class Program = ILModule.DefineType("Program", TypeAttributes.Public | TypeAttributes.Class); EntryPoint = Program.DefineMethod("Main", MethodAttributes.Public | MethodAttributes.Static); ILAssembly.SetEntryPoint(EntryPoint); EnterGenerationScope(EntryPoint.GetILGenerator()); }
/// <summary> /// Generates a type in the module /// </summary> /// <returns></returns> public TypeBuilder CreateType() { return(ILModule.DefineType(GetNewTypeName())); }