Ejemplo n.º 1
0
 public Parser(Scanner scanner, CodeGen codegen, SymbolTable symtab, ProgramOptions options,
     System.IO.StreamWriter listingWriter)
 {
     this.scanner = scanner;
     this.codegen = codegen;
     this.symtab = symtab;
     this.genlist = options.enableListing;
     this.listwriter = listingWriter;
     labelList_ID = new List<Symbol>();
     labelList_UD = new List<Symbol>();
 }
Ejemplo n.º 2
0
 public Assembler(ProgramOptions options)
 {
     genlist = options.enableListing;
     outname = options.outputName;
     if (genlist)
     {
         listwriter = new System.IO.StreamWriter(new System.IO.MemoryStream());
     }
     scanner = new Scanner();
     symtab = new SymbolTable(scanner);
     codegen = new CodeGen(scanner, symtab, options, listwriter);
     parser = new Parser(scanner, codegen, symtab, options, listwriter);
 }
Ejemplo n.º 3
0
        static void Do(string[] args)
        {
            string fname;
            Assembler assembler;
            ProgramOptions opts = new ProgramOptions();

            DissectInput(args);
            #if DEBUG
            //PrintDissectedInput();
            #endif
            if (hasErrors) return;
            ParseInput(opts);
            if (hasErrors) return;

            foreach (Argument a in arglist)
            {
                if (a.type == ArgType.String)
                {
                    fname = a.str;
                    if (!System.IO.File.Exists(fname))
                    {
                        PrintError("FATAL: File '" + fname + "' does not exist");
                        return;
                    }
                    assembler = new Assembler(opts);
                    assembler.AssembleUnit(fname);
                }
            }
        }
Ejemplo n.º 4
0
        static void ParseInput(ProgramOptions options)
        {
            int fncount;

            fncount = 0;
            foreach (Argument a in arglist)
            {
                if (a.type == ArgType.Option)
                {
                    switch (a.str)
                    {
                        case "o":
                            if (a.param == null)
                            {
                                PrintError("Output filename expected");
                                return;
                            }
                            options.outputName = a.param;
                            break;
                        case "f":
                            switch (a.param)
                            {
                                case "bin":
                                    options.outtype = OutputType.Raw; break;
                                case "txt":
                                    options.outtype = OutputType.Text; break;
                                case "hex":
                                    options.outtype = OutputType.Hex; break;
                                case "elf":
                                    options.outtype = OutputType.Elf; break;
                                case null:
                                    PrintError("Output format expected");
                                    return;
                                default:
                                    PrintError("Unknown output format: '" + a.param + "'");
                                    return;
                            }
                            break;
                        case "l":
                            options.enableListing = true;
                            break;
                        case "nogp":
                            options.useGPbased = false;
                            break;
                        case "noat":
                            options.useAT = false;
                            break;
                        default:
                            PrintError("Unknown option: '" + a.str + "'");
                            return;
                    }
                }
                else if (a.type == ArgType.String)
                {
                    ++fncount;
                }
            }

            if (fncount == 0)
            {
                PrintError("No input files specified");
            }
            else if (fncount > 1 && options.outputName != null)
            {
                PrintError("Output filename can't be specified if there are multiple input files");
            }
        }