Skip to content

Commit 8d14018

Browse files
committed
Decoding Constant with Prov
1 parent 4348cb1 commit 8d14018

File tree

1 file changed

+15
-7
lines changed
  • kmir/src/kmir/kdist/mir-semantics/rt

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ Constant operands are simply decoded according to their type.
7474
```k
7575
rule <k> operandConstant(constOperand(_, _, mirConst(KIND, TY, _)))
7676
=>
77-
typedValue(#decodeConstant(KIND, {TYPEMAP[TY]}:>TypeInfo), TY, mutabilityNot)
77+
typedValue(#decodeConstant(KIND, {TYPEMAP[TY]}:>TypeInfo, MEM), TY, mutabilityNot)
7878
...
7979
</k>
8080
<types> TYPEMAP </types>
81+
<memory> MEM </memory>
8182
requires TY in_keys(TYPEMAP)
8283
andBool isTypeInfo(TYPEMAP[TY])
8384
[preserves-definedness] // valid Map lookup checked
@@ -851,19 +852,19 @@ bit width, signedness, and possibly truncating or 2s-complementing the value.
851852
The `Value` sort above operates at a higher level than the bytes representation found in the MIR syntax for constant values. The bytes have to be interpreted according to the given `TypeInfo` to produce the higher-level value. This is currently only defined for `PrimitiveType`s (primitive types in MIR).
852853

853854
```k
854-
syntax Value ::= #decodeConstant ( ConstantKind, TypeInfo ) [function]
855+
syntax Value ::= #decodeConstant ( ConstantKind, TypeInfo, Map ) [function]
855856
856857
//////////////////////////////////////////////////////////////////////////////////////
857858
// decoding the correct amount of bytes depending on base type size
858859
859860
// Boolean: should be one byte with value one or zero
860-
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), typeInfoPrimitiveType(primTypeBool)) => BoolVal(false)
861+
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), typeInfoPrimitiveType(primTypeBool), _MEM) => BoolVal(false)
861862
requires 0 ==Int Bytes2Int(BYTES, LE, Unsigned) andBool lengthBytes(BYTES) ==Int 1
862-
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), typeInfoPrimitiveType(primTypeBool)) => BoolVal(true)
863+
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), typeInfoPrimitiveType(primTypeBool), _MEM) => BoolVal(true)
863864
requires 1 ==Int Bytes2Int(BYTES, LE, Unsigned) andBool lengthBytes(BYTES) ==Int 1
864865
865866
// Integer: handled in separate module for numeric operations
866-
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), TYPEINFO)
867+
rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), TYPEINFO, _MEM)
867868
=>
868869
#decodeInteger(BYTES, #intTypeOf(TYPEINFO))
869870
requires #isIntType(TYPEINFO)
@@ -872,16 +873,23 @@ The `Value` sort above operates at a higher level than the bytes representation
872873
873874
////////////////////////////////////////////////////////////////////////////////////////////////
874875
// FIXME Char type
875-
// rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _)), typeInfoPrimitiveType(primTypeChar))
876+
// rule #decodeConstant(constantKindAllocated(allocation(BYTES, _, _, _), _MEM), typeInfoPrimitiveType(primTypeChar))
876877
// =>
877878
// Str(...)
878879
/////////////////////////////////////////////////////////////////////////////////////////////////
879880
881+
rule #decodeConstant(constantKindAllocated(allocation(_BYTES, provenanceMap(
882+
provenanceMapEntry(_SIZE, allocId(ID:Int)) .ProvenanceMapEntries
883+
), _ALIGN, _MUT)), typeInfoRefType(_TY), MEMORY)
884+
=>
885+
RefAlloc(ID)
886+
requires ID in_keys(MEMORY)
887+
[preserves-definedness] // AllocId in Memory is checked, TY in Types checked previously
880888
881889
/////////////////////////////////////////////////////////////////////////////////////////////////
882890
// TODO Float decoding: not supported natively in K
883891
884-
rule #decodeConstant(_, _) => Any [owise]
892+
rule #decodeConstant(_, _, _) => Any [owise]
885893
```
886894

887895
## Primitive operations on numeric data

0 commit comments

Comments
 (0)