Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for memset hook. #3722

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions k-distribution/include/kframework/builtin/domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,21 @@ is not a valid index.
syntax Bytes ::= replaceAtBytes(dest: Bytes, index: Int, src: Bytes) [function, hook(BYTES.replaceAt)]
```

### Multiple bytes update

You can modify a `Bytes` to return a `Bytes` which is equal to `dest` except
the `count` bytes starting at `index` are replaced with `count` bytes of value
`Int2Bytes(1, v, LE/BE)` in O(count) time. This does not create a new `Bytes`
object and will instead modify the original on concrete backends.
This will throw an exception if `index` + `count` is not a valid index.
The acceptable range of values for `v` is -128 to 127. This will throw an
exception if `v` is outside of this range.
This is implemented only for the LLVM backend.

```k
syntax Bytes ::= memsetBytes(dest: Bytes, index: Int, count: Int, v: Int) [function, hook(BYTES.memset)]
```

### Bytes padding

You can create a new `Bytes` object which is at least `length` bytes long
Expand Down
1 change: 1 addition & 0 deletions k-distribution/tests/regression-new/bytes-memset/1.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
memsetBytes(b"12345", 1, 3, 48)
3 changes: 3 additions & 0 deletions k-distribution/tests/regression-new/bytes-memset/1.test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<k>
b"10005" ~> .
</k>
1 change: 1 addition & 0 deletions k-distribution/tests/regression-new/bytes-memset/2.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
memsetBytes(b"10005", 1, 1, -1)
3 changes: 3 additions & 0 deletions k-distribution/tests/regression-new/bytes-memset/2.test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<k>
b"1\xff005" ~> .
</k>
7 changes: 7 additions & 0 deletions k-distribution/tests/regression-new/bytes-memset/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEF=test
EXT=test
TESTDIR=.
KOMPILE_BACKEND=llvm
KOMPILE_FLAGS=--syntax-module TEST

include ../../../include/kframework/ktest.mak
7 changes: 7 additions & 0 deletions k-distribution/tests/regression-new/bytes-memset/test.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) K Team. All Rights Reserved.
module TEST
imports BYTES
imports INT

configuration <k> $PGM:Bytes </k>
endmodule