Skip to content

Commit c8c6f7f

Browse files
committed
add explicit end rule, use MaybeValue for retVal
1 parent a36ebd5 commit c8c6f7f

File tree

1 file changed

+24
-3
lines changed
  • kmir/src/kmir/kdist/mir-semantics

1 file changed

+24
-3
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ module KMIR-CONFIGURATION
6464
imports KMIR-SYNTAX
6565
imports INT-SYNTAX
6666
67-
syntax RetVal ::= "NoRetVal"
68-
| Int // FIXME is this enough?
67+
syntax RetVal ::= MaybeValue
6968
7069
syntax StackFrame ::= StackFrame(caller:Ty, // index of caller function
7170
dest:Place, // place to store return value
@@ -75,7 +74,7 @@ module KMIR-CONFIGURATION
7574
7675
configuration <kmir>
7776
<k> #init($PGM:Pgm) </k>
78-
<retVal> NoRetVal </retVal>
77+
<retVal> NoValue </retVal>
7978
<currentFunc> ty(-1) </currentFunc> // to retrieve caller
8079
// unpacking the top frame to avoid frequent stack read/write operations
8180
<currentFrame>
@@ -430,6 +429,28 @@ stack frame, at the _target_.
430429
// [preserves-definedness] // valid list indexing and projection checked
431430
```
432431

432+
When a `terminatorKindReturn` is executed but the optional target is empty
433+
(`noBasicBlockIdx`), the program is ended, using the returned value from `_0`
434+
as the program's `retVal`.
435+
The call stack is not necessarily empty at this point so it is left untouched.
436+
437+
```k
438+
syntax KItem ::= "#EndProgram"
439+
440+
rule [endprogram]:
441+
<k> #execTerminator(terminator(terminatorKindReturn, _SPAN)) ~> _
442+
=>
443+
#EndProgram
444+
</k>
445+
<retVal> _ => {LOCALS[0]}:>MaybeValue </retVal>
446+
<currentFrame>
447+
<target> noBasicBlockIdx </target>
448+
<locals> LOCALS </locals>
449+
...
450+
</currentFrame>
451+
```
452+
453+
433454
`Call` is calling another function, setting up its stack frame and
434455
where the returned result should go.
435456

0 commit comments

Comments
 (0)