Compiler documentation
Welcome to the Wind Language Compiler Documentation! This page will guide you through the internals of the Wind compiler and how it transforms your Wind code into executable programs.
Command Line Options
The Wind compiler provides a few command-line options to control the compilation process.
-o <output>
: Specify the output file name for the compiled program.-h
: Display the help message with available options.-ej
: Compile as an object file without linking.-sa
: Output the generated AST in a human-readable format.-si
: Output the generated IR in a human-readable format.-ss
: Output the generated assembly code.
Example
Here is an example of compiling a Wind program using the Wind compiler:
windc hello.w -ss -o hello
This command compiles the hello.w
source file, outputs the generated assembly code, and creates an executable named hello
.
Overview
The Wind compiler is a lightweight and efficient tool that translates Wind source code into machine code that can be executed by the target system. It performs several stages of compilation to analyze, optimize, and generate the final executable.
The key stages of the Wind compiler include:
- Lexical Analysis: The source code is broken down into tokens for further processing.
- Syntax Analysis: The tokens are parsed into an abstract syntax tree (AST) to represent the structure of the program.
- Compilation: The AST is transformed into an intermediate representation (IR) that can be optimized.
- Optimization: The IR is optimized to improve performance and reduce resource usage.
- Code Generation: The optimized IR is translated into assembly code for the target system.
- Assembly: Via GNU Assembler, the assembly code is converted into machine code that can be executed.
- Linking: The compiled code is linked with runtime libraries to create the final executable or the object file.
Code Generation
Currently Wind supports only x86_64 architecture. The generated assembly code is compatible with the x86_64 instruction set and can be executed on systems that support this architecture.
The generated assembly code is designed to be efficient and optimized for performance. It leverages the capabilities of the x86_64 architecture to achieve high performance and low resource usage.
The assembly is generated by the fully hand-written backend which is designed to be simple and efficient. The backend generates assembly code directly from the IR without the need for an intermediate representation.
The assembly into machine code is done by the GNU Assembler (as
), I have plans to write a custom assembler in the future but executable formats are pretty complex so it's not a priority.
Runtime Library
The Wind compiler relies on a set of runtime libraries to provide essential functionality to the compiled programs. These libraries include functions for error handling, memory management, and initialization of the program.