Beispiel #1
0
        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);
        }
Beispiel #2
0
        /**
         *  Parses the command line, loads the assembly, builds a closure of all the items
         *  to be built, and transforms the into source code, and writes an output C++
         *  program.
         *  @return Full path to the written CPP file.
         */
        public string CallCompiler(string inputAssemblyName)
        {
            var commandLineParse = _commandLineParse;

            if (!IsNullOrEmpty(inputAssemblyName))
            {
                commandLineParse.ApplicationInputAssembly = inputAssemblyName;
            }

            var dir = Directory.GetCurrentDirectory();

            inputAssemblyName = Path.Combine(dir, commandLineParse.ApplicationInputAssembly);

            var asm        = Assembly.LoadFile(inputAssemblyName);
            var definition = asm.EntryPoint; // TODO: what if this is not an application, but a library without an entry point?
            var start      = Environment.TickCount;

            var closureEntities = _getClosureEntitiesUtils
                                  .BuildClosureEntities(definition, typeof(CrString).Assembly);

            var sb = closureEntities.BuildFullSourceCode();
            var compilationTime = Environment.TickCount - start;

            Console.WriteLine("Compilation time: {0} ms", compilationTime);

            var fullPath = commandLineParse.OutputCpp.GetFullFileName();

            sb.ToFile(fullPath);

            Console.WriteLine("Wrote output CPP file '{0}'.", fullPath);
            return(fullPath);

            // TODO: this should be a flag, not necessarily do it automatically.
            //NativeCompilationUtils.CompileAppToNativeExe(commandLineParse.OutputCpp,
            //                                             commandLineParse.ApplicationNativeExe);
        }
Beispiel #3
0
        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...
        }