aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/compiler.go
diff options
context:
space:
mode:
authorFlorent Revest <revest@chromium.org>2024-11-28 01:49:47 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-12-09 18:35:48 +0000
commit07e46fbc2bd7ff8782c975596672e4e3d3891865 (patch)
treee5b5faf3f3225f930127716f3242b31b667dd36d /pkg/compiler/compiler.go
parent9ac0fdc66500475f1914254ef369b32d51adbff9 (diff)
pkg/compiler: handle string syscall attributes
Diffstat (limited to 'pkg/compiler/compiler.go')
-rw-r--r--pkg/compiler/compiler.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go
index 978255219..fa23ce6bf 100644
--- a/pkg/compiler/compiler.go
+++ b/pkg/compiler/compiler.go
@@ -210,34 +210,36 @@ func (comp *compiler) structIsVarlen(name string) bool {
func (comp *compiler) parseIntAttrs(descs map[string]*attrDesc, parent ast.Node,
attrs []*ast.Type) map[*attrDesc]uint64 {
- intAttrs, _ := comp.parseAttrs(descs, parent, attrs)
+ intAttrs, _, _ := comp.parseAttrs(descs, parent, attrs)
return intAttrs
}
func (comp *compiler) parseAttrs(descs map[string]*attrDesc, parent ast.Node, attrs []*ast.Type) (
- map[*attrDesc]uint64, map[*attrDesc]prog.Expression) {
+ map[*attrDesc]uint64, map[*attrDesc]prog.Expression, map[*attrDesc]string) {
_, parentType, parentName := parent.Info()
resInt := make(map[*attrDesc]uint64)
resExpr := make(map[*attrDesc]prog.Expression)
+ resString := make(map[*attrDesc]string)
for _, attr := range attrs {
if unexpected, _, ok := checkTypeKind(attr, kindIdent); !ok {
comp.error(attr.Pos, "unexpected %v, expect attribute", unexpected)
- return resInt, resExpr
+ return resInt, resExpr, resString
}
if len(attr.Colon) != 0 {
comp.error(attr.Colon[0].Pos, "unexpected ':'")
- return resInt, resExpr
+ return resInt, resExpr, resString
}
desc := descs[attr.Ident]
if desc == nil {
comp.error(attr.Pos, "unknown %v %v attribute %v", parentType, parentName, attr.Ident)
- return resInt, resExpr
+ return resInt, resExpr, resString
}
_, dupInt := resInt[desc]
_, dupExpr := resExpr[desc]
- if dupInt || dupExpr {
+ _, dupString := resString[desc]
+ if dupInt || dupExpr || dupString {
comp.error(attr.Pos, "duplicate %v %v attribute %v", parentType, parentName, attr.Ident)
- return resInt, resExpr
+ return resInt, resExpr, resString
}
switch desc.Type {
@@ -245,18 +247,20 @@ func (comp *compiler) parseAttrs(descs map[string]*attrDesc, parent ast.Node, at
resInt[desc] = 1
if len(attr.Args) != 0 {
comp.error(attr.Pos, "%v attribute has args", attr.Ident)
- return nil, nil
+ return nil, nil, nil
}
case intAttr:
resInt[desc] = comp.parseAttrIntArg(attr)
case exprAttr:
resExpr[desc] = comp.parseAttrExprArg(attr)
+ case stringAttr:
+ resString[desc] = comp.parseAttrStringArg(attr)
default:
comp.error(attr.Pos, "attribute %v has unknown type", attr.Ident)
- return nil, nil
+ return nil, nil, nil
}
}
- return resInt, resExpr
+ return resInt, resExpr, resString
}
func (comp *compiler) parseAttrExprArg(attr *ast.Type) prog.Expression {
@@ -289,6 +293,19 @@ func (comp *compiler) parseAttrIntArg(attr *ast.Type) uint64 {
return sz.Value
}
+func (comp *compiler) parseAttrStringArg(attr *ast.Type) string {
+ if len(attr.Args) != 1 {
+ comp.error(attr.Pos, "%v attribute is expected to have 1 argument", attr.Ident)
+ return ""
+ }
+ arg := attr.Args[0]
+ if !arg.HasString {
+ comp.error(attr.Pos, "%v argument must be a string", attr.Ident)
+ return ""
+ }
+ return arg.String
+}
+
func (comp *compiler) getTypeDesc(t *ast.Type) *typeDesc {
if desc := builtinTypes[t.Ident]; desc != nil {
return desc