// REGISTERS

        /*
         * Generates code to fetch the value of a named constant or variable and push it on to the stack.
         * @param	currentLevel	routine level where the vname occurs.
         * @param	frameSize		anticipated size of the local stack frame when the constant or variable is fetched at run-time.
         * @param	valSize			size of the constant or variable's value.
         */
        private void EncodeAssign(Identifier identifier, Frame frame, int valSize)
        {
            // If indexed = true, code will have been generated to load an index value.
            if (valSize > 255)
            {
                errorReporter.ReportRestriction("can't store values larger than 255 words");
                valSize = 255;                 // to allow code generation to continue
            }
            (identifier.Declaration.Entity as AddressableEntity).EncodeAssign(emitter, frame, valSize, identifier);
        }
Ejemplo n.º 2
0
        // REGISTERS

        // Generates code to fetch the value of a named constant or variable
        // and push it on to the stack.
        // currentLevel is the routine level where the vname occurs.
        // frameSize is the anticipated size of the local stack frame when
        // the constant or variable is fetched at run-time.
        // valSize is the size of the constant or variable's value.

        void EncodeStore(Vname vname, Frame frame, int valSize)
        {
            var baseObject = vname.Visit(this, frame) as AddressableEntity;

            // If indexed = true, code will have been generated to load an index
            // value.
            if (valSize > 255)
            {
                _errorReporter.ReportRestriction("can't store values larger than 255 words");
                valSize = 255; // to allow code generation to continue
            }
            baseObject.EncodeStore(_emitter, frame, valSize, vname);
        }
        /// Appends an instruction, with the given fields, to the object code.
        /// <param name="op">the opcode</param>
        /// <param name="length">the length field</param>
        /// <param name="register">the register field</param>
        /// <param name="operand">the operand field</param>
        /// <returns>the code address of the new instruction</returns>
        public int Emit(OpCode op, int length, Register register, int operand)
        {
            if (length > 255)
            {
                errorReporter.ReportRestriction("length of operand can't exceed 255 words");
                length = 255;                 // to allow code generation to continue
            }

            Instruction nextInstr = new Instruction(op, register, length, operand);

            int currentInstrAddr = NextInstrAddr;

            if (NextInstrAddr == Machine.PrimitiveBase)
            {
                errorReporter.ReportRestriction("too many instructions for code segment");
            }
            else
            {
                Machine.Code[NextInstrAddr++] = nextInstr;
            }
            return(currentInstrAddr);
        }