From 54e0cede4384b7c1655f9183577bfccc11d9a7d5 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Tue, 10 Jan 2017 16:45:52 +0100 Subject: 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. --- csource/csource.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'csource') 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: -- cgit mrf-deployment