forked from kframework/c-semantics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.k
33 lines (29 loc) · 1.05 KB
/
string.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
module LIBC-STRING
imports LIBC-BOOTSTRAP-SYNTAX
imports C-SYNTAX
imports C-DYNAMIC-SYNTAX
imports C-TYPING-SYNTAX
imports C-MEMORY-READING-SYNTAX
imports C-MEMORY-WRITING-SYNTAX
imports C-SYMLOC-SYNTAX
// try to use getString
// fixme should detect overlaps
syntax KItem ::= strcpy(SymLoc, SymLoc, SymLoc)
rule prepareBuiltin(Identifier("strcpy"),
hrItem(tv(Dest:SymLoc, t(_, pointerType(_)))) hs::
hrItem(tv(Src:SymLoc, t(_, pointerType(_)))))
=> strcpy(Dest, Src, Dest)
[structural]
rule (.K => read(Src:SymLoc, t(.Set, char)))
~> strcpy(_, (Src => Src +bytes 1), _)
[structural]
rule (tv(I:Int, T:Type) => write(Dest, I, T))
~> strcpy((Dest:SymLoc => Dest +bytes 1), _, _)
requires I =/=Int 0
[structural]
rule tv(0, T:Type)
~> strcpy(Dest:SymLoc, _, Orig:SymLoc)
=> write(Dest, 0, T)
~> tv(Orig, t(.Set, pointerType(t(.Set, char))))
[structural]
endmodule