This project is an LLVM-based compiler for a custom programming language called "Lang".
- CMake (version 3.15 or higher)
- LLVM (version 14.0.0 or higher)
- A C++17 compatible compiler
You can use the provided build.sh
script to configure, clean, and build the project:
-
Clone the repository:
git clone https://github.com/jsilll/lang.git cd lang
-
Make the build script executable:
chmod +x build.sh
-
Configure the project:
./build.sh configure
-
Build the project:
./build.sh build
Alternatively, you can run all steps at once:
./build.sh all
The build.sh
script supports several options:
--llvm-dir <path>
: Set LLVM_DIR (default: /usr/lib/llvm-14)--build-type <type>
: Set CMAKE_BUILD_TYPE (default: Debug)--c-compiler <path>
: Set CMAKE_C_COMPILER (default: clang)--cxx-compiler <path>
: Set CMAKE_CXX_COMPILER (default: clang++)--ccache <path>
: Set CMAKE_CXX_COMPILER_LAUNCHER (default: ccache)
After building, you can run the compiler using:
./src/compiler <input_file> [options]
Available options:
--until=<stage>
: Run the compiler until a specific stagelex
: Run until the lexing stageast
: Run until the parsing stage
--emit=<output>
: Select the kind of output desiredlex
: Dump the lexed tokens of the input filesrc
: Dump the original source code of the input file (not implemented yet)ast
: Dump the abstract syntax tree of the input file
-
Memory Management: The project uses an Arena allocator for efficient memory management of AST nodes.
-
Error Reporting: The compiler implements a robust error reporting system that provides detailed information about lexing and parsing errors.
-
LLVM Integration: The project leverages LLVM libraries for code generation and optimization.
-
Modular Architecture: The compiler is divided into distinct phases (lexing, parsing, etc.) for better maintainability and extensibility.
-
Type System: A basic type system is implemented, with a TypeContext for managing types.
-
Resolver: A resolver stage is implemented to perform semantic analysis on the AST.
src/
: Contains the main source filesAlloc/
: Custom allocatorsAST/
: Abstract Syntax Tree related codeLex/
: Lexer implementationParse/
: Parser implementationsSema/
: Semantic analysis codeSupport/
: Utility classes and functionsmain.cpp
: Entry point of the compiler
include/
: Header filesADT/
: Abstract Data Types
CMakeLists.txt
: CMake configuration files
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.