Example #1
0
        static void PrintInspection(string target)
        {
            if (!System.IO.File.Exists(target))
            {
                throw new FileNotFoundException($"Source input file {target} not found.", target);
            }

            var type = Inspector.DetectPackageOutputType(target);

            switch (type)
            {
            case AssemblerPackageOutputType.Elf64:
                PrintInspectionElf64(target);
                break;

            case AssemblerPackageOutputType.PE:
                PrintInspectionPE(target);
                break;

            default:
                Console.Error.WriteLine($"Inspection of binary file type {type} is not yet supproted");
                throw new NotImplementedException($"Inspection of binary file type {type} is not yet supproted");
            }
        }
Example #2
0
        static int Main(string[] args)
        {
            Console.WriteLine("PicoVM - A tiny toy virtual machine");
            Console.WriteLine(" (c) 2020 Sean McElroy");
            Console.WriteLine(" Released under the MIT License; all rights reserved.\r\n");

            if (args.Length == 0)
            {
                Help();
                Console.Error.WriteLine("No command specified.");
                return(-1);
            }

            var command = args[0];

            if (string.Compare(command, "asm", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (args.Length != 5)
                {
                    Help();
                    Console.Error.WriteLine("Incorrect options for asm command.");
                    return(-2);
                }

                var output = args[1];
                var type   = args[2];
                var format = args[3];
                var input  = args[4];

                var compilation = Assemble(output, type, format, input);
            }
            else if (string.Compare(command, "inspect", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (args.Length != 2)
                {
                    Help();
                    Console.Error.WriteLine("Incorrect options for inspect command.");
                    return(-2);
                }

                var exec = args[1];
                PrintInspection(exec);
                return(0);
            }
            else if (string.Compare(command, "run", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (args.Length != 2)
                {
                    Help();
                    Console.Error.WriteLine("Incorrect options for run command.");
                    return(-2);
                }

                var exec   = args[1];
                var type   = Inspector.DetectPackageOutputType(exec);
                var loaded = Load(exec, type);
                var result = Execute(loaded);
            }
            else if (string.Compare(command, "asmrun", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (args.Length != 5)
                {
                    Help();
                    Console.Error.WriteLine("Incorrect options for asmrun command.");
                    return(-2);
                }

                var output = args[1];
                var type   = args[2];
                var format = args[3];
                var input  = args[4];

                var compilation = Assemble(output, type, format, input);
                var loaded      = Load(output, type);
                var result      = Execute(loaded);
            }
            else if (string.Compare(command, "help", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                Help();
            }
            else
            {
                Help();
                Console.Error.WriteLine($"Unknown option {command}.");
                return(-3);
            }

            return(0);
        }