// 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 EncodeAssign(Identifier identifier, Frame frame, int valSize) { AddressableEntity baseObject = identifier.Declaration.Entity as AddressableEntity; // If indexed = true, code will have been generated to load an index // value. if (valSize > 255) { errorReporter.ReportMessage("can't store values larger than 255 words"); valSize = 255; // to allow code generation to continue } baseObject.EncodeAssign(emitter, frame, valSize, identifier); }
/// <summary> /// Appends an instruction, with the given fields, to the object code. /// </summary> /// <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.ReportMessage("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.ReportMessage("too many instructions for code segment"); } else { Machine.Code[NextInstrAddr++] = nextInstr; } return(currentInstrAddr); }