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

@@ -52,10 +52,6 @@ func (l *lexer) lex() error {
l.next()
case '\n':
l.next()
case '<':
l.tok(1, tok.Lt)
case '>':
l.tok(1, tok.Gt)
case '(':
l.tok(1, tok.Lparen)
case ')':
@@ -68,8 +64,14 @@ func (l *lexer) lex() error {
l.tok(1, tok.Colon)
case ',':
l.tok(1, tok.Comma)
case '|':
l.tok(1, tok.Or)
case '*':
l.tok(1, tok.Star)
case '+':
l.tok(1, tok.Plus)
case '%':
l.tok(1, tok.Modulo)
case '^':
l.tok(1, tok.Xor)
case '"':
start := l.loc
l.next() // Skip opening quote
@@ -81,13 +83,16 @@ func (l *lexer) lex() error {
l.next() // Skip closing quote
default:
switch {
case l.peek(1) == '/':
case l.peek(0) == '/' && l.peek(1) == '/':
l.skip(l.count(toFirst('\n')))
l.next() // Consume newline
case l.match("/", tok.Divide):
case l.match("[[", tok.Ldeco):
case l.match("]]", tok.Rdeco):
case l.match("->", tok.Arrow):
case l.match("-", tok.Minus):
case l.match("fn", tok.Function):
case l.match("op", tok.Operator):
case l.match("enum", tok.Enum):
case l.match("type", tok.Type):
case l.match("match", tok.Match):
@@ -95,6 +100,19 @@ func (l *lexer) lex() error {
l.tok(l.count(alphaNumericOrUnderscore), tok.Identifier)
case unicode.IsNumber(l.peek(0)):
l.tok(l.count(unicode.IsNumber), tok.Integer)
case l.match("&&", tok.AndAnd):
case l.match("&", tok.And):
case l.match("||", tok.OrOr):
case l.match("|", tok.Or):
case l.match("!=", tok.NotEqual):
case l.match("==", tok.Equal):
case l.match("=", tok.Assign):
case l.match("<<", tok.Shl):
case l.match("<=", tok.Le):
case l.match("<", tok.Lt):
case l.match(">=", tok.Ge):
case l.match(">>", tok.Shr):
case l.match(">", tok.Gt):
default:
return fmt.Errorf("%v: unexpected '%v'", l.loc, string(l.runes[0]))
}