Exemplo n.º 1
0
 public MSIL(string aMnemonic, Compiler aCompiler)
 {
     IL       = aMnemonic;
     Compiler = aCompiler;
     CPUArch  = ILCompiler.CPUArchitecture;
     ILCompiler.Logger.Write(aMnemonic + "...Loaded");
 }
Exemplo n.º 2
0
        public static async Task <bool> install(GameType gameType, CPUArch cpuArch, string path, ProgressBar progressBar)
        {
            Task <bool> installTask = installTaskImpl(gameType, cpuArch, path, progressBar);
            await Task.WhenAny(installTask);

            return(installTask.Result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load Kernel startup type in input dll, by scanning Kernel attribute
        /// </summary>
        /// <param name="cpu">The Current target platform</param>
        /// <returns></returns>
        private Type LoadKernel(CPUArch cpu)
        {
            var xAssembly = Assembly.LoadFile(ILCompiler.InputDll);

            /* Search For Kernel Attribute */
            foreach (var xType in xAssembly.GetExportedTypes())
            {
                foreach (var xAttr in xType.CustomAttributes)
                {
                    if (xAttr.AttributeType == typeof(KernelAttribute))
                    {
                        if ((CPUArch)xAttr.ConstructorArguments[0].Value == cpu)
                        {
                            Core.NasmHeaders.Add("global Kernel_Main");
                            Core.NasmHeaders.Add(string.Format("Kernel_Main equ (_Kernel_Main - {0})", xAttr.ConstructorArguments[1].Value));

                            return(xType);
                        }
                    }
                    else if (xAttr.AttributeType == typeof(ApplicationAttribute))
                    {
                        if ((CPUArch)xAttr.ConstructorArguments[0].Value == cpu)
                        {
                            BuildingApplication = true;
                            return(xType);
                        }
                    }
                }
            }
            throw new Exception("No Input kernel found");
        }
Exemplo n.º 4
0
            static CPU()
            {
                ProcCount = (uint)Environment.ProcessorCount;
                var arch = Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture;

                Arch = arch switch {
                    ProcessorArchitecture.Amd64 => CPUArch.X64,
                    ProcessorArchitecture.Arm => CPUArch.Arm64,
                    _ => throw new PlatformNotSupportedException($"Unknown processor architecture ({arch})")
                };
            }
        }
Exemplo n.º 5
0
        private static void countFiles(GameType gameType, CPUArch cpuArch)
        {
            switch (cpuArch)
            {
            case CPUArch.x64:
            {
                total += ZipManager.countFiles(Properties.Resources.x64);
                break;
            }

                /*case CPUArch.x86:
                 *  {
                 *      total += ZipManager.countFiles(Properties.Resources.x86);
                 *      break;
                 *  }*/
            }

            switch (gameType)
            {
            case GameType.BFG:
            {
                total += ZipManager.countFiles(Properties.Resources._base);
                total += ZipManager.countFiles(Properties.Resources.base_BFG);
                break;
            }

            case GameType.NEW:
            {
                total += ZipManager.countFiles(Properties.Resources._base);
                total += ZipManager.countFiles(Properties.Resources.base_NEW);
                break;
            }

            case GameType.CLASSIC:
            {
                total += ZipManager.countFiles(Properties.Resources.base_CLASSIC);
                break;
            }
            }
        }
Exemplo n.º 6
0
 public ApplicationAttribute(CPUArch aCpuArch = CPUArch.x86)
 {
     CPUArch = aCpuArch;
 }
Exemplo n.º 7
0
        private static async Task <bool> installTaskImpl(GameType gameType, CPUArch cpuArch, string path, ProgressBar progressBar)
        {
            await Task.Run(() =>
            {
                bool removeSettings = Boolean.Parse(Properties.Resources.RemoveSettings);
                if (removeSettings)
                {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        Win32SettingsRemover.removeSettings();
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        UnixSettingsRemover.removeSettings();
                    }
                    else
                    {
                        MessageBox.Show("Unsupported Operating System");
                    }
                }

                countFiles(gameType, cpuArch);

                progressBar.Invoke(new Action(() =>
                {
                    progressBar.Maximum = total;
                }));

                switch (cpuArch)
                {
                case CPUArch.x64:
                    {
                        ZipManager.extractFiles(Properties.Resources.x64, path, progressBar);
                        break;
                    }

                    /*case CPUArch.x86:
                     *  {
                     *      ZipManager.extractFiles(Properties.Resources.x86, path, progressBar);
                     *      break;
                     *  }*/
                }

                switch (gameType)
                {
                case GameType.BFG:
                    {
                        ZipManager.extractFiles(Properties.Resources._base, path + "/base", progressBar);
                        ZipManager.extractFiles(Properties.Resources.base_BFG, path + "/base", progressBar);
                        break;
                    }

                case GameType.NEW:
                    {
                        ZipManager.extractFiles(Properties.Resources._base, path + "/base", progressBar);
                        ZipManager.extractFiles(Properties.Resources.base_NEW, path + "/base", progressBar);
                        break;
                    }

                case GameType.CLASSIC:
                    {
                        ZipManager.extractFiles(Properties.Resources.base_CLASSIC, path, progressBar);
                        break;
                    }
                }
            });

            return(true);
        }
