Saturday, February 14, 2015

Table – Encode Virtual Function

The six encode functions did the same thing except with a different dictionary, a pointer that was obtained from one of six dictionary access functions.  With the dictionary pointers in an array, a new single dictionary access function was added to the program model with an operand type argument.

A single encode function can be implemented but it needs to obtain the correct operand type for the code being encoded.  The encode function is passed a token pointer and the token contains the pointer to the table entry for the code.  Therefore, an operand type member was added to the table class, but using the token table entry to get the operand type is not the best way to get the operand type (it would be more of a calling chain that is being eliminated).

Since the encode function is virtual, once the new table class hierarchy is implemented, the code with operand class will have its own encode function.  Being a member of the table class, the encode function will have direct access to the operand type member, so there is no need to go through the token anyway.

The table encode virtual function previously called the encode function contained in the encode function pointer member if it was set.  For now this encode function was modified to do what the previous six encode functions did.  If the code has an operand, then the dictionary for the operand type is called to add the entry in the token to the dictionary and the resulting entry index is inserted into the program.  The function call chain is still present (which is in the process of being eliminated).  For other codes, nothing is done, which is what the default encode virtual function will do.

The encode function pointer member was no longer used and was removed along with its access function and the six old encode functions.  To avoid modifying all the table entries (except those with operands), the encode function argument of the table constructor was changed to dummy void pointer (so the encode function pointer initializer in the entries are ignored) and the operand type member is initialized to the No enumerator.

For the codes with operands, a new table constructor was added with an operand type argument and without the encode function pointer argument.  This constructor was made the main constructor with the original constructor calling it.  Since the operand type member can be used to determine if the code has an operand, the Operand table flag was removed and the is code with operand access function was changed to use the new member instead of the flag.

[branch table commit f549771028]