@@ -9,10 +9,10 @@ use crate::esbmc::ESBMCParseResult;
9
9
use crate :: irep:: Irept ;
10
10
use log:: trace;
11
11
12
- pub fn cbmc2esbmc ( input : & str , output : & str ) {
12
+ pub fn cbmc2esbmc ( entrypoint : & str , input : & str , output : & str ) {
13
13
trace ! ( "cbmc2esbmc mode, {} {}" , input, output) ;
14
14
15
- let result = crate :: cbmc:: process_cbmc_file ( input) ;
15
+ let result = crate :: cbmc:: process_cbmc_file ( input, entrypoint ) ;
16
16
std:: fs:: remove_file ( output) . ok ( ) ;
17
17
18
18
let converted = ESBMCParseResult :: from ( result) ;
@@ -22,7 +22,7 @@ pub fn cbmc2esbmc(input: &str, output: &str) {
22
22
}
23
23
24
24
trait IrepAdapter {
25
- fn to_esbmc_irep ( self ) -> Irept ;
25
+ fn to_esbmc_irep ( self , entrypoint : & str ) -> Irept ;
26
26
}
27
27
28
28
pub fn irep_contains ( irep : & Irept , id : & str ) -> bool {
@@ -57,6 +57,7 @@ impl From<CBMCParseResult> for ESBMCParseResult {
57
57
symbols_irep : Vec :: with_capacity ( data. symbols_irep . len ( ) ) ,
58
58
functions_irep : Vec :: with_capacity ( data. functions_irep . len ( ) ) ,
59
59
} ;
60
+ let entrypoint = & data. entrypoint ;
60
61
61
62
// First, we need to walk through the symbols and map all the
62
63
// ref-types into concrete types
@@ -69,7 +70,7 @@ impl From<CBMCParseResult> for ESBMCParseResult {
69
70
sym. stype . fix_type ( & type_cache) ;
70
71
type_cache. insert ( tagname, sym. stype . clone ( ) ) ;
71
72
}
72
- adapted. symbols_irep . push ( sym. to_esbmc_irep ( ) ) ;
73
+ adapted. symbols_irep . push ( sym. to_esbmc_irep ( entrypoint ) ) ;
73
74
}
74
75
75
76
// A symbol might have been defined later, we need to check everything again
@@ -102,8 +103,8 @@ impl From<CBMCParseResult> for ESBMCParseResult {
102
103
}
103
104
}
104
105
105
- let function_name = esbmcfixes:: fix_name ( & foo. name ) ;
106
- let mut function_irep = foo. to_esbmc_irep ( ) ;
106
+ let function_name = esbmcfixes:: fix_name ( & foo. name , entrypoint ) ;
107
+ let mut function_irep = foo. to_esbmc_irep ( entrypoint ) ;
107
108
function_irep. fix_type ( & type_cache) ;
108
109
adapted. functions_irep . push ( ( function_name, function_irep) ) ;
109
110
}
@@ -115,32 +116,11 @@ impl From<CBMCParseResult> for ESBMCParseResult {
115
116
mod esbmcfixes {
116
117
use super :: HashSet ;
117
118
use super :: Irept ;
118
- pub fn fix_name ( name : & str ) -> String {
119
- match name {
120
- "__CPROVER__start" => String :: from ( "__ESBMC_main" ) ,
121
- "_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_add_i8" => {
122
- "__ESBMC_main" . to_string ( )
123
- }
124
- "_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_sub_i8" => {
125
- "__ESBMC_main" . to_string ( )
126
- }
127
- "_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_mul_i8" => {
128
- "__ESBMC_main" . to_string ( )
129
- }
130
- "_RNvNtNtCsesPP5EAma4_4core3num6verify24checked_unchecked_shr_i8" => {
131
- "__ESBMC_main" . to_string ( )
132
- }
133
- "_RNvNtNtCsesPP5EAma4_4core3num6verify25checked_unchecked_add_i16" => {
134
- "__ESBMC_main" . to_string ( )
135
- }
136
- "_RNvNtNtCsesPP5EAma4_4core3num6verify25checked_unchecked_add_i32" => {
137
- "__ESBMC_main" . to_string ( )
138
- }
139
- "_RNvNtNtCsesPP5EAma4_4core3num6verify25checked_unchecked_add_i64" => {
140
- "__ESBMC_main" . to_string ( )
141
- }
142
- _ => String :: from ( name) ,
119
+ pub fn fix_name ( name : & str , entry : & str ) -> String {
120
+ if name == entry {
121
+ return "__ESBMC_main" . to_string ( ) ;
143
122
}
123
+ return String :: from ( name) ;
144
124
}
145
125
146
126
pub fn fix_expression ( irep : & mut Irept ) {
@@ -233,7 +213,7 @@ mod esbmcfixes {
233
213
}
234
214
235
215
impl IrepAdapter for CBMCInstruction {
236
- fn to_esbmc_irep ( self ) -> Irept {
216
+ fn to_esbmc_irep ( self , entrypoint : & str ) -> Irept {
237
217
let mut result = Irept :: default ( ) ;
238
218
assert_ne ! ( self . instr_type, 19 ) ;
239
219
@@ -286,19 +266,19 @@ impl IrepAdapter for CBMCInstruction {
286
266
}
287
267
288
268
impl IrepAdapter for CBMCFunction {
289
- fn to_esbmc_irep ( self ) -> Irept {
269
+ fn to_esbmc_irep ( self , entrypoint : & str ) -> Irept {
290
270
let mut result = Irept :: from ( "goto-program" ) ;
291
271
for instr in self . instructions {
292
272
if instr. code . id == "nil" || instr. code . named_subt [ "statement" ] . id != "output" {
293
- result. subt . push ( instr. to_esbmc_irep ( ) ) ;
273
+ result. subt . push ( instr. to_esbmc_irep ( entrypoint ) ) ;
294
274
}
295
275
}
296
276
result
297
277
}
298
278
}
299
279
300
280
impl IrepAdapter for CBMCSymbol {
301
- fn to_esbmc_irep ( self ) -> Irept {
281
+ fn to_esbmc_irep ( self , entrypoint : & str ) -> Irept {
302
282
let mut result = Irept :: default ( ) ;
303
283
result. named_subt . insert ( "type" . to_string ( ) , self . stype ) ;
304
284
result. named_subt . insert ( "symvalue" . to_string ( ) , self . value ) ;
@@ -315,8 +295,8 @@ impl IrepAdapter for CBMCSymbol {
315
295
. named_subt
316
296
. insert ( "mode" . to_string ( ) , Irept :: from ( & self . mode ) ) ;
317
297
318
- let name = esbmcfixes:: fix_name ( self . name . as_str ( ) ) ;
319
- let basename = esbmcfixes:: fix_name ( self . base_name . as_str ( ) ) ;
298
+ let name = esbmcfixes:: fix_name ( self . name . as_str ( ) , entrypoint ) ;
299
+ let basename = esbmcfixes:: fix_name ( self . base_name . as_str ( ) , entrypoint ) ;
320
300
321
301
assert_ne ! ( basename, "num::verify::checked_unchecked_add_i8" ) ;
322
302
@@ -786,7 +766,7 @@ mod tests {
786
766
787
767
generate_cbmc_gbf ( test_path. to_str ( ) . unwrap ( ) , cbmc_gbf. as_str ( ) ) ;
788
768
789
- cbmc2esbmc ( cbmc_gbf. as_str ( ) , esbmc_gbf. as_str ( ) ) ;
769
+ cbmc2esbmc ( "__CPROVER__start" , cbmc_gbf. as_str ( ) , esbmc_gbf. as_str ( ) ) ;
790
770
run_esbmc_gbf ( & esbmc_gbf, args, expected) ;
791
771
std:: fs:: remove_file ( & cbmc_gbf) . ok ( ) ;
792
772
std:: fs:: remove_file ( & esbmc_gbf) . ok ( ) ;
@@ -801,7 +781,11 @@ mod tests {
801
781
std:: path:: Path :: new ( & cargo_dir) . join ( format ! ( "resources/test/{}" , input_goto) ) ;
802
782
803
783
let esbmc_gbf = format ! ( "{}.goto" , input_goto) ; // TODO: generate UUID!
804
- cbmc2esbmc ( test_path. to_str ( ) . unwrap ( ) , esbmc_gbf. as_str ( ) ) ;
784
+ cbmc2esbmc (
785
+ "__CPROVER__start" ,
786
+ test_path. to_str ( ) . unwrap ( ) ,
787
+ esbmc_gbf. as_str ( ) ,
788
+ ) ;
805
789
run_esbmc_gbf ( & esbmc_gbf, args, expected) ;
806
790
std:: fs:: remove_file ( & esbmc_gbf) . ok ( ) ;
807
791
}
0 commit comments