Exemplo n.º 8
0
 public PlugAttribute(string aTargetSymbol, CPUArch aCpuArch = CPUArch.x86)
 {
     TargetString = aTargetSymbol;
     CPUArch      = aCpuArch;
 }
Exemplo n.º 9
0
 public KernelAttribute(CPUArch aCpuArch, string aOrganize)
 {
     CPUArch  = aCpuArch;
     Organize = aOrganize;
 }
Exemplo n.º 10
0
 public Instruction(string aMnemonic, CPUArch aCPUArch = CPUArch.x86)
 {
     Code    = aMnemonic;
     CPUArch = aCPUArch;
 }
Exemplo n.º 11
0
 private void radioButton4_CheckedChanged(object sender, EventArgs e)
 {
     this.cpuArch = CPUArch.x86;
 }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            InputFiles = new List <string>();
            bool DoLogging      = false;
            bool DoOptimization = false;

            try
            {
                #region Parsing
                if (args.Length > 0)
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "-cpu")
                        {
                            switch (args[i + 1])
                            {
                            case "x86":
                                CPUArchitecture = CPUArch.x86;
                                break;

                            case "x64":
                                CPUArchitecture = CPUArch.x64;
                                break;

                            case "arm":
                                CPUArchitecture = CPUArch.ARM;
                                break;

                            default:
                                CPUArchitecture = CPUArch.none;
                                break;
                            }
                            i++;
                        }
                        else if (args[i] == "-o")
                        {
                            OutputFile = args[i + 1];
                            i++;
                        }
                        else if (args[i] == "-d")
                        {
                            DoLogging = true;
                        }
                        else if (args[i] == "-i")
                        {
                            var xInput = args[i + 1].Split(';');

                            InputDll = xInput[0];

                            if (!File.Exists(InputDll))
                            {
                                throw new Exception("Kernel Assembly not found");
                            }

                            for (int j = 1; j < xInput.Length; j++)
                            {
                                if (!File.Exists(xInput[j]))
                                {
                                    throw new Exception("Some of binded files does not exist");
                                }

                                if (!Path.IsPathRooted(InputDll))
                                {
                                    InputFiles.Add(Path.Combine(Environment.CurrentDirectory, xInput[j]));
                                }
                                else
                                {
                                    InputFiles.Add(xInput[j]);
                                }
                            }
                            i++;
                        }
                        else if (args[i] == "-optimize")
                        {
                            DoOptimization = true;
                        }
                    }
                }
                else
                {
                    throw new Exception("No Input Parameter");
                }
                #endregion

                if (CPUArchitecture == CPUArch.none)
                {
                    throw new Exception("No Output Platform Selected");
                }

                if (InputDll == string.Empty || InputDll == null)
                {
                    throw new Exception("No input kernel assembly");
                }
                else if (!Path.IsPathRooted(InputDll))
                {
                    InputDll = Path.Combine(Environment.CurrentDirectory, InputDll);
                }

                if (OutputFile == string.Empty || OutputFile == null)
                {
                    OutputFile = Environment.CurrentDirectory;
                }
                else
                {
                    OutputFile = Path.Combine(Environment.CurrentDirectory, OutputFile);
                }

                //Create missing directory
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));

                /* Building Starts Here */
                Logger = new Logger(OutputFile, DoLogging);
                Logger.Write("@ILCompiler", "Initialized parameters", "Building Started...");
                Logger.Write("Architecture     : " + CPUArchitecture);
                Logger.Write("Output Directory : " + OutputFile);
                Logger.Write("Input Assembly   : " + InputDll);
                Compiler xCompiler = new Compiler(DoOptimization);
                try
                {
                    xCompiler.Start();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                Logger.Dump();
                xCompiler.FlushAsmFile();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }