tint: Add operator support to intrinsic-gen

Adapt the builtin parsing and resolving to also support operators.
Will be used to generate intrinsic table entries for operators.

This will simplify maintenance of the operators, and will greatly
simplify the [AbstractInt -> i32|u32] [AbstractFloat -> f32|f16] logic.

Bug: tint:1504
Change-Id: Id75735ea24e501877418812185796f3fba88a521
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89026
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2022-05-09 18:08:23 +00:00
committed by Dawn LUCI CQ
parent d84daed72c
commit e6e96def66
18 changed files with 783 additions and 347 deletions

View File

@@ -26,7 +26,8 @@ type Sem struct {
Types []*Type
TypeMatchers []*TypeMatcher
EnumMatchers []*EnumMatcher
Functions []*Function
Builtins []*Intrinsic
Operators []*Intrinsic
// Maximum number of open-types used across all builtins
MaxOpenTypes int
// Maximum number of open-numbers used across all builtins
@@ -42,7 +43,8 @@ func New() *Sem {
Types: []*Type{},
TypeMatchers: []*TypeMatcher{},
EnumMatchers: []*EnumMatcher{},
Functions: []*Function{},
Builtins: []*Intrinsic{},
Operators: []*Intrinsic{},
}
}
@@ -121,16 +123,16 @@ type TemplateNumberParam struct {
Name string
}
// Function describes the overloads of a builtin function
type Function struct {
// Intrinsic describes the overloads of a builtin or operator
type Intrinsic struct {
Name string
Overloads []*Overload
}
// Overload describes a single overload of a function
// Overload describes a single overload of a builtin or operator
type Overload struct {
Decl ast.FunctionDecl
Function *Function
Decl ast.IntrinsicDecl
Intrinsic *Intrinsic
TemplateParams []TemplateParam
OpenTypes []*TemplateTypeParam
OpenNumbers []TemplateParam
@@ -164,7 +166,13 @@ func (u StageUses) List() []string {
// Format implements the fmt.Formatter interface
func (o Overload) Format(w fmt.State, verb rune) {
fmt.Fprintf(w, "fn %v", o.Function.Name)
switch o.Decl.Kind {
case ast.Builtin:
fmt.Fprintf(w, "fn ")
case ast.Operator:
fmt.Fprintf(w, "op ")
}
fmt.Fprintf(w, "%v", o.Intrinsic.Name)
if len(o.TemplateParams) > 0 {
fmt.Fprintf(w, "<")
for i, t := range o.TemplateParams {