-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathbits.k
59 lines (48 loc) · 2.08 KB
/
bits.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module C-BITS-SYNTAX
imports BITS-SYNTAX
imports FLOAT-SYNTAX
imports C-TYPING-SORTS
syntax KItem ::= fillToBytes(KItem) [strict]
syntax KItem ::= "fillToBytes-aux" "(" K "," List ")" [function]
syntax KItem ::= makeUnknown(KItem) [strict]
syntax CValue ::= stripUnknown(CValue) [function]
syntax Int ::= maxIntPtrValue(IntPtr) [function]
endmodule
module C-BITS
imports C-BITS-SYNTAX
imports BOOL
imports INT
imports C-DYNAMIC-SYNTAX
imports C-SETTINGS-SYNTAX
// this maintains byte order
rule fillToBytes(dataList(L::List))
=> fillToBytes-aux(dataList(L), .List)
[structural]
rule fillToBytes-aux(dataList(
ListItem(piece(N::BitValue, Len::Int)) L::List),
L'::List)
=> fillToBytes-aux(dataList(L), L' ListItem(piece(N, Len)))
requires Len ==Int cfg:bitsPerByte
[structural]
rule fillToBytes-aux(dataList(ListItem(piece(N::BitValue, Len::Int))), L'::List)
=> fillToBytes-aux(dataList(
ListItem(piece(N, Len)) ListItem(piece(0, 1))),
L')
requires Len <Int cfg:bitsPerByte
[structural]
rule fillToBytes-aux(dataList(
ListItem(piece(N::BitValue, Len::Int))
ListItem(piece(N'::BitValue, Len'::Int)) L::List), L'::List)
=> fillToBytes-aux(dataList(ListItem(piece(N, Len) bit:: piece(N', Len')) L), L')
requires Len +Int Len' <=Int cfg:bitsPerByte
[structural]
rule fillToBytes-aux(dataList(.List), L::List) => dataList(L)
[structural]
rule makeUnknown(tv(I:Int, T::UType)) => tv(unknown(I), T)
rule makeUnknown(tv(V::CValue, T::UType)) => tv(V, T)
requires notBool isInt(V)
rule stripUnknown(unknown(V::CValue)) => V
rule stripUnknown(V::CValue) => V [owise]
rule maxIntPtrValue(_:SymLoc) => (1 <<Int (cfg:bitsPerByte *Int cfg:ptrsize -Int 1)) -Int 1
rule maxIntPtrValue(encodedPtr(_, N:Int, M:Int)) => (1 <<Int (cfg:bitsPerByte *Int (M -Int N +Int 1) -Int 1)) -Int 1
endmodule