Skip to content

Commit ef71ebb

Browse files
committed
[driver,filer] implement bitcode file writing and dump REPL command
1 parent 013896b commit ef71ebb

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/driver.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ pub fn main_loop(stage: Stage) {
111111
Err(err) => print!("Error occured during loading: {}\n", err)
112112
};
113113
continue;
114+
} else if &input[0..5] == ".dump" {
115+
let mut path = input[6..].to_string();
116+
match path.pop() {
117+
Some(_) => (),
118+
None => {
119+
print!("Error occured during dumping: empty path\n");
120+
continue;
121+
}
122+
};
123+
match filer::dump_bitcode(&path, ir_container.get_module_provider()) {
124+
Ok(_) => (),
125+
Err(_) => print!("Error occured during dumping\n")
126+
};
127+
continue;
128+
} else if input.as_str() == ".help\n" {
129+
print!("Enter Kaleidoscope expressions or special commands.\n");
130+
print!("Special commands are:\n");
131+
print!(".quit -- quit\n");
132+
print!(".load <path> -- load .ks file\n");
133+
print!(".dump <path> -- dump bitcode of currently open module\n");
134+
print!(".help -- show this help message\n");
135+
continue;
114136
//< ch-0 ch-1 ch-2 ch-3 parser-driver
115137
}
116138

src/filer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::path::Path;
88

99
use llvm_sys::prelude::LLVMValueRef;
1010

11+
use iron_llvm::bitcode::write_bitcode_to_file;
12+
1113
use builder;
1214
use builder::IRBuilder;
1315
use lexer;
@@ -85,3 +87,7 @@ pub fn load_stdlib(parser_settings: &mut parser::ParserSettings,
8587

8688
Ok(try!(load_ks(path, parser_settings, context, module_provider)))
8789
}
90+
91+
pub fn dump_bitcode(path: &str, module_provider: &mut builder::ModuleProvider) -> Result<(), ()> {
92+
write_bitcode_to_file(module_provider.get_module(), path)
93+
}

0 commit comments

Comments
 (0)