Skip to content

Commit ac5e454

Browse files
tautschnigkiro-agentshigoel
authored
Eliminate Python dependency from CBMC pipeline (#576)
The CBMC backend relied on a Python post-processing step (process_json.py) to merge a 4000-line defaults.json of built-in symbols into the Lean-generated symbol table before passing it to symtab2gb. This made the pipeline harder to maintain, required Python as a runtime dependency, and kept critical symbol definitions outside of Lean where they could not benefit from type checking. *Description of changes:* Generate all 38 CBMC built-in symbols directly in Lean (DefaultSymbols.lean), parameterized by ArchConfig and module name, and emit the symbol table in the {"symbolTable": ...} wrapper that symtab2gb expects. This turns the pipeline into a simple two-step flow (strata → symtab2gb) with no Python intermediary. Remove the now-unused Python scripts (process_json.py, defaults.py), defaults.json, and legacy shell wrappers (run_strata_cbmc.sh, compare_cbmc_json.sh). Update all pipeline scripts and documentation to reflect the simplified flow. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: Kiro <kiro-agent@users.noreply.github.com> Co-authored-by: Shilpi Goel <shigoel@gmail.com>
1 parent aa0e403 commit ac5e454

16 files changed

Lines changed: 629 additions & 4338 deletions

File tree

.github/workflows/cbmc.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ jobs:
9595
- name: Run legacy CBMC test (C_Simp)
9696
shell: bash
9797
run: |
98-
export CBMC_DIR="$(dirname $(which cbmc))/"
99-
./Strata/Backends/CBMC/run_strata_cbmc.sh Strata/Backends/CBMC/tests/simpleTest.csimp.st
98+
lake exe StrataToCBMC Strata/Backends/CBMC/tests/simpleTest.csimp.st > symtab.json
99+
symtab2gb symtab.json --out full.goto
100+
goto-instrument --enforce-contract simpleTest full.goto full_checking.goto
101+
OUTPUT=$(cbmc full_checking.goto --function simpleTest --trace)
102+
echo "$OUTPUT"
103+
[[ "$OUTPUT" == *"VERIFICATION SUCCESSFUL"* ]]
100104
- name: Run Python CBMC pipeline tests
101105
shell: bash
102106
run: |

Strata/Backends/CBMC/GOTO/CoreToCProverGOTO.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import Strata.Languages.Core.Verifier
88
import Strata.Backends.CBMC.GOTO.InstToJson
9+
import Strata.Backends.CBMC.GOTO.DefaultSymbols
910
import Strata.Backends.CBMC.GOTO.LambdaToCProverGOTO
1011
import Strata.DL.Imperative.ToCProverGOTO
1112

@@ -261,7 +262,9 @@ def getGotoJson (programName : String) (env : Program) : IO CProverGOTO.Json :=
261262
open Strata in
262263
def writeToGotoJson (programName symTabFileName gotoFileName : String) (env : Program) : IO Unit := do
263264
let json ← getGotoJson programName env
264-
IO.FS.writeFile symTabFileName json.symtab.pretty
265+
let symtabObj := match json.symtab with | .obj m => m | _ => .empty
266+
let symtab := CProverGOTO.wrapSymtab symtabObj (moduleName := programName)
267+
IO.FS.writeFile symTabFileName symtab.pretty
265268
IO.FS.writeFile gotoFileName json.goto.pretty
266269

267270
end CoreToGOTO

Strata/Backends/CBMC/GOTO/CoreToGOTOPipeline.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ symtab/goto JSON.
400400
-/
401401
def emitProcWithLifted (Env : Core.Expression.TyEnv) (procName : String)
402402
(ctx : CoreToGOTO.CProverGOTO.Context) (liftedFuncs : List Core.Function)
403-
(extraSyms : Lean.Json)
403+
(extraSyms : Lean.Json) (moduleName : String)
404404
: IO (Lean.Json × Lean.Json) := do
405405
let json ← IO.ofExcept (CoreToGOTO.CProverGOTO.Context.toJson procName ctx)
406406
let mut symtabObj := match json.symtab with | .obj m => m | _ => .empty
@@ -427,7 +427,8 @@ def emitProcWithLifted (Env : Core.Expression.TyEnv) (procName : String)
427427
| .obj m => for (k, v) in m.toList do
428428
symtabObj := symtabObj.insert k v
429429
| _ => pure ()
430-
return (Lean.Json.obj symtabObj, Lean.Json.mkObj [("functions", Lean.Json.arr gotoFns)])
430+
let symtab := CProverGOTO.wrapSymtab symtabObj (moduleName := moduleName)
431+
return (symtab, Lean.Json.mkObj [("functions", Lean.Json.arr gotoFns)])
431432

432433
/-! ## High-level pipeline steps
433434
@@ -493,7 +494,7 @@ public def coreToGotoFiles (tcPgm : Core.Program) (Env : Core.Expression.TyEnv)
493494
| .ok s => pure (Lean.toJson s)
494495
| .error e => throw s!"{e}"
495496
let (symtab, goto) ←
496-
match ← emitProcWithLifted Env procName ctx liftedFuncs extraSyms |>.toBaseIO with
497+
match ← emitProcWithLifted Env procName ctx liftedFuncs extraSyms (moduleName := baseName) |>.toBaseIO with
497498
| .ok r => pure r
498499
| .error e => throw s!"{e}"
499500
let symTabFile := s!"{baseName}.symtab.json"

0 commit comments

Comments
 (0)