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:
Ben Clayton
2022-05-18 18:56:58 +00:00
committed by Dawn LUCI CQ
parent aed7eb4b4c
commit c670018aea
7 changed files with 311 additions and 275 deletions

View File

@@ -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