| 1 : |
anton
|
1.1
|
Vmgen generates much of the code for efficient virtual machine (VM) |
| 2 : |
anton
|
1.2
|
interpreters from simple descriptions of the VM instructions. It |
| 3 : |
anton
|
1.1
|
generates code for executing VM instructions (with optional tracing), |
| 4 : |
|
|
for generating VM code, for disassembling VM code, and for profiling |
| 5 : |
|
|
VM instruction sequences. A VM instruction description looks like |
| 6 : |
|
|
this: |
| 7 : |
|
|
|
| 8 : |
|
|
add ( i1 i2 -- i ) |
| 9 : |
|
|
i = i1+i2; |
| 10 : |
|
|
|
| 11 : |
|
|
Vmgen supports several techniques for writing efficient interpreters: |
| 12 : |
|
|
virtual machine interpreters, threaded code, combining VM instructions |
| 13 : |
|
|
into superinstructions, keeping the top-of-stack in a register, |
| 14 : |
|
|
scheduling the dispatch of the next VM instruction, and a couple of |
| 15 : |
|
|
minor optimizations. Interpreters created with vmgen usually are |
| 16 : |
|
|
faster than competing interpreters and are typically only a factor of |
| 17 : |
|
|
2-10 slower than the code generateed by native-code compilers. |
| 18 : |
|
|
|
| 19 : |
|
|
Vmgen has special support for stack-based VMs (but it can also be |
| 20 : |
|
|
used to advantage when implementing a register-based VM). |
| 21 : |
|
|
|
| 22 : |
|
|
The main shortcoming in the current release is the lack of a user |
| 23 : |
|
|
manual; however, there is a paper describing vmgen's operation (at |
| 24 : |
|
|
http://www.complang.tuwien.ac.at/anton/vmgen/), and there is a simple, |
| 25 : |
anton
|
1.3
|
working and somewhat commented example of using vmgen. |
| 26 : |
|
|
|
| 27 : |
|
|
There are two versions of the example: in directory vmgen-ex you find |
| 28 : |
|
|
a version using many casts; in directory vmgen-ex2 you find a version |
| 29 : |
|
|
using unions instead of casts. |
| 30 : |
anton
|
1.2
|
|
| 31 : |
|
|
The current release requires GCC both for building and for compiling |
| 32 : |
|
|
the resulting interpreters (threaded code cannot be implemented in |
| 33 : |
|
|
ANSI C). |
| 34 : |
anton
|
1.1
|
|
| 35 : |
|
|
If you have bugs to report, suggestions to make, questions, or any |
| 36 : |
|
|
other feedback, mail me (anton@mips.complang.tuwien.ac.at). |
| 37 : |
|
|
|
| 38 : |
|
|
You can find vmgen at http://www.complang.tuwien.ac.at/anton/vmgen/. |
| 39 : |
|
|
|
| 40 : |
|
|
Vmgen is currently distributed with Gforth (because it needs Gforth to |
| 41 : |
|
|
run, and Gforth needs it to build), and is installed together with |
| 42 : |
|
|
Gforth (read INSTALL for instructions). |
| 43 : |
|
|
|
| 44 : |
|
|
Note that future versions of vmgen will probably require small changes |
| 45 : |
|
|
in programs written for the present version (e.g., requiring a few |
| 46 : |
|
|
additional macro definitions). |