Unicon example – bytecode generation in icont
Unicon’s bytecode translator outputs human-readable text in ucode files. The ucode format serves as both an assembler and object file format in the Unicon ecosystem. 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 for Unicon. Its back-end functions as an assembler and linker to form a complete bytecode program in binary format. Here are some of the details.
A C function about 400 lines long named gencode()
in icont’s lcode.c
module reads lines of ucode text and turns them into binary format following the code outline shown below. For each line, an opcode is read using the getopc()
function. After that, a gigantic switch
statement emits different binary code appropriate to different instruction opcodes.
It is no accident that there is an interesting...