Expand description
§Ygen - Yet another Code Generator
§Description
Ygen is a libary to build modern compilers and tools
It includes many features like IR Optimization, Argument parsing, and much more
There are many utility functions and classes to help you write many asspects of your compiler:
- Like the Colorize trait to colorize your strings (maybe used for printing errors)
- The TokenMngr in combination with the SrcMngr to easily write a lexer and store the source location (usefull for including debugging information)
§The YGEN-IR
The Ygen Internal Representation isn’t very different to LLVMs IR.
A tip:
To dump the Ir of a YGen-Module use the dump
-Function which dumps the entire IR into a string
If you want to print the IR out the stdout consider using the dumpColored
-Function which includes Color Information
But if you pipe that into a file it also includes the Color bytes which then look a bit sus so consider printing it to stderr
§Here is a quick introduction to the YGEN-IR:
A function is defined like this:
define i32 @add( i32 %0, i32 %1 ) {
entry:
%2 = add i32 %0, %1
ret i32 %2
}
So define
then the return type of the function, a @
, the function name and the arguments.
An important thing to understand is that you can only define every variable once because
it follows the SSA form.
In YGEN-iR there are many inbuild instructions Like in our add function example:
add
adds two numbersret
returns an constant or a variable
Re-exports§
pub use ygen_proc as proc_macro;
Modules§
- CodeGen
- Shared code generation classes (mainly used for register based architectures like x86_64, aarch64, …)
- IR
- The ir module: functions for building function ir
- Obj
- Writing/Reading object files
- Optimizations
- The pass manager module:
- Support
- Other utilites like:
- Target
- The target module: every stuff which has to do with targets. Like:
- debug
- Debugging information
- prelude
- Most common used functions, classes, enums of this Libary