Skip to content

Commit 932041f

Browse files
committed
feat: added check subcommand
1 parent c2bab05 commit 932041f

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use ast_parser::parse_ast_ctx;
2+
use astoir::{run_astoir_hir, run_astoir_mir};
3+
use lexer::lexer::lexer_parse_file;
4+
5+
use crate::{cli::IRLayer, quietlyquit_if_errors};
6+
7+
pub fn run_check(path: String, layer: IRLayer) {
8+
let lexer = lexer_parse_file(&path);
9+
quietlyquit_if_errors!();
10+
11+
let ast = parse_ast_ctx(&lexer.unwrap());
12+
quietlyquit_if_errors!();
13+
14+
match layer {
15+
IRLayer::HIR => {
16+
let hir = run_astoir_hir(ast.unwrap());
17+
quietlyquit_if_errors!();
18+
}
19+
20+
IRLayer::MIR => {
21+
let mir = run_astoir_mir(ast.unwrap());
22+
quietlyquit_if_errors!();
23+
}
24+
}
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub mod check;
2+
3+
#[macro_export]
4+
macro_rules! quietlyquit_if_errors {
5+
() => {
6+
if (diagnostics::has_diagnostics()) {
7+
diagnostics::dump_diagnostics();
8+
std::process::exit(445);
9+
}
10+
};
11+
}

compiler/compiler_main/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
use std::time::Instant;
2+
13
use clap::Parser;
24

35
use crate::{
46
cli::{CLICommand, Cli},
7+
cmds::check::run_check,
58
version::{GIT_HASH, VERSION},
69
};
710

811
pub mod cli;
12+
pub mod cmds;
913
pub mod version;
1014

1115
fn main() {
@@ -16,6 +20,21 @@ fn main() {
1620
println!("Quickfall v{} (commit {})", VERSION, GIT_HASH);
1721
}
1822

23+
CLICommand::Check { input, layer } => {
24+
let start = Instant::now();
25+
let count = input.len();
26+
27+
for file in input {
28+
run_check(file, layer);
29+
}
30+
31+
println!(
32+
"No problems could be found in the {} provided files! Checked in {:?}",
33+
count,
34+
start.elapsed()
35+
)
36+
}
37+
1938
_ => todo!(),
2039
}
2140
}

compiler/diagnostics/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ pub fn dump_diagnostics() {
7070
})
7171
}
7272

73+
pub fn has_diagnostics() -> bool {
74+
DIAGNOSTIC_CONTAINER.with_borrow(|f| return !f.diagnostics.is_empty())
75+
}
76+
7377
pub fn move_current_diagnostic_pos(pos: SpanPosition) {
7478
CURR_DIAGNOSTIC_POS.with_borrow_mut(|f| {
7579
*f = Some(pos);

0 commit comments

Comments
 (0)