Skip to content

Commit b5e58dc

Browse files
gtreptarv-auditor
andauthored
Generate symbolic arguments based on function signature (#525)
fixes: #495 - Creates a symbolic `KMIR-SYMBOLIC-LOCALS` module with symbolic counterparts to the `#init` and `#execFunction` symbols in `KMIR`. - Modifies `kmir gen-spec` to use `#initSymbolic` in the generated claim. --------- Co-authored-by: devops <[email protected]>
1 parent e50dc1f commit b5e58dc

File tree

6 files changed

+110
-5
lines changed

6 files changed

+110
-5
lines changed

kmir/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kmir"
7-
version = "0.3.116"
7+
version = "0.3.117"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

kmir/src/kmir/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from typing import Final
22

3-
VERSION: Final = '0.3.116'
3+
VERSION: Final = '0.3.117'

kmir/src/kmir/__main__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ def _kmir_gen_spec(opts: GenSpecOpts) -> None:
105105
config_with_cell_vars, _ = split_config_from(config)
106106

107107
lhs = CTerm(config)
108-
new_k_cell = KMIR.Symbols.END_PROGRAM
109-
rhs = CTerm(Subst({'K_CELL': new_k_cell})(config_with_cell_vars))
108+
109+
rhs_subst = Subst({'K_CELL': KMIR.Symbols.END_PROGRAM})
110+
rhs = CTerm(rhs_subst(config_with_cell_vars))
110111
claim, _ = cterm_build_claim(opts.input_file.stem.replace('_', '-'), lhs, rhs)
111112

112113
output_file = opts.output_file

kmir/src/kmir/kdist/mir-semantics/kmir.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
```k
44
requires "kmir-ast.md"
5+
requires "symbolic/kmir-symbolic-locals.md"
56
requires "rt/data.md"
67
requires "rt/configuration.md"
78
requires "lemmas/kmir-lemmas.md"
@@ -615,5 +616,6 @@ The top-level module `KMIR` includes both the control flow constructs (and trans
615616
module KMIR
616617
imports KMIR-CONTROL-FLOW
617618
imports KMIR-LEMMAS
619+
imports KMIR-SYMBOLIC-LOCALS
618620
619621
endmodule
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Symbolic locals for functions
2+
3+
This module contains rules that follow the same structure as `#init` in the KMIR module, however it reads the arguments for the signature of the start symbol and generates symbolic values for them.
4+
5+
```k
6+
requires "../kmir.md"
7+
8+
module KMIR-SYMBOLIC-LOCALS [symbolic]
9+
imports KMIR-CONTROL-FLOW
10+
11+
rule <k> #execFunction(
12+
monoItem(
13+
SYMNAME,
14+
monoItemFn(_, _, someBody(body((FIRST:BasicBlock _) #as BLOCKS,RETURNLOCAL:LocalDecl LOCALS:LocalDecls, ARGCOUNT, _, _, _)))
15+
),
16+
FUNCTIONNAMES
17+
)
18+
=>
19+
#reserveSymbolicsFor(LOCALS, ARGCOUNT)
20+
~> #execBlock(FIRST)
21+
...
22+
</k>
23+
<currentFunc> _ => #tyFromName(SYMNAME, FUNCTIONNAMES) </currentFunc>
24+
<currentFrame>
25+
<currentBody> _ => toKList(BLOCKS) </currentBody>
26+
<caller> _ => ty(-1) </caller> // no caller
27+
<dest> _ => place(local(-1), .ProjectionElems)</dest>
28+
<target> _ => noBasicBlockIdx </target>
29+
<unwind> _ => unwindActionUnreachable </unwind>
30+
<locals> _ => #reserveFor(RETURNLOCAL) </locals>
31+
</currentFrame>
32+
requires ARGCOUNT >Int 0
33+
[priority(25)]
34+
```
35+
36+
## Declare symbolic arguments based on their types
37+
38+
```k
39+
syntax KItem ::= #reserveSymbolicsFor( LocalDecls, Int )
40+
41+
rule <k> #reserveSymbolicsFor( .LocalDecls, _ ) => .K ... </k>
42+
43+
rule <k> #reserveSymbolicsFor( LOCALS:LocalDecls, 0 ) => .K ... </k>
44+
<locals> ... .List => #reserveFor(LOCALS) </locals> // No more arguments, treat the rest of the Decls normally
45+
46+
```
47+
48+
## Integers
49+
50+
```k
51+
// Unsigned
52+
rule <k> #reserveSymbolicsFor( localDecl(TY, _, MUT) LOCALS:LocalDecls, COUNT )
53+
=> #reserveSymbolicsFor( LOCALS:LocalDecls, COUNT -Int 1 )
54+
...
55+
</k>
56+
<locals> ... .List => ListItem(typedValue( Integer(?INT:Int, #bitWidth(PRIMTY), false), TY, MUT )) </locals>
57+
<types> ... TY |-> typeInfoPrimitiveType ( primTypeUint( PRIMTY ) ) ... </types>
58+
requires 0 <Int COUNT
59+
ensures #intConstraints( ?INT, PRIMTY )
60+
61+
// Signed
62+
rule <k> #reserveSymbolicsFor( localDecl(TY, _, MUT) LOCALS:LocalDecls, COUNT )
63+
=> #reserveSymbolicsFor( LOCALS:LocalDecls, COUNT -Int 1 )
64+
...
65+
</k>
66+
<locals> ... .List => ListItem(typedValue( Integer(?INT:Int, #bitWidth(PRIMTY), true), TY, MUT )) </locals>
67+
<types> ... TY |-> typeInfoPrimitiveType ( primTypeInt( PRIMTY ) ) ... </types>
68+
requires 0 <Int COUNT
69+
ensures #intConstraints( ?INT, PRIMTY )
70+
71+
syntax Bool ::= #intConstraints( Int, InTy ) [function, total]
72+
73+
rule #intConstraints( X, TY:IntTy ) => 0 -Int (2 ^Int (#bitWidth(TY) -Int 1)) <=Int X andBool X <Int 2 ^Int (#bitWidth(TY) -Int 1)
74+
rule #intConstraints( X, TY:UintTy ) => 0 <=Int X andBool X <Int 2 ^Int #bitWidth(TY)
75+
```
76+
77+
## Boolean Values
78+
79+
```k
80+
rule <k> #reserveSymbolicsFor( localDecl(TY, _, MUT) LOCALS:LocalDecls, COUNT )
81+
=> #reserveSymbolicsFor( LOCALS:LocalDecls, COUNT -Int 1 )
82+
...
83+
</k>
84+
<locals> ... .List => ListItem(typedValue( BoolVal( ?_BOOL:Bool ), TY, MUT )) </locals>
85+
<types> ... TY |-> typeInfoPrimitiveType ( primTypeBool ) ... </types>
86+
requires 0 <Int COUNT
87+
```
88+
89+
## Arbitrary Values
90+
91+
```k
92+
rule <k> #reserveSymbolicsFor( localDecl(TY, _, MUT) LOCALS:LocalDecls, COUNT )
93+
=> #reserveSymbolicsFor( LOCALS:LocalDecls, COUNT -Int 1 )
94+
...
95+
</k>
96+
<locals> ... .List => ListItem(typedValue( ?_VAL:Value, TY, MUT )) </locals>
97+
<types> ... TY |-> _:TypeInfo ... </types>
98+
requires 0 <Int COUNT
99+
[owise]
100+
101+
endmodule
102+
```

package/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.116
1+
0.3.117

0 commit comments

Comments
 (0)