-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c8d8414
Showing
8 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
on: [push, pull_request] | ||
|
||
name: Test | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install LLVM 18 | ||
run: | | ||
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz | ||
tar -xvf clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz | ||
- name: ls llvm de merde | ||
run: ls clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04 | ||
- name: Install toolchain | ||
run: rustup show | ||
|
||
- name: Run cargo fmt | ||
run: cargo fmt -- --check | ||
|
||
- name: Run cargo clippy | ||
run: | | ||
export LLVM_SYS_180_PREFIX="clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04" | ||
cargo clippy --all-features -- -D warnings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
*.ll |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "llvm-to-cairo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
inkwell = {git = "https://github.com/TheDan64/inkwell", features = ["llvm18-0"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[no_mangle] | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[toolchain] | ||
channel = "1.79.0" | ||
components = ["rustfmt", "clippy"] | ||
profile = "minimal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Check if a file is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <file_name>" | ||
exit 1 | ||
fi | ||
|
||
# Get the Rust file from the first argument | ||
rust_file="examples/$1/$1.rs" | ||
out_file="examples/$1/$1.ll" | ||
|
||
# Check if the file exists | ||
if [ ! -f "$rust_file" ]; then | ||
echo "File not found: $rust_file" | ||
exit 1 | ||
fi | ||
|
||
|
||
# Compile the Rust file to LLVM IR | ||
rustc --crate-type=lib -C opt-level=3 --emit=llvm-ir "$rust_file" -o $out_file | ||
|
||
echo "LLVM IR generated and saved to $out_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::path::Path; | ||
|
||
use inkwell::{context::Context, memory_buffer::MemoryBuffer}; | ||
|
||
pub fn compile(path: &str) { | ||
// Initialize LLVM context | ||
let context = Context::create(); | ||
// Parse the LLVM IR | ||
let module = context | ||
.create_module_from_ir( | ||
MemoryBuffer::create_from_file(Path::new(path)).expect("Failed to load llvm file"), | ||
) | ||
.expect("Failed to parse LLVM IR"); | ||
println!("Compiling LLVM IR {}", module.to_string()); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_compiles() { | ||
compile("examples/add/add.ll"); | ||
} | ||
} |