From 2e35bb9a19c0711162e650f3723e2dbe061051ee Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 10 Nov 2023 12:55:23 +0100 Subject: compiler: support flags as int first argument This commit adds support for the following syntax: int_flags = 1, 5, 8, 9 int32[int_flags] which is equivalent to: int_flags = 1, 5, 8, 9 flags[int_flags, int32] The second int type argument, align, is not allowed if the first argument is a flag. The compiler will also error if the first argument appears to be a flag (is ident and has no colon), but can't be found in the map of flags. Signed-off-by: Paul Chaignon --- pkg/compiler/consts.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pkg/compiler/consts.go') diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go index e9f7227e7..6fe3e7bc0 100644 --- a/pkg/compiler/consts.go +++ b/pkg/compiler/consts.go @@ -123,6 +123,13 @@ func (comp *compiler) addConst(infos map[string]*constInfo, pos ast.Pos, name st if _, builtin := comp.builtinConsts[name]; builtin { return } + // In case of intN[identA], identA may refer to a constant or to a set of + // flags. To avoid marking all flags as constants, we must check here + // whether identA refers to a flag. We have a check in the compiler to + // ensure an identifier can never refer to both a constant and flags. + if _, isFlag := comp.intFlags[name]; isFlag { + return + } info := getConstInfo(infos, pos) info.consts[name] = &Const{ Pos: pos, @@ -297,6 +304,11 @@ func (comp *compiler) patchConst(val *uint64, id *string, consts map[string]uint *val = v return true } + // This check is necessary because in intN[identA], identA may be a + // constant or a set of flags. + if _, isFlag := comp.intFlags[*id]; isFlag { + return true + } if missing != nil && *missing == "" { *missing = *id } -- cgit mrf-deployment