// Copyright 2021 The Tint Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package gen import ( "fmt" "io" "reflect" "strings" "text/template" "unicode" "dawn.googlesource.com/tint/tools/src/cmd/intrinsic-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() } } // WriteFile is a function that Generate() may call to emit a new file from a // template. // relpath is the relative path from the currently executing template. // content is the file content to write. type WriteFile func(relpath, content string) error // Generate executes the template tmpl using the provided semantic // information, writing the output to w. // See https://golang.org/pkg/text/template/ for documentation on the template // syntax. func Generate(s *sem.Sem, tmpl string, w io.Writer, writeFile WriteFile) error { g := generator{s: s} return g.generate(tmpl, w, writeFile) } func (g *generator) generate(tmpl string, w io.Writer, writeFile WriteFile) error { t, err := template.New("