Skip to content

Commit 38ba4b5

Browse files
authored
Move symtab2gb to codegen step (#1686)
1 parent fbf0533 commit 38ba4b5

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

+26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::fmt::Write;
3030
use std::io::BufWriter;
3131
use std::iter::FromIterator;
3232
use std::path::Path;
33+
use std::process::Command;
3334
use std::rc::Rc;
3435
use tracing::{debug, warn};
3536

@@ -152,6 +153,7 @@ impl CodegenBackend for GotocCodegenBackend {
152153
if let Some(restrictions) = vtable_restrictions {
153154
write_file(&base_filename, "restrictions.json", &restrictions, pretty);
154155
}
156+
symbol_table_to_gotoc(&tcx, &base_filename);
155157
}
156158
codegen_results(tcx, rustc_metadata, symtab.machine_model())
157159
}
@@ -388,3 +390,27 @@ fn collect_codegen_items<'tcx>(gcx: &GotocCtx<'tcx>) -> Vec<MonoItem<'tcx>> {
388390
}
389391
}
390392
}
393+
394+
fn symbol_table_to_gotoc(tcx: &TyCtxt, file: &Path) {
395+
let output_filename = file.with_extension("symtab.out");
396+
let input_filename = file.with_extension("symtab.json");
397+
398+
let args = vec![
399+
input_filename.clone().into_os_string(),
400+
"--out".into(),
401+
output_filename.into_os_string(),
402+
];
403+
// TODO get symtab2gb path from self
404+
let mut cmd = Command::new("symtab2gb");
405+
cmd.args(args);
406+
debug!("calling: `{:?} {:?}`", cmd.get_program(), cmd.get_args());
407+
408+
if cmd.status().is_err() {
409+
let err_msg = format!(
410+
"Failed to generate goto model:\n\tsymtab2gb failed on file {}.",
411+
input_filename.display()
412+
);
413+
tcx.sess.err(&err_msg);
414+
tcx.sess.abort_if_errors();
415+
}
416+
}

kani-driver/src/call_symtab.rs

-30
This file was deleted.

kani-driver/src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod call_cbmc_viewer;
1616
mod call_goto_cc;
1717
mod call_goto_instrument;
1818
mod call_single_file;
19-
mod call_symtab;
2019
mod cbmc_output_parser;
2120
mod concrete_playback;
2221
mod harness_runner;
@@ -44,7 +43,8 @@ fn cargokani_main(input_args: Vec<OsString>) -> Result<()> {
4443

4544
let mut goto_objs: Vec<PathBuf> = Vec::new();
4645
for symtab in &outputs.symtabs {
47-
goto_objs.push(ctx.symbol_table_to_gotoc(symtab)?);
46+
let goto_obj_filename = symtab.with_extension("out");
47+
goto_objs.push(goto_obj_filename);
4848
}
4949

5050
if ctx.args.only_codegen {
@@ -81,7 +81,8 @@ fn standalone_main() -> Result<()> {
8181

8282
let outputs = ctx.compile_single_rust_file(&args.input)?;
8383

84-
let goto_obj = ctx.symbol_table_to_gotoc(&outputs.symtab)?;
84+
let goto_obj = outputs.symtab.with_extension("out");
85+
ctx.record_temporary_files(&[&goto_obj]);
8586

8687
if ctx.args.only_codegen {
8788
return Ok(());

tests/cargo-ui/dry-run/expected

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
KANIFLAGS="--goto-c --log-level=warn --assertion-reach-checks --reachability=legacy -C symbol-mangling-version=v0" RUSTC=
22
RUSTFLAGS="--kani-flags" cargo rustc
3-
symtab2gb
43
goto-cc
54
goto-cc
65
--function harness

tests/expected/dry-run/expected

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
kani-compiler --goto-c
2-
symtab2gb
32
goto-cc
43
--function harness
54
goto-instrument

0 commit comments

Comments
 (0)