Unicon example – bytecode generation in icont
Unicon's compiled bytecode output format is human-readable text in ucode
files. Such ucode
files are initially generated, and then linked and converted into binary icode
format by a C program named icont
that is invoked by the Unicon translator. The icont
program plays the role of code generator, assembler, and linker to form a complete bytecode program in binary format. Here are some of the details.
The gencode()
C function in icont
reads lines of ucode
text and turns them into binary format following the outline illustrated here. There is an interesting similarity between this pseudo-code and the fetch-decode-execute loop used in the bytecode interpreter. Here, we are fetching text bytecode from input, decoding the opcode, and writing binary bytecode with slight differences in format depending on the bytecode:
void gencode() { while ((op = getopc(&name)) != EOF) { ...