diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2017-01-10 16:45:52 +0100 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@google.com> | 2017-01-17 13:25:33 +0100 |
| commit | 54e0cede4384b7c1655f9183577bfccc11d9a7d5 (patch) | |
| tree | 68e1f734a5e82ac7ecbe2968942d9983650ed8f8 /csource | |
| parent | f6c7b90523285663e51fc6804ae2c0c171bb390c (diff) | |
prog: add bitfields to templates
Now it's possible to use `int32:18` to denote a bitfield of size 18 as a struct field.
This fixes #72.
Diffstat (limited to 'csource')
| -rw-r--r-- | csource/csource.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/csource/csource.go b/csource/csource.go index 25276b237..2d18e391a 100644 --- a/csource/csource.go +++ b/csource/csource.go @@ -197,7 +197,13 @@ loop: switch typ { case prog.ExecArgConst: arg := read() - fmt.Fprintf(w, "\tNONFAILING(*(uint%v_t*)0x%x = (uint%v_t)0x%x);\n", size*8, addr, size*8, arg) + bfOff := read() + bfLen := read() + if bfOff == 0 && bfLen == 0 { + fmt.Fprintf(w, "\tNONFAILING(*(uint%v_t*)0x%x = (uint%v_t)0x%x);\n", size*8, addr, size*8, arg) + } else { + fmt.Fprintf(w, "\tNONFAILING(STORE_BY_BITMASK(uint%v_t, %v, %v, %v, %v);\n", size*8, addr, arg, bfOff, bfLen) + } case prog.ExecArgResult: fmt.Fprintf(w, "\tNONFAILING(*(uint%v_t*)0x%x = %v);\n", size*8, addr, resultRef()) case prog.ExecArgData: @@ -235,6 +241,9 @@ loop: switch typ { case prog.ExecArgConst: fmt.Fprintf(w, ", 0x%xul", read()) + // Bitfields can't be args of a normal syscall, so just ignore them. + read() // bit field offset + read() // bit field length case prog.ExecArgResult: fmt.Fprintf(w, ", %v", resultRef()) default: |
