Migrate all uses to use this and the new `unique_type<T>()` and `types()` methods.
Remove the `type_mgr()` accessor. `TypeManager` is now an implementation detail of the module, allowing us to unify the allocation of types and nodes (if we so wish).
Fixes: tint:337
Bug: tint:307
Change-Id: I233fa9dc73d60515dd721f02ea7ba089ef7d374f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33667
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
First step to moving this to the `ast::Module`.
Also remove a bunch of redundant includes to `type_manager.h` as this is already included in `context.h`
Bug: tint:307
Bug: tint:337
Change-Id: Ic4baffa7b76ddefa29f56f758c25b1003ef40888
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33665
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Synthesize Tint types for handle variables and function parameters.
Bug: tint:109
Change-Id: I3c155e03b154c5ebf46e79c96a6e2b054dbca9b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33341
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
The reason being that some tests called parse() twice, which will silently destruct the first parser.
Once the `Module` owns the AST nodes, the second call will end up deleting all the AST nodes. Tests would then perform use-after-free for the AST nodes belonging to the first parser / module.
There's no reason why the unique_ptr can't be returned, which is cleaner overall.
Bug: tint:335
Change-Id: I7ff2e9777a7ebeb76702f806294fe4c2c49bd7c9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33241
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Change-Id: I2fed4cf2a052686e2121066588686f05907a169f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33200
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
It's valid to look for but not find an underlying memory object
declaration.
Bug: tint:109
Change-Id: I7296d79550a50050d2438996dc3e0c8d09a6babd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33140
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
We convert types of samplers, images, and sampled images entirely
differently, but still find it useful to generalize ParserImpl::ConvertType
to cover them.
Fake it: Make ConvertType return void for them.
Bug: tint:109
Change-Id: I0982eb987d0914db8227bc0fce552989831129b9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33020
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Change-Id: I56a314d0c4eb1f1dfdb8804024a5824e5456356c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32940
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Remove all redundant std::move()s. I've also removed calls to
std::move() in tests, even if they act as an optimization. This is for
two reasons:
(a) Performance is not important for testing, and this helps with
readability.
(b) A whole bunch tests were relying on std::move() clearing vectors so
they can be repopulated and used again. This is undefined behavior:
> Objects of types defined in the C++ standard library may be moved from
> (12.8). Move operations may be explicitly specified or implicitly
> generated. Unless otherwise specified, such moved-from objects shall
> be placed in a valid but unspecified state.
All of these UB cases have been fixed.
Removed all duplicate variables left over from:
`auto* foo_ptr = foo.get()`
which became:
`auto* foo_ptr = foo`
Bug: tint:322
Change-Id: Ibd08a2379671382320fd4d8da296ccc6a378b8af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32900
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is a minimal effort to fix up the code. There's substantial code
cleanup which can now be done, which is done in the next change.
Bug: tint:322
Change-Id: Iafcf5e814837d9534889e8c21333de4931a19cfa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32864
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
create() is currently just a simple forwarder to std::make_unique<>, but
will be later replaced with a function that returns a raw pointer,
and owned by the context.
Bug: tint:322
Change-Id: I281fe91864a98365db5ccd40e264d042e6476172
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32861
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
create() is currently just a simple forwarder to std::make_unique<>, but
will be later replaced with a function that returns a raw pointer,
and owned by the context.
Bug: tint:322
Change-Id: I72558482c4b6aff7a655087ee010b3e16b006192
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32860
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
In a near-future change, AST nodes, such as ast::BlockStatement will no longer
be std::unique_ptrs, and will have to be constructed and owned by an external
class. This means AST nodes can no longer allocate default child nodes.
Bug: tint:322
Change-Id: I36a1cf55c31a1dabccde272b2be415f98c16b18f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32677
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds the result_type type_name into the AST dump if available.
Bug: tint:310, tint:308
Change-Id: Iea678fd4f7a2dadbfca86f29043c75459c421cb3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32780
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
In a near-future change, AST nodes, such as ast::BlockStatement will no longer
be std::unique_ptrs, and will have to be constructed and owned by an external
class. This means AST nodes can no longer allocate default child nodes.
Bug: tint:322
Change-Id: I2a571d0a4727d6dc3d6c38e8b6602e131292f49c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32676
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
In a near-future change, AST nodes, such as ast::BlockStatement will no longer
be std::unique_ptrs, and will have to be constructed and owned by an external
class. This means AST nodes can no longer allocate default child nodes.
Bug: tint:322
Change-Id: I3db9b3c037896f07b84b14b7b8d4da0f066b69b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32679
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
In a near-future change, AST nodes, such as ast::BlockStatement will no longer
be std::unique_ptrs, and will have to be constructed and owned by an external
class. This means AST nodes can no longer allocate default child nodes.
Bug: tint:322
Change-Id: Iddb5605b9bc0de80ad2710ced0e429f89410af2f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32675
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
A common base class is required to move from std::unique_ptr<> to raw pointers for AST types.
Also unifies a bunch of similar APIs.
Bug: tint:322
Change-Id: If829f8c3f22069adf62751365f1f1eeb646aba08
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32660
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Use synchronization tokens to ensure the parser can resynchronize on error.
Bug: tint:282
Change-Id: I8bb033f8a723eb8f2bc029e1ffc8350174c964e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32284
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
I feel this reads better.
Bug: tint:282
Change-Id: I04fe42a0347ea050e93e5cf5ccae7259bc79bb58
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32283
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
A number of tests check the first encountered error is correct.
As the parser currently aborts after the first error, later errors are ignored.
Once the parser supports resynchronization, we'll emit multiple error messages, and these tests will start to fail. Fix them now.
Bug: tint:282
Change-Id: If8d0c41f030c652500b2e3b7284297b7a448d23e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32282
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Split out statments that are non-block (non-loops, etc) into a separate function.
These all end with a semi-colon, which is important for resynchronization on errors (coming up in another change).
Bug: tint:282
Change-Id: I0e58c4938f2bbe859dc6ffb8dcd45c8cf26101da
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32281
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reduces code, paves the way for multiple errors with resynchronization points.
Bug: tint:282
Change-Id: I68018ea8cabe4ec347afa21d1220126d6348d3d1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32280
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
For values of type T* and std::unique_ptr<T>.
This allows us to replace all occurances of `res.value->member` with: `res->member`, which also asserts that `res` is not in an error state.
Brings the verbosity back down to pre-expect and pre-maybe levels.
Bug: tint:282
Change-Id: Ib00018affca53ac5e71ee2140e7e0cd607b83715
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
And use it for the non-ParserImpl::expect_xxx() methods.
Another step towards supporting multiple error messages, as the caller can now test to see if the specific call errored, or didn't match, instead of using a global error state.
Makes reading the control flow conditionals a bit easier too.
Change-Id: Ie8627b8499ec9079167965da2a566401cd6bd903
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32102
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
And use it for the ParserImpl::expect_xxx() methods.
This is the first step towards supporting multiple error messages, as
the caller can now test to see if the specific call errored, instead of
using a global error state.
Also cleans up a bunch of code.
Bug: tint:282
Change-Id: I5e39fc33bd1e16620cee80d27fa728bc2af3387e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32101
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reduces code. Keeps things more consistent.
Bug: tint:282
Change-Id: Iff280880eb033fbcee4c6095c2da2d4af06835b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32103
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
All the call sites of `storage_class()` add their own error handling, so transform this into `expect_storage_class()`.
Also makes error messages more consistent.
Bug: tint:282
Change-Id: I5131acd84f91fc7494ed6b90965853b7d0fc37f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32104
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
All the call sites of `variable_ident_decl()` add their own error handling, so transform this into `expect_variable_ident_decl()`.
Also makes error messages more consistent.
Bug: tint:282
Change-Id: I0b5ac984018ba78896ddec0320636f5b5c4ad0b2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32100
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
The `expect_` prefixes now clearly indicate when a method will internally error, or produce a valid AST object.
Verified by code coverage.
Bug: tint:282
Change-Id: Icbdae9db02bd48c69aec010a4f8fdc5a496125f8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32002
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
... for those that will internally error if the grammar does not match,
otherwise will always return a valid AST object.
This helps identify whether the caller is expected to error or not.
Bug: tint:282
Change-Id: Ied94f717526a63033f2e6c9e94fca43dbf0b8f05
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32001
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This Cl updates the storage textures to have `storage` in the name. So,
`texture_ro_1d` -> `texture_storage_ro_1d`
Bug: tint:286
Change-Id: I0a9ea02f15de2681d64e272cb42be51a940b6a13
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31840
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Parse all decorations with the same function, and create a
`ast::DecorationList`. Once the parser has progressed to the consumer of
the decorations, we attempt to downcast these to the required type,
erroring if they're the wrong kind.
While the error message could be improved further, this greatly reduces
the headscratching around crbug.com/tint/291.
Also knocks another 223 lines off parser_impl.cc.
Bug: tint:291
Bug: tint:282
Change-Id: I7506faeb56d876e5446d900c7c134669a9db6409
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31660
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
`expect_block()` takes a start and end token, along with a function to parse a lexical block body.
This reduces code, keeps error messages consistent, and also gives us a future place to try resynchronising the parser so we can have more than one error emitted.
`expect_paren_block()` and `expect_brace_block()` are convenience helpers for providing the start and end tokens for common block types.
Bug: tint:282
Change-Id: I432a0301727b131a6fce875687b952dfc6889a4b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31736
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
The only place that calls `pipeline_stage()` expects a stage to exist, so follow the `expect_` pattern.
Bug: tint:282
Change-Id: Ie18d24ed25a5f882e66a8e553e53b4fb52dcf6fa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31734
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL updates Tint to support the `texture_1d` format for sampled
textures. This is alongside the old `texture_sampled_1d` to allow
migration time.
The WGSL writer will always output the new form when converting to WGSL.
Bug: tint:286
Change-Id: I96f0308ad3c28ade96bcab7e24aa0b405e3c4f05
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31380
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
... to match() and expect_ident().
The uses of these two functions frequently want to know the souce of the matched token.
Bug: tint:282
Change-Id: I5279fc2e0834f48d419c6d8c9888189f6212c44a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31732
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
These will be used to simplify common parser patterns.
Bug: tint:282
Change-Id: Ia281b9aa66b98f4afc726e876fe8aeae5ff4f12c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31724
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Have slightly different overloads.
Long term we will want to be able to emit more than one error in a single parse.
Bug: tint:282
Bug: tint:291
Change-Id: Ide61c6ca75d45065e917b8fa16a097048397e31b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31723
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Once a `Decoration` has been parsed, it'll be placed into a `DecorationList` and validated later in the parse. In order to create error diagnostics that refer back to the decoration, we need to know its source.
Bug: tint:282
Bug: tint:291
Change-Id: I38de708adbd041601b61d7e0a4d0402e9a2fe526
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31722
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is the first step in unifying the way decorations are parsed - i.e. instead of parsing decorations in different ways based on the predicted grammar that follows, we can parse decorations blocks in a unified way, then later verify what we have is as expected.
`StructDecoration` has been transformed from an `enum class` to a proper class so it can derive from `Decoration`.
Bug: tint:282
Bug: tint:291
Change-Id: Iaf12d266068d03edf695acdf2cd21e6cc3ea8eb3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31663
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This CL fixes up the various lint errors.
Change-Id: If4d3077b55aadec33980452c43917194d803fac6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31680
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This test reproduces the unhelpful error message described in tint:291.
Bug: tint:291
Change-Id: Ie93cc59d981691981ba978b690d11c93dfe46ae0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31571
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Will now print with better formatting and colors on terminals that support it.
Bug: tint:282
Change-Id: Ibff341cb1dc2dcbda6fa0d72e24fdcb172990138
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31570
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
I had originally created `Formatter` as an interface as I was intending to implement this differently for linux and windows (for terminal coloring).
Color printing is instead implemented by the `Printer` interface / PIMPL classes.
Replace the multi-boolean constructor with a `Style` struct, as this will make life easier when we want to add / remove flags.
Bug: tint:282
Change-Id: I630073ed7a76c023348b66e8a8517b00b2b6a0d2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31569
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
... for the content. Everything should be using a `Source::File*` now.
Bug: tint:282
Change-Id: I9bebb94995a946a5919ba6503f2b0ee2058f0fb1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31482
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Keep the `ParserImpl::error()` format identical to the old error style for now.
Use the explicit `ParserImpl::diagnostics()` method for the error message tests, updating the tests to match the new, improved output.
Bug: tint:282
Change-Id: Ia7e1237170f0f5203a8cfa256322df29e90e2791
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31481
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Translate OpSpecConstantTrue, OpSpecConstantFalse, and OpSpecConstant.
The latter only can be used with integer or float scalars.
If the constant has a SpecId decoration, then generate a module-scope
decorated constant. Otherwise generate a module-scope constant without
decorations.
Register the ID so we know to use the declared const identifier in
expressions later in the module.
Bug: tint:156
Change-Id: Icd6e9b60225ced7ee99963c4f85cec1eb0e3ae6b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31541
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This includes a couple of position fixes in `lexer.cc`.
The source for identifiers (vars, params, etc) now refer to the identifier, not the first token of the construct.
Bug: tint:282
Change-Id: I58cb8422a4af1c7dc5f84431fd7f06b823b514c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31444
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Use `source().range.begin.line` and `source().range.begin.column` instead.
Bug: tint:282
Change-Id: I6c9bf8766d6db2c9d8e7e1b8bafb2eea93e065d8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31441
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This was a temporary overload to break up the changes into smaller chunks.
Change all call sites to use one of the other constructors.
Bug: tint:282
Change-Id: I500fe9700d22f72312827808caa22f7feef7b294
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31440
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is the first step in improving the error messages produced while parsing.
The `line` and `column` information of `Source` has been moved to `Source::Location`.
`Source::Range` has been added that contains a `Location` interval - allowing error messages to highlight the full region of the error.
The `File` information provides an optional file path, and pre-splits the content into lines. These lines can be used to print the full line containing an error.
This CL contains a few temporary changes that help split up this work, and to ease integration with Tint.
Bug: tint:282
Change-Id: I7aa501b0a9631f286e8e93fd7396bdbe38175727
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31420
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
There were a number of places where we were declaring classes derived from `testing::TestWithParam<T>` and then adding the same `parser()` helper logic.
Move this common logic down to a new `ParserImplTestWithParam<T>` class, and derive from that instead.
Removes a whole bunch of copy-pasta.
Change-Id: I8f308b77817fd6327c045d2fdee4462b7f32897a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31401
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
- Apply the AccessControlType wrappar around the struct type for any
variable in the StorageBuffer storage class.
- Drop the NonWritable member decorations for the struct type.
Bug: tint:108
Change-Id: I6496c8c3e8b5d92b2ed0071385915d2b8065a80d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31020
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL merges the StorageAccess enum with the AccessControl enum. The
enum is moved up to src/ast and placed in its own file for clarity.
Change-Id: I95a905a399b5d2e046ea1ea429b35f2064510c2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31242
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
These are _mostly_ covered in the over various test files, but unlike those, these new tests always parse from the root translation unit.
These new tests also use a new testing class which may be extended to verify error output for different error styles (verbosity, colors, etc).
Change-Id: I105488f9b16d90279af4cc418a1c845b6e239e9e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31263
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
With the addition of the AccessControlType we want to look through the
access control as well as the aliases as we work through the type tree.
This CL renames UnwrapAliasesIfNeeded to be UnwrapIfNeeded and
UnwrapAliasPtrAlias to UnwrapAll.
Change-Id: I5b027919c3143a89be24c4d87b8106f70358c03b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31104
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: David Neto <dneto@google.com>
Change-Id: I5774e4cfc8a570522ac6533d69b5b87f7e5e0b6c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31081
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
They should only be singly-assigned.
This is required because consts can hold pointers, but
var's cannot. And we need to support pointer arguments.
Bug: tint:275
Change-Id: I00a58734725bd08d40df71c736854a93c364a33c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30923
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
If is_const is true, then dump VariableConst{...
For ast::DecoratedVariable, dump "DecoratedVariableConst{..."
when it's const.
Change-Id: I8383e5bc989e4ee20e3a5812f346d5f9a7990dbb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30920
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL removes the `type IDENT = struct` format in favour of the
`struct IDENT` variant.
Bug: tint:175
Change-Id: I4fde8012fd07f811cd0bd80445198f6bbc92b720
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30661
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL adds the parsing of structs with names. The parsing of type
aliased structs remains to allow for migration to the new system. The
named struct format is always emitted.
Bug: tint:175
Change-Id: Ic0579dedbd2dd0edc7dfd30bc2ec02972091e718
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30341
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This CL changes the AST dumping order to emit alias types before global
variables. This makes the output easier to read as the types come before
the usages.
Bug: tint:175
Change-Id: Ib7325384b910472e89d6d01853503be989ce4210
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30281
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL moves the StructType name into the constructor of the struct
type instead of receiving through an accessor. The |set_name| accessor
is removed as it should not be needed anymore. All call sites have been
updated.
The vertex pulling transform was fixed to correctly register an alias
for the structure being created so it will be emitted.
Bug: tint:175
Change-Id: I8802931d9bdbc6c2f12982eea9032931939d195c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30280
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL updates the WGSL parser to allow global variable decorations
to accept multiple blocks.
Bug: tint:240
Change-Id: Iaf8f794d285d87af6e2ff8c93e34d88331eedccb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29840
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL updates the WGSL parser to allow array decorations to accept
multiple blocks. The stride decoration on arrays was turned into a
proper decoration object instead of just storing the stride directly.
Bug: tint:240
Change-Id: I6cdc7400d8847e3e043b846ea5c9f86cb795cf86
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29780
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: David Neto <dneto@google.com>
This CL updates the struct member decoration parsing to allow multiple
blocks of decorations.
Bug: tint:240
Change-Id: I97293ef30333f63c33bbc6e728dba11abc020c7c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29280
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This CL updates to match the spec change allowing multiple struct
decorations.
Bug: tint:240
Change-Id: Id859c6a331c67c46597fc3c70de06d6cc0f486ec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29260
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This CL removes the cast operator and converts the tests over to using
type constructors.
Bug: tint:241
Change-Id: I2526acb61f5624b2e1c068612a2ddcc748c92aed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28860
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL updates Tint to use 'bitcast' instead of 'as' for the OpBitcast
conversions.
Bug: tint:241
Change-Id: I53a80de10421b2d9cc009527eebe5ff07e1285c2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28801
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This CL removes the import mechanism, the identifier paths and updates
all of the standard library methods to be builtins.
Bug: tint:242
Change-Id: If09b98a155ae49ced3986ba2c9b517a060693006
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28720
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL removes the EntryPoint node and transitions everything to the
stage decoration.
Change-Id: Ib2840155905c8fa60ff35870f0c4b6705efb73ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28705
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL adds the emission of StageDecoration to entry point functions.
EntryPoint nodes are still emitted. We duplicate the function emission
if there are multiple entry points pointing to the same function.
Change-Id: Icb48a063f5c6a30948bbe2c37c7fce7431af5864
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28665
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL adds parsing of the stage decoration to the WGSL parser. The
decoration is not hooked up yet so it's effectively ignored.
Change-Id: I8d86c55cee189f993c10b6da31a9c388ba452021
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28664
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This Cl fixes the function parsing so the opening brace is required.
This will return an error now. The statement::body_stmt is changed to
make the open paren optional.
Bug: tint:236
Change-Id: I3faee1fd5add19aebcdb86943d6f4190c03d0f7a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28520
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This CL adds parsing of the `workgroup_size` function decoration.
Change-Id: Ia90efc2c014ac0e1614429280cc903d30cf8171d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28663
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL updates the variable decorations to require ()'s around
parameters.
Bug: tint:238
Change-Id: I835879f41349756ace553a52fc2d460173e70dce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28583
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL updates the array decorations to the new syntax requiring ()'s
around parameters.
Bug: tint:238
Change-Id: I5a8b19e302fbd3f78392553d8d1c5e882b900180
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28601
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL updates the parsing of struct decorations to require ()'s around
parameters.
Bug: tint:238
Change-Id: Ia35ca5c260c3c57b5fc95788bd1aef07f75edc39
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28600
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
This Cl adds the AST, WGSL-Reader and SPIRV-Writer support for the
`texture_multisampled_2d` type.
Bug: tint:237
Change-Id: Ib3eb831227b49f32162801f1e1b4e474774c78b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28480
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Until now, we were only setting the function name.
Bug: tint:3
Change-Id: I6d82f6e9744201a04cc8969013694e2e8304a928
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28080
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Set source location on function variable declarations, const
declarations, and most normal instructions.
Bug: tint:3
Change-Id: I469afcdf1b7d8f6d1e64617189a6fa329056737f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27700
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is required so we actually emit values that are only used
in phis.
Bug: tint:3, tint:215
Change-Id: I9d957a697839b8d09246905c3f28064f0bc01731
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27701
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
If OpLine debug instructions are present, use their line and column
numbers. Otherwise, use the instruction number as the line number, starting
counting from 1.
Bug: tint:3
Change-Id: Ia46c10732922b80b5737b13af1ef71f4259a3555
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27680
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
If a definition occurs in the first block of an IfSelection or
SwitchSelection, then it should count as belonging to the scope of the
parent of that if or switch selection. This prevents some bad hoisting
decisions.
Bug: tint:3, tint:213
Change-Id: I89df5e8cbc163577e19e78c2bf393eb1eec4a0aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27660
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Follow the actual SPIR-V type when computing a composite extract
instad of the canonicalized view in the optimizer's type manager.
Do this so we can generate the correct member name for a struct,
rather than using the member name for the other representative
struct type. The optimizer's type canonicalizer is insensitive to
struct member names.
Prompted by tint:213, for which the original case was an
access chain.
Bug: tint:3, tint:213
Change-Id: I8705c7ee655fe47c8b7a3658db524fe18833efdb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27603
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Follow the actual SPIR-V type when computing an access chain expression,
instead of the canonicalized view in the optimizer's type manager.
Do this so we can generate the correct member name for a struct,
rather than using the member name for the other representative
struct type. The optimizer's type canonicalizer is insensitive to
struct member names.
Fixes tint:213
Bug: tint:3, tint:213
Change-Id: I88ec42a4cb049b011a59d5522e4cb39bc181a4fb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27602
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL updates the WGSL parser to consume the closing } of an empty
struct.
Bug: tint:218
Change-Id: I0b17d2178b1b4b7f44fcf007da867db07dc2a6ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27600
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This cl adds some missing doc comments.
Change-Id: Ic5452c2f9a40ddcc4642062a338f602632f3e057
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27520
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
This Cl updates the AST dump command to emit struct members after
emitting the type alias.
Change-Id: I5e0c3d8f2cc56525586646c613839c2e014d471f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27320
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
The `const_expr` can recurse into itself if there are type declarations
inside the const_expr (e.g. vec2<f32>(f32(1.0), f32(2.0))). Currently
there is no limit on the amount of recursion which can be triggered.
This CL sets a limit of 128 nested type declarations at which point an
error will be emitted.
Bug: chromium:1112144
Change-Id: Ifae45034dc9de35aed78ba8eddf584a46c7a55ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27340
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Block statements will now be parsed in ParserImpl::statement()
Change-Id: I28f63d4a53c85c0306c57df545f78b4562c6ea7b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27262
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This CL adds stride support to the WGSL reader.
Bug: tint:178
Change-Id: Id6b5163438e562a371255ad3fb992d0a716543e7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26040
Reviewed-by: David Neto <dneto@google.com>
- drop ColMajor, MatrixStride member decoration
- RowMajor matrix decoration is an error
Bug: tint:3, tint:99, tint:31
Change-Id: I7eb1ec53813a4b1ada971e8725dc91ffdf97bd43
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25920
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL updates the SPIR-V Reader to create BlockStatements instead of
StatementLists.
Bug: tint:136
Change-Id: I957019446ca00306187de701f86ae3e0dd5c5eb8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25740
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL updates the WGSL Reader to create BlockStatements instead of
StatementLists.
Bug: tint:135
Change-Id: Ifda394023553a625dad67be7d4e0dc815292282a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25724
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL converts the LoopStatement class to using a BlockStatement
internally. All usages have been updated execept for the two readers.
Bug: tint:130
Change-Id: Ied4b82f0ef49c7b92caa040bcf73050093022df7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25723
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL converts the IfStatement and ElseStatement classes to using a
BlockStatement internally. All usages have been updated execept for the
two readers.
Bug: tint:130
Change-Id: I59a5b92f22f35f27f17e005aa9b266f4a2b0ef25
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25722
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL converts the CaseStatement class to using a BlockStatement
internally. All usages have been updated execept for the two readers.
Bug: tint:130
Change-Id: Idb9114230f7d9eb0f2208af635316edb0a0e8f99
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25721
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL converts the Function class to using a BlockStatement
internally. All usages have been updated execept for the two readers.
Bug: tint:130
Change-Id: I7159cf2d3ed5cb8a34d51fbe848b88f0e5479605
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25720
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This CL removes the KillStatement from the AST and replaces all test
usage with DiscardStatement.
Bug: tint:169
Change-Id: Ie68dd3cdd54056f144d10506f05cc1f6903d1cda
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25605
Reviewed-by: David Neto <dneto@google.com>
This CL changes the SPIRV-Reader to generate DiscardStatements instead
of KillStatements for an OpKill.
Bug: tint:168
Change-Id: Ic4223b614c822c6ad449f61aedaddc9605c42535
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25642
Reviewed-by: David Neto <dneto@google.com>
This CL adds parsing of the `discard` keyword to the WGSL reader.
Bug: tint:167
Change-Id: Iff91076a65715131f5f0f9bd1c8b6bf3a37cd3c7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25604
Reviewed-by: David Neto <dneto@google.com>
This CL updates the WGSL parser to handle a void function call.
Fixes: tint:45
Change-Id: If5b2a4b9e62f0b10e0f2e2e10c0ca2586c5268e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25322
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Still TODO: OpSelect over arrays and structures, as permitted in SPIR-V 1.4
Bug: tint:3, tint:99
Change-Id: I70f6c8a43ea3339cd715813c6eb0128d66ff0df8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25301
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds support for handling uniform data. Currently the uniform is
added to a buffer where the number is the binding value. This will need
to be updated to accept the correct mapping from the embedder.
Bug: tint:8
Change-Id: Icccccbe599a9555defa6136e384745f4093df020
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25104
Reviewed-by: David Neto <dneto@google.com>
Old way:
- struct decorated with BufferBlock
- Uniform storage class
New way
- struct decorated with Block
- StorageBuffer storage class
Also fixes the result type for an access chain.
Bug: tint:99
Change-Id: I2324ba94bb19b369d206313de798bdfec6099fe0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24605
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Emits it as a module-level variable. Deconstruct and throw away
the gl_PerVertex struct.
Not handled: unusual patterns that are technically valid but
which don't occur in practice:
- loading, storing, or producing intermediate values of the whole structure.
- multiple definitions of the per-vertex structure (e.g. if someone had
put both a vertex shader and a tessellation shader in the same
module.)
Bug: tint:3, tint:99
Change-Id: I3ad9ff6ab780a002367f01f385bfa7d6ddba6db9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24880
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds a `_stride_` into the array type name to differentiate an
array of 8 elements and a runtime array of stride 8.
Bug: tint:102
Change-Id: Iaf10fe5957acde16a9ccdf2a0fd8a83e47bb57bc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24962
Reviewed-by: David Neto <dneto@google.com>
Take the type of a const-definition (or a write to a hoisted variable)
from the generated expression rather than the directly-converted type
from the SPIR-V ID.
This prepares the way for remapping storage buffers from
Uniform/BufferBlock to StorageBuffer/Block representation.
Bug: tint:99
Change-Id: I6104d8ad96312053562468a3cdb247932c1cb6cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24604
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Use the fact that in WGSL the scope corresponding to the loop construct
encloses the scope for its associated continue construct.
In our construct data structure, the two are adjacent but not
overlapping.
This improvement means that when a definition is in a loop construct,
but used only in the loop or associated continue construct, then no
hoisting is required.
Bug: tint:3
Change-Id: I8d33b8f76303ab2868306847e846b4c26899e746
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24420
Reviewed-by: dan sinclair <dsinclair@google.com>
When we hoist a variable out of a continue construct, put it
in associated loop construct, if it exists. This reduces its
lifetime in WGSL, and easier to understand as a code reader.
Change-Id: I8f0cc37640bfe67874cbc27b55029e79e9a8992c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24321
Reviewed-by: dan sinclair <dsinclair@google.com>
The special case is not "single-block-loop" but rather the
case where a continue target is also its own loop header.
This can occur for single-block loops and multi-block loops.
Bug: tint:3
Change-Id: I4af1410793caf8b26a1f781e221fc0b395f07aa3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24320
Reviewed-by: dan sinclair <dsinclair@google.com>
For each OpPhi, make a variable to carry values from predecessor blocks
to the OpPhi. Declare the variable at the smallest scope enclosing all
the predecessor blocks (where we write to it), and the OpPhi (where we
read from it).
Bug: tint:3
Change-Id: I7898b4b903d9ee1a25a7466e3c5aaf6840550e2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24181
Reviewed-by: dan sinclair <dsinclair@google.com>
Compensate for the fact that dominance does not correspond
exactly to scoping. A definition can dominate a use, but when mapped
in a naive way to constant definitiion and its use, the definition
name goes out of scope by the time you reach the use.
This is correct for storable types.
Bug: tint:3
Change-Id: I03e6c5ba68393151485ed4cdbe6b2b3d7773d1ad
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24141
Reviewed-by: dan sinclair <dsinclair@google.com>
Avoid sinking expensive operations into control flow such as loops.
The heuristic way to achieve that is to avoid moving combinatorial
values across *any* structured construct boundaries.
Bug: tint:3
Change-Id: I91502b01166a0db64c0e652331591850df75f9d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24140
Reviewed-by: dan sinclair <dsinclair@google.com>
The process of passing the module through this reader, the WGSL semantics,
and the SPIR-V writer will sanitize the module such that the end result
should satisfy SPV_ENV_WEBGPU_0 requirements.
Being more forgiving about the input SPIR-V will be a quality-of-life
improvement.
Bug: tint:3
Change-Id: Ib54cbf729b9e078d797a1ef31422bad497daa5a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23942
Reviewed-by: dan sinclair <dsinclair@google.com>
Commit-Queue: dan sinclair <dsinclair@google.com>
This CL adds the basis of the Metal Shading Language backend.
Bug: tint:8
Change-Id: I85976250eb41ac12203a5db116444e993c3d09d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23700
Reviewed-by: David Neto <dneto@google.com>
Use the shortcut for zero-values: a type constructor without
any parameters. Scalars still use plain literals like false, 1u, 1.0.
Change-Id: Ie436f1af28cbab0b4c87a07b057deb04632eb534
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23680
Reviewed-by: dan sinclair <dsinclair@google.com>
When a type alias is created, map the SPIR-V type ID to the
type alias, not the underlying type. Only unpack the alias as
needed when inspecting the content structure to make values.
Bug: tint:3
Change-Id: I11011ddd190d89c81d3323f684a5e13f17dde09d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23582
Reviewed-by: dan sinclair <dsinclair@google.com>
This Cl updates the system to allow zero initializers. This allows:
```
var a : vec3<f32> = vec3<f32>();
```
Bug: tint:34
Change-Id: I84d6b431914c4ddf112ed375fae028d912f4a080
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23660
Reviewed-by: David Neto <dneto@google.com>
TODOs in the test file are or were in the function_arithmetic_test.cc
Change-Id: I679dbf0019e12e26488ccc310dfb03a535628e0b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23462
Reviewed-by: dan sinclair <dsinclair@google.com>
When parsing the `u` in `1024u` we were not advancing the lexer to the
next token which would give parse errors.
Change-Id: I8473b55992ff01d24f9d961878afa6b54d855e68
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23460
Reviewed-by: David Neto <dneto@google.com>
This CL cleans up various formatting and lint errors.
Change-Id: Ieee14db90e36acc8b469d58abb84fcf3595321bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23224
Reviewed-by: David Neto <dneto@google.com>
Add a guard variable for flow control within that if-selection.
Also, the premerge blocks are always surrounded by an if-selection,
to ensure we cause reconvergence at the end of the original if-selection
construct, just like in the original SPIR-V.
Bug: tint:3
Change-Id: I614c6840e539bf9a338058beb5b6f70484e3320a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23182
Reviewed-by: dan sinclair <dsinclair@google.com>
We've already written those tests.
Bug: tint:3
Change-Id: Ic836be43b5f1220e3563e4d27abd9b5e2ab54460
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23180
Reviewed-by: dan sinclair <dsinclair@google.com>
This supports the extended instructions used by the compute_boids
example.
Bug: tint:3
Change-Id: I364c343217139e489377dd2a9330058114023caa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23126
Reviewed-by: dan sinclair <dsinclair@google.com>
- Avoid redundant switch-break.
WGSL does an implicit break at the end of a switch case, because
it has fallthrough.
TODO: Emit fallthrough
Bug: tint:3
Change-Id: Ida44b13181a01a2c1459c0447dac496ba5b97ffc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22961
Reviewed-by: dan sinclair <dsinclair@google.com>
In BlockInfo, remove the backpointers from true-head, false-head, and
premerge-head to the if-selection header block.
Convert the forward references from if-selection to its internal heads
from pointers to IDs.
Bug: tint:3
Change-Id: Ic931df519795e14374bff4f60ad37a4b32f79c91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23140
Reviewed-by: dan sinclair <dsinclair@google.com>
Produce less noise in ASTs for a common case.
Also test that an empty continuing construct doesn't show up in the
AST. That's currently handled by the AST code. We want to keep this
behaviour even if the AST implementation changes. Right now
code change is needed when emitting the start of a continuing
construct.
Bug: tint:3
Change-Id: I96a12087e305c64647561f65d87acda907ae9c42
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22844
Reviewed-by: dan sinclair <dsinclair@google.com>
This emits the equivalent of break-if, break-unless, continue-if,
continue-unless. But we do it via a regular if-then-else.
Adds a test matrix.
Adds all required tests except for those needing OpSwitch.
Bug: tint:3
Change-Id: I960a40aa00f95f394a92a099c8b12104010ad49f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22603
Reviewed-by: dan sinclair <dsinclair@google.com>
This is a bit pathological.
Bug: tint:3
Change-Id: I448796c712049f88cef9a592c218d94a0daddb75
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22760
Reviewed-by: dan sinclair <dsinclair@google.com>
Prefix should match a method name on FunctionEmitter
Bug: tint:3
Change-Id: I0af9fb33210d09a59e5cacdade986668fe685682
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22681
Reviewed-by: dan sinclair <dsinclair@google.com>
A merge block must be dominated by its own header.
This CL checks the cases where that fails because the
merge block is also the:
- the default or case header for a switch (a different header)
- the true-head, false-head, or premerge-head for an if-selection
with a different header
Bug: tint:3
Change-Id: I6dd1fae162e9d33bd9a0b43d3ca9558cebed058b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22680
Reviewed-by: dan sinclair <dsinclair@google.com>
This is a bit pathological.
Bug: tint:3
Change-Id: I820d7d1bfd298a22be6c6014e7d4d00f1097759e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22740
Reviewed-by: dan sinclair <dsinclair@google.com>
This fixes the pathological cases nobody wants, and arguably
should be added to the SPIR-V spec.
If we really really want to support these cases, we can revisit.
Bug: tint:3
Change-Id: I0a75490d451676caa0933e3761098ba1fe3f8b60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22664
Reviewed-by: dan sinclair <dsinclair@google.com>
This is the case where a block can't be a "continue block"
for more than one header. It can only be a continue block for
the innermost loop it's inside of.
Bug: tint:3
Change-Id: Ic19ca544ab8a30cb1ff16d2c828abb260facba90
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22601
Reviewed-by: dan sinclair <dsinclair@google.com>
In this example, a branch escapes an if-selection.
This is caught by ClassifyCFGEdges
Bug: tint:3
Change-Id: I5586e8bb5f9de0cdf57ad46708fcee12cd31f6aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22600
Reviewed-by: dan sinclair <dsinclair@google.com>
The `>>>` symbol was folded into the `>>` symbol in WGSL. This CL
removes `>>>` from Tint.
Change-Id: I9d900de9a6026a8099796b94aad44483f0c6813f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22582
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
The `unless` statement was removed from the WGSL grammar so remove it
from Tint.
Change-Id: I31a185f5c5e3e88b667caea1c9a88aee80c0b810
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22581
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL removes the conditional forms of the break and continue
statements as they are no longer in the WGSL spec.
Change-Id: I46224d6cb5ce706cfc95d35ab0a4eea46abf62a9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22580
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This Cl clarifies that IntLiteral is a signed value, which matches with
the usage of UintLiteral.
Change-Id: Ic8f0e2382cb66eb6b09daed096886dcc55e6b0f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22540
Reviewed-by: David Neto <dneto@google.com>
The name conditions isn't quite correct for the case statement. This CL
updates the code to use selectors instead of conditions.
Change-Id: I98b8050b11e2328f97e4443469572ab47d7c1555
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22520
Reviewed-by: David Neto <dneto@google.com>
This is preparation for emitting nested control flow.
Bug: tint:3
Change-Id: I90fc7edba8cb9937f722e6f5e94c7f222d34c403
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21801
Reviewed-by: dan sinclair <dsinclair@google.com>
In this case, a basic block is a continue target
for both an outer loop and is also for itself as a
single-block loop.
Bug: Tint:3
Change-Id: If361004a4b871966674ca972922c45e712ce7c9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22420
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL adds the missing case_selectors option from the grammar updates.
Change-Id: Ia6c110e917dd574711d396fb34ad53a2a67cf1fe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22306
Reviewed-by: David Neto <dneto@google.com>
This CL updates a few names, addeds a return_stmt method and re-orders
some code to closer match the current WGSL specification.
Change-Id: I388be1c22d5d10229fdfcdb2ff929c410f5ae638
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22305
Reviewed-by: David Neto <dneto@google.com>
The intrinsic methods were removed from the WGSL grammar and are treated
as builtin functions. This Cl updates Tint to match.
Bug: tint:41
Change-Id: I3f9ff6c17f1ca57ad159d883fd5a966657caeb4f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22301
Reviewed-by: David Neto <dneto@google.com>
This CL removes the builtin_decoration from the parser in favour of
using IDENT tokens for builtins. We still convert to an enum in the
parser and validate the value provided.
Bug: tint:41
Change-Id: If5dc3844e3325c75951e7b320c123cf66cb8e106
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22300
Reviewed-by: David Neto <dneto@google.com>
The NOP command was added for complete SPIR-V bijectivity which is no
longer a goal of WGSL. The NOP command has been removed from the spec,
so remove from Tint.
Change-Id: Ic640d9d3b987a19668dc169ff549444921c5bbb8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22160
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This Cl adds tests for more of the cast code along with adding a few
missing cast cases.
Bug: tint:5
Change-Id: I417d46661bb310f27329f3e2459b76aa61a49d31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22040
Reviewed-by: David Neto <dneto@google.com>
Do so systmatically. Before we had tested some as a side effect
of other objectives.
Fix the error message for when we have a bad exit from a loop construct
that bypasses not only the continue construct but the loop merge block
itself.
Bug: tint:3
Change-Id: Iaf8fc9bcd3162002aa906efa90a244ef5f439911
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21580
Reviewed-by: dan sinclair <dsinclair@google.com>
Remove TOOD about special code for finding badly nested selections.
This is already adequately covered by the dominance-violation checks,
and related tests:
ClassifyCFGEdges_DomViolation_BeforeIfToSelectionInterior
ClassifyCFGEdges_DomViolation_BeforeSwitchToSelectionInterior
ClassifyCFGEdges_DomViolation_BeforeLoopToLoopBodyInterior
ClassifyCFGEdges_DomViolation_BeforeContinueToContinueInterior
ClassifyCFGEdges_DomViolation_AfterContinueToContinueInterior
Bug: tint:3
Change-Id: I8c547474d1422a54078d748b39a7d22a500d5d1d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21482
Reviewed-by: dan sinclair <dsinclair@google.com>
ClassifyCFGEdges_Forward_LoopToContinue is already covered via
ClassifyCFGEdges_LoopContinue_LoopBodyToContinue and ...ConditionalFromNestedIf
and other LoopContinue cases
Bug: tint:3
Change-Id: I4a89a82c0c9a08939036a20f13932c18e1f90df6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21560
Reviewed-by: dan sinclair <dsinclair@google.com>
Unordered float compares are not supported directly by WGSL.
Translate them as negated ordered compares.
Bug: tint:3
Change-Id: I4fea7c924054cffc9a39a8be3b3d9f088d302114
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21540
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Finds the "then", the "else", and "premerge" nodes.
The premerge node, if it exists, is the first block where
the normal forward flow of the "then" and "else" clauses
converge, but before the merge block.
Finds error case where there a block has both an if-break
edge and a forward-to-premerge. There is no good way
to model that in a high level language.
Bug: tint:3
Change-Id: I759fc539f3480e38d091041db6a9abd15f3df769
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21240
Reviewed-by: dan sinclair <dsinclair@google.com>
This also refactors break detection.
Bug: tint:3
Change-Id: I3a3e01c8d76d7c6fc2a14b3dbff136acd487e802
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21220
Reviewed-by: dan sinclair <dsinclair@google.com>
The names for brace and bracket got flipped in the spec, update Tint to
match.
Change-Id: Ifbad5f239834b77b9aa27ef21b9d704cab742f4f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21260
Reviewed-by: David Neto <dneto@google.com>
Push constants won't be supported by WebGPU. This CL removes them from
Tint.
For the SPIR-V reader case, this means the push constant will cause a
unknown storage class error.
Bug: tint:19
Change-Id: I10b09ce589b6b370fc828af0cd56e6213c5bc694
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21180
Reviewed-by: David Neto <dneto@google.com>
These used to be classified as kToMerge
Bug: tint:3
Change-Id: I63fb286c371582676e5943a3082c0614b9c8d5d0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21081
Reviewed-by: dan sinclair <dsinclair@google.com>
Distinguish between selections constructs starting with with
OpBranchConditional and those starting with OpSwitch.
We'll use this in a followup CL to track break from a switch.
Bug: tint:3
Change-Id: I8d000cb42325535a4937c84f83a83c98a9b8d4c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21080
Reviewed-by: dan sinclair <dsinclair@google.com>
Classify CFG edges:
- loop backedge
- a structured exit:
- loop break
- loop continue
- selection break
- fallthrough
- forward (any of the rest)
Also error out when there should have been a merge instruction.
(More than one unique fallthrough or forward edge).
Includes lots of tests.
Bug: tint:3
Change-Id: I70f27680bdf098213056522abf04ac58a6b478ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20481
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL fixes up some issues which give compile errors when building
with Visual Studio.
Change-Id: Ib76644d869dd2adccd579621d18804d84b65a74c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20940
Reviewed-by: David Neto <dneto@google.com>
This CL splits the TypeConstructor code out of the generic
ConstructorExpression to make the code separation clearer.
Bug: tint:5
Change-Id: I441955c3b09a30b2d02f542f4b7c8e80ff8d9d86
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20640
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL adds the beginning of break and continue support. The
conditional versions are not supported, just the non-conditional.
Bug: tint:5
Change-Id: I84418cffd3e29dc011c4313bf9aa3da4833c009f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20500
Reviewed-by: David Neto <dneto@google.com>
Label basic blocks with:
- their nearest enclosing structured control flow constructs.
- their nearest enclosing continue construct, if any
- their nearest enclosing loop construct, if any
A construct consists of a span of blocks in the computed block order.
It knows its parent construct, if any, and its nesting depth.
Bug: tint:3
Change-Id: Ia945706e8ea2435d6c40fb4e36dc2daeeb9780d0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20421
Reviewed-by: dan sinclair <dsinclair@google.com>
This is gives us the fundamental ordering of blocks in relation
to a structured construct.
Bug: tint:3
Change-Id: I76eb39403131305398808c33ce4cee256a1c23c2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20266
Reviewed-by: dan sinclair <dsinclair@google.com>
TEST=Built fuzzer in local checkout of Chromium with tint integrated.
BUG=dawn:14
Change-Id: I84aacd41f893070c3af40f5e640361e177689f9e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20343
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL updates the type determiner such that variable result types
end up wrapped inside pointers, constants do not. The result of Member
and Array accessors are also pointers if the source was a pointer.
Change-Id: I6694367daf6ba1db929e54a975dfea8404fca40c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20265
Reviewed-by: David Neto <dneto@google.com>
Also, list remaining logical instructions to be tested
Bug: tint:3
Change-Id: I48dda1d3637bc7c4d75358e26fb9de8f0c6f0bb6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20261
Reviewed-by: dan sinclair <dsinclair@google.com>
Record header/merge cross-links, and single_block_loop attribute of BlockInfo.
Also checks that they are sane: only target blocks in the same function.
Bug: tint:3
Change-Id: I715f7ed354a556e92d58a4c9ba6f306c746c3641
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20080
Reviewed-by: dan sinclair <dsinclair@google.com>
Each basic block must have a terminator, and if the terminator branches
to another block, that block must name a label in the same function.
Bug: tint:3
Change-Id: If22bece6a8041fef362c02b05e4dfee999a3e5bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20046
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL adds the code to generate the negation and not operators.
Bug: tint:5
Change-Id: Ibb4d374586e1415a2a678e375c64ba69bbc20367
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20143
Reviewed-by: David Neto <dneto@google.com>
- branch-conditional where both targets are the same
- switch where the default target is the same as a case target
Bug: tint:3
Change-Id: If5a3e1fead43ae3d528341f3e54dcae959d9eb8c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20061
Reviewed-by: dan sinclair <dsinclair@google.com>
Separate them into different test files, to match SPIR-V spec sections
Bug: tint:3
Change-Id: I89fe76230740da060d57ac23870069a5483b2d7d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20043
Reviewed-by: dan sinclair <dsinclair@google.com>
Test non-nested sequences and selections.
Bug: tint:3
Change-Id: Ibbbcd428d701d9e7d4da1682f94c2bdbef00121b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19920
Reviewed-by: dan sinclair <dsinclair@google.com>
Fix bad merge around emission of OpBitcast.
Change-Id: Iacc5ba1c3940745e4b2c46878bbc416397ec555f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20047
Reviewed-by: David Neto <dneto@google.com>
Also, it's not clear if OpSRem has a direct mapping.
Bug: tint:3
Change-Id: Ie7834253cf14109fbebd2ece8e18d9899b29753b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19881
Reviewed-by: dan sinclair <dsinclair@google.com>
(I expect that) the WGSL signed division operator expects both operands
to be signed and the result will also be signed.
When the operands of a SPIR-V OpSDiv is unsigned, then wrap
the operand in an as-cast to the corresponding signed type.
When the result type of a SPIR-V OpSDiv instruction is unsigned,
we have to wrap the generated WGSL operator with an as-cast to
that unsigned type.
This first CL addresses OpSDiv. We'll address other operations in future CLs.
Bug: tint:3
Change-Id: If3849ceb44b21db87c1efd2c6a2cd63c6d648c88
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19800
Reviewed-by: dan sinclair <dsinclair@google.com>
The AST only wants expressions, not their result types.
But the SPIR-V reader wants to track the AST type as well.
So introduce a TypedExpression concept for internal use.
Bug: tint:3
Change-Id: Ia832f7422440ef0e8e04630cdca98cae20e18921
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20040
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL renames the parts of the identifier to segments and then adds a
path() and name() methods to get the respective parts of the identifier.
Change-Id: I1a365df7cb83ac0dd3d6be9ec6ccb83bfc73dd91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19762
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
BUG=dawn:16
Change-Id: I1da30fed82a310007674801e3b1e853b25d5b573
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19640
Reviewed-by: dan sinclair <dsinclair@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This CL cleans up some lint errors.
Change-Id: Ibfe9768cc4272d015a35a8d7edde0390b8fc66a5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19504
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL removes the premerge statement and replaces it with a `premerge`
reserved word.
Change-Id: Ic9bc13878ed26e1733eb65dd1ba30d9bef095cb6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19380
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL removes the regardless statement and turns `regardless` into a
reserved word.
Change-Id: I50c521111b90dbadddaeb36674e8c40205186076
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19361
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Also adds generic support for generating a combinatorial value
as a const definition.
Bug: tint:3
Change-Id: Idae758d146264491679710967e48ea270436be91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19107
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL converts a few more std::vector<std::unique_ptr<foo>>'s to
FooList aliases.
Change-Id: If0dd672f11beaeabd9e89e82903c2174b11be6e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19103
Reviewed-by: David Neto <dneto@google.com>
If a non-const variable in a function has a kNone storage class we
update it to kFunction. If there is a storage class other then kFunction
we emit an error.
Bug: tint:5
Change-Id: If45eb91bd0a0095e625eb1d0e1d1e361c784e35d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19102
Reviewed-by: David Neto <dneto@google.com>
This CL adds the relational add expression to the spirv writer.
Bug: tint:5
Change-Id: Ideed225c63e60f53a019b79803809f8e973299c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18605
Reviewed-by: David Neto <dneto@google.com>
Tests FunctionEmitter directly.
This is mostly refactoring to be able to selectively run parts of the
parsing flow, and to access relevant internal data.
Bug: tint:3
Change-Id: Ic2b166a2e9623a7e30e6769806088d12e78dcf45
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18704
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL completes a few of the DISABLED tests.
Change-Id: I38806fb9381240d6e3da700f1fb2dac5f899ca6d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19000
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Match the more common usage for the expression type.
Bug: tint:37
Change-Id: Ia5d48a0444742ec4e304ea1036e499b3d7cad682
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18981
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL adds various using statements for the
std::vector<std::unique_ptr<CLASS>> constructs found in the AST.
Change-Id: Ic9a2357cd73b2aafd99e961a38727f2f9874cde5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18920
Reviewed-by: David Neto <dneto@google.com>
VS2017 took issue with treating size_t and uint32_t the same. It also
couldn't find various alphanumeric is* functions without the <cctype>
header. Gcc complainted about a variable potentially used uninitialized.
Change-Id: I452b68c6597bae254f32e5a350656e65c8934b6e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18901
Reviewed-by: dan sinclair <dsinclair@google.com>
Fix typos in SPIR-V IDs that were causing the optimizer to assert
out when building up its internal data structures.
Bug: tint:3
Change-Id: I27210623b0d3d241dbd6afe6bef63e88a02b390e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18640
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL removes a std::move which triggers a -Wpessimizing-move error
Change-Id: I378f32a808a86a0944a4bb41f243b7416c10a9fd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18602
Reviewed-by: dan sinclair <dsinclair@google.com>
Only emit functions that have bodies.
Don't emit their bodies yet.
Emit them so that callees precede callers.
Bug: tint:3
Change-Id: Ia67ba2fe1d47c7c7d5c290d1d4fc5256fa293b51
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18620
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL renames VariableStatement to VariableDeclStatement to make it
clearer what it was modeling.
Bug: tint:25
Change-Id: Idd0d27fad7cc402f286e1abad74092c9d1961d91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18341
Reviewed-by: David Neto <dneto@google.com>
This Cl updates the names of the initializer expressions to be clearer.
* InitializerExpression -> ConstructorExpression
* ConstInitializerExpression -> ScalarConstructorExpression
* TypeInitializerExpression -> TypeConstructorExpression
Bug: tint:26
Change-Id: Ib046497f589cc65d1d64bc172015588348feeffe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18340
Reviewed-by: David Neto <dneto@google.com>
Handle as many member decorations as the Tint AST can express right now.
See crbug.com/tint/30
Bug: tint:3
Change-Id: I6d04f1beb438b3d952a76886fbd9c6b7ea701d81
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18160
Reviewed-by: dan sinclair <dsinclair@google.com>
Bug: tint:3
Change-Id: I9655ddbe48f2660f88be68bc52c9467d805043ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18080
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Add a Context::Reset method to clear state.
Hide the member behind an accessor.
Change-Id: Iafb7c39249f66f70c5a99a8ed1c69f2c0238834f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17742
Reviewed-by: dan sinclair <dsinclair@google.com>
This CL updates the SPIR-V writer to generate the OpConstantTrue,
OpConstantFalse and OpConstant instructions.
Bug: tint:5
Change-Id: I660554c491e4eb569e3902fce0973fae3f27e6c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17820
Reviewed-by: David Neto <dneto@google.com>
This CL moves all test files to the anonymous namespace.
Change-Id: Ie5ae0efe907c03eeb441e90f31c976844172b594
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17900
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL fixes up several documentation and linter warnings.
Change-Id: Ic367ba1937f20dfe47a8c8e4035c17e8a3d0f2e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17880
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This CL updates the SPIR-V writer to emit the OpTypeFunction and
OpFunction instructions.
Bug: tint:5
Change-Id: I85ead161ca37304a977213257a825ff268d29f2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17741
Reviewed-by: David Neto <dneto@google.com>
This Cl replaces the TypeManager singleton with a context object.
Bug: tint:29
Change-Id: Ia662709db1b562c34955633977ce4363f28f238e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17780
Reviewed-by: David Neto <dneto@google.com>
This CL adds a helper to emit a block of statements from the WGSL
writer.
Change-Id: I6fe62d894882c0a0fdc8865967bfa4887f3a65a3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17761
Reviewed-by: David Neto <dneto@google.com>
For now, it only handles scalar types
Bug: tint:3
Change-Id: Ic20e18a4f80790e6cd10d4c06dd2abfd8f67a304
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17700
Reviewed-by: dan sinclair <dsinclair@google.com>
Define the ID targeted by the entry point. Do this to avoid
asserts in the optimizer code
Bug: tint:3
Change-Id: Idbd4c8a058f2d51ff44696d2029502044d01b424
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17562
Reviewed-by: dan sinclair <dsinclair@google.com>