Skip to content

Commit 5510645

Browse files
committed
feat: added llvm as an optional package
1 parent 40482a6 commit 5510645

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

compiler/compiler_main/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ astoir = { path = "../astoir" }
88
ast = { path = "../ast" }
99
ast_parser = { path = "../ast_parser" }
1010
lexer = { path = "../lexer" }
11-
llvm_ir_bridge = { path = "../llvm_ir_bridge" }
11+
llvm_ir_bridge = { path = "../llvm_ir_bridge", optional = true }
1212
diagnostics = { path = "../diagnostics" }
13-
compiler_utils = { path = "../compiler_utils"}
13+
compiler_utils = { path = "../compiler_utils" }
14+
15+
[features]
16+
llvm = ["llvm_ir_bridge"]

compiler/compiler_main/src/cmds/astoir.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use ast_parser::parse_ast_ctx;
44
use astoir::{IRLevel, run_astoir_hir, run_astoir_mir};
55
use diagnostics::{DiagnosticResult, dump_diagnostics};
66
use lexer::lexer::lexer_parse_file;
7+
8+
use std::process::exit;
9+
10+
#[cfg(feature = "llvm_ir_bridge")]
711
use llvm_ir_bridge::bridge_llvm;
812

913
pub fn parse_astoir_command(arguments: Vec<String>) {
@@ -43,16 +47,24 @@ pub fn parse_astoir_command(arguments: Vec<String>) {
4347
},
4448

4549
IRLevel::LLVM => {
46-
let ctx = run_astoir_mir(ast.unwrap());
47-
let res_path = arguments[i].clone() + ".llvm";
48-
49-
dump_diagnostics();
50-
51-
let ctx = bridge_llvm(&ctx.unwrap());
52-
53-
dump_diagnostics();
54-
55-
ctx.module.print_to_file(res_path);
50+
#[cfg(feature = "llvm_ir_bridge")] {
51+
let ctx = run_astoir_mir(ast.unwrap());
52+
let res_path = arguments[i].clone() + ".llvm";
53+
54+
dump_diagnostics();
55+
56+
let ctx = bridge_llvm(&ctx.unwrap());
57+
58+
dump_diagnostics();
59+
60+
ctx.module.print_to_file(res_path);
61+
}
62+
63+
#[cfg(not(feature = "llvm_ir_bridge"))] {
64+
println!("LLVM target is not bundled!");
65+
66+
exit(0);
67+
}
5668
}
5769
}
5870
}

0 commit comments

Comments
 (0)