コード例 #1
0
        public static void Build(Dictionary <string, string> args)
        {
            BuilderSettings           settings  = new BuilderSettings();
            AssemblyGeneratorSettings asettings = SettingsManager.GetSettings <AssemblyGeneratorSettings>();
            LinkerSettings            ls        = SettingsManager.GetSettings <LinkerSettings>();
            HlCompilerSettings        hls       = SettingsManager.GetSettings <HlCompilerSettings>();

            ArgumentSyntaxParser.Parse(
                args,
                settings,
                asettings,
                ls,
                hls
                );

            SettingsManager.SaveSettings(ls);
            SettingsManager.SaveSettings(asettings);
            SettingsManager.SaveSettings(hls);

            List <string> ar = new List <string>();

            foreach (string key in args.Keys)
            {
                ar.Add('-' + key);
                string[] vals = args[key].Split(' ');
                ar.AddRange(vals);
            }

            Build(settings, ar.ToArray());
        }
コード例 #2
0
        public override void Help()
        {
            BuilderSettings           settings  = new BuilderSettings();
            AssemblyGeneratorSettings asettings = SettingsManager.GetSettings <AssemblyGeneratorSettings>();
            LinkerSettings            ls        = SettingsManager.GetSettings <LinkerSettings>();
            HlCompilerSettings        hls       = SettingsManager.GetSettings <HlCompilerSettings>();

            HelpSubSystem.WriteSubsystem("vis build", settings, asettings, ls, hls);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ByteChkR/VisCPU
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Arguments:");
                Console.WriteLine("\t-c : Compile Main File");
                Console.WriteLine("\t-clean : Clean Build Directory");
                Console.WriteLine("\t-r : Run Dynamic Commandline");
                Console.WriteLine("\t-o : Optimize Assembly");
                Console.WriteLine("\t-d : Debug(Make all labels and data sections visible)");

                return;
            }

            bool compile   = args.Any(x => x == "-c");
            bool clean     = args.Any(x => x == "-clean");
            bool run       = args.Any(x => x == "-r");
            bool optimized = args.Any(x => x == "-o");
            bool debug     = args.Any(x => x == "-d");

            FirstSetup.Start();

            LinkerSettings linkerSettings = SettingsManager.GetSettings <LinkerSettings>();

            linkerSettings.NoHiddenItems = debug;
            SettingsManager.SaveSettings(linkerSettings);

            AssemblyGeneratorSettings gsettings = SettingsManager.GetSettings <AssemblyGeneratorSettings>();

            gsettings.Format = "v1"; //Set Raw Assembly Mode
            SettingsManager.SaveSettings(gsettings);

            HlCompilerSettings settings = SettingsManager.GetSettings <HlCompilerSettings>();

            settings.OptimizeAll = optimized;
            SettingsManager.SaveSettings(settings);

            string output = null;

            output = compile ? VisHelper.Compile(clean) : FirstSetup.DefaultFile;

            if (run)
            {
                if (output == null)
                {
                    Console.WriteLine($"Output file error.");

                    FirstSetup.End(EndOptions.Default);

                    return;
                }

                ConsoleLoop(output);
            }

            FirstSetup.End(EndOptions.Default);
        }
