/* Add a pcode instruction. *Index returns the index of the instruction so that */ /* branches can be patched up. if Index is NIL, then it won't bother returning */ /* anything. */ public void AddPcodeInstruction(Pcodes Opcode, out int Index, int LineNumber) { ToList(); Index = OpcodeList.Count; OpcodeRec opcodeRec = new OpcodeRec(); opcodeRec.Opcode = Opcode; OpcodeList.Add(opcodeRec); LineNumberArray.Add(LineNumber); Debug.Assert(OpcodeList.Count == LineNumberArray.Count); }
/* get the number of words for the specified instruction opcode */ public static int GetInstructionLength(Pcodes OpcodeWord) { switch (OpcodeWord) { case Pcodes.epFuncCallUnresolved: /* <opcode> ^"<functionname>" ^[paramlist] <returntype> <reserved> <reserved> */ case Pcodes.epFuncCallResolved: /* <opcode> ^"<functionname>" ^[paramlist] <returntype> ^<OpcodeRec> <maxstackdepth> */ return(6); case Pcodes.epFuncCallExternal: /* <opcode> ^"<methodname>" ^[paramlist] <returntype> */ return(4); case Pcodes.epOperationBooleanEqual: /* <opcode> */ case Pcodes.epOperationBooleanNotEqual: case Pcodes.epOperationBooleanAnd: case Pcodes.epOperationBooleanOr: case Pcodes.epOperationBooleanNot: case Pcodes.epOperationBooleanToInteger: case Pcodes.epOperationBooleanToFloat: case Pcodes.epOperationBooleanToDouble: case Pcodes.epOperationIntegerAdd: case Pcodes.epOperationIntegerSubtract: case Pcodes.epOperationIntegerNegation: case Pcodes.epOperationIntegerMultiply: case Pcodes.epOperationIntegerDivide: case Pcodes.epOperationIntegerModulo: case Pcodes.epOperationIntegerShiftLeft: case Pcodes.epOperationIntegerShiftRight: case Pcodes.epOperationIntegerGreaterThan: case Pcodes.epOperationIntegerLessThan: case Pcodes.epOperationIntegerGreaterThanOrEqual: case Pcodes.epOperationIntegerLessThanOrEqual: case Pcodes.epOperationIntegerEqual: case Pcodes.epOperationIntegerNotEqual: case Pcodes.epOperationIntegerAbs: case Pcodes.epOperationIntegerToBoolean: case Pcodes.epOperationIntegerToFloat: case Pcodes.epOperationIntegerToDouble: case Pcodes.epOperationFloatAdd: case Pcodes.epOperationFloatSubtract: case Pcodes.epOperationFloatNegation: case Pcodes.epOperationFloatMultiply: case Pcodes.epOperationFloatDivide: case Pcodes.epOperationFloatGreaterThan: case Pcodes.epOperationFloatLessThan: case Pcodes.epOperationFloatGreaterThanOrEqual: case Pcodes.epOperationFloatLessThanOrEqual: case Pcodes.epOperationFloatEqual: case Pcodes.epOperationFloatNotEqual: case Pcodes.epOperationFloatAbs: case Pcodes.epOperationFloatToBoolean: case Pcodes.epOperationFloatToInteger: case Pcodes.epOperationFloatToDouble: case Pcodes.epOperationDoubleAdd: case Pcodes.epOperationDoubleSubtract: case Pcodes.epOperationDoubleNegation: case Pcodes.epOperationDoubleMultiply: case Pcodes.epOperationDoubleDivide: case Pcodes.epOperationDoubleGreaterThan: case Pcodes.epOperationDoubleLessThan: case Pcodes.epOperationDoubleGreaterThanOrEqual: case Pcodes.epOperationDoubleLessThanOrEqual: case Pcodes.epOperationDoubleEqual: case Pcodes.epOperationDoubleNotEqual: case Pcodes.epOperationDoubleAbs: case Pcodes.epOperationDoubleToBoolean: case Pcodes.epOperationDoubleToInteger: case Pcodes.epOperationDoubleToFloat: case Pcodes.epOperationDoubleSinF: case Pcodes.epOperationDoubleSinD: case Pcodes.epOperationDoubleCosF: case Pcodes.epOperationDoubleCosD: case Pcodes.epOperationDoubleTanF: case Pcodes.epOperationDoubleTanD: case Pcodes.epOperationDoubleAtanF: case Pcodes.epOperationDoubleAtanD: case Pcodes.epOperationDoubleLnF: case Pcodes.epOperationDoubleLnD: case Pcodes.epOperationDoubleExpF: case Pcodes.epOperationDoubleExpD: case Pcodes.epOperationDoubleSqrtF: case Pcodes.epOperationDoubleSqrtD: case Pcodes.epOperationDoubleFloorF: case Pcodes.epOperationDoubleFloorD: case Pcodes.epOperationDoubleCeilF: case Pcodes.epOperationDoubleCeilD: case Pcodes.epOperationDoubleRoundF: case Pcodes.epOperationDoubleRoundD: case Pcodes.epOperationDoubleCoshF: case Pcodes.epOperationDoubleCoshD: case Pcodes.epOperationDoubleSinhF: case Pcodes.epOperationDoubleSinhD: case Pcodes.epOperationDoubleTanhF: case Pcodes.epOperationDoubleTanhD: case Pcodes.epOperationDoublePowerF: case Pcodes.epOperationDoublePowerD: case Pcodes.epGetByteArraySize: /* <opcode> */ case Pcodes.epGetIntegerArraySize: case Pcodes.epGetFloatArraySize: case Pcodes.epGetDoubleArraySize: case Pcodes.epLoadImmediateNILArrayByte: /* <opcode> */ case Pcodes.epLoadImmediateNILArrayInt32: /* <opcode> */ case Pcodes.epLoadImmediateNILArrayFloat: /* <opcode> */ case Pcodes.epLoadImmediateNILArrayDouble: /* <opcode> */ case Pcodes.epMakeByteArray: /* <opcode> */ case Pcodes.epMakeIntegerArray: case Pcodes.epMakeFloatArray: case Pcodes.epMakeDoubleArray: case Pcodes.epStackPop: /* <opcode> */ case Pcodes.epDuplicate: /* <opcode> */ case Pcodes.epNop: /* <opcode> */ case Pcodes.epResizeByteArray2: /* <opcode> */ case Pcodes.epResizeIntegerArray2: case Pcodes.epResizeFloatArray2: case Pcodes.epResizeDoubleArray2: case Pcodes.epStoreByteIntoArray2: /* <opcode> */ case Pcodes.epStoreIntegerIntoArray2: case Pcodes.epStoreFloatIntoArray2: case Pcodes.epStoreDoubleIntoArray2: case Pcodes.epLoadByteFromArray2: /* <opcode> */ case Pcodes.epLoadIntegerFromArray2: case Pcodes.epLoadFloatFromArray2: case Pcodes.epLoadDoubleFromArray2: case Pcodes.epOperationIntegerAnd: case Pcodes.epOperationIntegerOr: case Pcodes.epOperationIntegerXor: case Pcodes.epOperationIntegerNot: case Pcodes.epOperationDoubleAsinF: case Pcodes.epOperationDoubleAsinD: case Pcodes.epOperationDoubleAcosF: case Pcodes.epOperationDoubleAcosD: case Pcodes.epOperationDoubleSqrF: case Pcodes.epOperationDoubleSqrD: case Pcodes.epOperationTestIntegerNegative: case Pcodes.epOperationTestFloatNegative: case Pcodes.epOperationTestDoubleNegative: case Pcodes.epOperationGetSignInteger: case Pcodes.epOperationGetSignFloat: case Pcodes.epOperationGetSignDouble: case Pcodes.epCopyArrayByte: /* <opcode> */ case Pcodes.epCopyArrayInteger: case Pcodes.epCopyArrayFloat: case Pcodes.epCopyArrayDouble: case Pcodes.epMinInt: case Pcodes.epMinFloat: case Pcodes.epMinDouble: case Pcodes.epMaxInt: case Pcodes.epMaxFloat: case Pcodes.epMaxDouble: case Pcodes.epMinMaxInt: case Pcodes.epMinMaxFloat: case Pcodes.epMinMaxDouble: case Pcodes.epAtan2Float: case Pcodes.epAtan2Double: return(1); case Pcodes.epReturnFromSubroutine: /* <opcode> <argcount> */ case Pcodes.epStackPopMultipleUnder: /* <opcode> <numwords> */ case Pcodes.epBranchUnconditional: /* <opcode> <branchoffset> */ case Pcodes.epBranchIfZero: case Pcodes.epBranchIfNotZero: case Pcodes.epStoreIntegerOnStack: /* <opcode> <stackindex> */ case Pcodes.epStoreFloatOnStack: case Pcodes.epStoreDoubleOnStack: case Pcodes.epStoreArrayOfByteOnStack: case Pcodes.epStoreArrayOfInt32OnStack: case Pcodes.epStoreArrayOfFloatOnStack: case Pcodes.epStoreArrayOfDoubleOnStack: case Pcodes.epLoadIntegerFromStack: case Pcodes.epLoadFloatFromStack: case Pcodes.epLoadDoubleFromStack: case Pcodes.epLoadArrayFromStack: case Pcodes.epLoadImmediateInteger: /* <opcode> <integer>; also used for boolean & fixed */ case Pcodes.epLoadImmediateFloat: /* <opcode> ^<float> */ case Pcodes.epLoadImmediateDouble: /* <opcode> ^<double> */ case Pcodes.epMakeByteArrayFromString: /* <opcode> ^"<data>" */ return(2); default: Debug.Assert(false); throw new ArgumentException(); } }