Skip to content

Commit b1b5726

Browse files
committed
create binary in build process
1 parent 2c00c26 commit b1b5726

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

examples/cool_app/config.toml

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

examples/cool_app/lib/math.lv

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

examples/cool_app/main.lv

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

examples/cool_app/num.lv

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/blush/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
blush::combiner::Combiner, checker::Checker,
66
codegen::emitters::x86_64_linux_nasm::CodeGenerator, ir::IRGenerator, parser::Parser,
77
};
8+
use std::fs::File;
9+
use std::io::Write;
810
use std::{
911
error::Error,
1012
fs,
@@ -18,7 +20,7 @@ pub mod printer;
1820
pub struct Blush {}
1921

2022
impl Blush {
21-
pub fn build(path: String) -> Result<(), Box<dyn Error>> {
23+
pub fn build(path: &str, just_asm: bool) -> Result<(), Box<dyn Error>> {
2224
let path_buf = PathBuf::from(path);
2325
let file_tree = collect_files(&path_buf)?;
2426

@@ -69,7 +71,13 @@ impl Blush {
6971
let ir = IRGenerator::new(checker.types).program_ir(&checked_program);
7072
let asm = CodeGenerator::new().gen_asm(&ir);
7173

72-
println!("\n---\n{asm}\n---\n");
74+
if just_asm {
75+
println!("\n{asm}\n");
76+
} else {
77+
let path = Path::new(path);
78+
let mut out_file = File::create(path.join("out.asm"))?;
79+
out_file.write_all(asm.as_bytes())?;
80+
}
7381

7482
Ok(())
7583
}

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION");
2323
struct Cli {
2424
#[command(subcommand)]
2525
command: Commands,
26+
27+
#[arg(long)]
28+
asm: bool,
2629
}
2730

2831
#[derive(Subcommand)]
@@ -39,7 +42,7 @@ fn main() {
3942
match cli.command {
4043
Commands::Build { path } => {
4144
println!();
42-
let res = Blush::build(path);
45+
let res = Blush::build(&path, cli.asm);
4346
match res {
4447
Ok(()) => {
4548
blush::printer::success("Build complete!");

0 commit comments

Comments
 (0)