gmSCOpcodeClass
- Mark Juras
Owned by Mark Juras
The Opcode Service Class
The service class Opcode works with the intermediate language streams. Its methods actively manage and reference the operations of the intermediate language. Their description and use assumes a knowledge of the intermediate language and of its internal structure. The methods in this class assume the operation code and symbol conventions of the Basic processor. The methods that deal with the non processor specific language stream are contained in the Emit class.The field codeStore
Prototypeextern int codeStore;
The field codptr
Prototypeextern UBYTE* codptr;
The field language_nuser
Prototypeextern int language_nuser;
The field lcstate
Prototypeextern int lcstate;
The field opcLength
Prototypeextern int opcLength[];
The field pcnt
Prototypeextern int pcnt;
The field userint
Prototypeextern UBYTE* userint;
The method Opcode_AddVariable
Prototypeint Opcode_AddVariable(char* varName,int subRoot,int varType,int after);
Parameter | Description |
varName | Contains the name of the variable to be added. |
subRoot | Specifies the root offset of the subprogram to which the variable is to be added. It is assumed that the currently loaded code belongs to this subprogram. |
varType | Specifies the binary type of the variable. |
after | Specifies if zero, that the DCL should be placed first in the code; if not zero, the DCL is placed after any beginning DCL or comment operations in the code. |
The method returns the length of the DCL operation code added if the variable add was successful; else it returns zero.
The method Opcode_CommentOut
Prototypeint Opcode_CommentOut(int iStart,int cmtType);
Parameter | Description | ||||||||||||
iStart | is the offset in the global code block of the component whose presence is causing the need to comment out the statement. | ||||||||||||
cmtType | Specifies how the commented out code is to appear, or not appear, in the output:
|
The method returns the offset in the global code block of the inserted CMT operation unless that operation was stored at the back of the code block. In that case, -1 is returned.
The method Opcode_Delete
Prototypevoid Opcode_Delete(int icode,int nDelete);
Parameter | Description |
icode | Specifies the offset in the global code block where the deletion is to begin. |
nDelete | Specifies the number of existing operations to be deleted. |
The method itself has no return value.
The method Opcode_DumpCode
Prototypevoid Opcode_DumpCode(int iStart,int iEnd);
Parameter | Description |
iStart | Specifies the starting offset of the code to be displayed. |
iEnd | Specifies the ending offset. The method checks that the value of iEnd does not exceed the current length of the code storage area stored in pcnt. |
The method has no return value.
The method Opcode_FindArgumentEnd
Prototypeint Opcode_FindArgumentEnd(UBYTE* userCode,int iStart,int iEnd);
Parameter | Description |
userCode | Specifies the code block that contains the argument code. |
iStart | Specifies the offset of the start of the argument code. |
iEnd | Specifies the offset of the end of the search region. This is normally simply set to the overall length of the code block. |
The method returns the end of the argument code which is the offset of the first operation following the ARG operation.
The method Opcode_FindLvalueEnd
Prototypeint Opcode_FindLvalueEnd(int icode,tQuantity* xQuant);
Parameter | Description |
icode | Specifies the offset of the start of the suspected Lvalue code. |
xQuant | Receives the binary type of the Lvalue, if non-NULL. |
If the operation code starting at icode does specify an Lvalue, then the method returns the offset of the first byte beyond its end. If not, then a zero is returned.
The method Opcode_GetArgumentType
Prototypeint Opcode_GetArgumentType(int subRoot,int icode,int lcode,tQuantity* xQuant);
Parameter | Description |
subRoot | Specifies the root offset of the component to which the code belongs. |
icode | Specifies the offset of the start of the code subsegment whose binary type is needed. This may or may not be an actual argument description. |
lcode | Specifies the end of the subsegment. If it is nonzero, then it simply specifies the length of the subsegment. If it is zero, and the opcode at the start is LEV, then the entire argument code is evaluated. This is the typical use of this method. If it is zero and the starting opcode is not LEV, then only that one opcode is evaluated. |
xQuant | Receives detailed quantity information about the type of the code segment, if specified. |
The method returns the binary type code of the code segment.
The method Opcode_GetCallArgs
Prototypeint Opcode_GetCallArgs(int subRoot,int lastNew,int funcCode,int* qeAddr,int* qeType, int* qeContext,int* qeFlags,int nArg);
Parameter | Description |
subRoot | Specifies the root offset of the method performing the call. |
lastNew | Specifies the byte code offset of the start of the code for the actual statement performing the call. |
funcCode | Specifies the offset of the operation that is doing the call. |
qeAddr | Receives the starting offset of the code for each argument. |
qeType | Receives the quantity type code for each argument. |
qeContext | Receives any context flags associated with the argument, if not NULL, |
qeFlags | Receives any migration status flags associated with the argument, if not NULL. |
nArg | Specifies the number of parameters associated with the method. At this level, all methods have a fixed number of parameters that is determined when they are defined and that must be known when this method is called. |
If this method is unable to isolate the calling argument code it returns a zero; else it returns the number of arguments as found and as specified in the parameter nArg.
The method Opcode_GetCode
Prototypevoid* Opcode_GetCode(void)
The method Opcode_GetInfo
PrototypeUBYTE* Opcode_GetInfo(int opcode);
Offset | Description of content |
OPCODE_LENGTH | Length of each opcode entry |
OPCODE_NIDENT | Length of each opcode identifier |
OPCODE_IDENT | Offset of identifier |
OPCODE_VALUE | Offset of value |
OPCODE_TYPE | Offset of type |
OPCODE_ROLE | Offset of role |
OPCODE_SUBCODES | Offset of subcode count |
OPCODE_SUBLIST | Offset of offset of subcode list |
OPCODE_INTERFACE | Offset of interface offset |
Its parameter is:
Parameter | Description |
opcode | Specifies the sequence number of the desired opcode. This was the opc attribute of opcode when it was defined. These are normally defined as constants in a language specific header file. |
The method returns a byte pointer to the information for the specified opcode. If there is no opcode defined with the specified index, a NULL is returned.
The method Opcode_GetLength
Prototypeint Opcode_GetLength(void);
The method Opcode_GetListEntry
PrototypeUBYTE* Opcode_GetListEntry(int base,int entry);
Parameter | Description |
base | Specifies the base address in metalanguage storage of the augmented list. |
entry | Specifies the number of the desired entry from the list. |
The method returns a pointer to the actual entry information or NULL if no entry information is available for the desired entry.
The method Opcode_GetMember
Prototypeint Opcode_GetMember(int opcode,int subcode);
Parameter | Description |
opcode | Specifies the index of the opcode controlling the operation.This was the opc attribute of opcode when it was defined. |
subcode | Specifies the sequence number of the desired subcode associated the operation. |
If the operation does not have a library member associated with it then this method returns a zero; else the offset in language storage of the associated member is returned.
The method Opcode_GetMemberType
Prototypeint Opcode_GetMemberType(int opcode,int subcode,tQuantity* xQuant);
Parameter | Description |
opcode | Specifies the index of the opcode controlling the operation.This was the opc attribute of opcode when it was defined. |
subcode | Specifies the sequence number of the desired subcode associated the operation. |
xQuant | Receives the type and context attributes of the information if it is not NULL. |
If the specified operation has a library component associated with it then the type of that component is returned; else a TYP_VOID is returned.
The method Opcode_GetNext
Prototypeint Opcode_GetNext(UBYTE* pcode,int opadr,int codeEnd);
Type | Len Meaning |
OPCTYP_ARITHMETIC | 2 is an arithmetic operation with hierarchy |
OPCTYP_SINGLEBYTE | 1 consists of a single byte operation code |
OPCTYP_DOUBLEBYTE | 2 Consists of a 2-byte operation code |
OPCTYP_SHORTVALUE | 3 Operation code followed by 2-byte value |
OPCTYP_SYMBOLADDR | 5 Operation code followed by 4-byte symbol address |
OPCTYP_STRINGADDR | 5 Operation code followed by 4-byte string address |
OPCTYP_OPCODEADDR | 5 Operation code followed by 4-byte pcode offset |
OPCTYP_BINARYTYPE | 2 2-byte operation specifying binary type |
OPCTYP_LIBRARYADR | 5 Operation code followed by 4-byte library offset |
OPCTYP_LIBPATTERN | 5 Operation code followed by 4-byte pattern offset |
OPCTYP_OBJECTTYPE | 5 Operation code followed by 4-byte object type code |
Its parameters are:
Parameter | Description |
pcode | Contains the code block being traversed. |
opadr | Specifies the offset in the code block of the current operation. |
codeEnd | Specifies the traversal length of the code block. |
The method returns the offset of the following operation if there is one. If the current operation is the last one, then a minus one is returned.
The method Opcode_GetOperation
Prototypeint Opcode_GetOperation(UBYTE* pcode,int opadr,int* subcode);
Parameter | Description |
pcode | Contains the code block whose operations are being examined. |
opadr | Specifies the offset in the code block of the desired operation. |
subcode | returns the subcode associated with the operation. |
The method returns the opcode of the operation.
The method Opcode_GetPrevious
Prototypeint Opcode_GetPrevious(UBYTE* pcode,int opadr,int codeEnd);
Parameter | Description |
pcode | Contains the code block being traversed. |
opadr | Specifies the offset of an operation in the code block that is known to precede the current one. |
codeEnd | Specifies the offset in the code block of the current operation. |
The operation offset returned by this method will be between these two offsets or will simply be set equal to the starting offset.
The method Opcode_GetRoleStatus
Prototypeint Opcode_GetRoleStatus(int opcode,int subcode,int* status);
Parameter | Description |
opcode | Specifies the index of the opcode controlling the operation. This was the opc attribute of opcode when it was defined. |
subcode | Specifies the sequence number of the desired subcode associated the operation. |
status | returns the status code of the operation if not NULL. |
The method returns the role code of the operation.
The method Opcode_GetString
Prototypeint Opcode_GetString(int iStart,int iEnd,char* sValue);
Parameter | Description |
iStart | Specifies the offset of the first operation defining the value. |
iEnd | Specifies the offset immediately beyond the last operation for the value. |
sValue | Receives the computed string. |
The method returns one if the computation was successful, else it returns zero.
The method Opcode_GetSubcodeLabel
Prototypechar* Opcode_GetSubcodeLabel(int opcode,int subcode);
Parameter | Description |
opcode | Specifies the index of the opcode controlling the operation. This was the opc attribute of opcode when it was defined. |
subcode | Specifies the sequence number of the desired subcode associated the operation. |
The method returns a character pointer to the label for the subcode in null-terminated form. If the subcode has no label defined, then a NULL is returned.
The method Opcode_MoveCode
Prototypeint Opcode_MoveCode(int iDest,int iStart,int nCode,int nMove);
Parameter | Description |
iDest | Specifies the offset in the global code block of the destination of the move. |
iStart | Specifies the offset of the source of the move. |
nCode | Specifies the overall length of the byte code. |
nMove | Specifies the number of byte codes to move. |
The method returns the offset of the code destination once the move has been completed.
The method Opcode_ReadOpcodes
Prototypeint Opcode_ReadOpcodes(char* command,int nCommand);
Byte | Description of content |
0 | Length of opcode information always 11 here |
1-4 | Opcode identifier terminated by a null byte--all have 3 chars |
5 | Value to be assigned for that opcode |
6 | Opcode type code |
7 | Opcode role code |
8 | Number of subcodes |
9-12 | Offset in storage of subcode list (set to zero here) |
13-16 | Offset of interface class root offset |
Within each opcode statement there are a series of subcode statements stored as a standard list. Each entry has the following structure:
Byte | Description of content |
0 | Length of symbol information |
1+ | Actual symbol terminated by a null |
2 | The integer identifier for the symbol |
3-6 | The offset of the supporting class member |
The start of the assembled opcode information is storage in the LNGINF_OPCODES location in boot record of user interface storage. The parameters of this method are:
Parameter | Description |
command | Contains the actual Opcodes command as entered in a Language definition script. As this method processes the opcode and subcode subcommands introduced by this command, it uses this buffer to contain them. |
nCommand | Specifies the size of the command buffer. It is needed since that buffer is used within this method to contain its subcommands. |
The method Opcode_Replace
Prototypevoid Opcode_Replace(int icode,int opcode,int subcode,int nReplace);
Parameter | Description |
icode | Specifies the offset in the global code block where the replacement is to begin. |
opcode | Specifies the index of the opcode of the operation to be inserted. |
subcode | Contains the sequence number of the desired subcode associated the operation. |
nReplace | Specifies the number of existing operations to be replaced. A value of zero indicates that the new operation should simply be inserted. |
The method has no return value.
The method Opcode_SetCode
Prototypevoid Opcode_SetCode(void* ptr);
Parameter | Description |
ptr | Specifies a new value for the codptr field. |
The method has no return value.
The method Opcode_SetLength
Prototypevoid Opcode_SetLength(int iValue);
Parameter | Description |
iValue | Specifies a new value for the pcnt field. |
The method has no return value.
The method Opcode_SetOperation
Prototypevoid Opcode_SetOperation(UBYTE* pcode,int opadr,int opc,int subcode);
Parameter | Description |
pcode | Contains the code block to receive the operation. |
opadr | Specifies the offset in the code block where the operation is to be stored. |
opc | Specifies the index of the opcode of the operation to be inserted. |
subcode | Specifies the value of the desired subcode associated the operation. |
The method has no return value.
The method Opcode_SetSubcodeMember
Prototypeint Opcode_SetSubcodeMember(int opcode,int subcode,int iRoot);
Parameter | Description |
opcode | Specifies the sequence number of the desired opcode. This was the opc attribute of the opcode when it was defined. These are normally defined as constants in a language specific header file. |
subcode | Specifies the sequence number of the desired subcode of the opcode. This was the subcode attribute when it was defined in the metalanguage. These codes will also normally be defined as constants in the language specific header file using a symbol like OPC_subcodelabel. A subcode of -1 means that the overall class member is being defined for the opcode. |
Root | Specifies the root address of the class member in the language storage area. |
If the opcode is does not have subcodes then a one is returned and the root is not stored. If the opcode-subcode combination already has a member root associated with it, then a two is returned and the root is not stored. If there is no root yet associated with the pair, then the root is stored in the table and a zero is returned.
The method Opcode_Sizeof
Prototypeint Opcode_Sizeof(int opc);
Parameter | Description |
opc | Specifies the index of the opcode whose operation length is needed. |
The method returns the length in bytes of the associated operation.
The method Opcode_TraverseArgs
Prototypeint Opcode_TraverseArgs(int subRoot,int iCall,int nTemp,VisitArgument_ptr VisitArgument);
Member | Description of use |
nTemp | Initialized at the value of nTemp parameter as passed in and not used beyond that here. |
lastNew | Code offset of operation following the last encountered NEW opcode. |
lastTmp | Code offset of operation following the last encountered TMP opcode. |
lastLev[] | Code offset of operation following the last encountered LEV opcode at each call nesting level. |
argRoot | Root offset of current argument being called |
argType | Initialized at zero, not used within this method |
objRoot | Initialized at zero, not used within this method |
argBase[] | Root offset of current argument being called at each call nesting level. |
nLev | Current call nesting level |
delta | Initialized at zero and is the value finally returned by this method |
iCall | Initialized at the value of iCall parameter as passed in and not used beyond that here. |
iStart | Current code offset of the ARG operation for the current argument. |
The parameters of this method are:
Parameter | Description |
subRoot | Specifies the root offset of the subprogram whose code is currently loaded in the global code block. |
iCall | Specifies a unique call identifier which can be used for debugging purposes. |
nTemp | Specifies the sequence number to be assigned to any temporary that has to be created. The use of this value has been deprecated. |
VisitArgument | specifies the service handle of the method that is to perform the actual argument code check |
The method returns the final value of the delta member of the communication structure. If non-zero that the content of the global code block was changed as a result of the traversal.
Table of Contents