public static void CallCompiler(string inputAssemblyName, string outputExeName) { var commandLineParse = CommandLineParse.Instance; if (!String.IsNullOrEmpty(inputAssemblyName)) { commandLineParse.ApplicationInputAssembly = inputAssemblyName; } if (!String.IsNullOrEmpty(outputExeName)) { commandLineParse.ApplicationNativeExe = outputExeName; commandLineParse.OutputCpp = Path.ChangeExtension(commandLineParse.ApplicationNativeExe, ".cpp"); } var dir = Directory.GetCurrentDirectory(); inputAssemblyName = Path.Combine(dir, commandLineParse.ApplicationInputAssembly); var asm = Assembly.LoadFile(inputAssemblyName); var definition = asm.EntryPoint; var start = Environment.TickCount; var closureEntities = ClosureEntitiesUtils.BuildClosureEntities(definition, typeof(CrString).Assembly); var sb = closureEntities.BuildFullSourceCode(); var end = Environment.TickCount - start; Console.WriteLine("Compilation time: {0} ms", end); var fullPath = commandLineParse.OutputCpp.GetFullFileName(); sb.ToFile(fullPath); NativeCompilationUtils.CompileAppToNativeExe(commandLineParse.OutputCpp, commandLineParse.ApplicationNativeExe); }
public void CallCompiler(string inputAssemblyName, string outputExeName) { var commandLineParse = CommandLineParse.Instance; if (!String.IsNullOrEmpty(inputAssemblyName)) { commandLineParse.ApplicationInputAssembly = inputAssemblyName; } if (!String.IsNullOrEmpty(outputExeName)) { commandLineParse.ApplicationNativeExe = outputExeName; } var dir = Directory.GetCurrentDirectory(); inputAssemblyName = Path.Combine(dir, commandLineParse.ApplicationInputAssembly); var asm = Assembly.LoadFile(inputAssemblyName); var definition = asm.EntryPoint; var start = Environment.TickCount; OptimizationLevelBase.ClearOptimizations(); OptimizationLevelBase.Instance = new OptimizationLevels(); OptimizationLevelBase.Instance.EnabledCategories.Clear(); OptimizationLevelBase.Instance.EnabledCategories.AddRange(OptimizationList); OptimizationLevelBase.UpdateOptimizationsFromCategories(OptimizationLevelBase.OptimizationPasses); OptimizationLevelBase.SortOptimizations(); // OptimizationLevelBase.Instance = new OptimizationLevels(); // OptimizationLevelBase.OptimizerLevel = 2; // OptimizationLevelBase.Instance.EnabledCategories.Add(OptimizationCategories.All); var closureEntities = ClosureEntitiesUtils.BuildClosureEntities(definition, typeof(CrString).Assembly); var sb = closureEntities.BuildFullSourceCode(); var end = Environment.TickCount - start; CompilerErrors += String.Format("Compilation time: {0} ms", end); var opcodes = closureEntities.MethodImplementations; var intermediateOutput = "-------------IL:-------------\n"; foreach (var opcode in opcodes) { intermediateOutput += " " + opcode.Key + ": \n"; if (opcode.Value.Kind != MethodKind.CilInstructions) { intermediateOutput += "// Provided By Framework \n\n"; continue; } try { var instructions = MethodBodyReader.GetInstructions(((CilMethodInterpreter)opcode.Value).Method); foreach (var op in instructions) { var oper = string.Format("\t{0}", op);; intermediateOutput += " " + oper + "\n"; } } catch (Exception) { intermediateOutput += "// Method has no body \n\n"; } intermediateOutput += "\n"; } intermediateOutput += "\n-------------IR:-------------\n"; foreach (var opcode in opcodes) { intermediateOutput += " " + opcode.Key + ": \n"; if (opcode.Value.Kind != MethodKind.CilInstructions) { intermediateOutput += "// Provided By Framework \n\n"; continue; } var cilInterpreter = (CilMethodInterpreter)opcode.Value; foreach (var op in cilInterpreter.MidRepresentation.LocalOperations) { var oper = string.Format("{1}\t({0})", op.Kind, op);; intermediateOutput += " " + oper + "\n"; } intermediateOutput += "\n"; } OutputCode = sb.ToString(); ILCode = intermediateOutput; //TODO: Make this call all the different compilers i.e. TestHelloWorld_GCC.exe etc... }
public Program(CommandLineParse commandLineParse, ClosureEntitiesUtils getClosureEntitiesUtils) { _commandLineParse = commandLineParse; _getClosureEntitiesUtils = getClosureEntitiesUtils; }