+\r
+ //\r
+ // Quick hack\r
+ //\r
+ if (output_file == null){\r
+ int pos = first_source.LastIndexOf (".");\r
+\r
+ output_file = first_source.Substring (0, pos) + ".exe";\r
+ }\r
+\r
+ context.CodeGen = new CodeGen (output_file, output_file);\r
+\r
+ //\r
+ // The second pass of the compiler\r
+ //\r
+ context.ResolveTree ();\r
+ context.PopulateTypes ();\r
+\r
+ //\r
+ // Before emitting, we need to get the core\r
+ // types emitted from the user defined types\r
+ // or from the system ones.\r
+ //\r
+ context.TypeManager.InitCoreTypes ();\r
+\r
+ //\r
+ // The code generator\r
+ //\r
+ context.EmitCode ();\r
+ \r
+ if (context.Report.Errors > 0){\r
+ error ("Compilation failed");\r
+ return;\r
+ }\r
+ \r
+ context.CloseTypes ();\r
+\r
+ PEFileKinds k = PEFileKinds.ConsoleApplication;\r
+ \r
+ if (target == Target.Library || target == Target.Module)\r
+ k = PEFileKinds.Dll;\r
+ else if (target == Target.Exe)\r
+ k = PEFileKinds.ConsoleApplication;\r
+ else if (target == Target.WinExe)\r
+ k = PEFileKinds.WindowApplication;\r
+\r
+ if (target == Target.Exe || target == Target.WinExe){\r
+ MethodInfo ep = context.EntryPoint;\r
+\r
+ if (ep == null){\r
+ context.Report.Error (5001, "Program " + output_file +\r
+ " does not have an entry point defined");\r
+ return;\r
+ }\r
+ \r
+ context.CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);\r
+ }\r
+ \r
+ context.CodeGen.Save (context.Report, output_file);\r
+\r
+ if (context.Report.Errors > 0){\r
+ error ("Compilation failed");\r
+ return;\r
+ }\r
+\r
+ notice ("Success");\r