コード例 #4
0
ファイル: FileCompilation.cs プロジェクト: ByteChkR/VisCPU
        public FileCompilation(FileReference file)
        {
            Reference = file;
            Source    = File.ReadAllText(Reference.File);
            Tokens    = Tokenizer.Tokenize(Source);
            ResolveConstantItems();
            ProcessFileReferences();

            AssemblyGeneratorSettings s = SettingsManager.GetSettings <AssemblyGeneratorSettings>();

            if (s.Format.Contains("-ovars"))
            {
                (string name, AddressItem item)[] emptyItems = CreateDataSection_Reduced();
コード例 #5
0
        public static void Build(IEnumerable <string> args)
        {
            BuilderSettings           settings  = new BuilderSettings();
            AssemblyGeneratorSettings asettings = SettingsManager.GetSettings <AssemblyGeneratorSettings>();
            LinkerSettings            ls        = SettingsManager.GetSettings <LinkerSettings>();
            HlCompilerSettings        hls       = SettingsManager.GetSettings <HlCompilerSettings>();

            ArgumentSyntaxParser.Parse(
                args.ToArray(),
                settings,
                asettings,
                ls,
                hls
                );

            SettingsManager.SaveSettings(ls);
            SettingsManager.SaveSettings(asettings);
            SettingsManager.SaveSettings(hls);
            Build(settings, args);
        }
コード例 #6
0
        public override List <byte> Assemble(LinkerResult result)
        {
            List <byte> instrBytes = new List <byte>();

            AssemblyGeneratorSettings settings = SettingsManager.GetSettings <AssemblyGeneratorSettings>();

            Log("Using format: {0}", settings.Format);

            uint emptyVarSize = GetTotalEmptyVarSize(result);

            if (settings.Format.Contains("-ovars"))
            {
                float savedSpace = emptyVarSize / (float)GetTotalVarCount(result);
                Log("Saved Space: {0}%", Math.Round(savedSpace, 2) * 100);
            }

            if (settings.Format.StartsWith("v2"))
            {
                if (settings.Format.Contains("-ovars"))
                {
                    instrBytes.AddRange(BitConverter.GetBytes(emptyVarSize));
                }
                else
                {
                    instrBytes.AddRange(BitConverter.GetBytes(0u));
                }
                instrBytes.AddRange(BitConverter.GetBytes(( uint )1));
                instrBytes.AddRange(BitConverter.GetBytes(settings.GlobalOffset));
                instrBytes.AddRange(BitConverter.GetBytes(( uint )0));
            }

            Dictionary <string, AddressItem> consts =
                result.Constants.ApplyOffset(settings.GlobalOffset).ToDictionary(x => x.Key, x => x.Value);

            Dictionary <string, AddressItem> labels =
                result.Labels.ApplyOffset(settings.GlobalOffset).ToDictionary(x => x.Key, x => x.Value);

            FileCompilation.ApplyToAllTokens(
                result.LinkedBinary,
                consts,
                new List <uint>()
                );                             //Apply global constants

            List <uint> indexList = new List <uint>();

            FileCompilation.ApplyToAllTokens(result.LinkedBinary, labels, indexList);

            FixEmptyVars(( uint )result.DataSection.Count, CleanEmptyItems(result));

            Dictionary <string, AddressItem> ds =
                result.DataSectionHeader.
                ApplyOffset(
                    settings.GlobalOffset +
                    ( uint )result.LinkedBinary.Count * CpuSettings.InstructionSize
                    ).
                ToDictionary(x => x.Key, x => x.Value);

            result.ApplyDataOffset(
                ( int )(settings.GlobalOffset +
                        result.LinkedBinary.Count * CpuSettings.InstructionSize)
                );

            FileCompilation.ApplyToAllTokens(result.LinkedBinary, ds, indexList);



            foreach (KeyValuePair <(int, int), Dictionary <string, AddressItem> > resultHiddenAddressItem in result.
                     HiddenConstantItems)
            {
                FileCompilation.ApplyToTokens(
                    result.LinkedBinary,
                    resultHiddenAddressItem.Value,
                    new List <uint>(),
                    resultHiddenAddressItem.Key.Item1,
                    resultHiddenAddressItem.Key.Item2
                    );                          //Apply global constants
            }

            foreach (KeyValuePair <(int, int), Dictionary <string, AddressItem> > resultHiddenAddressItem in result.
                     HiddenLabelItems)
            {
                Dictionary <string, AddressItem> hiddenLabels =
                    resultHiddenAddressItem.Value.ApplyOffset(settings.GlobalOffset).
                    ToDictionary(x => x.Key, x => x.Value);

                FileCompilation.ApplyToTokens(
                    result.LinkedBinary,
                    hiddenLabels,
                    indexList,
                    resultHiddenAddressItem.Key.Item1,
                    resultHiddenAddressItem.Key.Item2
                    );                          //Apply global constants
            }

            foreach (KeyValuePair <(int, int), Dictionary <string, AddressItem> > resultHiddenAddressItem in result.
                     HiddenDataSectionItems)
            {
                Dictionary <string, AddressItem> hds = resultHiddenAddressItem.Value.ApplyOffset(
                    settings.GlobalOffset +
                    ( uint )result.LinkedBinary.Count *
                    CpuSettings.InstructionSize
                    ).
                                                       ToDictionary(
                    x => x.Key,
                    x => x.Value
                    );

                FileCompilation.ApplyToTokens(
                    result.LinkedBinary,
                    hds,
                    indexList,
                    resultHiddenAddressItem.Key.Item1,
                    resultHiddenAddressItem.Key.Item2
                    );                          //Apply global constants
            }

            for (int i = 0; i < result.LinkedBinary.Count; i++)
            {
                List <byte>          bytes = new List <byte>();
                AToken               instr = result.LinkedBinary[i][0];
                IEnumerable <AToken> args  = result.LinkedBinary[i].Skip(1);

                uint opCode =
                    CpuSettings.InstructionSet.GetInstruction(
                        CpuSettings.InstructionSet.GetInstruction(
                            instr.GetValue(),
                            result.LinkedBinary[i].Length - 1
                            )
                        );

                bytes.AddRange(BitConverter.GetBytes(opCode));

                foreach (AToken aToken in args)
                {
                    if (aToken is ValueToken vToken)
                    {
                        bytes.AddRange(BitConverter.GetBytes(vToken.Value));
                    }
                    else
                    {
                        EventManager <ErrorEvent> .SendEvent(new TokenRecognitionFailureEvent( aToken.GetValue()));
                    }
                }

                if (bytes.Count > CpuSettings.ByteSize)
                {
                    EventManager <ErrorEvent> .SendEvent(new InvalidArgumentCountEvent( i ));
                }

                bytes.AddRange(Enumerable.Repeat(( byte )0, ( int )CpuSettings.ByteSize - bytes.Count));

                instrBytes.AddRange(bytes);
            }

            List <byte> v = result.DataSection.SelectMany(BitConverter.GetBytes).ToList();

            instrBytes.AddRange(v);

            if (settings.Format.StartsWith("v3"))
            {
                instrBytes.InsertRange(0, indexList.SelectMany(BitConverter.GetBytes));

                instrBytes.InsertRange(0, BitConverter.GetBytes(0u));
                instrBytes.InsertRange(0, BitConverter.GetBytes(( uint )indexList.Count));
                instrBytes.InsertRange(0, BitConverter.GetBytes(2u));
                if (settings.Format.Contains("-ovars"))
                {
                    instrBytes.InsertRange(0, BitConverter.GetBytes(emptyVarSize));
                }
                else
                {
                    instrBytes.InsertRange(0, BitConverter.GetBytes(0u));
                }

                if (settings.Format.StartsWith("v3-pic"))
                {
                    List <uint> symbolTable = new List <uint>();
                    symbolTable.Add(( uint )result.Labels.Count);

                    foreach (KeyValuePair <string, AddressItem> keyValuePair in result.Labels)
                    {
                        uint[] bs = keyValuePair.Key.ToCharArray().
                                    Select(x => ( uint )x).
                                    ToArray();

                        symbolTable.Add(( uint )keyValuePair.Key.Length);
                        symbolTable.Add(keyValuePair.Value.Address);
                        symbolTable.AddRange(bs);
                    }

                    instrBytes.InsertRange(0, symbolTable.SelectMany(BitConverter.GetBytes));
                }
            }

            return(instrBytes);
        }