Skip to content

Commit 495ffd7

Browse files
removed entrypoint requirement
1 parent d27dd09 commit 495ffd7

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

src/adapter.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::esbmc::ESBMCParseResult;
99
use crate::irep::Irept;
1010
use log::trace;
1111

12-
pub fn cbmc2esbmc(entrypoint: &str, input: &str, output: &str) {
12+
pub fn cbmc2esbmc(input: &str, output: &str) {
1313
trace!("cbmc2esbmc mode, {} {}", input, output);
1414

15-
let result = crate::cbmc::process_cbmc_file(input, entrypoint);
15+
let result = crate::cbmc::process_cbmc_file(input);
1616
std::fs::remove_file(output).ok();
1717

1818
let converted = ESBMCParseResult::from(result);
@@ -22,7 +22,7 @@ pub fn cbmc2esbmc(entrypoint: &str, input: &str, output: &str) {
2222
}
2323

2424
trait IrepAdapter {
25-
fn to_esbmc_irep(self, entrypoint: &str) -> Irept;
25+
fn to_esbmc_irep(self) -> Irept;
2626
}
2727

2828
pub fn irep_contains(irep: &Irept, id: &str) -> bool {
@@ -57,7 +57,6 @@ impl From<CBMCParseResult> for ESBMCParseResult {
5757
symbols_irep: Vec::with_capacity(data.symbols_irep.len()),
5858
functions_irep: Vec::with_capacity(data.functions_irep.len()),
5959
};
60-
let entrypoint = &data.entrypoint;
6160

6261
// First, we need to walk through the symbols and map all the
6362
// ref-types into concrete types
@@ -70,7 +69,6 @@ impl From<CBMCParseResult> for ESBMCParseResult {
7069
sym.stype.fix_type(&type_cache);
7170
type_cache.insert(tagname, sym.stype.clone());
7271
}
73-
adapted.symbols_irep.push(sym.to_esbmc_irep(entrypoint));
7472
}
7573

7674
// A symbol might have been defined later, we need to check everything again
@@ -103,8 +101,8 @@ impl From<CBMCParseResult> for ESBMCParseResult {
103101
}
104102
}
105103

106-
let function_name = esbmcfixes::fix_name(&foo.name, entrypoint);
107-
let mut function_irep = foo.to_esbmc_irep(entrypoint);
104+
let function_name = esbmcfixes::fix_name(&foo.name);
105+
let mut function_irep = foo.to_esbmc_irep();
108106
function_irep.fix_type(&type_cache);
109107
adapted.functions_irep.push((function_name, function_irep));
110108
}
@@ -116,10 +114,7 @@ impl From<CBMCParseResult> for ESBMCParseResult {
116114
mod esbmcfixes {
117115
use super::HashSet;
118116
use super::Irept;
119-
pub fn fix_name(name: &str, entry: &str) -> String {
120-
if name == entry {
121-
return "__ESBMC_main".to_string();
122-
}
117+
pub fn fix_name(name: &str) -> String {
123118
return String::from(name);
124119
}
125120

@@ -210,7 +205,7 @@ mod esbmcfixes {
210205
"bitand",
211206
"struct",
212207
"return",
213-
"r_ok"
208+
"r_ok",
214209
]
215210
.map(|x| x.to_string()),
216211
);
@@ -248,7 +243,7 @@ mod esbmcfixes {
248243
}
249244

250245
impl IrepAdapter for CBMCInstruction {
251-
fn to_esbmc_irep(self, entrypoint: &str) -> Irept {
246+
fn to_esbmc_irep(self) -> Irept {
252247
let mut result = Irept::default();
253248
assert_ne!(self.instr_type, 19);
254249

@@ -301,19 +296,19 @@ impl IrepAdapter for CBMCInstruction {
301296
}
302297

303298
impl IrepAdapter for CBMCFunction {
304-
fn to_esbmc_irep(self, entrypoint: &str) -> Irept {
299+
fn to_esbmc_irep(self) -> Irept {
305300
let mut result = Irept::from("goto-program");
306301
for instr in self.instructions {
307302
if instr.code.id == "nil" || instr.code.named_subt["statement"].id != "output" {
308-
result.subt.push(instr.to_esbmc_irep(entrypoint));
303+
result.subt.push(instr.to_esbmc_irep());
309304
}
310305
}
311306
result
312307
}
313308
}
314309

315310
impl IrepAdapter for CBMCSymbol {
316-
fn to_esbmc_irep(self, entrypoint: &str) -> Irept {
311+
fn to_esbmc_irep(self) -> Irept {
317312
let mut result = Irept::default();
318313
result.named_subt.insert("type".to_string(), self.stype);
319314
result.named_subt.insert("symvalue".to_string(), self.value);
@@ -330,8 +325,8 @@ impl IrepAdapter for CBMCSymbol {
330325
.named_subt
331326
.insert("mode".to_string(), Irept::from(&self.mode));
332327

333-
let name = esbmcfixes::fix_name(self.name.as_str(), entrypoint);
334-
let basename = esbmcfixes::fix_name(self.base_name.as_str(), entrypoint);
328+
let name = esbmcfixes::fix_name(self.name.as_str());
329+
let basename = esbmcfixes::fix_name(self.base_name.as_str());
335330

336331
assert_ne!(basename, "num::verify::checked_unchecked_add_i8");
337332

@@ -765,6 +760,8 @@ mod tests {
765760
Err(err) => panic!("Could not get ESBMC bin. {}", err),
766761
};
767762
let output = Command::new(esbmc)
763+
.arg("--function")
764+
.arg("__CPROVER__start")
768765
.arg("--binary")
769766
.arg(input_gbf)
770767
.args(args)
@@ -785,9 +782,9 @@ mod tests {
785782
assert_eq!(status, output.status.code().unwrap());
786783
}
787784

788-
use crate::ByteWriter;
789785
use crate::cbmc;
790786
use crate::cbmc2esbmc;
787+
use crate::ByteWriter;
791788

792789
fn run_test(input_c: &str, args: &[&str], expected: i32) {
793790
let cargo_dir = match std::env::var("CARGO_MANIFEST_DIR") {
@@ -800,8 +797,7 @@ mod tests {
800797
let esbmc_gbf = format!("{}.esbmc.goto", input_c);
801798

802799
generate_cbmc_gbf(test_path.to_str().unwrap(), cbmc_gbf.as_str());
803-
804-
cbmc2esbmc("__CPROVER__start", cbmc_gbf.as_str(), esbmc_gbf.as_str());
800+
cbmc2esbmc(cbmc_gbf.as_str(), esbmc_gbf.as_str());
805801
run_esbmc_gbf(&esbmc_gbf, args, expected);
806802
std::fs::remove_file(&cbmc_gbf).ok();
807803
std::fs::remove_file(&esbmc_gbf).ok();
@@ -816,11 +812,7 @@ mod tests {
816812
std::path::Path::new(&cargo_dir).join(format!("resources/test/{}", input_goto));
817813

818814
let esbmc_gbf = format!("{}.goto", input_goto); // TODO: generate UUID!
819-
cbmc2esbmc(
820-
"__CPROVER__start",
821-
test_path.to_str().unwrap(),
822-
esbmc_gbf.as_str(),
823-
);
815+
cbmc2esbmc(test_path.to_str().unwrap(), esbmc_gbf.as_str());
824816
run_esbmc_gbf(&esbmc_gbf, args, expected);
825817
std::fs::remove_file(&esbmc_gbf).ok();
826818
}

src/cbmc.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,13 @@ pub struct CBMCParseResult {
100100
pub reader: ByteReader,
101101
pub symbols_irep: Vec<CBMCSymbol>,
102102
pub functions_irep: Vec<CBMCFunction>,
103-
pub entrypoint: String,
104103
}
105104

106-
pub fn process_cbmc_file(path: &str, entrypoint: &str) -> CBMCParseResult {
105+
pub fn process_cbmc_file(path: &str) -> CBMCParseResult {
107106
let mut result = CBMCParseResult {
108107
reader: ByteReader::read_file(path),
109108
functions_irep: Vec::new(),
110109
symbols_irep: Vec::new(),
111-
entrypoint: String::from(entrypoint),
112110
};
113111

114112
result.reader.check_cbmc_header().unwrap();
@@ -234,6 +232,6 @@ mod tests {
234232
let test_path = std::path::Path::new(&cargo_dir).join("resources/test/hello-gb.goto");
235233
assert!(test_path.exists());
236234

237-
crate::cbmc::process_cbmc_file(test_path.to_str().unwrap(), "__CPROVER__start");
235+
crate::cbmc::process_cbmc_file(test_path.to_str().unwrap());
238236
}
239237
}

src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ enum Commands {
5151

5252
#[derive(Args)]
5353
struct CmdArgs {
54-
entrypoint: String,
5554
input: std::path::PathBuf,
5655
output: std::path::PathBuf,
5756
}
@@ -63,11 +62,7 @@ fn main() {
6362

6463
match cli.command {
6564
Commands::CBMC2ESBMC(args) => {
66-
cbmc2esbmc(
67-
&args.entrypoint,
68-
&args.input.to_str().unwrap(),
69-
args.output.to_str().unwrap(),
70-
);
65+
cbmc2esbmc(&args.input.to_str().unwrap(), args.output.to_str().unwrap());
7166
}
7267
_ => panic!("Command not implemented yet"),
7368
};

0 commit comments

Comments
 (0)