mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 13:38:00 +00:00
tint: intrinsics.def Support [[precedence]] decoration
Add support for a [[precedence(N)]] decoration on intrinsic table type declarations. This will be used to ensure the type with the lowest conversion rank is matched when a matcher could match multiple types for a given abstract numeric argument type. Bug: tint:1504 Change-Id: I96475b000c0917bbfa4e2873b1731ce048b96a7d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90664 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
aed7eb4b4c
commit
c670018aea
@@ -142,7 +142,7 @@ func (p *parser) decorations() ast.Decorations {
|
||||
values := []string{}
|
||||
if p.match(tok.Lparen) != nil {
|
||||
for p.err == nil {
|
||||
values = append(values, p.string())
|
||||
values = append(values, string(p.next().Runes))
|
||||
if p.match(tok.Comma) == nil {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -100,6 +100,16 @@ func TestParser(t *testing.T) {
|
||||
Name: "T",
|
||||
}},
|
||||
},
|
||||
}, { ///////////////////////////////////////////////////////////////////
|
||||
utils.ThisLine(),
|
||||
`[[deco(1, "x")]] type T`, ast.AST{
|
||||
Types: []ast.TypeDecl{{
|
||||
Decorations: ast.Decorations{
|
||||
{Name: "deco", Values: []string{"1", "x"}},
|
||||
},
|
||||
Name: "T",
|
||||
}},
|
||||
},
|
||||
}, { ///////////////////////////////////////////////////////////////////
|
||||
utils.ThisLine(),
|
||||
"match M : A",
|
||||
|
||||
@@ -17,6 +17,7 @@ package resolver
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/cmd/intrinsic-gen/ast"
|
||||
"dawn.googlesource.com/dawn/tools/src/cmd/intrinsic-gen/sem"
|
||||
@@ -179,6 +180,17 @@ func (r *resolver) ty(a ast.TypeDecl) error {
|
||||
}
|
||||
t.DisplayName = d.Values[0]
|
||||
}
|
||||
if d := a.Decorations.Take("precedence"); d != nil {
|
||||
if len(d.Values) != 1 {
|
||||
return fmt.Errorf("%v expected a single integer value for 'precedence' decoration", d.Source)
|
||||
}
|
||||
n, err := strconv.Atoi(d.Values[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v %v", d.Source, err)
|
||||
}
|
||||
t.Precedence = n
|
||||
}
|
||||
|
||||
if len(a.Decorations) != 0 {
|
||||
return fmt.Errorf("%v unknown decoration", a.Decorations[0].Source)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package sem
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"dawn.googlesource.com/dawn/tools/src/cmd/intrinsic-gen/ast"
|
||||
)
|
||||
@@ -89,6 +90,7 @@ type Type struct {
|
||||
Decl ast.TypeDecl
|
||||
Name string
|
||||
DisplayName string
|
||||
Precedence int
|
||||
}
|
||||
|
||||
// TypeMatcher declares a type matcher
|
||||
@@ -99,6 +101,13 @@ type TypeMatcher struct {
|
||||
Types []*Type
|
||||
}
|
||||
|
||||
func (t TypeMatcher) PrecedenceSortedTypes() []*Type {
|
||||
out := make([]*Type, len(t.Types))
|
||||
copy(out, t.Types)
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Precedence > out[j].Precedence })
|
||||
return out
|
||||
}
|
||||
|
||||
// EnumMatcher declares a enum matcher
|
||||
type EnumMatcher struct {
|
||||
TemplateParams []TemplateParam
|
||||
|
||||
Reference in New Issue
Block a user