Skip to content

Commit 1ee2475

Browse files
committed
Updated Ptr with Address and Offset. Added projection update rules
1 parent 10ead82 commit 1ee2475

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

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

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,58 @@ The solution is to use rewrite operations in a downward pass through the project
581581
andBool (FORCE orBool MUT ==K mutabilityMut)
582582
[preserves-definedness]
583583
584+
rule <k> #projectedUpdate(
585+
_DEST,
586+
typedValue(Ptr(OFFSET, place(LOCAL, PLACEPROJ), MUT, _ADDRESS, _OFFSET2), _, _),
587+
projectionElemDeref PROJS,
588+
UPDATE,
589+
_CTXTS,
590+
FORCE
591+
)
592+
=>
593+
#projectedUpdate(
594+
toStack(OFFSET, LOCAL),
595+
#localFromFrame({STACK[OFFSET -Int 1]}:>StackFrame, LOCAL, OFFSET),
596+
appendP(PLACEPROJ, PROJS), // apply ptr (reference) projections first, then rest
597+
UPDATE,
598+
.Contexts, // previous contexts obsolete
599+
FORCE
600+
)
601+
...
602+
</k>
603+
<stack> STACK </stack>
604+
requires 0 <Int OFFSET
605+
andBool OFFSET <=Int size(STACK)
606+
andBool isStackFrame(STACK[OFFSET -Int 1])
607+
andBool (FORCE orBool MUT ==K mutabilityMut)
608+
[preserves-definedness]
609+
610+
rule <k> #projectedUpdate(
611+
_DEST,
612+
typedValue(Ptr(OFFSET, place(local(I), PLACEPROJ), MUT, _ADDRESS, _OFFSET2), _, _),
613+
projectionElemDeref PROJS,
614+
UPDATE,
615+
_CTXTS,
616+
FORCE
617+
)
618+
=>
619+
#projectedUpdate(
620+
toLocal(I),
621+
{LOCALS[I]}:>TypedLocal,
622+
appendP(PLACEPROJ, PROJS), // apply ptr (reference) projections first, then rest
623+
UPDATE,
624+
.Contexts, // previous contexts obsolete
625+
FORCE
626+
)
627+
...
628+
</k>
629+
<locals> LOCALS </locals>
630+
requires OFFSET ==Int 0
631+
andBool 0 <=Int I
632+
andBool I <Int size(LOCALS)
633+
andBool (FORCE orBool MUT ==K mutabilityMut)
634+
[preserves-definedness]
635+
584636
rule <k> #projectedUpdate(toLocal(I), _ORIGINAL, .ProjectionElems, NEW, CONTEXTS, false)
585637
=>
586638
#setLocalValue(place(local(I), .ProjectionElems), #buildUpdate(NEW, CONTEXTS))
@@ -837,9 +889,10 @@ A `CopyForDeref` `RValue` has the semantics of a simple `Use(operandCopy(...))`,
837889
TODO
838890

839891
```k
892+
// FIXME: Address is currently hardcoded to 0 so that the alignment check passes everytime
840893
rule <k> rvalueAddressOf( MUTABILITY, PLACE)
841894
=>
842-
typedValue( Ptr( 0, PLACE, MUTABILITY), TyUnknown, MUTABILITY ) // TyUnknown and MUTABILITY will be overwritten to the Local's type
895+
typedValue( Ptr( 0, PLACE, MUTABILITY, 0, 0), TyUnknown, MUTABILITY ) // TyUnknown and MUTABILITY will be overwritten to the Local's type
843896
...
844897
</k>
845898
@@ -906,7 +959,12 @@ Error cases for `castKindIntToInt`
906959
Casting between two raw pointers. FIXME: No validity checks are currently performed
907960

908961
```k
909-
rule <k> #cast( typedValue(Ptr(DEPTH, PLACE, PTR_MUT), _TY_FROM, LOCAL_MUT), castKindPtrToPtr, TY_TO) => typedValue(Ptr(DEPTH, PLACE, PTR_MUT), TY_TO, LOCAL_MUT) ... </k>
962+
// FIXME: Address and Offset are blindly transferred through
963+
rule <k> #cast( typedValue(Ptr(DEPTH, PLACE, PTR_MUT, ADDRESS, OFFSET), _TY_FROM, LOCAL_MUT), castKindPtrToPtr, TY_TO)
964+
=>
965+
typedValue(Ptr(DEPTH, PLACE, PTR_MUT, ADDRESS, OFFSET), TY_TO, LOCAL_MUT)
966+
...
967+
</k>
910968
// <types> TYPEMAP </types>
911969
// requires TY_TO #in TYPEMAP
912970
// requires #is_valid_cast(TY_FROM.layout(), TY_TO.layout())
@@ -1377,20 +1435,15 @@ The `unOpNot` operation works on boolean and integral values, with the usual sem
13771435
13781436
rule #compute(
13791437
BOP,
1380-
typedValue(Ptr(_ARG1, _, _), _, _),
1381-
typedValue(Integer(_ARG2, WIDTH, _), _, _),
1438+
typedValue(Ptr(_, _, _, ADDRESS, _), _, _),
1439+
typedValue(Integer(VAL, WIDTH, _), _, _),
13821440
false) // unchecked
13831441
=>
13841442
typedValue(
1385-
Integer(4242, WIDTH, false),
1443+
Integer(onInt(BOP, VAL, ADDRESS), WIDTH, false),
13861444
TyUnknown,
13871445
mutabilityNot
13881446
)
1389-
// typedValue(
1390-
// Integer(onInt(BOP, ARG1, ARG2), WIDTH, false),
1391-
// TyUnknown,
1392-
// mutabilityNot
1393-
// )
13941447
requires isBitwise(BOP)
13951448
[preserves-definedness]
13961449

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ High-level values can be
3434
// stack depth (initially 0), place, borrow kind
3535
| Range( List )
3636
// homogenous values for array/slice
37-
| Ptr( Int, Place, Mutability ) // Same as ref for now until I understand how to handle better
38-
// address, metadata for ref/ptr
37+
| Ptr( Int, Place, Mutability, Int, Int)
38+
// stack depth (initially zero), place, mutablility, address, offset NOTE: First 3 fields are the same as Reference, last are needed for low level instructions
3939
| "Any"
4040
// arbitrary value for transmute/invalid ptr lookup
4141
```

0 commit comments

Comments
 (0)