Node:VM disassembler, Next:, Previous:Peephole optimization, Up:Using the generated code



VM disassembler

A VM code disassembler is optional for an interpretive system, but highly recommended during its development and maintenance, because it is very useful for detecting bugs in the front end (and for distinguishing them from VM interpreter bugs).

Vmgen supports VM code disassembling by generating file-disasm.i. This code has to be wrapped into a function, as is done in vmgen-ex/disasm.c. You can use this file almost verbatim. In addition to vm_A2B(a,b), vm_out, printarg_type(value), which are explained above, the following macros and variables are used in file-disasm.i (and you have to define them):


ip
This variable points to the opcode of the current VM instruction.
IP IPTOS
IPTOS is the first argument of the current VM instruction, and IP points to it; this is just as in the engine, but here ip points to the opcode of the VM instruction (in contrast to the engine, where ip points to the next cell, or even one further).
VM_IS_INST(Inst i, int n)
Tests if the opcode i is the same as the nth entry in the VM instruction table.