mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Rename 'intrinsic' to 'builtin'
This matches the term used in the WGSL spec. Change-Id: I4603332b828450c126ef806f1064ed54f372013f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/78787 Reviewed-by: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/tok"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/tok"
|
||||
)
|
||||
|
||||
// AST is the parsed syntax tree of the intrinsic definition file
|
||||
@@ -17,13 +17,13 @@ package gen
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/list"
|
||||
"dawn.googlesource.com/tint/tools/src/lut"
|
||||
)
|
||||
|
||||
// IntrinsicTable holds data specific to the intrinsic_table.inl.tmpl template
|
||||
type IntrinsicTable struct {
|
||||
// BuiltinTable holds data specific to the intrinsic_table.inl.tmpl template
|
||||
type BuiltinTable struct {
|
||||
// The semantic info
|
||||
Sem *sem.Sem
|
||||
|
||||
@@ -42,7 +42,7 @@ type IntrinsicTable struct {
|
||||
OpenNumbers []OpenNumber // kOpenNumbers table content
|
||||
Parameters []Parameter // kParameters table content
|
||||
Overloads []Overload // kOverloads table content
|
||||
Functions []Function // kIntrinsics table content
|
||||
Functions []Function // kBuiltins table content
|
||||
}
|
||||
|
||||
// OpenType is used to create the C++ OpenTypeInfo structure
|
||||
@@ -68,9 +68,9 @@ type Parameter struct {
|
||||
// The parameter usage (parameter name)
|
||||
Usage string
|
||||
|
||||
// Index into IntrinsicTable.MatcherIndices, beginning the list of matchers
|
||||
// Index into BuiltinTable.MatcherIndices, beginning the list of matchers
|
||||
// required to match the parameter type. The matcher indices index
|
||||
// into IntrinsicTable::TMatchers and / or IntrinsicTable::NMatchers.
|
||||
// into BuiltinTable::TMatchers and / or BuiltinTable::NMatchers.
|
||||
// These indices are consumed by the matchers themselves.
|
||||
// The first index is always a TypeMatcher.
|
||||
MatcherIndicesOffset *int
|
||||
@@ -84,15 +84,15 @@ type Overload struct {
|
||||
NumOpenTypes int
|
||||
// Total number of open numbers for the overload
|
||||
NumOpenNumbers int
|
||||
// Index to the first open type in IntrinsicTable.OpenTypes
|
||||
// Index to the first open type in BuiltinTable.OpenTypes
|
||||
OpenTypesOffset *int
|
||||
// Index to the first open number in IntrinsicTable.OpenNumbers
|
||||
// Index to the first open number in BuiltinTable.OpenNumbers
|
||||
OpenNumbersOffset *int
|
||||
// Index to the first parameter in IntrinsicTable.Parameters
|
||||
// Index to the first parameter in BuiltinTable.Parameters
|
||||
ParametersOffset *int
|
||||
// Index into IntrinsicTable.MatcherIndices, beginning the list of matchers
|
||||
// Index into BuiltinTable.MatcherIndices, beginning the list of matchers
|
||||
// required to match the return type. The matcher indices index
|
||||
// into IntrinsicTable::TMatchers and / or IntrinsicTable::NMatchers.
|
||||
// into BuiltinTable::TMatchers and / or BuiltinTable::NMatchers.
|
||||
// These indices are consumed by the matchers themselves.
|
||||
// The first index is always a TypeMatcher.
|
||||
ReturnMatcherIndicesOffset *int
|
||||
@@ -109,10 +109,10 @@ type Function struct {
|
||||
OverloadsOffset *int
|
||||
}
|
||||
|
||||
// Helper for building the IntrinsicTable
|
||||
type intrinsicTableBuilder struct {
|
||||
// Helper for building the BuiltinTable
|
||||
type BuiltinTableBuilder struct {
|
||||
// The output of the builder
|
||||
IntrinsicTable
|
||||
BuiltinTable
|
||||
|
||||
// Lookup tables.
|
||||
// These are packed (compressed) once all the entries have been added.
|
||||
@@ -127,7 +127,7 @@ type intrinsicTableBuilder struct {
|
||||
|
||||
// Helper for building a single overload
|
||||
type overloadBuilder struct {
|
||||
*intrinsicTableBuilder
|
||||
*BuiltinTableBuilder
|
||||
// Maps TemplateParam to index in openTypes
|
||||
openTypeIndex map[sem.TemplateParam]int
|
||||
// Maps TemplateParam to index in openNumbers
|
||||
@@ -138,9 +138,9 @@ type overloadBuilder struct {
|
||||
openNumbers []OpenNumber
|
||||
// All parameters declared by the overload
|
||||
parameters []Parameter
|
||||
// Index into IntrinsicTable.MatcherIndices, beginning the list of matchers
|
||||
// Index into BuiltinTable.MatcherIndices, beginning the list of matchers
|
||||
// required to match the return type. The matcher indices index
|
||||
// into IntrinsicTable::TMatchers and / or IntrinsicTable::NMatchers.
|
||||
// into BuiltinTable::TMatchers and / or BuiltinTable::NMatchers.
|
||||
// These indices are consumed by the matchers themselves.
|
||||
// The first index is always a TypeMatcher.
|
||||
returnTypeMatcherIndicesOffset *int
|
||||
@@ -148,7 +148,7 @@ type overloadBuilder struct {
|
||||
|
||||
// layoutMatchers assigns each of the TMatchers and NMatchers a unique index
|
||||
// in the C++ Matchers::type and Matchers::number arrays, respectively.
|
||||
func (b *intrinsicTableBuilder) layoutMatchers(s *sem.Sem) {
|
||||
func (b *BuiltinTableBuilder) layoutMatchers(s *sem.Sem) {
|
||||
// First MaxOpenTypes of TMatchers are open types
|
||||
b.TMatchers = make([]sem.Named, s.MaxOpenTypes)
|
||||
for _, m := range s.Types {
|
||||
@@ -169,11 +169,11 @@ func (b *intrinsicTableBuilder) layoutMatchers(s *sem.Sem) {
|
||||
}
|
||||
|
||||
// buildOverload constructs an Overload for a sem.Overload
|
||||
func (b *intrinsicTableBuilder) buildOverload(o *sem.Overload) (Overload, error) {
|
||||
func (b *BuiltinTableBuilder) buildOverload(o *sem.Overload) (Overload, error) {
|
||||
ob := overloadBuilder{
|
||||
intrinsicTableBuilder: b,
|
||||
openTypeIndex: map[sem.TemplateParam]int{},
|
||||
openNumberIndex: map[sem.TemplateParam]int{},
|
||||
BuiltinTableBuilder: b,
|
||||
openTypeIndex: map[sem.TemplateParam]int{},
|
||||
openNumberIndex: map[sem.TemplateParam]int{},
|
||||
}
|
||||
|
||||
if err := ob.buildOpenTypes(o); err != nil {
|
||||
@@ -279,7 +279,7 @@ func (b *overloadBuilder) buildReturnType(o *sem.Overload) error {
|
||||
}
|
||||
|
||||
// matcherIndex returns the index of TMatcher or NMatcher in
|
||||
// IntrinsicTable.TMatcher or IntrinsicTable.NMatcher, respectively.
|
||||
// BuiltinTable.TMatcher or BuiltinTable.NMatcher, respectively.
|
||||
func (b *overloadBuilder) matcherIndex(n sem.Named) (int, error) {
|
||||
switch n := n.(type) {
|
||||
case *sem.Type, *sem.TypeMatcher:
|
||||
@@ -342,10 +342,10 @@ func (b *overloadBuilder) collectMatcherIndices(fqn sem.FullyQualifiedName) ([]i
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// buildIntrinsicTable builds the IntrinsicTable from the semantic info
|
||||
func buildIntrinsicTable(s *sem.Sem) (*IntrinsicTable, error) {
|
||||
b := intrinsicTableBuilder{
|
||||
IntrinsicTable: IntrinsicTable{
|
||||
// buildBuiltinTable builds the BuiltinTable from the semantic info
|
||||
func buildBuiltinTable(s *sem.Sem) (*BuiltinTable, error) {
|
||||
b := BuiltinTableBuilder{
|
||||
BuiltinTable: BuiltinTable{
|
||||
Sem: s,
|
||||
TMatcherIndex: map[sem.Named]int{},
|
||||
NMatcherIndex: map[sem.Named]int{},
|
||||
@@ -383,5 +383,5 @@ func buildIntrinsicTable(s *sem.Sem) (*IntrinsicTable, error) {
|
||||
b.lut.parameters.Compact()
|
||||
b.lut.overloads.Compact()
|
||||
|
||||
return &b.IntrinsicTable, nil
|
||||
return &b.BuiltinTable, nil
|
||||
}
|
||||
@@ -22,15 +22,15 @@ import (
|
||||
"text/template"
|
||||
"unicode"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/sem"
|
||||
)
|
||||
|
||||
type generator struct {
|
||||
s *sem.Sem
|
||||
t *template.Template
|
||||
cached struct {
|
||||
intrinsicTable *IntrinsicTable // lazily built by intrinsicTable()
|
||||
permuter *Permuter // lazily built by permute()
|
||||
builtinTable *BuiltinTable // lazily built by builtinTable()
|
||||
permuter *Permuter // lazily built by permute()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (g *generator) generate(tmpl string, w io.Writer, writeFile WriteFile) erro
|
||||
"IsDeclarable": isDeclarable,
|
||||
"IsFirstIn": isFirstIn,
|
||||
"IsLastIn": isLastIn,
|
||||
"IntrinsicTable": g.intrinsicTable,
|
||||
"BuiltinTable": g.builtinTable,
|
||||
"Permute": g.permute,
|
||||
"Eval": g.eval,
|
||||
"WriteFile": func(relpath, content string) (string, error) { return "", writeFile(relpath, content) },
|
||||
@@ -121,17 +121,17 @@ func (g *generator) eval(template string, args ...interface{}) (string, error) {
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
// intrinsicTable lazily calls and returns the result of buildIntrinsicTable(),
|
||||
// builtinTable lazily calls and returns the result of buildBuiltinTable(),
|
||||
// caching the result for repeated calls.
|
||||
func (g *generator) intrinsicTable() (*IntrinsicTable, error) {
|
||||
if g.cached.intrinsicTable == nil {
|
||||
func (g *generator) builtinTable() (*BuiltinTable, error) {
|
||||
if g.cached.builtinTable == nil {
|
||||
var err error
|
||||
g.cached.intrinsicTable, err = buildIntrinsicTable(g.s)
|
||||
g.cached.builtinTable, err = buildBuiltinTable(g.s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return g.cached.intrinsicTable, nil
|
||||
return g.cached.builtinTable, nil
|
||||
}
|
||||
|
||||
// permute lazily calls buildPermuter(), caching the result for repeated
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/fileutils"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
"unicode"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/tok"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/tok"
|
||||
)
|
||||
|
||||
// Lex produces a list of tokens for the given source code
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/lexer"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/tok"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/lexer"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/tok"
|
||||
)
|
||||
|
||||
func TestLexTokens(t *testing.T) {
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// intrinsic-gen parses the <tint>/src/intrinsics.def file, then scans the
|
||||
// builtin-gen parses the <tint>/src/builtins.def file, then scans the
|
||||
// project directory for '<file>.tmpl' files, to produce '<file>' source code
|
||||
// files.
|
||||
package main
|
||||
@@ -25,14 +25,14 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/gen"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/parser"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/resolver"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/gen"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/parser"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/resolver"
|
||||
"dawn.googlesource.com/tint/tools/src/fileutils"
|
||||
"dawn.googlesource.com/tint/tools/src/glob"
|
||||
)
|
||||
|
||||
const defProjectRelPath = "src/intrinsics.def"
|
||||
const defProjectRelPath = "src/builtins.def"
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
@@ -43,13 +43,13 @@ func main() {
|
||||
|
||||
func showUsage() {
|
||||
fmt.Println(`
|
||||
intrinsic-gen generates the intrinsic table for the Tint compiler
|
||||
builtin-gen generates the builtin table for the Tint compiler
|
||||
|
||||
intrinsic-gen parses the <tint>/src/intrinsics.def file, then scans the project
|
||||
builtin-gen parses the <tint>/src/builtins.def file, then scans the project
|
||||
directory for '<file>.tmpl' files, to produce '<file>' source code files.
|
||||
|
||||
usage:
|
||||
intrinsic-gen
|
||||
builtin-gen
|
||||
|
||||
optional flags:`)
|
||||
flag.PrintDefaults()
|
||||
@@ -58,7 +58,7 @@ optional flags:`)
|
||||
}
|
||||
|
||||
func run() error {
|
||||
// Load the intrinsics definition file
|
||||
// Load the builtins definition file
|
||||
projectRoot := fileutils.ProjectRoot()
|
||||
defPath := filepath.Join(projectRoot, defProjectRelPath)
|
||||
|
||||
@@ -161,10 +161,10 @@ const header = `// Copyright 2021 The Tint Authors.
|
||||
// limitations under the License.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// File generated by tools/intrinsic-gen
|
||||
// File generated by tools/builtin-gen
|
||||
// using the template:
|
||||
// %v
|
||||
// and the intrinsic defintion file:
|
||||
// and the builtin defintion file:
|
||||
// %v
|
||||
//
|
||||
// Do not modify this file directly
|
||||
@@ -12,16 +12,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package parser provides a basic parser for the Tint intrinsic definition
|
||||
// Package parser provides a basic parser for the Tint builtin definition
|
||||
// language
|
||||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/lexer"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/tok"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/lexer"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/tok"
|
||||
)
|
||||
|
||||
// Parse produces a list of tokens for the given source code
|
||||
@@ -17,8 +17,8 @@ package parser_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/parser"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/parser"
|
||||
)
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/tok"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/sem"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/tok"
|
||||
)
|
||||
|
||||
type resolver struct {
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/parser"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/resolver"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/parser"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/resolver"
|
||||
)
|
||||
|
||||
func TestResolver(t *testing.T) {
|
||||
@@ -17,7 +17,7 @@ package sem
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/intrinsic-gen/ast"
|
||||
"dawn.googlesource.com/tint/tools/src/cmd/builtin-gen/ast"
|
||||
)
|
||||
|
||||
// Sem is the root of the semantic tree
|
||||
@@ -27,9 +27,9 @@ type Sem struct {
|
||||
TypeMatchers []*TypeMatcher
|
||||
EnumMatchers []*EnumMatcher
|
||||
Functions []*Function
|
||||
// Maximum number of open-types used across all intrinsics
|
||||
// Maximum number of open-types used across all builtins
|
||||
MaxOpenTypes int
|
||||
// Maximum number of open-numbers used across all intrinsics
|
||||
// Maximum number of open-numbers used across all builtins
|
||||
MaxOpenNumbers int
|
||||
// The alphabetically sorted list of unique parameter names
|
||||
UniqueParameterNames []string
|
||||
@@ -121,7 +121,7 @@ type TemplateNumberParam struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// Function describes the overloads of an intrinsic function
|
||||
// Function describes the overloads of a builtin function
|
||||
type Function struct {
|
||||
Name string
|
||||
Overloads []*Overload
|
||||
Reference in New Issue
Block a user