The Thrush Compiler is a monolithic compiler that transfers the source code of Thrush files directly to the specified destination. The process includes static type analysis, code generation, destination-specific optimizations, machine-specific code compilation, and finally, emitting or linking.
Warning
The compiler is in an early development phase. It may contain bugs when testing certain syntax. Continue on your own.
Among the dependencies required by the compiler is LLVM infrastructure.
Automatically:
$ git clone --depth=1 https://github.com/thrushlang/compiler-builder
$ cd compiler-builder
$ cargo run You must first clone the repository and access it locally.
$ git clone --depth=1 https://github.com/thrushlang/thrushc
$ cd thrushcNow you need to have Rust installed with a recent version.
- >= Rust (v1.18.5)
- Rust 2024 Edition
Now you need to compile the compiler with Rust.
$ cargo run -- --helpA list of the commands supported by the Thrush Compiler command line.
Warning
This might be a bit outdated, it could be information that's somewhat distant from the changes.
The Thrush Compiler
Usage: thrushc [-flags|--flags] [files..]
General Commands:
• -h, --help optional[opt|emit|print|code-model|reloc-model] Show help message.
• -v, --version Show the version.
General flags:
• -build-dir Specifies the compiler artifacts directory.
Linkage flags:
• -clang-link [/usr/bin/clang] Specifies the path for use of an external Clang for linking purpose.
• -gcc-link [usr/bin/gcc] Specifies GNU Compiler Collection (GCC) for linking purpose.
• -start Marks the start of arguments to the active external or built-in linking compiler.
• -end Marks the end of arguments to the active external or built-in linker compiler.
Compiler flags:
• -target [x86_64] Set the target arquitecture.
• -target-triple [x86_64-pc-linux-gnu|x86_64-pc-windows-msvc] Set the target triple. For more information, see 'https://clang.llvm.org/docs/CrossCompilation.html'.
• -cpu [haswell|alderlake|ivybridge|pentium|pantherlake] Specify the CPU to optimize.
• -cpu-features [+sse2,+cx16,+sahf,-tbm] Specify the new features of the CPU to use.
• -emit [llvm-bc|llvm-ir|asm|unopt-llvm-ir|unopt-llvm-bc|unopt-asm|obj|ast|tokens] Compile the code into specified representation.
• -print [llvm-ir|unopt-llvm-ir|asm|unopt-asm|tokens] Displays the final compilation on standard output.
• -opt [O0|O1|O2|O3|Os|Oz] Optimization level.
• -dbg Enable generation of debug information (DWARF).
• -dbg-for-inlining Enable debug information specifically optimized for inlined functions.
• -dbg-for-profiling Emit extra debug info to support source-level profiling tools.
• -dbg-dwarf-version [v4|v5] Configure the Dwarf version for debugging purposes.
JIT compiler flags:
• -jit Enable the use of the JIT Compiler for code execution.
• -jit-libc Specify the C runtime to link for code execution via the JIT Compiler.
• -jit-link Specify, add, and link an external dynamic library for code execution via the JIT Compiler.
Extra compiler flags:
• --opt-passes [-p{passname,passname}] Pass a list of custom optimization passes. For more information, see: 'https://releases.llvm.org/17.0.1/docs/CommandGuide/opt.html#cmdoption-opt-passname'.
• --modificator-passes [loopvectorization;loopunroll;loopinterleaving;loopsimplifyvectorization;mergefunctions;callgraphprofile;forgetallscevinloopunroll;licmmssaaccpromcap=0;licmmssaoptcap=0;] Pass a list of custom modificator optimization passes.
• --reloc-model [static|pic|dynamic] Indicate how references to memory addresses and linkage symbols are handled.
• --code-model [small|medium|large|kernel] Define how code is organized and accessed at machine code level.
• --target-triple-darwin-variant [arm64-apple-ios15.0-macabi] Specify the darwin target variant triple.
• --macos-version [15.0.0] Specify the MacOS SDK version.
• --ios-version [17.4.0] Specify the iOS SDK version.
• --enable-ansi-color It allows ANSI color formatting in compiler diagnostics.
Omission compiler flags:
• --omit-frame-pointer Regardless of the optimization level, it omits the emission of the frame pointer.
• --omit-uwtable It omits the unwind table required for exception handling and stack tracing.
• --omit-direct-access-external-data It omits direct access to external data references, forcing all external data loads to be performed indirectly via the Global Offset Table (GOT).
• --omit-rtlib-got It omits the runtime library dependency on the Global Offset Table (GOT), essential when generating non-Position Independent Code (PIC) with ARM.
• --omit-default-opt It omits default optimization that occurs even without specified optimization.
Debug compiler flags:
• --debug-clang-command Displays the generated command for Clang in the phase of linking.
• --debug-gcc-commands Displays the generated command for GCC in the phase of linking.
Useful flags:
• --export-compiler-errors Export compiler error diagnostics to files.
• --export-compiler-warnings Export compiler warning diagnostics to files.
• --export-diagnostics-path [diagnostics/] Specify the path where diagnostic files will be exported.
• --clean-exported-diagnostics Clean the exported diagnostics directory.
• --clean-build Clean the compiler build folder that holds everything.
• --clean-tokens Clean the compiler folder that holds the lexical analysis tokens.
• --clean-assembler Clean the compiler folder containing emitted assembler.
• --clean-llvm-ir Clean the compiler folder containing the emitted LLVM IR.
• --clean-llvm-bitcode Clean the compiler folder containing emitted LLVM Bitcode.
• --clean-objects Clean the compiler folder containing emitted object files.
• --no-obfuscate-archive-names Stop generating name obfuscation for each file; this does not apply to the final build.
• --no-obfuscate-ir Stop generating name obfuscation in the emitted IR code.
• --print-targets Show the current target supported.
• --print-supported-cpus Show the current supported CPUs for the current target.
• --print-host-target-triple Show the host target triple.
• --print-opt-passes Show all available optimization passes through '--opt-passes=p{passname, passname}'.The language syntax is under construction at the same time as the compiler. It may be outdated compared to the compiler, as the latter progresses more rapidly. This will be normalized once a valid and sufficiently stable beta is released.
Thrush Programming Language - General Syntax
Currently, the only backend available for the thrush compiler to compile is the current LLVM, using the LLVM-C API.
The compiler has Clang compiled for Linux & Windows inside the executable in case the programmer does not have access to it; however, you can specify a custom Clang & GCC.
The code generation is in 3 phases.
- Intermediate Code Generation (
LLVM IR). - Emit object files (
.o). - Linking with some linker through the
ClangorGCCC compilers. ~ Rust 2015 be like
In summary:
The LLVM backend infrastructure is the default code generator for the Thrush Programming Language. It offers full scope and portability across many architectures or targets.
17.0.6
Between version 16-17, the introduction to the change of typed pointers was made, which are now almost a standard in the backend.
Some programming languages like Swift tend to use versions lower than 16 of LLVM, for reasons of compatibility with code generation that differs between higher and lower versions of LLVM, and version 16 offers legacy support for languages that need it.
We only need support for C and nothing else. We are not interested in FFI with C++ for the moment, nor in mangling with it either. 17 is enough and from there on.
Beyond the standard triple targets, the compiler also supports all architectures available through the LLVM-C API. These include:
x86_64AArch64RISC-VARMMIPSPowerPCSystemZAMDGPUHexagonLanaiLoongArchMSP430NVPTXSPARCXCoreBPFSPIR-VWebAssembly
The GCC compiler backend is still under construction.
In the future, you will be able to use it with the -gcc-backend flag to use the GCC backend code generator instead of the default LLVM one.
However, it is only available on GNU/Linux.
You must also have libgccjit.so dynamically installed in your distribution so that the compiler doesn't get scared at runtime when using GCC.
Currently, the very same Rust is using libgccjit as a library for an AOT backend prototype for Rust. Called rustc_codegen_gcc. Thrush will integrate it in his own way for use in the language.
For more information: Rust - GCC AOT Code Generation
Regarding the concept of bootstrapping in compilers (For more information: https://www.bootstrappable.org/).
The decision was made to fully implement all the programming language functions in the compiler written in Rust, because it proposes a development approach similar to what Gleam Team did for Gleam Programming Language, and also to lighten the workload, given that we are already using LLVM.

%20v1.3.png)