GNU lightning
GNU lightning is a free-software library for generating assembly language code (actually machine code) at run-time. Version 2.1.3, released in September 2019, supports backends for SPARC (32-bit), x86 (32- and 64-bit), MIPS, ARM (32- and 64-bit), ia64, HPPA, PowerPC (32-bit), Alpha, S390 and RISC-V (64-bit).
01Advantages over other libraries
The features GNU lightning provides make it useful for Just-in-Time Compilation. In comparison to libraries such as LLVM or libJIT, GNU lightning provides only a low-level interface for assembling from a standardized RISC assembly language, loosely based on the SPARC and MIPS architectures, into the target architecture's machine language.
02Disadvantages
It does not provide register allocation, data-flow or control-flow analysis, or optimization. Starting from 2.x, it generates code via intermediate graph, rather than one by one from each of its standardized instructions. This change allows inter-instruction optimization such as register allocation and dead code elimination.
03Instruction set
GNU lightning's instruction set is based loosely on existing RISC architectures.
Types
When required instructions handle data with these 9 types:
| Type | C equivalent |
|---|---|
| c | signed char |
| uc | unsigned char |
| s | short |
| us | unsigned short |
| i | int |
| ui | unsigned int |
| l | long |
| f | float |
| d | double |
04Projects that use GNU lightning
GNU Smalltalk, GNU Guile, and CLISP make use of GNU lightning for just-in-time compilation. GNU lightning was first developed as a tool to be used in GNU Smalltalk's dynamic translator from bytecodes to native code. GNU Guile 2.9.2 and later stop using GNU lightning 2.x instead their own fork based on GNU lightning 1.4 for native code generation, because GNU lightning 2.x devotes more complexity to inter-instruction optimization.
Sources and credits
This article is adapted from the Wikipedia article “GNU lightning”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.