Skip to content

Commit

Permalink
feat: Add LLVM backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwtw committed Jan 14, 2024
1 parent a531400 commit 9f795e6
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 34 deletions.
99 changes: 68 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ smallmap = "*"
log = "*"
indexmap = "*"
uuid = { version = "*", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }
inkwell = { version = "*", optional = true, features = ["llvm16-0-no-llvm-linking"] }

[build-dependencies]
cbindgen = "*"
lalrpop = { version = "*", optional = true }
llvm-sys = { version = "160", optional = true, features = ["prefer-dynamic"] }

[features]
default = ["use_lalrpop"]
use_lalrpop = ["lalrpop", "lalrpop-util"]
default = ["use_lalrpop", "llvm_backend"]
use_lalrpop = ["lalrpop", "lalrpop-util"]
llvm_backend = ["inkwell", "llvm-sys"]
37 changes: 37 additions & 0 deletions lib/src/backend/llvm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::backend::*;
use crate::prelude::*;
use inkwell::builder::Builder;
use inkwell::context::Context;
use inkwell::module::Module;

struct LLVMBackendImpl<'ctx> {
ctx: &'ctx Context,
module: Module<'ctx>,
builder: Builder<'ctx>,
}

pub struct LLVMBackend {}

impl CodeGenBackend for LLVMBackend {
type Label = ();

fn new(mgr: UnitsManager, app: ModuleContext) -> Self {
todo!()
}

fn gen_function(self, func: usize) -> Result<Box<dyn TargetCode>, CodeGenError> {
todo!()
}

fn define_label<S: AsRef<str>>(&mut self, label: Option<S>) -> Self::Label {
todo!()
}

fn gen_variable_load(&mut self, variable: &mut Variable) {
todo!()
}

fn gen_operator(&mut self, operator: &mut OperatorExpression) {
todo!()
}
}
3 changes: 3 additions & 0 deletions lib/src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(feature = "llvm_backend")]
mod llvm;
mod lua;

pub use lua::LuaBackend;

use crate::ast::{OperatorExpression, Variable};
Expand Down
2 changes: 1 addition & 1 deletion viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
stc-rs = { path = "../lib" }
stc-rs = { path = "../lib", features = ["llvm_backend", "use_lalrpop"] }
pretty_env_logger = "*"
log = "*"
gtk4 = "*"
Expand Down

0 comments on commit 9f795e6

Please sign in to comment.