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

bpf2go: use [16]byte instead of uint128 #799

Merged
merged 1 commit into from Sep 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions btf/format.go
Expand Up @@ -174,8 +174,6 @@ func (gf *GoFormatter) writeIntLit(i *Int) error {
return fmt.Errorf("bool with size %d", i.Size)
}
gf.w.WriteString("bool")
case Signed:
fmt.Fprintf(&gf.w, "int%d", bits)
case Char:
if i.Size != 1 {
return fmt.Errorf("char with size %d", i.Size)
Expand All @@ -184,8 +182,16 @@ func (gf *GoFormatter) writeIntLit(i *Int) error {
// we are dealing with unsigned, since this works nicely with []byte
// in Go code.
fallthrough
case Unsigned:
fmt.Fprintf(&gf.w, "uint%d", bits)
case Unsigned, Signed:
stem := "uint"
if i.Encoding == Signed {
stem = "int"
}
if i.Size > 8 {
fmt.Fprintf(&gf.w, "[%d]byte /* %s%d */", i.Size, stem, i.Size*8)
} else {
fmt.Fprintf(&gf.w, "%s%d", stem, bits)
}
default:
return fmt.Errorf("can't encode %s", i.Encoding)
}
Expand Down
2 changes: 1 addition & 1 deletion btf/format_test.go
Expand Up @@ -20,7 +20,7 @@ func TestGoTypeDeclaration(t *testing.T) {
{&Int{Size: 4, Encoding: Signed}, "type t int32"},
{&Int{Size: 8}, "type t uint64"},
{&Typedef{Name: "frob", Type: &Int{Size: 8}}, "type t uint64"},
{&Int{Size: 16}, "type t uint128"},
{&Int{Size: 16}, "type t [16]byte /* uint128 */"},
{&Enum{Values: []EnumValue{{"FOO", 32}}, Size: 4}, "type t uint32; const ( tFOO t = 32; )"},
{&Enum{Values: []EnumValue{{"BAR", 1}}, Size: 1, Signed: true}, "type t int8; const ( tBAR t = 1; )"},
{
Expand Down