예제 #1
0
        public void Export(Program program, TextWriter writer)
        {
            // Create new compiler
            InstructionAssembler compiler = new InstructionAssembler(program.Processor);
            string hexPattern = compiler.WideInstructions ? "{0:X5}" : "{0:X4}";

            // Compile each instruction and write as hex
            for (int i = 0; i < program.Instructions.Count; i++)
            {
                int result;

                // Compile instruction
                if (program.Instructions[i] == null)
                    result = 0;
                else
                    result = compiler.Assemble(program.Instructions[i]);

                // Write result
                writer.WriteLine(hexPattern, result);
            }
        }
예제 #2
0
        public void Export(Program program, TextWriter writer)
        {
            // Only PicoBlaze currently supported
            if (program.Processor != Processor.PicoBlaze)
                throw new ExportException("VhdlExporter currently only supports the PicoBlaze 1");

            // Create new compiler
            InstructionAssembler compiler = new InstructionAssembler(program.Processor);

            // Create hex lines
            StringBuilder[] hexLines = new StringBuilder[16];

            for (int i = 0; i < 16; i++)
            {
                hexLines[i] = new StringBuilder(64);
            }

            // Compile each instruction into the hex line
            //  This is done in reverse so the highest addresses appear first
            for (int i = program.Instructions.Count - 1; i >= 0; i--)
            {
                int result;

                // Compile instruction
                if (program.Instructions[i] == null)
                    result = 0;
                else
                    result = compiler.Assemble(program.Instructions[i]);

                // Write result
                hexLines[i / 16].Append(result.ToString("X4"));
            }

            // Write VHDL to writer
            writer.WriteLine(VhdlSkeleton1, EntityName);

            for (int i = 0; i < 16; i++)
                writer.WriteLine(VhdlSkeletonLine1, i, hexLines[i]);

            writer.WriteLine(VhdlSkeleton2);

            for (int i = 0; i < 16; i++)
                writer.WriteLine(VhdlSkeletonLine2, i, hexLines[i], (i == 15) ? ")" : ",");

            writer.WriteLine(VhdlSkeleton3);
        }