Ejemplo n.º 1
0
        public byte[] BuildScript(string[] lines)
        {
            IEnumerable <Semanteme> semantemes = null;

            try
            {
                semantemes = Semanteme.ProcessLines(lines);
            }
            catch (Exception e)
            {
                throw new InternalTestFailureException("Error parsing the script");
            }

            var sb = new ScriptBuilder();

            byte[] script = null;

            try
            {
                foreach (var entry in semantemes)
                {
                    Trace.WriteLine($"{entry}");
                    entry.Process(sb);
                }
                script = sb.ToScript();
            }
            catch (Exception e)
            {
                throw new InternalTestFailureException("Error assembling the script");
            }

            return(script);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }
            if (!File.Exists(args[0]))
            {
                return;
            }
            var    lines      = File.ReadAllLines(args[0]);
            var    semantemes = Semanteme.ProcessLines(lines);
            var    table      = new AddressTable(semantemes);
            var    script     = table.ToScript();
            string out_path   = args.Length >= 2 ? args[1] : Path.ChangeExtension(args[0], "avm");

            File.WriteAllBytes(out_path, script);
        }
Ejemplo n.º 3
0
        public static void AssembleFile(string[] args)
        {
            string sourceFilePath = null;

            try
            {
                sourceFilePath = args[0];
            }
            catch
            {
                throw new CommandException("Could not obtain input filename");
            }

            string[] lines = null;
            try
            {
                lines = File.ReadAllLines(sourceFilePath);
            }
            catch
            {
                throw new CommandException("Error reading " + sourceFilePath);
            }

            IEnumerable <Semanteme> semantemes = null;

            try
            {
                semantemes = Semanteme.ProcessLines(lines);
            }
            catch (Exception e)
            {
                throw new CommandException("Error parsing " + sourceFilePath + " :" + e.Message);
            }

            var sb = new ScriptBuilder();

            byte[] script = null;

            try
            {
                foreach (var entry in semantemes)
                {
                    logger.Message($"{entry}");
                    entry.Process(sb);
                }
                script = sb.ToScript();
            }
            catch (Exception e)
            {
                throw new CommandException("Error assembling " + sourceFilePath + " :" + e.Message);
            }

            var extension  = Path.GetExtension(sourceFilePath);
            var outputName = sourceFilePath.Replace(extension, ScriptExtension);

            try
            {
                File.WriteAllBytes(outputName, script);
            }
            catch
            {
                throw new CommandException("Error generating " + outputName);
            }
        }