SecondPass() public method

public SecondPass ( ) : void
return void
Example #1
0
        public void ShouldResolveLabelsOutsideScope()
        {
            const string input =
            @"
            vectors
            {
            BRK = EmptyVector
            IRQ = EmptyVector
            NMI = EmptyVector
            Reset = Main
            }

            procedure Main
            {
            jsr Test
            }

            procedure Test
            {
            php
            rep #$30
            pha

            lda #$03

            pla
            plp
            rts
            }

            interrupt EmptyVector
            {
            }
            ";
            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());

            driver.Parse();
            driver.SecondPass();

            var mainProcedure = driver.GlobalScope.Children[0];
            Assert.Equal(true, mainProcedure.IsLabelValid("Test"));
            Assert.Equal(3, mainProcedure.AddressFor("Test"));
        }
Example #2
0
        public void ShouldFailOnInvalidVectorsLabel()
        {
            const string input = @"
            vectors
            {
            BRK = EmptyVector
            NMI = EmptyVector
            IRQ = EmptyVector
            Reset = NotValidReset
            }

            procedure Main
            {
            sei
            clc
            xce
            }

            interrupt EmptyVector
            {
            }
            ";
            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());
            driver.Parse();
            Assert.Throws<CompilerErrorException>(() => driver.SecondPass());
        }
Example #3
0
        public void VectorsIsRequired()
        {
            const string input = @"
            header
            {
            CartridgeName = ""HELLO WORLD SNES""
            RomSpeed = SlowROM
            MapMode = LoROM
            SramSize = 0
            Country = Japan
            Developer = 0
            Version = 0
            }

            procedure Main
            {
            sei
            clc
            xce
            }
            "
            ;
            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());
            driver.Parse();
            Assert.Throws<CompilerErrorException>(() => driver.SecondPass());
            Assert.Equal(1, driver.Errors.Count);
        }
Example #4
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.Error.WriteLine("No source file provided.");
                return 1;
            }

            if (Path.GetExtension(args[0]) != ".zcpu")
            {
                Console.Error.WriteLine("The source file is in the wrong format. The source file must ends with .zcpu.");
                return 1;
            }

            ZealCpuDriver driver = new ZealCpuDriver(args[0]);
            try
            {
                driver.Parse();
                driver.SecondPass();
            }
            catch(CompilerErrorException)
            {
                foreach (var error in driver.Errors)
                {
                    printErrorMessage(error);
                }

            #if DEBUG
                Console.Read();
            #endif

                return 1;
            }

            FileStream outputRom = new FileStream(Path.ChangeExtension(args[0], ".sfc"), FileMode.Create);

            CpuCodeGenerator codeGenerator = new CpuCodeGenerator(outputRom);
            codeGenerator.Header = driver.Header;

            foreach (var scope in driver.GlobalScope.Children)
            {
                codeGenerator.Scope = scope;

                List<CpuInstructionStatement> instructions = new List<CpuInstructionStatement>();

                foreach (var statement in scope.Statements)
                {
                    if (statement is CpuInstructionStatement)
                    {
                        instructions.Add((CpuInstructionStatement)statement);
                    }
                }

                codeGenerator.Instructions = instructions;
                codeGenerator.Generate();
            }

            SfcRomWriter romWriter = new SfcRomWriter(outputRom);
            romWriter.Driver = driver;
            romWriter.Write();

            outputRom.Close();

            using (FileStream newRom = new FileStream(Path.ChangeExtension(args[0], ".sfc"), FileMode.Open))
            {
                SfcRomWriter checksumWriter = new SfcRomWriter(newRom);
                checksumWriter.Driver = driver;
                checksumWriter.ComputeChecksum();
            }

            return 0;
        }