@@ -64,8 +64,7 @@ module KMIR-CONFIGURATION
64
64
imports KMIR-SYNTAX
65
65
imports INT-SYNTAX
66
66
67
- syntax RetVal ::= "NoRetVal"
68
- | Int // FIXME is this enough?
67
+ syntax RetVal ::= MaybeValue
69
68
70
69
syntax StackFrame ::= StackFrame(caller:Ty, // index of caller function
71
70
dest:Place, // place to store return value
@@ -75,7 +74,7 @@ module KMIR-CONFIGURATION
75
74
76
75
configuration <kmir>
77
76
<k> #init($PGM:Pgm) </k>
78
- <retVal> NoRetVal </retVal>
77
+ <retVal> NoValue </retVal>
79
78
<currentFunc> ty(-1) </currentFunc> // to retrieve caller
80
79
// unpacking the top frame to avoid frequent stack read/write operations
81
80
<currentFrame>
@@ -430,6 +429,28 @@ stack frame, at the _target_.
430
429
// [preserves-definedness] // valid list indexing and projection checked
431
430
```
432
431
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
+
433
454
` Call ` is calling another function, setting up its stack frame and
434
455
where the returned result should go.
435
456
0 commit comments