diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-12-05 14:46:00 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-19 11:54:01 +0000 |
| commit | ed571339c6ff5ed764283737a0aa68451085e84d (patch) | |
| tree | f809f9dcd1782d7b281d2bb6b60fb3be5fa8704f /pkg/compiler/testdata | |
| parent | e59ec59b027f921a6bfbe5014b15c2a802445ada (diff) | |
pkg/compiler: support if[expr] attributes
The expression may either include integers/consts or reference other
fields in the structure via value[field1:field2:field3].
The fields on this path must all belong to structures and must not have
any if conditions themselves.
For unions, mandate that the last field has no conditions (it will be
the default one).
For structs, convert conditional fields into fields of a union type of
the following form:
anonymous_union [
value T (if[expression])
void void
]
Diffstat (limited to 'pkg/compiler/testdata')
| -rw-r--r-- | pkg/compiler/testdata/all.txt | 20 | ||||
| -rw-r--r-- | pkg/compiler/testdata/consts.txt | 1 | ||||
| -rw-r--r-- | pkg/compiler/testdata/errors.txt | 37 | ||||
| -rw-r--r-- | pkg/compiler/testdata/errors2.txt | 61 |
4 files changed, 119 insertions, 0 deletions
diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index f7639c761..d1baef2f9 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -349,3 +349,23 @@ compressed$1(a compressed_image) (no_generate, no_minimize) compressed$2(a ptr[in, compressed_image]) (no_generate, no_minimize) compressed$3(a ptr[in, struct_compressed]) (no_generate, no_minimize) compressed$4(a ptr[in, union_compressed]) (no_generate, no_minimize) + +struct$conditional { + f0 int32 + f1 int64 (if[value[f0] == 1]) + f2 struct$conditional2 + f3 union$conditional3 +} [packed] + +struct$conditional2 { + f3 int32 (if[value[parent:parent:f0] == 2]) + f4 int32 (if[value[struct$conditional:f0] == 2]) +} [packed] + +union$conditional3 [ + u1 int32 (if[value[parent:parent:f0] == 3]) + u2 int32 (if[value[struct$conditional:f0] == 3]) + u3 const[0xabcd, int64] +] + +conditional(a ptr[in, struct$conditional]) diff --git a/pkg/compiler/testdata/consts.txt b/pkg/compiler/testdata/consts.txt index 29cdfb6a0..7b2845d7a 100644 --- a/pkg/compiler/testdata/consts.txt +++ b/pkg/compiler/testdata/consts.txt @@ -29,6 +29,7 @@ foo$0(a templ0[CONST18]) type templ1[C] { f1 const[CONST19, int8] f2 const[C, int8] + f3 int64 (if[value[f1] & CONST27 != 0]) } foo$1(a ptr[in, templ1[CONST20]]) diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt index 1be1bd070..4f3186698 100644 --- a/pkg/compiler/testdata/errors.txt +++ b/pkg/compiler/testdata/errors.txt @@ -470,3 +470,40 @@ union$directions [ compressed$test(a int32) compressed_image ### compressed_image can't be syscall return + +define FLAG1 = 1 +define FLAG2 = 2 + +some_nested_flags { + f1 int32 +} + +conditional_fields { + f1 int32 + f2 some_nested_flags (if[value[f1] & FLAG1]) + f3 some_nested_flags (if[value[f1] & FLAG1], if[value[f1] & FLAG1]) ### duplicate arg/field f3 attribute if + f4 some_nested_flags (if[value & FLAG1]) ### value reference must have only one argument + f5 some_nested_flags (if[value[f1] & FLAG1, FLAG2]) ### if attribute is expected to have only one argument + f6 some_nested_flags (if[value[f1, FLAG2] & FLAG1]) ### value reference must have only one argument + f7 some_nested_flags (if[5]) + f8 some_nested_flags + f9 some_nested_flags (if[value[f8:f1] & FLAG1]) + f10 some_nested_flags (if[value[f8:f1, A] & FLAG1]) ### value reference must have only one argument + f11 some_nested_flags (if[value[f8:f1[A]] & FLAG1]) ### value aguments must not have any further arguments + f12 some_nested_flags (if[f1 == "A"]) ### the token must be either an integer or an identifier + f13 some_nested_flags (if["ABCD"]) ### if argument must be an expression + f14 some_nested_flags (if[X[Y]]) ### consts in expressions must not have any arguments + f15 conditional_fields_union1 + f16 conditional_fields_union2 +} + +conditional_fields_union1 [ + u1 int32 (if [value[parent:f1] & FLAG1]) + u2 int32 (if [value[parent:f1] & FLAG2]) ### unions must not have if conditions on the last field +] + +conditional_fields_union2 [ + u1 int32 (if [value[parent:f1] & FLAG1]) + u2 int32 ### either no fields have conditions or all except the last + u3 int32 +] diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt index d08f3e01e..0f10ea278 100644 --- a/pkg/compiler/testdata/errors2.txt +++ b/pkg/compiler/testdata/errors2.txt @@ -447,3 +447,64 @@ foo$non_minimizable_via_union(a ptr[in, union_non_minimizable]) (no_generate) ## resource for_fmt[int32] foo$fmt_copyin(a ptr[in, fmt[dec, for_fmt]]) foo$fmt_copyout(a ptr[out, fmt[dec, for_fmt]]) ### resource for_fmt cannot be created in fmt + + +define FLAG1 1 +define FLAG2 2 + +some_nested_nested_flags { + f4 int32 +} + +some_nested_flags { + f1 int32 + f2 array[some_nested_nested_flags] + f4 for_fmt + f5 int32 (if[value[f1] == 0]) + f6 some_nested_nested_flags +} [packed] + +conditional_fields { + f1 int32 + f2 some_nested_flags (if[value[f1] & FLAG1]) + f3 some_nested_flags + f4 int32 (if[value[f3:f1] != 0]) + f5 int32 (if[value[f3:f2:f4] != 0]) ### value path f2 does not refer to a struct + f6 int32 (if[value[f3:f4] != 0]) ### f4 does not refer to an integer + f7 int32 (if[value[f3:some_field] != 0]) ### value target some_field does not exist in some_nested_flags + f8 int32 (if[value[f3:f5] != 0]) ### f5 has conditions, so value path cannot reference it + f9 int32 (if[value[parent:a] != 0]) ### value target a does not exist in conditional_fields + f10 int32 (if[value[f3:f6] != 0]) ### f6 does not refer to an integer + f11 len[f2, int32] ### f2 has conditions, so len path cannot reference it + f12 union_cond_fields + f13 int32:8 (if[1]) ### bitfields may not have conditions +} [packed] + +union_cond_fields [ + u1 int32 (if[value[parent:parent:f1] != 0]) + u2 int32 (if[value[parent:parent:unknown] != 0]) ### value target unknown does not exist in conditional_fields + u3 int64 +] + +foo$conditional(a ptr[in, conditional_fields]) + +conditional_non_packed { + f0 int64 + f1 conditional_non_packed_nested ### variable size field f1 in the middle of non-packed struct conditional_non_packed + f2 int64 +} + +conditional_non_packed_nested { + f3 int64 (if[value[parent:parent:f0]]) + f4 int32 +} [packed] + +foo$conditional2(a ptr[in, conditional_non_packed]) + +conditional_non_packed2 { + f0 int64 + f1 int8 (if[value[f0] == 0]) ### variable size field f1 in the middle of non-packed struct conditional_non_packed2 + f2 int64 +} + +foo$conditional3(a ptr[in, conditional_non_packed2]) |
