Example #1
0
        static void Compile(string filename, Hashtable defines)
        {
            SimpleToken st = new SimpleToken(null, SimpleTokenType.Id, filename, 0, 0);
            Tokenizer tokenizer = new Tokenizer(st, defines);
            tokenizer.Go();

            GlobalSymbolTable.CompileAll();
            GlobalSymbolTable.EliminateDuplicateObjects();
            byte[] memory = new byte[Options.memorySize];
            GlobalSymbolTable.ToMemory(memory);
            Dis.Mem = memory;
            if (Options.saveBinary)
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".binary";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".BINARY"))
                        outputFilename += ".binary";
                }
                int n = GlobalSymbolTable.varAddress;
                if ((n & 0xffff) != (memory[8] + (memory[9] << 8)))
                {
                    throw new Exception("internal error writing .binary file; please report");
                }
                Console.WriteLine("writing {0} bytes to {1}", n, outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory, 0, n);
            }
            else	// save .eeprom
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".eeprom";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".EEPROM"))
                        outputFilename += ".eeprom";
                }
                Console.WriteLine("writing 32768 bytes to {0}", outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory);
            }
            if (Options.saveDat)
            {
                string outputFilename = filename.Substring(0, filename.Length - 5) + ".dat";
                if (Options.outputFilename != "")
                {
                    outputFilename = Options.outputFilename;
                    if (!outputFilename.ToUpper().EndsWith(".DAT"))
                        outputFilename += ".dat";
                }
                int start = (memory[0x12] + memory[0x13]) * 4;
                int n = memory[0x14] + memory[0x15] * 256 // assumes 1st PUB's code immediately follows DAT
                    - start;
                start += 0x0010;
                Console.WriteLine("writing {0} bytes to {1}", n, outputFilename);
                BinaryWriter bw = new BinaryWriter(new FileStream(outputFilename, FileMode.Create));
                bw.Write(memory, start, n);
            }
            if (Options.saveSob)
                GlobalSymbolTable.WriteSobs();
        }
Example #2
0
        public override bool Std(out Stmt s)
        {
            s = null;

            if (this.Column != 0)
                throw new ParseException("OBJ must be in 1st column", this);
            Tokenizer.Advance();	// past "OBJ".
            if (Tokenizer.Current.Text == "(eol)")
                Tokenizer.Advance("(eol)");

            while (Tokenizer.Current is IdToken)
            {
                IdToken objName = Tokenizer.GetToken() as IdToken;

                Expr countExpr = null;
                if (Tokenizer.Current.Text == "[")
                {
                    Tokenizer.Advance("[");
                    countExpr = ParseExpression(Tokenizer, 13);
                    Tokenizer.Advance("]");
                }

                Tokenizer.Advance(":");
                string filename = "";
                int lineNumber = Tokenizer.Current.LineNumber;
                int column = Tokenizer.Current.Column;

                while (Tokenizer.Current is IntToken)
                {
                    IntToken intToken = Tokenizer.GetToken() as IntToken;
                    filename += (char)intToken.IntValue;
                    if (Tokenizer.Current.Text != ",")
                        break;
                    Tokenizer.Advance(",");
                }
                if (filename == "")
                    throw new ParseException("Expected object file name", Tokenizer.Current);
                filename.Trim();
                if (!filename.ToUpper().EndsWith(".SPIN"))
                    filename += ".spin";
                // filename always includes .spin suffix.

                SimpleToken filenameToken = new SimpleToken(Tokenizer, SimpleTokenType.Id, filename, lineNumber, column);
                bool needsVarSpace = true;
                if (Tokenizer.Current.Text.ToUpper() == "POINTER")
                {
                    Tokenizer.Advance();
                    needsVarSpace = false;
                }
                Tokenizer.Advance("(eol)");
                SymbolTable.AddObjSymbol(objName, filenameToken, countExpr, needsVarSpace);
                Tokenizer tokenizer = new Tokenizer(filenameToken, Tokenizer.Defines);
                tokenizer.Go();
            }
            return true;
        }