@@ -137,20 +137,25 @@ def run_cmd(cmd, label=None, cwd=None, env=None, output_to=None, quiet=False, ve
137
137
138
138
return process .returncode
139
139
140
+ def rustc_flags (mangler , symbol_table_passes ):
141
+ flags = [
142
+ "-Z" , "codegen-backend=gotoc" ,
143
+ "-Z" , "trim-diagnostic-paths=no" ,
144
+ "-Z" , f"symbol-mangling-version={ mangler } " ,
145
+ "-Z" , f"symbol_table_passes={ ' ' .join (symbol_table_passes )} " ,
146
+ "-Z" , "human_readable_cgu_names" ,
147
+ f"--cfg={ RMC_CFG } " ]
148
+ if "RUSTFLAGS" in os .environ :
149
+ flags += os .environ ["RUSTFLAGS" ].split (" " )
150
+ return flags
151
+
140
152
# Generates a symbol table from a rust file
141
153
def compile_single_rust_file (input_filename , base , output_filename , verbose = False , debug = False , keep_temps = False , mangler = "v0" , dry_run = False , use_abs = False , abs_type = "std" , symbol_table_passes = []):
142
154
if not keep_temps :
143
155
atexit .register (delete_file , output_filename )
144
156
atexit .register (delete_file , base + ".type_map.json" )
145
157
146
- build_cmd = [RMC_RUSTC_EXE ,
147
- "-Z" , "codegen-backend=gotoc" ,
148
- "-Z" , "trim-diagnostic-paths=no" ,
149
- "-Z" , f"symbol-mangling-version={ mangler } " ,
150
- "-Z" , f"symbol_table_passes={ ' ' .join (symbol_table_passes )} " ,
151
- "--crate-type=lib" ,
152
- "-Z" , "human_readable_cgu_names" ,
153
- f"--cfg={ RMC_CFG } " ]
158
+ build_cmd = [RMC_RUSTC_EXE , "--crate-type=lib" ] + rustc_flags (mangler , symbol_table_passes )
154
159
155
160
if use_abs :
156
161
build_cmd += ["-Z" , "force-unstable-if-unmarked=yes" ,
@@ -159,8 +164,6 @@ def compile_single_rust_file(input_filename, base, output_filename, verbose=Fals
159
164
160
165
build_cmd += ["-o" , base + ".o" , input_filename ]
161
166
162
- if "RUSTFLAGS" in os .environ :
163
- build_cmd += os .environ ["RUSTFLAGS" ].split (" " )
164
167
build_env = os .environ
165
168
if debug :
166
169
add_rmc_rustc_debug_to_env (build_env )
@@ -171,19 +174,9 @@ def compile_single_rust_file(input_filename, base, output_filename, verbose=Fals
171
174
def cargo_build (crate , target_dir , verbose = False , debug = False , mangler = "v0" , dry_run = False , symbol_table_passes = []):
172
175
ensure (os .path .isdir (crate ), f"Invalid path to crate: { crate } " )
173
176
174
- rustflags = [
175
- "-Z" , "codegen-backend=gotoc" ,
176
- "-Z" , "trim-diagnostic-paths=no" ,
177
- "-Z" , f"symbol-mangling-version={ mangler } " ,
178
- "-Z" , f"symbol_table_passes={ ' ' .join (symbol_table_passes )} " ,
179
- "-Z" , "human_readable_cgu_names" ,
180
- f"--cfg={ RMC_CFG } " ]
181
- rustflags = " " .join (rustflags )
182
- if "RUSTFLAGS" in os .environ :
183
- rustflags = os .environ ["RUSTFLAGS" ] + " " + rustflags
184
-
177
+ rustflags = rustc_flags (mangler , symbol_table_passes )
185
178
build_cmd = ["cargo" , "build" , "--lib" , "--target-dir" , str (target_dir )]
186
- build_env = {"RUSTFLAGS" : rustflags ,
179
+ build_env = {"RUSTFLAGS" : " " . join ( rustflags ) ,
187
180
"RUSTC" : RMC_RUSTC_EXE ,
188
181
"PATH" : os .environ ["PATH" ],
189
182
}
@@ -198,16 +191,25 @@ def append_unwind_tip(text):
198
191
return text + unwind_tip
199
192
200
193
# Generates a goto program from a symbol table
201
- def symbol_table_to_gotoc (json_filename , cbmc_filename , verbose = False , keep_temps = False , dry_run = False ):
202
- if not keep_temps :
203
- atexit .register (delete_file , cbmc_filename )
204
- cmd = ["symtab2gb" , json_filename , "--out" , cbmc_filename ]
205
- return run_cmd (cmd , label = "to-gotoc" , verbose = verbose , dry_run = dry_run )
194
+ def symbol_table_to_gotoc (json_files , verbose = False , keep_temps = False , dry_run = False ):
195
+ out_files = []
196
+ for json in json_files :
197
+ out_file = json + ".out"
198
+ out_files .append (out_file )
199
+ if not keep_temps :
200
+ atexit .register (delete_file , out_file )
201
+
202
+ cmd = ["symtab2gb" , json , "--out" , out_file ]
203
+ if run_cmd (cmd , label = "to-gotoc" , verbose = verbose , dry_run = dry_run ) != EXIT_CODE_SUCCESS :
204
+ raise Exception ("Failed to run command: {}" .format (" " .join (cmd )))
205
+
206
+ return out_files
206
207
207
208
# Links in external C programs into a goto program
208
- def link_c_lib (src , dst , c_lib , verbose = False , quiet = False , function = "main" , dry_run = False ):
209
- cmd = ["goto-cc" ] + ["--function" , function ] + [src ] + c_lib + ["-o" , dst ]
210
- return run_cmd (cmd , label = "goto-cc" , verbose = verbose , quiet = quiet , dry_run = dry_run )
209
+ def link_c_lib (srcs , dst , c_lib , verbose = False , quiet = False , function = "main" , dry_run = False ):
210
+ cmd = ["goto-cc" ] + ["--function" , function ] + srcs + c_lib + ["-o" , dst ]
211
+ if run_cmd (cmd , label = "goto-cc" , verbose = verbose , quiet = quiet , dry_run = dry_run ) != EXIT_CODE_SUCCESS :
212
+ raise Exception ("Failed to run command: {}" .format (" " .join (cmd )))
211
213
212
214
# Runs CBMC on a goto program
213
215
def run_cbmc (cbmc_filename , cbmc_args , verbose = False , quiet = False , dry_run = False ):
0 commit comments