要求,纯C写就,轻量级。
TCC, LCC, PCC
结论: lcc比较适合用来写新的architecture, 即retargetable compiler. lcc规模较小,各个模块边界清晰,而且宏少,使用经验多,还有教程。 依赖少, 较易移植。缺点是不支持ARM处理器。
LCC - little C compiler
arch: x86, mips, alpha, sparc, microsoft cil
implement: ANSI C
license: LCC license
written in C
last release: sept. 2002
Retargeting能力比较强。
TCC - tiny C compiler,
arch: X86 + ARM processor,
license: LGPL licence
implement all ANSI C(C89/C90), much of C99, many GNU C extensions including inline assembly
written in C and assembly
last release: feb. 2013
tcc有自己的汇编器与连接器
PCC: portable c compiler
arch: x86, x64
implement: C99
license: BSD
written in: C
retarget 一般放在backend做 code generation产生 machine code.
TCC的retarget支持不强。
比如一个例子: 将tinycc编译retarget to a virtual processor I designed.
则必须要实现一个code generator backend for this architecture, 类似于目录下的
i386-gen.c, arm-gen.c, and c67-gen.c 文件实现。
注意:there are apparently some issues with byte ordering, such
that the compile and target hosts must have the same endianness if you
want the output to be sensible. But I don't know if that's due to the
the *-gen implementation itself or part of the core compiler code.
另外针对 assembler, tcc does not normally generate any intermediate assembly; it goes
directly from C code to object code.
LCC
lcc code generator is based on the lburg. Some retarget examples:
retargetable C compiler for network processor
http://www.iro.umontreal.ca/~aboulham/pdfs_sources/SCI02.pdf
A PDP-11 target for lcc
http://telegraphics.com.au/sw/info/lcc-pdp11.html
Retargeting lcc for Magic-1
http://www.homebrewcpu.com/retargeting_lcc.htm
vcode or tick cc
vcode: a retargetable, extensible, very fast dynamic code generation system,
This paper
appeared in PLDI '96. Slides are available
here .
vcode is a portable system to generate executable code at runtime. It
generates code in approximately 10 instructions per generated instruction,
and is easily extendible by clients. A tutorial describing it can be
obtained by clicking here.
A beta version of the system is also
available.
To get on the vcode mailing list, please email engler@lcs.mit.edu.
Click
here for a bit more information.
`C and tcc: A Language and Compiler for Dynamic Code Generation,
Quake 3
id Software's id Tech 3 engine relies on a modified version of LCC to compile the source code of each game module or third-party mod into bytecode targeting its virtual machine.[6] This means that modules are oblivious to the system beyond the system calls and limited file system scope offered by the engine, which is intended to reduce the threat posed by malicious mod authors. Another consideration is that games and mods written for the engine are portable without recompilation; only the virtual machine needs to be ported to new platforms in order to execute the modules.
id Tech 3 uses a virtual machine to control object behavior on the server, effects and prediction on the client and the user interface. This presents many advantages as mod authors do not need to worry about crashing the entire game with bad code, clients could show more advanced effects and game menus than was possible in Quake II and the user interface for mods was entirely customizable.
Virtual machine files are developed in ANSI C, using LCC to compile them to a 32-bit RISC pseudo-assembly format. A tool called q3asm then converts them to QVM files, which are multi-segmented files consisting of static data and instructions based on a reduced set of the input opcodes. Unless operations which require a specific endianness are used, a QVM file will run the same on any platform supported by Quake 3.
The virtual machine also contained bytecode compilers for the x86 and PowerPC architectures, executing QVM instructions via an interpreter.
https://github.com/id-Software/Quake-III-Arena/tree/master/q3asm
http://fabiensanglard.net/quake3/qvm.php
http://gamedev.stackexchange.com/questions/15107/how-can-i-edit-qvm-quake-virtual-machine-files
http://www.icculus.org/~phaethon/q3mc/q3vm_specs.html
没有评论:
发表评论