Skip to content

Commit bf79572

Browse files
authored
Major Infrastructure Upgrade: LLVM 21, Opaque Pointers, and GUI Tooling (#291)
* feat: upgrade to LLVM 21, implement opaque pointer support, and add GUI build tool This commit performs a major infrastructure upgrade to the LLVM backend, transitioning to LLVM 21 (via Inkwell 0.8.0). The primary focus is the implementation of "Opaque Pointer" safety, requiring explicit type tracking throughout the codegen. It also introduces a graphical build manager for the toolchain. Changes: - **LLVM Backend Upgrade**: - Upgraded Inkwell to 0.8.0 and LLVM-sys to 211.0.0. - Migrated from typed pointers to **Opaque Pointers**. - Updated all `build_load`, `build_store`, and `build_gep` calls to provide explicit LLVM types, as pointers no longer carry pointee information. - Refactored `address.rs` and `lvalue.rs` to infer Wave-level types during IR generation to ensure correct instruction emission. - **Optimization & Codegen**: - Replaced the legacy `PassManagerBuilder` with the new LLVM **PassBuilder**, supporting modern optimization pipelines (e.g., `default<O3>`). - Improved aggregate handling in function calls with better size-based packing/unpacking and bitcasting. - Adjusted IO logic (`printf`/`scanf`) to manually track C-string status since LLVM `ptr` is now ambiguous. - **Lexer Refactoring**: - Modularized the lexer by splitting logic into `core`, `cursor`, `trivia`, `literals`, `ident`, and `scan` modules. - Cleaned up internal imports and visibility. - **Build System & Tooling**: - Added a Tkinter-based **GUI Build Manager** to `x.py` for managing targets and installations visually. - Improved cross-compilation support in `x.py` for `x86_64-pc-windows-gnu` targets from Linux hosts using MinGW LLVM prefixes. - Fixed target directory pathing in the backend. - **Bug Fixes**: - Fixed type promotion for C varargs in `printf` (e.g., promoting small integers to `i32` and floats to `double`). This update modernizes the compiler backend and prepares the architecture for future LLVM versions while providing a more user-friendly build interface. Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> * action update Signed-off-by: LunaStev <luna@lunastev.org> --------- Signed-off-by: LunaStev <luna@lunastev.org>
1 parent 31ccaf7 commit bf79572

36 files changed

+2482
-1170
lines changed

.github/workflows/rust.yml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v4
18-
- name: Install LLVM 14
18+
- name: Install LLVM 21
1919
run: |
2020
sudo apt-get update
21-
sudo apt-get install llvm-14 llvm-14-dev clang-14 libclang-14-dev lld-14
22-
sudo ln -s /usr/lib/llvm-14/lib/libLLVM-14.so /usr/lib/libllvm-14.so
23-
- name: Set LLVM environment variables
24-
run: |
25-
export LLVM_SYS_140_PREFIX=/usr/lib/llvm-14
21+
sudo apt-get install -y wget software-properties-common
22+
wget https://apt.llvm.org/llvm.sh
23+
chmod +x llvm.sh
24+
sudo ./llvm.sh 21
25+
2626
- name: Build
2727
run: |
28-
source ~/.bashrc
28+
export LLVM_SYS_211_PREFIX=/usr/lib/llvm-21
2929
cargo clean
3030
cargo build --verbose
3131
- name: Run tests
@@ -37,32 +37,18 @@ jobs:
3737
steps:
3838
- uses: actions/checkout@v4
3939

40-
- name: Install LLVM 14
40+
- name: Install LLVM 21
4141
run: |
4242
brew update
43-
brew install llvm@14
43+
brew install llvm@21
4444
45-
- name: Set LLVM environment variables
45+
- name: Set LLVM env
4646
run: |
47-
if [ -d "/usr/local/opt/llvm@14" ]; then
48-
echo "LLVM_SYS_140_PREFIX=/usr/local/opt/llvm@14" >> $GITHUB_ENV
49-
echo "PATH=/usr/local/opt/llvm@14/bin:$PATH" >> $GITHUB_ENV
50-
else
51-
echo "LLVM_SYS_140_PREFIX=/opt/homebrew/opt/llvm@14" >> $GITHUB_ENV
52-
echo "PATH=/opt/homebrew/opt/llvm@14/bin:$PATH" >> $GITHUB_ENV
53-
fi
47+
echo "LLVM_SYS_211_PREFIX=$(brew --prefix llvm@21)" >> $GITHUB_ENV
48+
echo "LLVM_CONFIG_PATH=$(brew --prefix llvm@21)/bin/llvm-config" >> $GITHUB_ENV
5449
5550
- name: Build
5651
run: cargo build --verbose
5752

5853
- name: Run tests
5954
run: cargo test --verbose
60-
61-
build-windows:
62-
runs-on: windows-latest
63-
64-
steps:
65-
- uses: actions/checkout@v4
66-
67-
- name: Run Check
68-
run: cargo check --verbose
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// SPDX-License-Identifier: MPL-2.0
1111

12-
use super::{Lexer};
12+
use crate::{Lexer};
1313

1414
impl<'a> Lexer<'a> {
1515
pub(crate) fn is_at_end(&self) -> bool {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// SPDX-License-Identifier: MPL-2.0
1111

1212
use crate::token::*;
13-
use super::{Lexer, Token};
13+
use crate::{Lexer, Token};
1414

1515
impl<'a> Lexer<'a> {
1616
pub(crate) fn identifier(&mut self) -> String {

front/lexer/src/lexer/mod.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

front/lexer/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
//
1010
// SPDX-License-Identifier: MPL-2.0
1111

12-
pub mod lexer;
1312
pub mod token;
13+
pub mod core;
14+
pub mod cursor;
15+
pub mod trivia;
16+
pub mod literals;
17+
pub mod ident;
18+
pub mod scan;
1419

15-
pub use lexer::*;
20+
pub use crate::core::{Lexer, Token};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// SPDX-License-Identifier: MPL-2.0
1111

1212
use crate::token::*;
13-
use super::{Lexer, Token};
13+
use crate::{Lexer, Token};
1414

1515
impl<'a> Lexer<'a> {
1616
pub fn next_token(&mut self) -> Token {

llvm/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
name = "llvm"
33
version = "0.1.0"
44
edition = "2021"
5-
build = "build.rs"
65

76
[dependencies]
87
parser = { path = "../front/parser" }
98
lexer = { path = "../front/lexer" }
109
error = { path = "../front/error" }
11-
inkwell = { version = "0.5.0", features = ["llvm14-0"] }
12-
llvm-sys = { version = "140.1.3", features = ["no-llvm-linking"] }
10+
inkwell = { version = "0.8.0", features = ["llvm21-1"] }
11+
llvm-sys = { version = "211.0.0", features = ["prefer-dynamic"] }

0 commit comments

Comments
 (0)