Split Program into Program and ProgramBuilder

Program is now immutable*, and remains part of the public Tint
interface.

ProgramBuilder is the mutable builder for Programs, and is not part of
the public Tint interface. ast::Builder has been folded into
ProgramBuilder.

Immutable Programs can be cloned into a mutable ProgramBuilder with
Program::CloneAsBuilder().

Mutable ProgramBuilders can be moved into immutable Programs.

* - mostly immutable. It still has a move constructor and move
  assignment operator - required for practical usage - and the
  semantic information on AST nodes is still mutable.

Bug: tint:390
Change-Id: Ia856c50b1880c2f95c91467a9eef5024cbc380c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38240
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-26 16:57:10 +00:00
parent 1f7e18bbc0
commit a6b9a8eb2f
186 changed files with 3324 additions and 2645 deletions

View File

@ -246,8 +246,6 @@ source_set("libtint_core_src") {
"src/ast/bool_literal.h",
"src/ast/break_statement.cc",
"src/ast/break_statement.h",
"src/ast/builder.cc",
"src/ast/builder.h",
"src/ast/builtin.cc",
"src/ast/builtin.h",
"src/ast/builtin_decoration.cc",
@ -373,6 +371,8 @@ source_set("libtint_core_src") {
"src/inspector/scalar.h",
"src/namer.cc",
"src/namer.h",
"src/program_builder.cc",
"src/program_builder.h",
"src/program.cc",
"src/program.h",
"src/reader/reader.cc",
@ -792,6 +792,7 @@ source_set("tint_unittests_core_src") {
"src/ast/loop_statement_test.cc",
"src/ast/member_accessor_expression_test.cc",
"src/ast/module_clone_test.cc",
"src/ast/module_test.cc",
"src/ast/null_literal_test.cc",
"src/ast/return_statement_test.cc",
"src/ast/scalar_constructor_expression_test.cc",

View File

@ -56,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
auto src = parser.program();
// Clone the src program to dst
auto dst = src.Clone();
tint::Program dst(src.Clone());
// Expect the demangled AST printed with to_str() to match
tint::Demangler d;

View File

@ -19,6 +19,10 @@
#include <utility>
#include <vector>
#include "src/ast/module.h"
#include "src/program.h"
#include "src/program_builder.h"
namespace tint {
namespace fuzzers {
@ -81,10 +85,14 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
return 0;
}
TypeDeterminer td(&program);
{
ProgramBuilder builder = program.CloneAsBuilder();
TypeDeterminer td(&builder);
if (!td.Determine()) {
return 0;
}
program = Program(std::move(builder));
}
Validator v;
if (!v.Validate(&program)) {

View File

@ -502,9 +502,10 @@ int main(int argc, const char** argv) {
return 1;
}
tint::TypeDeterminer td(&program);
if (!td.Determine()) {
std::cerr << "Type Determination: " << td.error() << std::endl;
auto diags = tint::TypeDeterminer::Run(&program);
if (diags.contains_errors()) {
std::cerr << "Type Determination: ";
diag_formatter.format(reader->diagnostics(), diag_printer.get());
return 1;
}

View File

@ -60,8 +60,6 @@ set(TINT_LIB_SRCS
ast/bool_literal.h
ast/break_statement.cc
ast/break_statement.h
ast/builder.cc
ast/builder.h
ast/builtin_decoration.cc
ast/builtin_decoration.h
ast/builtin.cc
@ -187,6 +185,8 @@ set(TINT_LIB_SRCS
inspector/scalar.h
namer.cc
namer.h
program_builder.cc
program_builder.h
program.cc
program.h
reader/reader.cc
@ -422,6 +422,7 @@ if(${TINT_BUILD_TESTS})
ast/loop_statement_test.cc
ast/member_accessor_expression_test.cc
ast/module_clone_test.cc
ast/module_test.cc
ast/null_literal_test.cc
ast/return_statement_test.cc
ast/scalar_constructor_expression_test.cc

View File

@ -15,7 +15,7 @@
#include "src/ast/access_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::AccessDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/array_accessor_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayAccessorExpression);

View File

@ -15,7 +15,7 @@
#include "src/ast/assignment_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/binary_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BinaryExpression);

View File

@ -15,7 +15,7 @@
#include "src/ast/binding_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BindingDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/bitcast_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BitcastExpression);

View File

@ -15,7 +15,7 @@
#include "src/ast/block_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/bool_literal.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BoolLiteral);

View File

@ -15,7 +15,7 @@
#include "src/ast/break_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BreakStatement);

View File

@ -1,92 +0,0 @@
// Copyright 2020 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.
#include "src/ast/builder.h"
namespace tint {
namespace ast {
TypesBuilder::TypesBuilder(Program* p)
: program_(p) {}
Builder::Builder(Program* p) : program(p), ty(p), mod(p) {}
Builder::~Builder() = default;
Variable* Builder::Var(const std::string& name,
StorageClass storage,
type::Type* type) {
return Var(name, storage, type, nullptr, {});
}
Variable* Builder::Var(const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(program->Symbols().Register(name), storage, type,
false, constructor, decorations);
OnVariableBuilt(var);
return var;
}
Variable* Builder::Var(const Source& source,
const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(source, program->Symbols().Register(name),
storage, type, false, constructor, decorations);
OnVariableBuilt(var);
return var;
}
Variable* Builder::Const(const std::string& name,
StorageClass storage,
type::Type* type) {
return Const(name, storage, type, nullptr, {});
}
Variable* Builder::Const(const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(program->Symbols().Register(name), storage, type,
true, constructor, decorations);
OnVariableBuilt(var);
return var;
}
Variable* Builder::Const(const Source& source,
const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations) {
auto* var = create<Variable>(source, program->Symbols().Register(name),
storage, type, true, constructor, decorations);
OnVariableBuilt(var);
return var;
}
BuilderWithProgram::BuilderWithProgram() : Builder(new Program()) {}
BuilderWithProgram::~BuilderWithProgram() {
delete program;
}
} // namespace ast
} // namespace tint

View File

@ -1,804 +0,0 @@
// Copyright 2020 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.
#ifndef SRC_AST_BUILDER_H_
#define SRC_AST_BUILDER_H_
#include <memory>
#include <string>
#include <utility>
#include "src/ast/array_accessor_expression.h"
#include "src/ast/binary_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/call_expression.h"
#include "src/ast/expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/struct.h"
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/program.h"
#include "src/type/alias_type.h"
#include "src/type/array_type.h"
#include "src/type/bool_type.h"
#include "src/type/f32_type.h"
#include "src/type/i32_type.h"
#include "src/type/matrix_type.h"
#include "src/type/pointer_type.h"
#include "src/type/struct_type.h"
#include "src/type/u32_type.h"
#include "src/type/vector_type.h"
#include "src/type/void_type.h"
namespace tint {
namespace ast {
/// TypesBuilder holds basic `tint` types and methods for constructing
/// complex types.
class TypesBuilder {
public:
/// Constructor
/// @param program the program
explicit TypesBuilder(Program* program);
/// @return the tint AST type for the C type `T`.
template <typename T>
type::Type* Of() const {
return CToAST<T>::get(this);
}
/// @returns A boolean type
type::Bool* bool_() const { return program_->create<type::Bool>(); }
/// @returns A f32 type
type::F32* f32() const { return program_->create<type::F32>(); }
/// @returns A i32 type
type::I32* i32() const { return program_->create<type::I32>(); }
/// @returns A u32 type
type::U32* u32() const { return program_->create<type::U32>(); }
/// @returns A void type
type::Void* void_() const { return program_->create<type::Void>(); }
/// @return the tint AST type for a 2-element vector of the C type `T`.
template <typename T>
type::Vector* vec2() const {
return program_->create<type::Vector>(Of<T>(), 2);
}
/// @return the tint AST type for a 3-element vector of the C type `T`.
template <typename T>
type::Vector* vec3() const {
return program_->create<type::Vector>(Of<T>(), 3);
}
/// @return the tint AST type for a 4-element vector of the C type `T`.
template <typename T>
type::Type* vec4() const {
return program_->create<type::Vector>(Of<T>(), 4);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x2() const {
return program_->create<type::Matrix>(Of<T>(), 2, 2);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x3() const {
return program_->create<type::Matrix>(Of<T>(), 3, 2);
}
/// @return the tint AST type for a 2x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x4() const {
return program_->create<type::Matrix>(Of<T>(), 4, 2);
}
/// @return the tint AST type for a 3x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x2() const {
return program_->create<type::Matrix>(Of<T>(), 2, 3);
}
/// @return the tint AST type for a 3x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x3() const {
return program_->create<type::Matrix>(Of<T>(), 3, 3);
}
/// @return the tint AST type for a 3x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x4() const {
return program_->create<type::Matrix>(Of<T>(), 4, 3);
}
/// @return the tint AST type for a 4x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x2() const {
return program_->create<type::Matrix>(Of<T>(), 2, 4);
}
/// @return the tint AST type for a 4x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x3() const {
return program_->create<type::Matrix>(Of<T>(), 3, 4);
}
/// @return the tint AST type for a 4x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x4() const {
return program_->create<type::Matrix>(Of<T>(), 4, 4);
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @return the tint AST type for a array of size `n` of type `T`
type::Array* array(type::Type* subtype, uint32_t n) const {
return program_->create<type::Array>(subtype, n, ArrayDecorationList{});
}
/// @return the tint AST type for an array of size `N` of type `T`
template <typename T, int N = 0>
type::Array* array() const {
return array(Of<T>(), N);
}
/// Creates an alias type
/// @param name the alias name
/// @param type the alias type
/// @returns the alias pointer
type::Alias* alias(const std::string& name, type::Type* type) const {
return program_->create<type::Alias>(program_->Symbols().Register(name),
type);
}
/// @return the tint AST pointer to type `T` with the given StorageClass.
/// @param storage_class the storage class of the pointer
template <typename T>
type::Pointer* pointer(StorageClass storage_class) const {
return program_->create<type::Pointer>(Of<T>(), storage_class);
}
/// @param name the struct name
/// @param impl the struct implementation
/// @returns a struct pointer
type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
return program_->create<type::Struct>(program_->Symbols().Register(name),
impl);
}
private:
/// CToAST<T> is specialized for various `T` types and each specialization
/// contains a single static `get()` method for obtaining the corresponding
/// AST type for the C type `T`.
/// `get()` has the signature:
/// `static type::Type* get(Types* t)`
template <typename T>
struct CToAST {};
Program* const program_;
};
/// Helper for building common AST constructs.
class Builder {
public:
/// `i32` is a type alias to `int`.
/// Useful for passing to template methods such as `vec2<i32>()` to imitate
/// WGSL syntax.
/// Note: this is intentionally not aliased to uint32_t as we want integer
/// literals passed to the builder to match WGSL's integer literal types.
using i32 = decltype(1);
/// `u32` is a type alias to `unsigned int`.
/// Useful for passing to template methods such as `vec2<u32>()` to imitate
/// WGSL syntax.
/// Note: this is intentionally not aliased to uint32_t as we want integer
/// literals passed to the builder to match WGSL's integer literal types.
using u32 = decltype(1u);
/// `f32` is a type alias to `float`
/// Useful for passing to template methods such as `vec2<f32>()` to imitate
/// WGSL syntax.
using f32 = float;
/// Constructor
/// @param program the program to build
explicit Builder(Program* program);
virtual ~Builder();
/// @param expr the expression
/// @return expr
Expression* Expr(Expression* expr) { return expr; }
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(program->Symbols().Register(name));
}
/// @param source the source information
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const Source& source, const std::string& name) {
return create<IdentifierExpression>(source,
program->Symbols().Register(name));
}
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(program->Symbols().Register(name));
}
/// @param value the boolean value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(bool value) {
return create<ScalarConstructorExpression>(Literal(value));
}
/// @param value the float value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(f32 value) {
return create<ScalarConstructorExpression>(Literal(value));
}
/// @param value the integer value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(i32 value) {
return create<ScalarConstructorExpression>(Literal(value));
}
/// @param value the unsigned int value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(u32 value) {
return create<ScalarConstructorExpression>(Literal(value));
}
/// Converts `arg` to an `Expression` using `Expr()`, then appends it to
/// `list`.
/// @param list the list to append too
/// @param arg the arg to create
template <typename ARG>
void Append(ExpressionList& list, ARG&& arg) {
list.emplace_back(Expr(std::forward<ARG>(arg)));
}
/// Converts `arg0` and `args` to `Expression`s using `Expr()`,
/// then appends them to `list`.
/// @param list the list to append too
/// @param arg0 the first argument
/// @param args the rest of the arguments
template <typename ARG0, typename... ARGS>
void Append(ExpressionList& list, ARG0&& arg0, ARGS&&... args) {
Append(list, std::forward<ARG0>(arg0));
Append(list, std::forward<ARGS>(args)...);
}
/// @return an empty list of expressions
ExpressionList ExprList() { return {}; }
/// @param args the list of expressions
/// @return the list of expressions converted to `Expression`s using
/// `Expr()`,
template <typename... ARGS>
ExpressionList ExprList(ARGS&&... args) {
ExpressionList list;
list.reserve(sizeof...(args));
Append(list, std::forward<ARGS>(args)...);
return list;
}
/// @param list the list of expressions
/// @return `list`
ExpressionList ExprList(ExpressionList list) { return list; }
/// @param val the boolan value
/// @return a boolean literal with the given value
BoolLiteral* Literal(bool val) {
return create<BoolLiteral>(ty.bool_(), val);
}
/// @param val the float value
/// @return a float literal with the given value
FloatLiteral* Literal(f32 val) { return create<FloatLiteral>(ty.f32(), val); }
/// @param val the unsigned int value
/// @return a UintLiteral with the given value
UintLiteral* Literal(u32 val) { return create<UintLiteral>(ty.u32(), val); }
/// @param val the integer value
/// @return the SintLiteral with the given value
SintLiteral* Literal(i32 val) { return create<SintLiteral>(ty.i32(), val); }
/// @param args the arguments for the type constructor
/// @return an `TypeConstructorExpression` of type `ty`, with the values
/// of `args` converted to `Expression`s using `Expr()`
template <typename T, typename... ARGS>
TypeConstructorExpression* Construct(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param type the type to construct
/// @param args the arguments for the constructor
/// @return an `TypeConstructorExpression` of `type` constructed with the
/// values `args`.
template <typename... ARGS>
TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
return create<TypeConstructorExpression>(
type, ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `TypeConstructorExpression` of a 2-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* vec2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `TypeConstructorExpression` of a 3-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* vec3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `TypeConstructorExpression` of a 4-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* vec4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 2x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 2x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 2x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 3x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 3x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 3x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 4x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 4x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `TypeConstructorExpression` of a 4x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the array constructor
/// @return an `TypeConstructorExpression` of an array with element type
/// `T`, constructed with the values `args`.
template <typename T, int N = 0, typename... ARGS>
TypeConstructorExpression* array(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @param args the arguments for the array constructor
/// @return an `TypeConstructorExpression` of an array with element type
/// `subtype`, constructed with the values `args`.
template <typename... ARGS>
TypeConstructorExpression* array(type::Type* subtype,
uint32_t n,
ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.array(subtype, n), ExprList(std::forward<ARGS>(args)...));
}
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a `Variable` with the given name, storage and type. The variable
/// will be built with a nullptr constructor and no decorations.
Variable* Var(const std::string& name,
StorageClass storage,
type::Type* type);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `Variable` with the given name, storage and type
Variable* Var(const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations);
/// @param source the variable source
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `Variable` with the given name, storage and type
Variable* Var(const Source& source,
const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a constant `Variable` with the given name, storage and type. The
/// variable will be built with a nullptr constructor and no decorations.
Variable* Const(const std::string& name,
StorageClass storage,
type::Type* type);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `Variable` with the given name, storage and type
Variable* Const(const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations);
/// @param source the variable source
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `Variable` with the given name, storage and type
Variable* Const(const Source& source,
const std::string& name,
StorageClass storage,
type::Type* type,
Expression* constructor,
VariableDecorationList decorations);
/// @param func the function name
/// @param args the function call arguments
/// @returns a `CallExpression` to the function `func`, with the
/// arguments of `args` converted to `Expression`s using `Expr()`.
template <typename NAME, typename... ARGS>
CallExpression* Call(NAME&& func, ARGS&&... args) {
return create<CallExpression>(Expr(func),
ExprList(std::forward<ARGS>(args)...));
}
/// @param lhs the left hand argument to the addition operation
/// @param rhs the right hand argument to the addition operation
/// @returns a `BinaryExpression` summing the arguments `lhs` and `rhs`
template <typename LHS, typename RHS>
Expression* Add(LHS&& lhs, RHS&& rhs) {
return create<BinaryExpression>(BinaryOp::kAdd,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param lhs the left hand argument to the subtraction operation
/// @param rhs the right hand argument to the subtraction operation
/// @returns a `BinaryExpression` subtracting `rhs` from `lhs`
template <typename LHS, typename RHS>
Expression* Sub(LHS&& lhs, RHS&& rhs) {
return create<BinaryExpression>(BinaryOp::kSubtract,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param lhs the left hand argument to the multiplication operation
/// @param rhs the right hand argument to the multiplication operation
/// @returns a `BinaryExpression` multiplying `rhs` from `lhs`
template <typename LHS, typename RHS>
Expression* Mul(LHS&& lhs, RHS&& rhs) {
return create<BinaryExpression>(BinaryOp::kMultiply,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param arr the array argument for the array accessor expression
/// @param idx the index argument for the array accessor expression
/// @returns a `ArrayAccessorExpression` that indexes `arr` with `idx`
template <typename ARR, typename IDX>
Expression* IndexAccessor(ARR&& arr, IDX&& idx) {
return create<ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
Expr(std::forward<IDX>(idx)));
}
/// @param obj the object for the member accessor expression
/// @param idx the index argument for the array accessor expression
/// @returns a `MemberAccessorExpression` that indexes `obj` with `idx`
template <typename OBJ, typename IDX>
Expression* MemberAccessor(OBJ&& obj, IDX&& idx) {
return create<MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)),
Expr(std::forward<IDX>(idx)));
}
/// Creates a StructMemberOffsetDecoration
/// @param val the offset value
/// @returns the offset decoration pointer
StructMemberOffsetDecoration* MemberOffset(uint32_t val) {
return program->create<StructMemberOffsetDecoration>(source_, val);
}
/// Creates a Function
/// @param source the source information
/// @param name the function name
/// @param params the function parameters
/// @param type the function return type
/// @param body the function body
/// @param decorations the function decorations
/// @returns the function pointer
Function* Func(Source source,
std::string name,
ast::VariableList params,
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return program->create<ast::Function>(
source, program->Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations);
}
/// Creates a Function
/// @param name the function name
/// @param params the function parameters
/// @param type the function return type
/// @param body the function body
/// @param decorations the function decorations
/// @returns the function pointer
Function* Func(std::string name,
ast::VariableList params,
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(program->Symbols().Register(name), params,
type, create<ast::BlockStatement>(body),
decorations);
}
/// Creates a StructMember
/// @param source the source information
/// @param name the struct member name
/// @param type the struct member type
/// @returns the struct member pointer
StructMember* Member(const Source& source,
const std::string& name,
type::Type* type) {
return program->create<StructMember>(source,
program->Symbols().Register(name),
type, StructMemberDecorationList{});
}
/// Creates a StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @returns the struct member pointer
StructMember* Member(const std::string& name, type::Type* type) {
return program->create<StructMember>(source_,
program->Symbols().Register(name),
type, StructMemberDecorationList{});
}
/// Creates a StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @param decos the struct member decorations
/// @returns the struct member pointer
StructMember* Member(const std::string& name,
type::Type* type,
StructMemberDecorationList decos) {
return program->create<StructMember>(
source_, program->Symbols().Register(name), type, decos);
}
/// Creates a new Node owned by the Module, with the explicit Source.
/// When the Module is destructed, the `Node` will also be destructed.
/// @param source the source to apply to the Node
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, Node>* create(const Source& source,
ARGS&&... args) {
return program->create<T>(source, std::forward<ARGS>(args)...);
}
/// Creates a new Node owned by the Module, with the explicit Source.
/// When the Module is destructed, the `Node` will also be destructed.
/// @param source the source to apply to the Node
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, Node>* create(Source&& source, ARGS&&... args) {
return program->create<T>(std::move(source), std::forward<ARGS>(args)...);
}
/// Creates a new type::Type owned by the Module, using the Builder's
/// current Source. When the Module is destructed, the `Node` will also be
/// destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, Node>* create(ARGS&&... args) {
return program->create<T>(source_, std::forward<ARGS>(args)...);
}
/// Creates a new type::Type owned by the Module.
/// When the Module is destructed, owned Module and the returned `Type` will
/// also be destructed. Types are unique (de-aliased), and so calling create()
/// for the same `T` and arguments will return the same pointer.
/// @warning Use this method to acquire a type only if all of its type
/// information is provided in the constructor arguments `args`.<br>
/// If the type requires additional configuration after construction that
/// affect its fundamental type, build the type with `std::make_unique`, make
/// any necessary alterations and then call unique_type() instead.
/// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<type::Type, T>::value,
"T does not derive from type::Type");
return program->create<T>(std::forward<ARGS>(args)...);
}
/// Sets the current builder source to `src`
/// @param src the Source used for future create() calls
void SetSource(const Source& src) { source_ = src; }
/// Sets the current builder source to `loc`
/// @param loc the Source used for future create() calls
void SetSource(const Source::Location& loc) { source_ = Source(loc); }
/// @returns true if all required fields in the AST are present.
bool IsValid() const { return mod->IsValid(); }
/// @returns a reference to the program's AST root Module
ast::Module& AST() { return mod->AST(); }
/// @returns a reference to the program's SymbolTable
SymbolTable& Symbols() { return mod->Symbols(); }
/// The builder program
Program* const program;
/// The builder types
const TypesBuilder ty;
/// [DEPRECATED] Temporary alias to #program
Program* const mod;
protected:
/// Called whenever a new variable is built with `Var()`.
virtual void OnVariableBuilt(Variable*) {}
/// The source to use when creating AST nodes.
Source source_;
};
/// BuilderWithProgram is a `Builder` that constructs and owns its `Program`.
class BuilderWithProgram : public Builder {
public:
BuilderWithProgram();
~BuilderWithProgram() override;
};
//! @cond Doxygen_Suppress
// Various template specializations for TypesBuilder::CToAST.
template <>
struct TypesBuilder::CToAST<Builder::i32> {
static type::Type* get(const TypesBuilder* t) { return t->i32(); }
};
template <>
struct TypesBuilder::CToAST<Builder::u32> {
static type::Type* get(const TypesBuilder* t) { return t->u32(); }
};
template <>
struct TypesBuilder::CToAST<Builder::f32> {
static type::Type* get(const TypesBuilder* t) { return t->f32(); }
};
template <>
struct TypesBuilder::CToAST<bool> {
static type::Type* get(const TypesBuilder* t) { return t->bool_(); }
};
template <>
struct TypesBuilder::CToAST<void> {
static type::Type* get(const TypesBuilder* t) { return t->void_(); }
};
//! @endcond
} // namespace ast
} // namespace tint
#endif // SRC_AST_BUILDER_H_

View File

@ -15,7 +15,7 @@
#include "src/ast/builtin_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::BuiltinDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/call_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::CallExpression);

View File

@ -16,7 +16,7 @@
#include "src/ast/call_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/case_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::CaseStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/constant_id_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ConstantIdDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/continue_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ContinueStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/discard_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::DiscardStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/else_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ElseStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/fallthrough_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::FallthroughStatement);

View File

@ -18,7 +18,7 @@
#include <sstream>
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::FloatLiteral);

View File

@ -20,7 +20,7 @@
#include "src/ast/variable.h"
#include "src/ast/workgroup_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/type/multisampled_texture_type.h"
#include "src/type/sampled_texture_type.h"
#include "src/type/texture_type.h"

View File

@ -36,7 +36,7 @@ TEST_F(FunctionTest, Creation) {
auto* f = Func("func", params, ty.void_(), StatementList{},
FunctionDecorationList{});
EXPECT_EQ(f->symbol(), Symbols().Register("func"));
EXPECT_EQ(f->symbol(), Symbols().Get("func"));
ASSERT_EQ(f->params().size(), 1u);
EXPECT_EQ(f->return_type(), ty.void_());
EXPECT_EQ(f->params()[0], var);
@ -151,7 +151,7 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
auto* f = Func("func", VariableList{}, ty.void_(), StatementList{},
FunctionDecorationList{});
auto main_sym = Symbols().Register("main");
auto main_sym = Symbols().Get("main");
f->add_ancestor_entry_point(main_sym);
ASSERT_EQ(1u, f->ancestor_entry_points().size());
EXPECT_EQ(main_sym, f->ancestor_entry_points()[0]);

View File

@ -15,7 +15,7 @@
#include "src/ast/group_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::GroupDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/identifier_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);

View File

@ -16,7 +16,7 @@
#include "src/ast/else_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::IfStatement);

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@
#include <vector>
#include "src/ast/access_control.h"
#include "src/ast/builder.h"
#include "src/program_builder.h"
#include "src/type/sampler_type.h"
#include "src/type/storage_texture_type.h"
#include "src/type/texture_type.h"
@ -211,7 +211,7 @@ struct TextureOverloadCase {
type::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(Builder*)>);
std::function<ExpressionList(ProgramBuilder*)>);
/// Constructor for textureLoad() functions with non-storage textures
TextureOverloadCase(ValidTextureOverload,
const char*,
@ -219,7 +219,7 @@ struct TextureOverloadCase {
type::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(Builder*)>);
std::function<ExpressionList(ProgramBuilder*)>);
/// Constructor for textureLoad() with storage textures
TextureOverloadCase(ValidTextureOverload,
const char*,
@ -228,7 +228,7 @@ struct TextureOverloadCase {
type::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(Builder*)>);
std::function<ExpressionList(ProgramBuilder*)>);
/// Copy constructor
TextureOverloadCase(const TextureOverloadCase&);
/// Destructor
@ -240,13 +240,13 @@ struct TextureOverloadCase {
/// @param builder the AST builder used for the test
/// @returns the vector component type of the texture function return value
type::Type* resultVectorComponentType(ast::Builder* builder) const;
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test texture
ast::Variable* buildTextureVariable(ast::Builder* builder) const;
ast::Variable* buildTextureVariable(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a Variable holding the test sampler
ast::Variable* buildSamplerVariable(ast::Builder* builder) const;
ast::Variable* buildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload
ValidTextureOverload const overload;
@ -270,7 +270,7 @@ struct TextureOverloadCase {
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
const char* const function;
/// A function that builds the AST arguments for the overload
std::function<ExpressionList(Builder*)> const args;
std::function<ExpressionList(ProgramBuilder*)> const args;
};
std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data);

View File

@ -15,7 +15,7 @@
#include "src/ast/location_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::LocationDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/loop_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::LoopStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/member_accessor_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::MemberAccessorExpression);

View File

@ -18,8 +18,7 @@
#include <string>
#include <utility>
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/type/alias_type.h"
#include "src/type/struct_type.h"
@ -28,12 +27,13 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Module);
namespace tint {
namespace ast {
Module::Module() : Base(Source{}) {}
Module::Module(const Source& source) : Base(source) {}
Module::Module(std::vector<type::Type*> constructed_types,
Module::Module(const Source& source,
std::vector<type::Type*> constructed_types,
FunctionList functions,
VariableList global_variables)
: Base(Source{}),
: Base(source),
constructed_types_(std::move(constructed_types)),
functions_(std::move(functions)),
global_variables_(std::move(global_variables)) {}

View File

@ -31,13 +31,16 @@ namespace ast {
class Module : public Castable<Module, Node> {
public:
/// Constructor
Module();
/// @param source the source of the module
explicit Module(const Source& source);
/// Constructor
/// @param source the source of the module
/// @param constructed_types the list of types explicitly declared in the AST
/// @param functions the list of program functions
/// @param global_variables the list of global variables
Module(std::vector<type::Type*> constructed_types,
Module(const Source& source,
std::vector<type::Type*> constructed_types,
FunctionList functions,
VariableList global_variables);

View File

@ -16,7 +16,10 @@
#include "gtest/gtest.h"
#include "src/ast/case_statement.h"
#include "src/ast/module.h"
#include "src/demangler.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/reader/wgsl/parser.h"
#include "src/writer/wgsl/generator.h"
@ -114,12 +117,12 @@ fn main() -> void {
auto src = parser.program();
// Clone the src program to dst
auto dst = src.Clone();
Program dst(src.Clone());
// Expect the AST printed with to_str() to match
Demangler demanger;
EXPECT_EQ(demanger.Demangle(src.Symbols(), src.to_str()),
demanger.Demangle(dst.Symbols(), dst.to_str()));
EXPECT_EQ(demanger.Demangle(src.Symbols(), src.AST().to_str()),
demanger.Demangle(dst.Symbols(), dst.AST().to_str()));
// Check that none of the AST nodes or type pointers in dst are found in src
std::unordered_set<ast::Node*> src_nodes;
@ -142,8 +145,8 @@ fn main() -> void {
// comparison.
std::string src_wgsl;
{
tint::writer::wgsl::Generator src_gen(&src);
ASSERT_TRUE(src_gen.Generate());
writer::wgsl::Generator src_gen(&src);
ASSERT_TRUE(src_gen.Generate()) << src_gen.error();
src_wgsl = src_gen.result();
// Move the src program to a temporary that'll be dropped, so that the src
@ -154,8 +157,8 @@ fn main() -> void {
auto tmp = std::move(src);
}
// Print the dst program, check it matches the original source
tint::writer::wgsl::Generator dst_gen(&dst);
// Print the dst module, check it matches the original source
writer::wgsl::Generator dst_gen(&dst);
ASSERT_TRUE(dst_gen.Generate());
auto dst_wgsl = dst_gen.result();
ASSERT_EQ(src_wgsl, dst_wgsl);

139
src/ast/module_test.cc Normal file
View File

@ -0,0 +1,139 @@
// Copyright 2020 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.
#include "src/ast/module.h"
#include <sstream>
#include <utility>
#include "gmock/gmock.h"
#include "src/ast/function.h"
#include "src/ast/test_helper.h"
#include "src/ast/variable.h"
#include "src/type/alias_type.h"
#include "src/type/f32_type.h"
#include "src/type/struct_type.h"
namespace tint {
namespace ast {
namespace {
using ModuleTest = TestHelper;
TEST_F(ModuleTest, Creation) {
EXPECT_EQ(Program(std::move(*this)).AST().Functions().size(), 0u);
}
TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
const auto str = Program(std::move(*this)).AST().to_str();
auto* const expected = "Module{\n}\n";
EXPECT_EQ(str, expected);
}
TEST_F(ModuleTest, LookupFunction) {
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_EQ(func,
program.AST().Functions().Find(program.Symbols().Get("main")));
}
TEST_F(ModuleTest, LookupFunctionMissing) {
Program program(std::move(*this));
EXPECT_EQ(nullptr,
program.AST().Functions().Find(program.Symbols().Get("Missing")));
}
TEST_F(ModuleTest, IsValid_Empty) {
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, ty.f32());
AST().AddGlobalVariable(var);
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Null_GlobalVariable) {
AST().AddGlobalVariable(nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", StorageClass::kInput, nullptr);
AST().AddGlobalVariable(var);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Alias) {
auto* alias = ty.alias("alias", ty.f32());
AST().AddConstructedType(alias);
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Null_Alias) {
AST().AddConstructedType(nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Struct) {
auto* st = ty.struct_("name", {});
auto* alias = ty.alias("name", st);
AST().AddConstructedType(alias);
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
auto* st = ty.struct_("", {});
auto* alias = ty.alias("name", st);
AST().AddConstructedType(alias);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Function) {
auto* func = Func("main", VariableList(), ty.f32(), StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Null_Function) {
AST().Functions().Add(nullptr);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
TEST_F(ModuleTest, IsValid_Invalid_Function) {
auto* func = Func("main", VariableList{}, nullptr, StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}
} // namespace
} // namespace ast
} // namespace tint

View File

@ -15,7 +15,7 @@
#include "src/ast/null_literal.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::NullLiteral);

View File

@ -15,7 +15,7 @@
#include "src/ast/return_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/scalar_constructor_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression);

View File

@ -15,7 +15,7 @@
#include "src/ast/sint_literal.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::SintLiteral);

View File

@ -15,7 +15,7 @@
#include "src/ast/stage_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::StageDecoration);

View File

@ -15,7 +15,7 @@
#include "src/ast/stride_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::StrideDecoration);

View File

@ -16,7 +16,7 @@
#include "src/ast/struct_block_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::Struct);

View File

@ -15,7 +15,7 @@
#include "src/ast/struct_block_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::StructBlockDecoration);

View File

@ -16,7 +16,7 @@
#include "src/ast/struct_member_offset_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMember);

View File

@ -15,7 +15,7 @@
#include "src/ast/struct_member_offset_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMemberOffsetDecoration);

View File

@ -16,7 +16,7 @@
#include "src/ast/case_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement);

View File

@ -20,16 +20,15 @@
#include <utility>
#include "gtest/gtest.h"
#include "src/ast/builder.h"
#include "src/demangler.h"
#include "src/program.h"
#include "src/program_builder.h"
namespace tint {
namespace ast {
/// Helper class for testing
template <typename BASE>
class TestHelperBase : public BASE, public BuilderWithProgram {
class TestHelperBase : public BASE, public ProgramBuilder {
public:
/// Demangles the given string
/// @param s the string to demangle

View File

@ -15,7 +15,7 @@
#include "src/ast/type_constructor_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeConstructorExpression);

View File

@ -15,7 +15,7 @@
#include "src/ast/uint_literal.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::UintLiteral);

View File

@ -15,7 +15,7 @@
#include "src/ast/unary_op_expression.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::UnaryOpExpression);

View File

@ -18,7 +18,7 @@
#include "src/ast/constant_id_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::Variable);

View File

@ -15,7 +15,7 @@
#include "src/ast/variable_decl_statement.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement);

View File

@ -15,7 +15,7 @@
#include "src/ast/workgroup_decoration.h"
#include "src/clone_context.h"
#include "src/program.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_CLASS_ID(tint::ast::WorkgroupDecoration);

View File

@ -14,11 +14,14 @@
#include "src/clone_context.h"
#include "src/ast/function.h"
#include "src/ast/module.h"
#include "src/program.h"
#include "src/program_builder.h"
namespace tint {
CloneContext::CloneContext(Program* to, Program const* from)
CloneContext::CloneContext(ProgramBuilder* to, Program const* from)
: dst(to), src(from) {}
CloneContext::~CloneContext() = default;
@ -27,7 +30,15 @@ Symbol CloneContext::Clone(const Symbol& s) const {
}
void CloneContext::Clone() {
src->Clone(this);
for (auto* ty : src->AST().ConstructedTypes()) {
dst->AST().AddConstructedType(Clone(ty));
}
for (auto* var : src->AST().GlobalVariables()) {
dst->AST().AddGlobalVariable(Clone(var));
}
for (auto* func : src->AST().Functions()) {
dst->AST().Functions().Add(Clone(func));
}
}
ast::FunctionList CloneContext::Clone(const ast::FunctionList& v) {

View File

@ -19,7 +19,6 @@
#include <unordered_map>
#include <vector>
#include "src/ast/function.h"
#include "src/castable.h"
#include "src/source.h"
#include "src/symbol.h"
@ -29,26 +28,34 @@ namespace tint {
// Forward declarations
class Program;
class ProgramBuilder;
namespace ast {
class FunctionList;
} // namespace ast
/// CloneContext holds the state used while cloning AST nodes and types.
class CloneContext {
public:
/// Constructor
/// @param to the target program to clone into
/// @param from the source program to clone from
CloneContext(Program* to, Program const* from);
/// @param to the target ProgramBuilder to clone into
/// @param from the source Program to clone from
CloneContext(ProgramBuilder* to, Program const* from);
/// Destructor
~CloneContext();
/// Clones the Node or type::Type `a` into the program #dst if `a` is not
/// null. If `a` is null, then Clone() returns null. If `a` has been cloned
/// already by this CloneContext then the same cloned pointer is returned.
/// Clones the Node or type::Type `a` into the ProgramBuilder #dst if `a` is
/// not null. If `a` is null, then Clone() returns null. If `a` has been
/// cloned already by this CloneContext then the same cloned pointer is
/// returned.
///
/// Clone() may use a function registered with ReplaceAll() to create a
/// transformed version of the object. See ReplaceAll() for more information.
///
/// The Node or type::Type `a` must be owned by the program #src.
/// The Node or type::Type `a` must be owned by the Program #src.
///
/// @note Semantic information such as resolved expression type and intrinsic
/// information is not cloned.
@ -85,15 +92,16 @@ class CloneContext {
/// Clones the Symbol `s` into `dst`
///
/// The Symbol `s` must be owned by the program #src.
/// The Symbol `s` must be owned by the Program #src.
///
/// @param s the Symbol to clone
/// @return the cloned source
Symbol Clone(const Symbol& s) const;
/// Clones each of the elements of the vector `v` into the program #dst.
/// Clones each of the elements of the vector `v` into the ProgramBuilder
/// #dst.
///
/// All the elements of the vector `v` must be owned by the program #src.
/// All the elements of the vector `v` must be owned by the Program #src.
///
/// @param v the vector to clone
/// @return the cloned vector
@ -107,7 +115,8 @@ class CloneContext {
return out;
}
/// Clones each of the elements of the vector `v` into the Program #dst.
/// Clones each of the elements of the vector `v` into the ProgramBuilder
/// #dst.
///
/// All the elements of the vector `v` must be owned by the Program #src.
///
@ -134,7 +143,8 @@ class CloneContext {
/// // Replace all ast::UintLiterals with the number 42
/// CloneCtx ctx(&out, in)
/// .ReplaceAll([&] (CloneContext* ctx, ast::UintLiteral* l) {
/// return ctx->dst->create<ast::UintLiteral>(ctx->Clone(l->source()),
/// return ctx->dst->create<ast::UintLiteral>(
/// ctx->Clone(l->source()),
/// ctx->Clone(l->type()),
/// 42);
/// }).Clone();
@ -167,13 +177,13 @@ class CloneContext {
return *this;
}
/// Clone performs the clone of the entire program #src to #dst.
/// Clone performs the clone of the entire Program #src to #dst.
void Clone();
/// The target program to clone into.
Program* const dst;
/// The target ProgramBuilder to clone into.
ProgramBuilder* const dst;
/// The source program to clone from.
/// The source Program to clone from.
Program const* const src;
private:

View File

@ -14,15 +14,17 @@
#include "src/clone_context.h"
#include <utility>
#include "gtest/gtest.h"
#include "src/program.h"
#include "src/program_builder.h"
namespace tint {
namespace {
struct Cloneable : public Castable<Cloneable, ast::Node> {
Cloneable() : Base(Source{}) {}
explicit Cloneable(const Source& source) : Base(source) {}
Cloneable* a = nullptr;
Cloneable* b = nullptr;
@ -40,18 +42,23 @@ struct Cloneable : public Castable<Cloneable, ast::Node> {
void to_str(std::ostream&, size_t) const override {}
};
struct Replaceable : public Castable<Replaceable, Cloneable> {};
struct Replacement : public Castable<Replacement, Replaceable> {};
struct Replaceable : public Castable<Replaceable, Cloneable> {
explicit Replaceable(const Source& source) : Base(source) {}
};
struct Replacement : public Castable<Replacement, Replaceable> {
explicit Replacement(const Source& source) : Base(source) {}
};
TEST(CloneContext, Clone) {
Program original;
auto* original_root = original.create<Cloneable>();
original_root->a = original.create<Cloneable>();
original_root->a->b = original.create<Cloneable>();
original_root->b = original.create<Cloneable>();
ProgramBuilder builder;
auto* original_root = builder.create<Cloneable>();
original_root->a = builder.create<Cloneable>();
original_root->a->b = builder.create<Cloneable>();
original_root->b = builder.create<Cloneable>();
original_root->b->a = original_root->a; // Aliased
original_root->b->b = original.create<Cloneable>();
original_root->b->b = builder.create<Cloneable>();
original_root->c = original_root->b; // Aliased
Program original(std::move(builder));
// root
// ╭──────────────────┼──────────────────╮
@ -63,7 +70,7 @@ TEST(CloneContext, Clone) {
//
// C: Clonable
Program cloned;
ProgramBuilder cloned;
auto* cloned_root = CloneContext(&cloned, &original).Clone(original_root);
EXPECT_NE(cloned_root->a, nullptr);
@ -87,14 +94,15 @@ TEST(CloneContext, Clone) {
EXPECT_EQ(cloned_root->c, cloned_root->b); // Aliased
}
TEST(CloneContext, CloneWithReplaceAll) {
Program original;
auto* original_root = original.create<Cloneable>();
original_root->a = original.create<Cloneable>();
original_root->a->b = original.create<Replaceable>();
original_root->b = original.create<Replaceable>();
TEST(CloneContext, CloneWithReplacements) {
ProgramBuilder builder;
auto* original_root = builder.create<Cloneable>();
original_root->a = builder.create<Cloneable>();
original_root->a->b = builder.create<Replaceable>();
original_root->b = builder.create<Replaceable>();
original_root->b->a = original_root->a; // Aliased
original_root->c = original_root->b; // Aliased
Program original(std::move(builder));
// root
// ╭──────────────────┼──────────────────╮
@ -107,7 +115,7 @@ TEST(CloneContext, CloneWithReplaceAll) {
// C: Clonable
// R: Replaceable
Program cloned;
ProgramBuilder cloned;
auto* cloned_root = CloneContext(&cloned, &original)
.ReplaceAll([&](CloneContext* ctx, Replaceable* in) {
auto* out = cloned.create<Replacement>();
@ -161,18 +169,19 @@ TEST(CloneContext, CloneWithReplaceAll) {
}
TEST(CloneContext, CloneWithReplace) {
Program original;
auto* original_root = original.create<Cloneable>();
original_root->a = original.create<Cloneable>();
original_root->b = original.create<Cloneable>();
original_root->c = original.create<Cloneable>();
ProgramBuilder builder;
auto* original_root = builder.create<Cloneable>();
original_root->a = builder.create<Cloneable>();
original_root->b = builder.create<Cloneable>();
original_root->c = builder.create<Cloneable>();
Program original(std::move(builder));
// root
// ╭──────────────────┼──────────────────╮
// (a) (b) (c)
// Replaced
Program cloned;
ProgramBuilder cloned;
auto* replacement = cloned.create<Cloneable>();
auto* cloned_root = CloneContext(&cloned, &original)

View File

@ -22,11 +22,13 @@
#include "src/ast/constructor_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/function.h"
#include "src/ast/module.h"
#include "src/ast/null_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/program.h"
#include "src/type/access_control_type.h"
#include "src/type/array_type.h"
#include "src/type/f32_type.h"
@ -43,27 +45,27 @@
namespace tint {
namespace inspector {
Inspector::Inspector(const Program* program) : program_(*program) {}
Inspector::Inspector(const Program* program) : program_(program) {}
Inspector::~Inspector() = default;
std::vector<EntryPoint> Inspector::GetEntryPoints() {
std::vector<EntryPoint> result;
for (auto* func : program_.AST().Functions()) {
for (auto* func : program_->AST().Functions()) {
if (!func->IsEntryPoint()) {
continue;
}
EntryPoint entry_point;
entry_point.name = program_.Symbols().NameFor(func->symbol());
entry_point.remapped_name = program_.Symbols().NameFor(func->symbol());
entry_point.name = program_->Symbols().NameFor(func->symbol());
entry_point.remapped_name = program_->Symbols().NameFor(func->symbol());
entry_point.stage = func->pipeline_stage();
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
entry_point.workgroup_size_z) = func->workgroup_size();
for (auto* var : func->referenced_module_variables()) {
auto name = program_.Symbols().NameFor(var->symbol());
auto name = program_->Symbols().NameFor(var->symbol());
if (var->HasBuiltinDecoration()) {
continue;
}
@ -106,7 +108,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
std::map<uint32_t, Scalar> result;
for (auto* var : program_.AST().GlobalVariables()) {
for (auto* var : program_->AST().GlobalVariables()) {
if (!var->HasConstantIdDecoration()) {
continue;
}
@ -283,7 +285,7 @@ std::vector<ResourceBinding> Inspector::GetMultisampledTextureResourceBindings(
}
ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
auto* func = program_.AST().Functions().Find(program_.Symbols().Get(name));
auto* func = program_->AST().Functions().Find(program_->Symbols().Get(name));
if (!func) {
error_ += name + " was not found!";
return nullptr;

View File

@ -129,7 +129,7 @@ class Inspector {
const std::string& entry_point);
private:
const Program& program_;
const Program* program_;
std::string error_;
/// @param name name of the entry point to find

View File

@ -19,7 +19,6 @@
#include "gtest/gtest.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/bool_literal.h"
#include "src/ast/builder.h"
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
#include "src/ast/constant_id_decoration.h"
@ -44,6 +43,7 @@
#include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h"
#include "src/ast/workgroup_decoration.h"
#include "src/program_builder.h"
#include "src/type/access_control_type.h"
#include "src/type/array_type.h"
#include "src/type/bool_type.h"
@ -67,11 +67,10 @@ namespace tint {
namespace inspector {
namespace {
class InspectorHelper : public ast::BuilderWithProgram {
class InspectorHelper : public ProgramBuilder {
public:
InspectorHelper()
: td_(std::make_unique<TypeDeterminer>(mod)),
inspector_(std::make_unique<Inspector>(mod)),
: td_(std::make_unique<TypeDeterminer>(this)),
sampler_type_(type::SamplerKind::kSampler),
comparison_sampler_type_(type::SamplerKind::kComparisonSampler) {}
@ -611,8 +610,16 @@ class InspectorHelper : public ast::BuilderWithProgram {
return vec_type(base_type, 3);
}
Inspector& Build() {
if (inspector_) {
return *inspector_;
}
program_ = std::make_unique<Program>(std::move(*this));
inspector_ = std::make_unique<Inspector>(program_.get());
return *inspector_;
}
TypeDeterminer* td() { return td_.get(); }
Inspector* inspector() { return inspector_.get(); }
type::Array* u32_array_type(uint32_t count) {
if (array_type_memo_.find(count) == array_type_memo_.end()) {
@ -637,8 +644,8 @@ class InspectorHelper : public ast::BuilderWithProgram {
private:
std::unique_ptr<TypeDeterminer> td_;
std::unique_ptr<Program> program_;
std::unique_ptr<Inspector> inspector_;
type::Sampler sampler_type_;
type::Sampler comparison_sampler_type_;
std::map<uint32_t, type::Array*> array_type_memo_;
@ -694,8 +701,10 @@ class InspectorGetMultisampledTextureResourceBindingsTestWithParam
public testing::TestWithParam<GetMultisampledTextureTestParams> {};
TEST_F(InspectorGetEntryPointTest, NoFunctions) {
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ(0u, result.size());
}
@ -703,8 +712,10 @@ TEST_F(InspectorGetEntryPointTest, NoFunctions) {
TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {
AST().Functions().Add(MakeEmptyBodyFunction("foo", {}));
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ(0u, result.size());
}
@ -718,8 +729,10 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ("foo", result[0].name);
@ -742,8 +755,10 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(2u, result.size());
EXPECT_EQ("foo", result[0].name);
@ -774,8 +789,10 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints();
EXPECT_FALSE(inspector()->has_error());
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
EXPECT_FALSE(inspector.has_error());
ASSERT_EQ(2u, result.size());
EXPECT_EQ("foo", result[0].name);
@ -794,8 +811,10 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
});
AST().Functions().Add(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
uint32_t x, y, z;
@ -813,8 +832,10 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
});
AST().Functions().Add(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
uint32_t x, y, z;
@ -835,8 +856,10 @@ TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
});
AST().Functions().Add(foo);
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].input_variables.size());
@ -855,8 +878,10 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -886,8 +911,10 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -917,8 +944,10 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -944,8 +973,10 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -981,8 +1012,10 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -1022,10 +1055,13 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
// TODO(dsinclair): Update to run the namer transform when available.
// TODO(dsinclair): Update to run the namer transform when
// available.
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(2u, result.size());
@ -1075,10 +1111,13 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error();
// TODO(dsinclair): Update to run the namer transform when available.
// TODO(dsinclair): Update to run the namer transform when
// available.
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(2u, result.size());
@ -1136,8 +1175,10 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
@ -1153,8 +1194,10 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
// TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
// through
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) {
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_TRUE(inspector()->has_error());
Inspector& inspector = Build();
auto result = inspector.GetRemappedNameForEntryPoint("foo");
ASSERT_TRUE(inspector.has_error());
EXPECT_EQ("", result);
}
@ -1164,8 +1207,10 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) {
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) {
AST().Functions().Add(MakeEmptyBodyFunction("foo", {}));
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_TRUE(inspector()->has_error());
Inspector& inspector = Build();
auto result = inspector.GetRemappedNameForEntryPoint("foo");
ASSERT_TRUE(inspector.has_error());
EXPECT_EQ("", result);
}
@ -1179,10 +1224,13 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available.
// TODO(dsinclair): Update to run the namer transform when
// available.
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ("foo", result);
}
@ -1197,7 +1245,8 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available.
// TODO(dsinclair): Update to run the namer transform when
// available.
auto* bar = MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{
@ -1205,14 +1254,16 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
});
AST().Functions().Add(bar);
Inspector& inspector = Build();
{
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
auto result = inspector.GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ("foo", result);
}
{
auto result = inspector()->GetRemappedNameForEntryPoint("bar");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
auto result = inspector.GetRemappedNameForEntryPoint("bar");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ("bar", result);
}
}
@ -1224,7 +1275,9 @@ TEST_F(InspectorGetConstantIDsTest, Bool) {
AddConstantID<bool>("bar", 20, ty.bool_(), &val_true);
AddConstantID<bool>("baz", 300, ty.bool_(), &val_false);
auto result = inspector()->GetConstantIDs();
Inspector& inspector = Build();
auto result = inspector.GetConstantIDs();
ASSERT_EQ(3u, result.size());
ASSERT_TRUE(result.find(1) != result.end());
@ -1244,7 +1297,9 @@ TEST_F(InspectorGetConstantIDsTest, U32) {
AddConstantID<uint32_t>("foo", 1, ty.u32(), nullptr);
AddConstantID<uint32_t>("bar", 20, ty.u32(), &val);
auto result = inspector()->GetConstantIDs();
Inspector& inspector = Build();
auto result = inspector.GetConstantIDs();
ASSERT_EQ(2u, result.size());
ASSERT_TRUE(result.find(1) != result.end());
@ -1262,7 +1317,9 @@ TEST_F(InspectorGetConstantIDsTest, I32) {
AddConstantID<int32_t>("bar", 20, ty.i32(), &val_neg);
AddConstantID<int32_t>("baz", 300, ty.i32(), &val_pos);
auto result = inspector()->GetConstantIDs();
Inspector& inspector = Build();
auto result = inspector.GetConstantIDs();
ASSERT_EQ(3u, result.size());
ASSERT_TRUE(result.find(1) != result.end());
@ -1286,7 +1343,9 @@ TEST_F(InspectorGetConstantIDsTest, Float) {
AddConstantID<float>("baz", 300, ty.f32(), &val_neg);
AddConstantID<float>("x", 4000, ty.f32(), &val_pos);
auto result = inspector()->GetConstantIDs();
Inspector& inspector = Build();
auto result = inspector.GetConstantIDs();
ASSERT_EQ(4u, result.size());
ASSERT_TRUE(result.find(1) != result.end());
@ -1306,9 +1365,11 @@ TEST_F(InspectorGetConstantIDsTest, Float) {
}
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) {
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_TRUE(inspector()->has_error());
std::string error = inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_TRUE(inspector.has_error());
std::string error = inspector.error();
EXPECT_TRUE(error.find("not found") != std::string::npos);
}
@ -1332,8 +1393,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ub_func");
std::string error = inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ub_func");
std::string error = inspector.error();
EXPECT_TRUE(error.find("not an entry point") != std::string::npos);
}
@ -1360,8 +1423,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ(0u, result.size());
}
@ -1385,8 +1450,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1414,8 +1481,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1458,8 +1527,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(3u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1495,8 +1566,10 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetUniformBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1524,8 +1597,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1553,8 +1628,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1600,8 +1677,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(3u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1637,8 +1716,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1666,8 +1747,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1695,8 +1778,10 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -1720,9 +1805,10 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result =
inspector()->GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1769,9 +1855,10 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result =
inspector()->GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(3u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1807,9 +1894,10 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result =
inspector()->GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1838,9 +1926,10 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result =
inspector()->GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1868,9 +1957,10 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result =
inspector()->GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetReadOnlyStorageBufferResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -1890,8 +1980,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1907,8 +1999,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -1933,8 +2027,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -1957,8 +2053,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("foo");
ASSERT_TRUE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("foo");
ASSERT_TRUE(inspector.has_error()) << inspector.error();
}
TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
@ -1977,8 +2075,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -1999,8 +2099,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetComparisonSamplerResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetComparisonSamplerResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -2016,8 +2118,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetComparisonSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetComparisonSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -2043,8 +2147,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetComparisonSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetComparisonSamplerResourceBindings("ep_func");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -2067,8 +2173,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSamplerResourceBindings("foo");
ASSERT_TRUE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSamplerResourceBindings("foo");
ASSERT_TRUE(inspector.has_error()) << inspector.error();
}
TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
@ -2087,8 +2195,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetComparisonSamplerResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetComparisonSamplerResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(0u, result.size());
}
@ -2100,8 +2210,10 @@ TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {
});
AST().Functions().Add(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ(0u, result.size());
}
@ -2125,8 +2237,10 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -2137,8 +2251,8 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
// Prove that sampled and multi-sampled bindings are accounted
// for separately.
auto multisampled_result =
inspector()->GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
inspector.GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_TRUE(multisampled_result.empty());
}
@ -2216,8 +2330,10 @@ TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam,
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -2287,8 +2403,10 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);
@ -2299,8 +2417,8 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
// Prove that sampled and multi-sampled bindings are accounted
// for separately.
auto single_sampled_result =
inspector()->GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
inspector.GetSampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_TRUE(single_sampled_result.empty());
}
@ -2340,8 +2458,10 @@ TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) {
});
AST().Functions().Add(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
EXPECT_EQ(0u, result.size());
}
@ -2367,8 +2487,10 @@ TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam,
ASSERT_TRUE(td()->Determine()) << td()->error();
auto result = inspector()->GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
Inspector& inspector = Build();
auto result = inspector.GetMultisampledTextureResourceBindings("ep");
ASSERT_FALSE(inspector.has_error()) << inspector.error();
ASSERT_EQ(1u, result.size());
EXPECT_EQ(0u, result[0].bind_group);

View File

@ -15,44 +15,72 @@
#include "src/program.h"
#include <sstream>
#include <utility>
#include "src/ast/module.h"
#include "src/clone_context.h"
#include "src/type/struct_type.h"
#include "src/program_builder.h"
namespace tint {
Program::Program() : ast_(nodes_.Create<ast::Module>()) {}
Program::Program() = default;
Program::Program(Program&& rhs) = default;
Program::Program(Program&& program)
: types_(std::move(program.types_)),
nodes_(std::move(program.nodes_)),
ast_(std::move(program.ast_)),
symbols_(std::move(program.symbols_)) {
program.AssertNotMoved();
program.moved_ = true;
}
Program& Program::operator=(Program&& rhs) = default;
Program::Program(ProgramBuilder&& builder)
: types_(std::move(builder.Types())),
nodes_(std::move(builder.Nodes())),
ast_(nodes_.Create<ast::Module>(Source{},
builder.AST().ConstructedTypes(),
builder.AST().Functions(),
builder.AST().GlobalVariables())),
symbols_(std::move(builder.Symbols())) {
builder.MarkAsMoved();
}
Program::~Program() = default;
Program& Program::operator=(Program&& program) {
program.AssertNotMoved();
program.moved_ = true;
types_ = std::move(program.types_);
nodes_ = std::move(program.nodes_);
ast_ = std::move(program.ast_);
symbols_ = std::move(program.symbols_);
return *this;
}
Program Program::Clone() const {
Program out;
AssertNotMoved();
return Program(CloneAsBuilder());
}
ProgramBuilder Program::CloneAsBuilder() const {
AssertNotMoved();
ProgramBuilder out;
CloneContext(&out, this).Clone();
return out;
}
void Program::Clone(CloneContext* ctx) const {
for (auto* ty : AST().ConstructedTypes()) {
ctx->dst->AST().AddConstructedType(ctx->Clone(ty));
}
for (auto* var : AST().GlobalVariables()) {
ctx->dst->AST().AddGlobalVariable(ctx->Clone(var));
}
for (auto* func : AST().Functions()) {
ctx->dst->AST().Functions().Add(ctx->Clone(func));
}
}
bool Program::IsValid() const {
AssertNotMoved();
return ast_->IsValid();
}
std::string Program::to_str() const {
AssertNotMoved();
return ast_->to_str();
}
void Program::AssertNotMoved() const {
assert(!moved_);
}
} // namespace tint

View File

@ -15,26 +15,24 @@
#ifndef SRC_PROGRAM_H_
#define SRC_PROGRAM_H_
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include "src/ast/function.h"
#include "src/ast/module.h"
#include "src/ast/variable.h"
#include "src/block_allocator.h"
#include "src/symbol_table.h"
#include "src/traits.h"
#include "src/type/alias_type.h"
#include "src/type/type_manager.h"
namespace tint {
/// Represents all the source in a given program.
// Forward declarations
class CloneContext;
namespace ast {
class Module;
} // namespace ast
/// Program holds the AST, Type information and SymbolTable for a tint program.
class Program {
public:
/// ASTNodes is an alias to BlockAllocator<ast::Node>
@ -47,84 +45,65 @@ class Program {
/// @param rhs the Program to move
Program(Program&& rhs);
/// Move constructor from builder
/// @param builder the builder used to construct the program
explicit Program(ProgramBuilder&& builder);
/// Destructor
~Program();
/// Move assignment operator
/// @param rhs the Program to move
/// @return this Program
Program& operator=(Program&& rhs);
/// Destructor
~Program();
/// @returns a reference to the program's types
const type::Manager& Types() const { return types_; }
const type::Manager& Types() const {
AssertNotMoved();
return types_;
}
/// @returns a reference to the program's AST nodes storage
const ASTNodes& Nodes() const { return nodes_; }
const ASTNodes& Nodes() const {
AssertNotMoved();
return nodes_;
}
/// @returns a reference to the program's AST root Module
const ast::Module& AST() const { return *ast_; }
/// @returns a reference to the program's AST root Module
ast::Module& AST() { return *ast_; }
const ast::Module& AST() const {
AssertNotMoved();
return *ast_;
}
/// @returns a reference to the program's SymbolTable
const SymbolTable& Symbols() const { return symbols_; }
/// @returns a reference to the program's SymbolTable
SymbolTable& Symbols() { return symbols_; }
const SymbolTable& Symbols() const {
AssertNotMoved();
return symbols_;
}
/// @return a deep copy of this program
Program Clone() const;
/// Clone this program into `ctx->dst` using the provided CloneContext
/// The program will be cloned in this order:
/// * Constructed types
/// * Global variables
/// * Functions
/// @param ctx the clone context
void Clone(CloneContext* ctx) const;
/// @return a deep copy of this Program, as a ProgramBuilder
ProgramBuilder CloneAsBuilder() const;
/// @returns true if all required fields in the AST are present.
/// @returns true if the program not missing information
bool IsValid() const;
/// @returns a string representation of the program
/// @returns a string describing this program.
std::string to_str() const;
/// Creates a new Node owned by the Program. When the Program is
/// destructed, the Node will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, ast::Node>* create(ARGS&&... args) {
return nodes_.Create<T>(std::forward<ARGS>(args)...);
}
/// Creates a new type::Type owned by the Program.
/// When the Program is destructed, owned Program and the returned
/// `Type` will also be destructed.
/// Types are unique (de-aliased), and so calling create() for the same `T`
/// and arguments will return the same pointer.
/// @warning Use this method to acquire a type only if all of its type
/// information is provided in the constructor arguments `args`.<br>
/// If the type requires additional configuration after construction that
/// affect its fundamental type, build the type with `std::make_unique`, make
/// any necessary alterations and then call unique_type() instead.
/// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<type::Type, T>::value,
"T does not derive from type::Type");
return types_.Get<T>(std::forward<ARGS>(args)...);
}
private:
Program(const Program&) = delete;
/// Asserts that the program has not been moved.
void AssertNotMoved() const;
type::Manager types_;
ASTNodes nodes_;
ast::Module* ast_;
SymbolTable symbols_;
bool moved_ = false;
};
} // namespace tint

124
src/program_builder.cc Normal file
View File

@ -0,0 +1,124 @@
// 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.
#include "src/program_builder.h"
#include <assert.h>
#include <sstream>
#include "src/clone_context.h"
#include "src/type/struct_type.h"
namespace tint {
ProgramBuilder::ProgramBuilder()
: ty(this), ast_(nodes_.Create<ast::Module>(Source{})) {}
ProgramBuilder::ProgramBuilder(ProgramBuilder&& rhs)
: ty(std::move(rhs.ty)),
types_(std::move(rhs.types_)),
nodes_(std::move(rhs.nodes_)),
ast_(rhs.ast_),
symbols_(std::move(rhs.symbols_)) {
rhs.MarkAsMoved();
}
ProgramBuilder::~ProgramBuilder() = default;
ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) {
rhs.MarkAsMoved();
AssertNotMoved();
ty = std::move(rhs.ty);
types_ = std::move(rhs.types_);
nodes_ = std::move(rhs.nodes_);
ast_ = rhs.ast_;
symbols_ = std::move(rhs.symbols_);
return *this;
}
bool ProgramBuilder::IsValid() const {
return ast_->IsValid();
}
void ProgramBuilder::MarkAsMoved() {
AssertNotMoved();
moved_ = true;
}
void ProgramBuilder::AssertNotMoved() const {
assert(!moved_);
}
ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
ast::Variable* ProgramBuilder::Var(const std::string& name,
ast::StorageClass storage,
type::Type* type) {
return Var(name, storage, type, nullptr, {});
}
ast::Variable* ProgramBuilder::Var(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
false, constructor, decorations);
OnVariableBuilt(var);
return var;
}
ast::Variable* ProgramBuilder::Var(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
type, false, constructor, decorations);
OnVariableBuilt(var);
return var;
}
ast::Variable* ProgramBuilder::Const(const std::string& name,
ast::StorageClass storage,
type::Type* type) {
return Const(name, storage, type, nullptr, {});
}
ast::Variable* ProgramBuilder::Const(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(Symbols().Register(name), storage, type,
true, constructor, decorations);
OnVariableBuilt(var);
return var;
}
ast::Variable* ProgramBuilder::Const(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
auto* var = create<ast::Variable>(source, Symbols().Register(name), storage,
type, true, constructor, decorations);
OnVariableBuilt(var);
return var;
}
} // namespace tint

885
src/program_builder.h Normal file
View File

@ -0,0 +1,885 @@
// 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.
#ifndef SRC_PROGRAM_BUILDER_H_
#define SRC_PROGRAM_BUILDER_H_
#include <string>
#include <utility>
#include "src/ast/array_accessor_expression.h"
#include "src/ast/binary_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/call_expression.h"
#include "src/ast/expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/module.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/sint_literal.h"
#include "src/ast/struct.h"
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/program.h"
#include "src/symbol_table.h"
#include "src/type/alias_type.h"
#include "src/type/array_type.h"
#include "src/type/bool_type.h"
#include "src/type/f32_type.h"
#include "src/type/i32_type.h"
#include "src/type/matrix_type.h"
#include "src/type/pointer_type.h"
#include "src/type/struct_type.h"
#include "src/type/type_manager.h"
#include "src/type/u32_type.h"
#include "src/type/vector_type.h"
#include "src/type/void_type.h"
namespace tint {
class CloneContext;
/// ProgramBuilder is a mutable builder for a Program.
/// To construct a Program, populate the builder and then `std::move` it to a
/// Program.
class ProgramBuilder {
public:
/// ASTNodes is an alias to BlockAllocator<ast::Node>
using ASTNodes = BlockAllocator<ast::Node>;
/// `i32` is a type alias to `int`.
/// Useful for passing to template methods such as `vec2<i32>()` to imitate
/// WGSL syntax.
/// Note: this is intentionally not aliased to uint32_t as we want integer
/// literals passed to the builder to match WGSL's integer literal types.
using i32 = decltype(1);
/// `u32` is a type alias to `unsigned int`.
/// Useful for passing to template methods such as `vec2<u32>()` to imitate
/// WGSL syntax.
/// Note: this is intentionally not aliased to uint32_t as we want integer
/// literals passed to the builder to match WGSL's integer literal types.
using u32 = decltype(1u);
/// `f32` is a type alias to `float`
/// Useful for passing to template methods such as `vec2<f32>()` to imitate
/// WGSL syntax.
using f32 = float;
/// Constructor
ProgramBuilder();
/// Move constructor
/// @param rhs the builder to move
ProgramBuilder(ProgramBuilder&& rhs);
/// Destructor
virtual ~ProgramBuilder();
/// Move assignment operator
/// @param rhs the builder to move
/// @return this builder
ProgramBuilder& operator=(ProgramBuilder&& rhs);
/// @returns a reference to the program's types
type::Manager& Types() {
AssertNotMoved();
return types_;
}
/// @returns a reference to the program's AST nodes storage
ASTNodes& Nodes() {
AssertNotMoved();
return nodes_;
}
/// @returns a reference to the program's AST root Module
ast::Module& AST() {
AssertNotMoved();
return *ast_;
}
/// @returns a reference to the program's SymbolTable
SymbolTable& Symbols() {
AssertNotMoved();
return symbols_;
}
/// @returns true if the program not missing information
bool IsValid() const;
/// creates a new ast::Node owned by the Module. When the Module is
/// destructed, the ast::Node will also be destructed.
/// @param source the Source of the node
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, ast::Node>* create(const Source& source,
ARGS&&... args) {
AssertNotMoved();
return nodes_.Create<T>(source, std::forward<ARGS>(args)...);
}
/// creates a new ast::Node owned by the Module, injecting the current Source
/// as set by the last call to SetSource() as the only argument to the
/// constructor.
/// When the Module is destructed, the ast::Node will also be destructed.
/// @returns the node pointer
template <typename T>
traits::EnableIfIsType<T, ast::Node>* create() {
AssertNotMoved();
return nodes_.Create<T>(source_);
}
/// creates a new ast::Node owned by the Module, injecting the current Source
/// as set by the last call to SetSource() as the first argument to the
/// constructor.
/// When the Module is destructed, the ast::Node will also be destructed.
/// @param arg0 the first arguments to pass to the type constructor
/// @param args the remaining arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename ARG0, typename... ARGS>
traits::EnableIf</* T is ast::Node and ARG0 is not Source */
traits::IsTypeOrDerived<T, ast::Node>::value &&
!traits::IsTypeOrDerived<ARG0, Source>::value,
T>*
create(ARG0&& arg0, ARGS&&... args) {
AssertNotMoved();
return nodes_.Create<T>(source_, std::forward<ARG0>(arg0),
std::forward<ARGS>(args)...);
}
/// creates a new type::Type owned by the Module.
/// When the Module is destructed, owned Module and the returned
/// `Type` will also be destructed.
/// Types are unique (de-aliased), and so calling create() for the same `T`
/// and arguments will return the same pointer.
/// @warning Use this method to acquire a type only if all of its type
/// information is provided in the constructor arguments `args`.<br>
/// If the type requires additional configuration after construction that
/// affect its fundamental type, build the type with `std::make_unique`, make
/// any necessary alterations and then call unique_type() instead.
/// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<type::Type, T>::value,
"T does not derive from type::Type");
AssertNotMoved();
return types_.Get<T>(std::forward<ARGS>(args)...);
}
/// Marks this builder as moved, preventing any further use of the builder.
void MarkAsMoved();
//////////////////////////////////////////////////////////////////////////////
// TypesBuilder
//////////////////////////////////////////////////////////////////////////////
/// TypesBuilder holds basic `tint` types and methods for constructing
/// complex types.
class TypesBuilder {
public:
/// Constructor
/// @param builder the program builder
explicit TypesBuilder(ProgramBuilder* builder);
/// @return the tint AST type for the C type `T`.
template <typename T>
type::Type* Of() const {
return CToAST<T>::get(this);
}
/// @returns a boolean type
type::Bool* bool_() const { return builder->create<type::Bool>(); }
/// @returns a f32 type
type::F32* f32() const { return builder->create<type::F32>(); }
/// @returns a i32 type
type::I32* i32() const { return builder->create<type::I32>(); }
/// @returns a u32 type
type::U32* u32() const { return builder->create<type::U32>(); }
/// @returns a void type
type::Void* void_() const { return builder->create<type::Void>(); }
/// @return the tint AST type for a 2-element vector of the C type `T`.
template <typename T>
type::Vector* vec2() const {
return builder->create<type::Vector>(Of<T>(), 2);
}
/// @return the tint AST type for a 3-element vector of the C type `T`.
template <typename T>
type::Vector* vec3() const {
return builder->create<type::Vector>(Of<T>(), 3);
}
/// @return the tint AST type for a 4-element vector of the C type `T`.
template <typename T>
type::Type* vec4() const {
return builder->create<type::Vector>(Of<T>(), 4);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x2() const {
return builder->create<type::Matrix>(Of<T>(), 2, 2);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x3() const {
return builder->create<type::Matrix>(Of<T>(), 3, 2);
}
/// @return the tint AST type for a 2x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x4() const {
return builder->create<type::Matrix>(Of<T>(), 4, 2);
}
/// @return the tint AST type for a 3x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x2() const {
return builder->create<type::Matrix>(Of<T>(), 2, 3);
}
/// @return the tint AST type for a 3x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x3() const {
return builder->create<type::Matrix>(Of<T>(), 3, 3);
}
/// @return the tint AST type for a 3x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x4() const {
return builder->create<type::Matrix>(Of<T>(), 4, 3);
}
/// @return the tint AST type for a 4x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x2() const {
return builder->create<type::Matrix>(Of<T>(), 2, 4);
}
/// @return the tint AST type for a 4x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x3() const {
return builder->create<type::Matrix>(Of<T>(), 3, 4);
}
/// @return the tint AST type for a 4x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x4() const {
return builder->create<type::Matrix>(Of<T>(), 4, 4);
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @return the tint AST type for a array of size `n` of type `T`
type::Array* array(type::Type* subtype, uint32_t n) const {
return builder->create<type::Array>(subtype, n,
ast::ArrayDecorationList{});
}
/// @return the tint AST type for an array of size `N` of type `T`
template <typename T, int N = 0>
type::Array* array() const {
return array(Of<T>(), N);
}
/// creates an alias type
/// @param name the alias name
/// @param type the alias type
/// @returns the alias pointer
type::Alias* alias(const std::string& name, type::Type* type) const {
return builder->create<type::Alias>(builder->Symbols().Register(name),
type);
}
/// @return the tint AST pointer to type `T` with the given
/// ast::StorageClass.
/// @param storage_class the storage class of the pointer
template <typename T>
type::Pointer* pointer(ast::StorageClass storage_class) const {
return builder->create<type::Pointer>(Of<T>(), storage_class);
}
/// @param name the struct name
/// @param impl the struct implementation
/// @returns a struct pointer
type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
return builder->create<type::Struct>(builder->Symbols().Register(name),
impl);
}
private:
/// CToAST<T> is specialized for various `T` types and each specialization
/// contains a single static `get()` method for obtaining the corresponding
/// AST type for the C type `T`.
/// `get()` has the signature:
/// `static type::Type* get(Types* t)`
template <typename T>
struct CToAST {};
ProgramBuilder* builder;
};
//////////////////////////////////////////////////////////////////////////////
// AST helper methods
//////////////////////////////////////////////////////////////////////////////
/// @param expr the expression
/// @return expr
ast::Expression* Expr(ast::Expression* expr) { return expr; }
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const std::string& name) {
return create<ast::IdentifierExpression>(Symbols().Register(name));
}
/// @param source the source information
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const Source& source,
const std::string& name) {
return create<ast::IdentifierExpression>(source, Symbols().Register(name));
}
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const char* name) {
return create<ast::IdentifierExpression>(Symbols().Register(name));
}
/// @param value the boolean value
/// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(bool value) {
return create<ast::ScalarConstructorExpression>(Literal(value));
}
/// @param value the float value
/// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(f32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value));
}
/// @param value the integer value
/// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(i32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value));
}
/// @param value the unsigned int value
/// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(u32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value));
}
/// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to
/// `list`.
/// @param list the list to append too
/// @param arg the arg to create
template <typename ARG>
void Append(ast::ExpressionList& list, ARG&& arg) {
list.emplace_back(Expr(std::forward<ARG>(arg)));
}
/// Converts `arg0` and `args` to `ast::Expression`s using `Expr()`,
/// then appends them to `list`.
/// @param list the list to append too
/// @param arg0 the first argument
/// @param args the rest of the arguments
template <typename ARG0, typename... ARGS>
void Append(ast::ExpressionList& list, ARG0&& arg0, ARGS&&... args) {
Append(list, std::forward<ARG0>(arg0));
Append(list, std::forward<ARGS>(args)...);
}
/// @return an empty list of expressions
ast::ExpressionList ExprList() { return {}; }
/// @param args the list of expressions
/// @return the list of expressions converted to `ast::Expression`s using
/// `Expr()`,
template <typename... ARGS>
ast::ExpressionList ExprList(ARGS&&... args) {
ast::ExpressionList list;
list.reserve(sizeof...(args));
Append(list, std::forward<ARGS>(args)...);
return list;
}
/// @param list the list of expressions
/// @return `list`
ast::ExpressionList ExprList(ast::ExpressionList list) { return list; }
/// @param val the boolan value
/// @return a boolean literal with the given value
ast::BoolLiteral* Literal(bool val) {
return create<ast::BoolLiteral>(ty.bool_(), val);
}
/// @param val the float value
/// @return a float literal with the given value
ast::FloatLiteral* Literal(f32 val) {
return create<ast::FloatLiteral>(ty.f32(), val);
}
/// @param val the unsigned int value
/// @return a ast::UintLiteral with the given value
ast::UintLiteral* Literal(u32 val) {
return create<ast::UintLiteral>(ty.u32(), val);
}
/// @param val the integer value
/// @return the ast::SintLiteral with the given value
ast::SintLiteral* Literal(i32 val) {
return create<ast::SintLiteral>(ty.i32(), val);
}
/// @param args the arguments for the type constructor
/// @return an `ast::TypeConstructorExpression` of type `ty`, with the values
/// of `args` converted to `ast::Expression`s using `Expr()`
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* Construct(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param type the type to construct
/// @param args the arguments for the constructor
/// @return an `ast::TypeConstructorExpression` of `type` constructed with the
/// values `args`.
template <typename... ARGS>
ast::TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
type, ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 2-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 3-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 4-element vector of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x2 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x3 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x4 matrix of type
/// `T`, constructed with the values `args`.
template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the array constructor
/// @return an `ast::TypeConstructorExpression` of an array with element type
/// `T`, constructed with the values `args`.
template <typename T, int N = 0, typename... ARGS>
ast::TypeConstructorExpression* array(ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @param args the arguments for the array constructor
/// @return an `ast::TypeConstructorExpression` of an array with element type
/// `subtype`, constructed with the values `args`.
template <typename... ARGS>
ast::TypeConstructorExpression* array(type::Type* subtype,
uint32_t n,
ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
ty.array(subtype, n), ExprList(std::forward<ARGS>(args)...));
}
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a `ast::Variable` with the given name, storage and type. The
/// variable will be built with a nullptr constructor and no decorations.
ast::Variable* Var(const std::string& name,
ast::StorageClass storage,
type::Type* type);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `ast::Variable` with the given name, storage and type
ast::Variable* Var(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
/// @param source the variable source
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `ast::Variable` with the given name, storage and type
ast::Variable* Var(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a constant `ast::Variable` with the given name, storage and type.
/// The variable will be built with a nullptr constructor and no decorations.
ast::Variable* Const(const std::string& name,
ast::StorageClass storage,
type::Type* type);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `ast::Variable` with the given name, storage and type
ast::Variable* Const(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
/// @param source the variable source
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `ast::Variable` with the given name, storage and type
ast::Variable* Const(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
/// @param func the function name
/// @param args the function call arguments
/// @returns a `ast::CallExpression` to the function `func`, with the
/// arguments of `args` converted to `ast::Expression`s using `Expr()`.
template <typename NAME, typename... ARGS>
ast::CallExpression* Call(NAME&& func, ARGS&&... args) {
return create<ast::CallExpression>(Expr(func),
ExprList(std::forward<ARGS>(args)...));
}
/// @param lhs the left hand argument to the addition operation
/// @param rhs the right hand argument to the addition operation
/// @returns a `ast::BinaryExpression` summing the arguments `lhs` and `rhs`
template <typename LHS, typename RHS>
ast::Expression* Add(LHS&& lhs, RHS&& rhs) {
return create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param lhs the left hand argument to the subtraction operation
/// @param rhs the right hand argument to the subtraction operation
/// @returns a `ast::BinaryExpression` subtracting `rhs` from `lhs`
template <typename LHS, typename RHS>
ast::Expression* Sub(LHS&& lhs, RHS&& rhs) {
return create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param lhs the left hand argument to the multiplication operation
/// @param rhs the right hand argument to the multiplication operation
/// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs`
template <typename LHS, typename RHS>
ast::Expression* Mul(LHS&& lhs, RHS&& rhs) {
return create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
/// @param arr the array argument for the array accessor expression
/// @param idx the index argument for the array accessor expression
/// @returns a `ast::ArrayAccessorExpression` that indexes `arr` with `idx`
template <typename ARR, typename IDX>
ast::Expression* IndexAccessor(ARR&& arr, IDX&& idx) {
return create<ast::ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
Expr(std::forward<IDX>(idx)));
}
/// @param obj the object for the member accessor expression
/// @param idx the index argument for the array accessor expression
/// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx`
template <typename OBJ, typename IDX>
ast::Expression* MemberAccessor(OBJ&& obj, IDX&& idx) {
return create<ast::MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)),
Expr(std::forward<IDX>(idx)));
}
/// creates a ast::StructMemberOffsetDecoration
/// @param val the offset value
/// @returns the offset decoration pointer
ast::StructMemberOffsetDecoration* MemberOffset(uint32_t val) {
return create<ast::StructMemberOffsetDecoration>(source_, val);
}
/// creates a ast::Function
/// @param source the source information
/// @param name the function name
/// @param params the function parameters
/// @param type the function return type
/// @param body the function body
/// @param decorations the function decorations
/// @returns the function pointer
ast::Function* Func(Source source,
std::string name,
ast::VariableList params,
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(source, Symbols().Register(name), params, type,
create<ast::BlockStatement>(body),
decorations);
}
/// creates a ast::Function
/// @param name the function name
/// @param params the function parameters
/// @param type the function return type
/// @param body the function body
/// @param decorations the function decorations
/// @returns the function pointer
ast::Function* Func(std::string name,
ast::VariableList params,
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(Symbols().Register(name), params, type,
create<ast::BlockStatement>(body),
decorations);
}
/// creates a ast::StructMember
/// @param source the source information
/// @param name the struct member name
/// @param type the struct member type
/// @returns the struct member pointer
ast::StructMember* Member(const Source& source,
const std::string& name,
type::Type* type) {
return create<ast::StructMember>(source, Symbols().Register(name), type,
ast::StructMemberDecorationList{});
}
/// creates a ast::StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @returns the struct member pointer
ast::StructMember* Member(const std::string& name, type::Type* type) {
return create<ast::StructMember>(source_, Symbols().Register(name), type,
ast::StructMemberDecorationList{});
}
/// creates a ast::StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @param decorations the struct member decorations
/// @returns the struct member pointer
ast::StructMember* Member(const std::string& name,
type::Type* type,
ast::StructMemberDecorationList decorations) {
return create<ast::StructMember>(source_, Symbols().Register(name), type,
decorations);
}
/// Sets the current builder source to `src`
/// @param src the Source used for future create() calls
void SetSource(const Source& src) {
AssertNotMoved();
source_ = src;
}
/// Sets the current builder source to `loc`
/// @param loc the Source used for future create() calls
void SetSource(const Source::Location& loc) {
AssertNotMoved();
source_ = Source(loc);
}
/// The builder types
TypesBuilder ty;
protected:
/// Asserts that the builder has not been moved.
void AssertNotMoved() const;
/// Called whenever a new variable is built with `Var()`.
virtual void OnVariableBuilt(ast::Variable*) {}
private:
type::Manager types_;
ASTNodes nodes_;
ast::Module* ast_;
SymbolTable symbols_;
/// The source to use when creating AST nodes without providing a Source as
/// the first argument.
Source source_;
/// Set by MarkAsMoved(). Once set, no methods may be called on this builder.
bool moved_ = false;
};
//! @cond Doxygen_Suppress
// Various template specializations for ProgramBuilder::TypesBuilder::CToAST.
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::i32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->i32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::u32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->u32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::f32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->f32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<bool> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->bool_();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<void> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->void_();
}
};
//! @endcond
} // namespace tint
#endif // SRC_PROGRAM_BUILDER_H_

View File

@ -31,80 +31,101 @@ namespace {
using ProgramTest = ast::TestHelper;
TEST_F(ProgramTest, Creation) {
EXPECT_EQ(AST().Functions().size(), 0u);
Program program(std::move(*this));
EXPECT_EQ(program.AST().Functions().size(), 0u);
}
TEST_F(ProgramTest, ToStrEmitsPreambleAndPostamble) {
const auto str = mod->to_str();
Program program(std::move(*this));
const auto str = program.to_str();
auto* const expected = "Module{\n}\n";
EXPECT_EQ(str, expected);
}
TEST_F(ProgramTest, IsValid_Empty) {
EXPECT_TRUE(IsValid());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, ty.f32());
AST().AddGlobalVariable(var);
EXPECT_TRUE(IsValid());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Null_GlobalVariable) {
AST().AddGlobalVariable(nullptr);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, nullptr);
AST().AddGlobalVariable(var);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Alias) {
auto* alias = ty.alias("alias", ty.f32());
AST().AddConstructedType(alias);
EXPECT_TRUE(IsValid());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Null_Alias) {
AST().AddConstructedType(nullptr);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Struct) {
auto* st = ty.struct_("name", {});
auto* alias = ty.alias("name", st);
AST().AddConstructedType(alias);
EXPECT_TRUE(IsValid());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Struct_EmptyName) {
auto* st = ty.struct_("", {});
auto* alias = ty.alias("name", st);
AST().AddConstructedType(alias);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Function) {
auto* func = Func("main", ast::VariableList(), ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(IsValid());
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Null_Function) {
AST().Functions().Add(nullptr);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
TEST_F(ProgramTest, IsValid_Invalid_Function) {
auto* func = Func("main", ast::VariableList{}, nullptr, ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_FALSE(IsValid());
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());
}
} // namespace

View File

@ -46,7 +46,8 @@ class Reader {
/// @returns the full list of diagnostic messages.
const diag::List& diagnostics() const { return diags_; }
/// @returns the program. The program in the parser will be reset after this.
/// @returns the program. The program builder in the parser will be reset
/// after this.
virtual Program program() = 0;
protected:

View File

@ -632,15 +632,15 @@ struct SwitchStatementBuilder
/// @param cond the switch statement condition
explicit SwitchStatementBuilder(ast::Expression* cond) : condition(cond) {}
/// @param program the program to build into
/// @param builder the program builder
/// @returns the built ast::SwitchStatement
ast::SwitchStatement* Build(Program* program) const override {
ast::SwitchStatement* Build(ProgramBuilder* builder) const override {
// We've listed cases in reverse order in the switch statement.
// Reorder them to match the presentation order in WGSL.
auto reversed_cases = cases;
std::reverse(reversed_cases.begin(), reversed_cases.end());
return program->create<ast::SwitchStatement>(Source{}, condition,
return builder->create<ast::SwitchStatement>(Source{}, condition,
reversed_cases);
}
@ -658,10 +658,10 @@ struct IfStatementBuilder
/// @param c the if-statement condition
explicit IfStatementBuilder(ast::Expression* c) : cond(c) {}
/// @param program the program to build into
/// @param builder the program builder
/// @returns the built ast::IfStatement
ast::IfStatement* Build(Program* program) const override {
return program->create<ast::IfStatement>(Source{}, cond, body, else_stmts);
ast::IfStatement* Build(ProgramBuilder* builder) const override {
return builder->create<ast::IfStatement>(Source{}, cond, body, else_stmts);
}
/// If-statement condition
@ -676,10 +676,10 @@ struct IfStatementBuilder
/// @see StatementBuilder
struct LoopStatementBuilder
: public Castable<LoopStatementBuilder, StatementBuilder> {
/// @param program the program to build into
/// @param builder the program builder
/// @returns the built ast::LoopStatement
ast::LoopStatement* Build(Program* program) const override {
return program->create<ast::LoopStatement>(Source{}, body, continuing);
ast::LoopStatement* Build(ProgramBuilder* builder) const override {
return builder->create<ast::LoopStatement>(Source{}, body, continuing);
}
/// Loop-statement block body
@ -717,7 +717,7 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi,
const spvtools::opt::Function& function,
const EntryPointInfo* ep_info)
: parser_impl_(*pi),
program_(pi->get_program()),
builder_(pi->builder()),
ir_context_(*(pi->ir_context())),
def_use_mgr_(ir_context_.get_def_use_mgr()),
constant_mgr_(ir_context_.get_constant_mgr()),
@ -725,7 +725,7 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi,
fail_stream_(pi->fail_stream()),
namer_(pi->namer()),
function_(function),
i32_(program_.create<type::I32>()),
i32_(builder_.create<type::I32>()),
ep_info_(ep_info) {
PushNewStatementBlock(nullptr, 0, nullptr);
}
@ -749,12 +749,12 @@ FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) =
FunctionEmitter::StatementBlock::~StatementBlock() = default;
void FunctionEmitter::StatementBlock::Finalize(Program* program) {
void FunctionEmitter::StatementBlock::Finalize(ProgramBuilder* pb) {
assert(!finalized_ /* Finalize() must only be called once */);
for (size_t i = 0; i < statements_.size(); i++) {
if (auto* builder = statements_[i]->As<StatementBuilder>()) {
statements_[i] = builder->Build(program);
if (auto* sb = statements_[i]->As<StatementBuilder>()) {
statements_[i] = sb->Build(pb);
}
}
@ -786,7 +786,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(guard_name));
Source{}, builder_.Symbols().Register(guard_name));
auto* builder = AddStatementBuilder<IfStatementBuilder>(cond);
PushNewStatementBlock(
@ -811,7 +811,7 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
const ast::StatementList FunctionEmitter::ast_body() {
assert(!statements_stack_.empty());
auto& entry = statements_stack_[0];
entry.Finalize(&program_);
entry.Finalize(&builder_);
return entry.GetStatements();
}
@ -855,12 +855,12 @@ bool FunctionEmitter::Emit() {
<< statements_stack_.size();
}
statements_stack_[0].Finalize(&program_);
statements_stack_[0].Finalize(&builder_);
auto& statements = statements_stack_[0].GetStatements();
auto* body = create<ast::BlockStatement>(Source{}, statements);
program_.AST().Functions().Add(
create<ast::Function>(decl.source, program_.Symbols().Register(decl.name),
builder_.AST().Functions().Add(
create<ast::Function>(decl.source, builder_.Symbols().Register(decl.name),
std::move(decl.params), decl.return_type, body,
std::move(decl.decorations)));
@ -2013,7 +2013,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>(Source{},
program_.Symbols().Register(name))};
builder_.Symbols().Register(name))};
}
if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]);
@ -2035,7 +2035,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
auto name = namer_.Name(inst->result_id());
return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name))};
Source{}, builder_.Symbols().Register(name))};
}
default:
break;
@ -2079,7 +2079,7 @@ bool FunctionEmitter::EmitBasicBlock(const BlockInfo& block_info) {
// Close off previous constructs.
while (!statements_stack_.empty() &&
(statements_stack_.back().GetEndId() == block_info.id)) {
statements_stack_.back().Finalize(&program_);
statements_stack_.back().Finalize(&builder_);
statements_stack_.pop_back();
}
if (statements_stack_.empty()) {
@ -2266,7 +2266,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// Declare the guard variable just before the "if", initialized to true.
auto* guard_var = create<ast::Variable>(
Source{}, // source
program_.Symbols().Register(guard_name), // symbol
builder_.Symbols().Register(guard_name), // symbol
ast::StorageClass::kFunction, // storage_class
parser_impl_.Bool(), // type
false, // is_const
@ -2673,7 +2673,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
return create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(flow_guard)),
Source{}, builder_.Symbols().Register(flow_guard)),
MakeFalse(Source{}));
}
@ -2794,7 +2794,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
assert(!phi_var_name.empty());
auto* var = create<ast::Variable>(
Source{}, // source
program_.Symbols().Register(phi_var_name), // symbol
builder_.Symbols().Register(phi_var_name), // symbol
ast::StorageClass::kFunction, // storage_class
parser_impl_.ConvertType(def_inst->type_id()), // type
false, // is_const
@ -2833,7 +2833,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(var_name)),
Source{}, builder_.Symbols().Register(var_name)),
expr.expr));
}
}
@ -2871,7 +2871,7 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
AddStatement(create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(Source{},
program_.Symbols().Register(name)),
builder_.Symbols().Register(name)),
ast_expr.expr));
return true;
}
@ -3010,7 +3010,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(def_info->phi_var))};
Source{}, builder_.Symbols().Register(def_info->phi_var))};
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
@ -3073,7 +3073,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(unary_builtin_name)),
Source{}, builder_.Symbols().Register(unary_builtin_name)),
std::move(params))};
}
@ -3179,7 +3179,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
}
auto* func = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
ast::ExpressionList operands;
type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs.
@ -3205,20 +3205,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
}
const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(names[i & 3]));
Source{}, builder_.Symbols().Register(names[i & 3]));
}
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) {
case 1:
return create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register("x"));
Source{}, builder_.Symbols().Register("x"));
case 2:
return create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register("xy"));
Source{}, builder_.Symbols().Register("xy"));
case 3:
return create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register("xyz"));
Source{}, builder_.Symbols().Register("xyz"));
default:
break;
}
@ -3313,7 +3313,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
}
}
@ -3406,7 +3406,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
@ -3527,7 +3527,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
}
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
@ -3700,8 +3700,7 @@ type::Type* FunctionEmitter::RemapStorageClass(type::Type* type,
// buffer pointer.
const auto sc = GetStorageClassForPointerValue(result_id);
if (ast_ptr_type->storage_class() != sc) {
return parser_impl_.get_program().create<type::Pointer>(
ast_ptr_type->type(), sc);
return builder_.create<type::Pointer>(ast_ptr_type->type(), sc);
}
}
return type;
@ -3932,7 +3931,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const.
auto name = namer_.Name(inst.GetSingleWordInOperand(0));
auto* function = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
@ -3961,7 +3960,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
ss << intrinsic;
auto name = ss.str();
auto* ident = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(name));
Source{}, builder_.Symbols().Register(name));
ident->set_intrinsic(intrinsic);
ast::ExpressionList params;
@ -4008,7 +4007,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register("select")),
Source{}, builder_.Symbols().Register("select")),
std::move(params))};
}
return {};
@ -4058,7 +4057,7 @@ ast::Expression* FunctionEmitter::GetImageExpression(
}
auto name = namer_.Name(image->result_id());
return create<ast::IdentifierExpression>(GetSourceForInst(inst),
program_.Symbols().Register(name));
builder_.Symbols().Register(name));
}
ast::Expression* FunctionEmitter::GetSamplerExpression(
@ -4074,7 +4073,7 @@ ast::Expression* FunctionEmitter::GetSamplerExpression(
}
auto name = namer_.Name(image->result_id());
return create<ast::IdentifierExpression>(GetSourceForInst(inst),
program_.Symbols().Register(name));
builder_.Symbols().Register(name));
}
bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
@ -4261,7 +4260,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto* ident = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(builtin_name));
Source{}, builder_.Symbols().Register(builtin_name));
auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params));
@ -4569,14 +4568,14 @@ TypedExpression FunctionEmitter::MakeArrayLength(
}
auto* member_ident = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(field_name));
Source{}, builder_.Symbols().Register(field_name));
auto* member_access = create<ast::MemberAccessorExpression>(
Source{}, MakeExpression(struct_ptr_id).expr, member_ident);
// Generate the intrinsic function call.
std::string call_ident_str = "arrayLength";
auto* call_ident = create<ast::IdentifierExpression>(
Source{}, program_.Symbols().Register(call_ident_str));
Source{}, builder_.Symbols().Register(call_ident_str));
call_ident->set_intrinsic(ast::Intrinsic::kArrayLength);
ast::ExpressionList params{member_access};

View File

@ -33,9 +33,10 @@
#include "src/ast/case_statement.h"
#include "src/ast/expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/module.h"
#include "src/ast/statement.h"
#include "src/ast/storage_class.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/reader/spirv/construct.h"
#include "src/reader/spirv/entry_point_info.h"
#include "src/reader/spirv/fail_stream.h"
@ -345,9 +346,9 @@ class StatementBuilder : public Castable<StatementBuilder, ast::Statement> {
/// Constructor
StatementBuilder() : Base(Source{}) {}
/// @param program the program to build into
/// @returns the built AST node
virtual ast::Statement* Build(Program* program) const = 0;
/// @param builder the program builder
/// @returns the build AST node
virtual ast::Statement* Build(ProgramBuilder* builder) const = 0;
private:
bool IsValid() const override;
@ -355,15 +356,15 @@ class StatementBuilder : public Castable<StatementBuilder, ast::Statement> {
void to_str(std::ostream& out, size_t indent) const override;
};
/// A FunctionEmitter emits a SPIR-V function onto a Tint program.
/// A FunctionEmitter emits a SPIR-V function onto a Tint AST module.
class FunctionEmitter {
public:
/// Creates a FunctionEmitter, and prepares to write to the program
/// Creates a FunctionEmitter, and prepares to write to the AST module
/// in `pi`
/// @param pi a ParserImpl which has already executed BuildInternalModule
/// @param function the function to emit
FunctionEmitter(ParserImpl* pi, const spvtools::opt::Function& function);
/// Creates a FunctionEmitter, and prepares to write to the program
/// Creates a FunctionEmitter, and prepares to write to the AST module
/// in `pi`
/// @param pi a ParserImpl which has already executed BuildInternalModule
/// @param function the function to emit
@ -374,7 +375,7 @@ class FunctionEmitter {
/// Destructor
~FunctionEmitter();
/// Emits the function to program.
/// Emits the function to AST module.
/// @return whether emission succeeded
bool Emit();
@ -964,8 +965,8 @@ class FunctionEmitter {
/// Replaces any StatementBuilders with the built result, and calls the
/// completion callback (if set). Must only be called once, after all
/// statements have been added with Add().
/// @param program the program
void Finalize(Program* program);
/// @param builder the program builder
void Finalize(ProgramBuilder* builder);
/// Add() adds `statement` to the block.
/// Add() must not be called after calling Finalize().
@ -1043,19 +1044,18 @@ class FunctionEmitter {
/// @returns a boolean false expression.
ast::Expression* MakeFalse(const Source&) const;
/// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// Creates a new `ast::Node` owned by the ProgramBuilder.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) const {
return program_.create<T>(std::forward<ARGS>(args)...);
return builder_.create<T>(std::forward<ARGS>(args)...);
}
using StatementsStack = std::vector<StatementBlock>;
ParserImpl& parser_impl_;
Program& program_;
ProgramBuilder& builder_;
spvtools::opt::IRContext& ir_context_;
spvtools::opt::analysis::DefUseManager* def_use_mgr_;
spvtools::opt::analysis::ConstantManager* constant_mgr_;

View File

@ -139,7 +139,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -151,7 +151,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
@ -166,7 +166,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -180,7 +180,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
@ -195,7 +195,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -209,7 +209,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
@ -224,7 +224,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -240,7 +240,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
@ -255,7 +255,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -271,7 +271,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
@ -286,7 +286,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -304,7 +304,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
@ -319,7 +319,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -337,7 +337,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
@ -352,7 +352,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -372,7 +372,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
@ -387,7 +387,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -399,7 +399,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryArithTest, FNegate_Vector) {
@ -414,7 +414,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -430,7 +430,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
struct BinaryData {
@ -478,7 +478,8 @@ TEST_P(SpvBinaryArithTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str()))
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(ss.str()))
<< assembly;
}
@ -701,7 +702,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) {
<< assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -736,7 +737,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) {
<< assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -759,7 +760,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
INSTANTIATE_TEST_SUITE_P(
@ -847,7 +848,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) {
<< assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -882,7 +883,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) {
<< assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -905,7 +906,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
INSTANTIATE_TEST_SUITE_P(
@ -935,7 +936,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -948,7 +949,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
@ -965,7 +966,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -978,7 +979,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
@ -995,7 +996,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -1008,7 +1009,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
@ -1025,7 +1026,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -1038,7 +1039,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
@ -1055,7 +1056,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -1068,7 +1069,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, Dot) {
@ -1085,7 +1086,7 @@ TEST_F(SpvBinaryArithTestBasic, Dot) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_3
none
@ -1100,7 +1101,7 @@ TEST_F(SpvBinaryArithTestBasic, Dot) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvBinaryArithTestBasic, OuterProduct) {
@ -1119,7 +1120,7 @@ TEST_F(SpvBinaryArithTestBasic, OuterProduct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(got, HasSubstr(R"(VariableConst{
x_3
none

View File

@ -163,7 +163,8 @@ TEST_P(SpvBinaryBitTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str()))
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(ss.str()))
<< assembly;
}
@ -401,7 +402,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -413,7 +414,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
@ -428,7 +429,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -442,7 +443,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
@ -457,7 +458,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -471,7 +472,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
@ -486,7 +487,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -498,7 +499,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
@ -513,7 +514,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -529,7 +530,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
@ -544,7 +545,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -562,7 +563,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
@ -577,7 +578,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -595,7 +596,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
const auto assembly = CommonTypes() + R"(
@ -609,7 +610,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -625,7 +626,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
std::string BitTestPreamble() {
@ -664,7 +665,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -692,7 +693,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -722,7 +723,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -752,7 +753,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -780,7 +781,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -808,7 +809,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -838,7 +839,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -868,7 +869,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -896,7 +897,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -924,7 +925,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -954,7 +955,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -984,7 +985,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1012,7 +1013,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1040,7 +1041,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1070,7 +1071,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1100,7 +1101,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(p->get_program(), fe.ast_body());
const auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1

View File

@ -46,8 +46,8 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
const auto program_ast_str = p->get_program().to_str();
EXPECT_THAT(program_ast_str, Eq(R"(Module{
const auto got = p->program().AST().to_str();
const char* expect = R"(Module{
Function tint_symbol_1 -> __void
()
{
@ -64,7 +64,8 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
Return{}
}
}
)")) << program_ast_str;
)";
EXPECT_EQ(expect, got);
}
TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
@ -90,7 +91,7 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
{
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -106,17 +107,18 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
}
}
Return{})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
{
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(Return{
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Return{
{
ScalarConstructor[not set]{42}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
}
@ -147,7 +149,7 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) {
{
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_10
@ -178,16 +180,17 @@ Assignment{
Identifier[not set]{x_1}
}
Return{})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
{
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(Return{
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Return{
{
ScalarConstructor[not set]{42}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
}
@ -216,7 +219,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto program_ast_str = Demangler().Demangle(p->get_program());
const auto program_ast_str = Demangler().Demangle(p->program());
EXPECT_THAT(program_ast_str, HasSubstr(R"(Module{
Function x_50 -> __u32
(

View File

@ -7361,7 +7361,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromThen_ForwardWithinThen) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -7473,7 +7473,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromElse_ForwardWithinElse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -7600,7 +7600,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly;
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -7791,7 +7791,7 @@ TEST_F(SpvParserTest, EmitBody_If_Empty) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -7827,7 +7827,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_NoElse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -7875,7 +7875,7 @@ TEST_F(SpvParserTest, EmitBody_If_NoThen_Else) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -7931,7 +7931,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -7998,7 +7998,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8070,7 +8070,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8134,7 +8134,7 @@ TEST_F(SpvParserTest, EmitBody_If_Else_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8219,7 +8219,7 @@ TEST_F(SpvParserTest, EmitBody_If_Nest_If) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8309,7 +8309,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_TrueBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8364,7 +8364,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_FalseBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8415,7 +8415,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_BothBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8458,7 +8458,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_UnconditionalBackege) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8509,7 +8509,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_SingleBlockContinue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8574,7 +8574,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_MultiBlockContinue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8648,7 +8648,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_ContinueNestIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8720,7 +8720,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_MultiBlockContinueIsEntireLoop) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -8778,7 +8778,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Never) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -8838,7 +8838,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_TrueToBody_FalseBreaks) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -8905,7 +8905,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_FalseToBody_TrueBreaks) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -8979,7 +8979,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_NestedIfContinue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
If{
(
@ -9037,7 +9037,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyAlwaysBreaks) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -9086,7 +9086,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -9142,7 +9142,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -9204,7 +9204,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue_Early) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -9266,7 +9266,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse_Early) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -9319,7 +9319,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_NoCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9364,7 +9364,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_OneCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9418,7 +9418,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_TwoCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9478,7 +9478,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_CasesWithDup) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9544,7 +9544,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_NoDupCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9615,7 +9615,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_WithDupCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9687,7 +9687,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_SintValue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9757,7 +9757,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_UintValue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -9809,7 +9809,7 @@ TEST_F(SpvParserTest, EmitBody_Return_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Return{}
)";
ASSERT_EQ(expect, got);
@ -9835,7 +9835,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -9875,7 +9875,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Return{}
}
@ -9905,7 +9905,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Return{
{
ScalarConstructor[not set]{2}
@ -9944,7 +9944,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -10001,7 +10001,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_Loop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Return{
{
@ -10031,7 +10031,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Discard{}
)";
ASSERT_EQ(expect, got);
@ -10057,7 +10057,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -10097,7 +10097,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Discard{}
}
@ -10119,7 +10119,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Return{}
)";
ASSERT_EQ(expect, got);
@ -10145,7 +10145,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -10185,7 +10185,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Return{}
}
@ -10215,7 +10215,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InNonVoidFunction) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Return{
{
ScalarConstructor[not set]{0}
@ -10249,7 +10249,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_MultiBlockLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
continuing {
Assignment{
@ -10284,7 +10284,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_SingleBlockLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -10321,7 +10321,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_LastInCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -10381,7 +10381,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_NotLastInCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -10452,7 +10452,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopBreak_MultiBlockLoop_FromBody) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -10534,7 +10534,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
continuing {
Assignment{
@ -10576,7 +10576,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_LastInLoopConstruct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
Assignment{
Identifier[not set]{var_1}
@ -10630,7 +10630,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_BeforeLast) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
If{
(
@ -10699,7 +10699,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_FromSwitch) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -10769,7 +10769,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromThen) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -10812,7 +10812,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromElse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{false}
@ -10864,7 +10864,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Fallthrough) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -10915,7 +10915,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Forward) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11019,7 +11019,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Back_SingleBlock_Back) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11062,7 +11062,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11113,7 +11113,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11171,7 +11171,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11227,7 +11227,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11287,7 +11287,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11348,7 +11348,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11431,7 +11431,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnTrue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11526,7 +11526,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnFalse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11611,7 +11611,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11680,7 +11680,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11747,7 +11747,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11821,7 +11821,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -11890,7 +11890,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -11948,7 +11948,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12021,7 +12021,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12117,7 +12117,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12256,7 +12256,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12337,7 +12337,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12405,7 +12405,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Continue_FromHeader) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12462,7 +12462,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12534,7 +12534,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12622,7 +12622,7 @@ TEST_F(
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12701,7 +12701,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopContinue_FromSwitch) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -12789,7 +12789,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12886,7 +12886,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -12982,7 +12982,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -13091,7 +13091,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -13188,7 +13188,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -13269,7 +13269,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -13333,7 +13333,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_IfBreak_IfBreak_Same) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{0}
@ -13418,7 +13418,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Fallthrough_Fallthrough_Same) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -13509,7 +13509,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Forward_Forward_Same) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{var_1}
ScalarConstructor[not set]{1}
@ -13578,7 +13578,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = "unhandled case";
ASSERT_EQ(expect, got);
}
@ -13613,7 +13613,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = "unhandled case";
ASSERT_EQ(expect, got);
}

View File

@ -86,7 +86,7 @@ TEST_F(SpvParserTest_Composite_Construct, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -128,7 +128,7 @@ VariableDeclStatement{
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_Composite_Construct, Matrix) {
@ -143,7 +143,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -169,7 +169,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_Composite_Construct, Array) {
@ -184,7 +184,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -200,7 +200,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_Composite_Construct, Struct) {
@ -215,7 +215,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -233,7 +233,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
using SpvParserTest_CompositeExtract = SpvParserTest;
@ -250,7 +250,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -266,7 +266,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CompositeExtract, Vector_IndexTooBigError) {
@ -301,7 +301,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -313,7 +313,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CompositeExtract, Matrix_IndexTooBigError) {
@ -352,7 +352,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -367,7 +367,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CompositeExtract, Array) {
@ -386,7 +386,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -398,7 +398,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CompositeExtract, RuntimeArray_IsError) {
@ -437,7 +437,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -449,7 +449,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
@ -480,7 +480,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = fe.ast_body();
EXPECT_THAT(ToString(p->get_program(), got), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), got), HasSubstr(R"(
VariableConst{
x_2
none
@ -492,8 +492,8 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
}
}
})"))
<< ToString(p->get_program(), got);
EXPECT_THAT(ToString(p->get_program(), got), HasSubstr(R"(
<< ToString(p->builder().Symbols(), got);
EXPECT_THAT(ToString(p->builder().Symbols(), got), HasSubstr(R"(
VariableConst{
x_4
none
@ -505,7 +505,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
}
}
})"))
<< ToString(p->get_program(), got);
<< ToString(p->builder().Symbols(), got);
}
TEST_F(SpvParserTest_CompositeExtract, Struct_IndexTooBigError) {
@ -546,7 +546,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -567,7 +567,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
using SpvParserTest_CopyObject = SpvParserTest;
@ -585,7 +585,7 @@ TEST_F(SpvParserTest_CopyObject, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -605,7 +605,7 @@ VariableDeclStatement{
Identifier[not set]{x_1}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_CopyObject, Pointer) {
@ -624,7 +624,7 @@ TEST_F(SpvParserTest_CopyObject, Pointer) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -644,7 +644,7 @@ VariableDeclStatement{
Identifier[not set]{x_1}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
using SpvParserTest_VectorShuffle = SpvParserTest;
@ -665,7 +665,7 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -692,7 +692,7 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
@ -708,7 +708,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -751,7 +751,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
@ -768,7 +768,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10
none
@ -784,7 +784,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest_VectorShuffle, IndexTooBig_IsError) {

View File

@ -82,7 +82,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -93,7 +93,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
@ -108,7 +108,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -123,7 +123,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) {
@ -238,7 +238,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -250,7 +250,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
@ -266,7 +266,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -280,7 +280,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
@ -296,7 +296,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -308,7 +308,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
@ -324,7 +324,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -338,7 +338,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) {
@ -387,7 +387,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -401,7 +401,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
@ -417,7 +417,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -429,7 +429,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
@ -445,7 +445,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -459,7 +459,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
@ -475,7 +475,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -487,7 +487,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) {
@ -537,7 +537,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -549,7 +549,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
@ -565,7 +565,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -579,7 +579,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
@ -595,7 +595,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -607,7 +607,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
@ -623,7 +623,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -637,7 +637,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) {
@ -687,7 +687,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -701,7 +701,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
@ -717,7 +717,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -729,7 +729,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
@ -745,7 +745,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -759,7 +759,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
@ -775,7 +775,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1
none
@ -787,7 +787,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
// TODO(dneto): OpSConvert // only if multiple widths

View File

@ -59,7 +59,7 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->get_program());
auto got = Demangler().Demangle(p->program());
std::string expect = R"(Module{
Function x_100 -> __void
()
@ -83,7 +83,7 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->get_program());
auto got = Demangler().Demangle(p->program());
std::string expect = R"(Module{
Function x_100 -> __f32
()
@ -115,7 +115,7 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->get_program());
auto got = Demangler().Demangle(p->program());
std::string expect = R"(Module{
Function x_100 -> __void
(
@ -159,7 +159,7 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->get_program());
auto got = Demangler().Demangle(p->program());
std::string expect = R"(Module{
Function x_100 -> __void
(

View File

@ -183,7 +183,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -198,7 +198,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
@ -212,7 +212,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -227,7 +227,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
@ -241,7 +241,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -257,7 +257,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
@ -271,7 +271,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -287,7 +287,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
@ -301,7 +301,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -316,7 +316,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
@ -330,7 +330,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -345,7 +345,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
@ -359,7 +359,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -375,7 +375,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
@ -389,7 +389,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -405,7 +405,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
@ -419,7 +419,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -436,7 +436,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
@ -451,7 +451,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -468,7 +468,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
@ -482,7 +482,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -498,7 +498,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
@ -513,7 +513,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -529,7 +529,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
@ -543,7 +543,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -559,7 +559,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
@ -574,7 +574,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -590,7 +590,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
@ -605,7 +605,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -621,7 +621,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
INSTANTIATE_TEST_SUITE_P(Samples,
@ -709,7 +709,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -724,7 +724,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
@ -739,7 +739,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -754,7 +754,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
@ -769,7 +769,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -785,7 +785,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
@ -800,7 +800,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -816,7 +816,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
@ -831,7 +831,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -848,7 +848,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
@ -863,7 +863,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -880,7 +880,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
INSTANTIATE_TEST_SUITE_P(Samples,
@ -907,7 +907,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -923,7 +923,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
@ -938,7 +938,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -954,7 +954,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
@ -968,7 +968,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -985,7 +985,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
@ -1000,7 +1000,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -1017,7 +1017,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
INSTANTIATE_TEST_SUITE_P(Samples,
@ -1043,7 +1043,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SAbs) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1095,7 +1095,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMax) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1153,7 +1153,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMin) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1211,7 +1211,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SClamp) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1271,7 +1271,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMax) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1329,7 +1329,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMin) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1
@ -1387,7 +1387,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UClamp) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(p->get_program(), fe.ast_body());
auto body = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"(
VariableConst{
x_1

View File

@ -206,7 +206,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -218,7 +218,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
@ -233,7 +233,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -249,7 +249,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
struct BinaryData {
@ -296,7 +296,8 @@ TEST_P(SpvBinaryLogicalTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str()))
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(ss.str()))
<< assembly;
}
@ -702,7 +703,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -718,7 +719,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
@ -733,7 +734,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -757,7 +758,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
@ -772,7 +773,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -788,7 +789,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
@ -803,7 +804,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -827,7 +828,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
@ -842,7 +843,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -858,7 +859,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
@ -873,7 +874,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -897,7 +898,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
@ -912,7 +913,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -928,7 +929,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
@ -943,7 +944,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -967,7 +968,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
@ -982,7 +983,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -998,7 +999,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
@ -1013,7 +1014,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -1037,7 +1038,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
@ -1052,7 +1053,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -1068,7 +1069,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
@ -1083,7 +1084,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -1107,7 +1108,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
@ -1122,7 +1123,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1139,7 +1140,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
@ -1154,7 +1155,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1171,7 +1172,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
@ -1186,7 +1187,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1203,7 +1204,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
@ -1218,7 +1219,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1243,7 +1244,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
@ -1258,7 +1259,7 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1287,7 +1288,7 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
using SpvLogicalTest = SpvParserTestBase<::testing::Test>;
@ -1304,7 +1305,7 @@ TEST_F(SpvLogicalTest, Any) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1323,7 +1324,7 @@ TEST_F(SpvLogicalTest, Any) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvLogicalTest, All) {
@ -1338,7 +1339,7 @@ TEST_F(SpvLogicalTest, All) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1357,7 +1358,7 @@ TEST_F(SpvLogicalTest, All) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvLogicalTest, IsNan_Scalar) {
@ -1372,7 +1373,7 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1387,7 +1388,7 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvLogicalTest, IsNan_Vector) {
@ -1402,7 +1403,7 @@ TEST_F(SpvLogicalTest, IsNan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1421,7 +1422,7 @@ TEST_F(SpvLogicalTest, IsNan_Vector) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvLogicalTest, IsInf_Scalar) {
@ -1436,7 +1437,7 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1451,7 +1452,7 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvLogicalTest, IsInf_Vector) {
@ -1466,7 +1467,7 @@ TEST_F(SpvLogicalTest, IsInf_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1
@ -1485,7 +1486,7 @@ TEST_F(SpvLogicalTest, IsInf_Vector) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
// TODO(dneto): Kernel-guarded instructions.

View File

@ -51,7 +51,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreBoolConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{true}
@ -84,7 +84,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreUintConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{42}
@ -113,7 +113,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreIntConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{42}
@ -142,7 +142,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreFloatConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{42.000000}
@ -172,7 +172,7 @@ TEST_F(SpvParserTest, EmitStatement_LoadBool) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_2
none
@ -201,7 +201,7 @@ TEST_F(SpvParserTest, EmitStatement_LoadScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_2
@ -243,7 +243,7 @@ TEST_F(SpvParserTest, EmitStatement_UseLoadedScalarTwice) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_2
@ -281,7 +281,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreToModuleScopeVar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{42}
@ -349,14 +349,14 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorSwizzle) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
MemberAccessor[not set]{
Identifier[not set]{myvar}
Identifier[not set]{z}
}
ScalarConstructor[not set]{42}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorConstOutOfBounds) {
@ -413,7 +413,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorNonConstIndex) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
ArrayAccessor[not set]{
Identifier[not set]{myvar}
@ -451,7 +451,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Matrix) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
ArrayAccessor[not set]{
Identifier[not set]{myvar}
@ -495,7 +495,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Array) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
ArrayAccessor[not set]{
Identifier[not set]{myvar}
@ -538,7 +538,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
MemberAccessor[not set]{
Identifier[not set]{myvar}
@ -587,7 +587,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_DifferOnlyMemberName) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
MemberAccessor[not set]{
Identifier[not set]{myvar}
@ -601,7 +601,7 @@ Assignment{
Identifier[not set]{ancientness}
}
ScalarConstructor[not set]{420.000000}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitStatement_AccessChain_StructNonConstIndex) {
@ -698,7 +698,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_RuntimeArray) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
ArrayAccessor[not set]{
MemberAccessor[not set]{
@ -739,7 +739,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Compound_Matrix_Vector) {
<< assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
MemberAccessor[not set]{
ArrayAccessor[not set]{
@ -813,7 +813,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
<< assembly << p->error();
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
RTArr -> __array__u32_stride_4
S Struct{
@ -848,7 +848,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
MemberAccessor[not set]{
Identifier[not set]{myvar}
@ -865,7 +865,7 @@ Assignment{
ScalarConstructor[not set]{1}
}
ScalarConstructor[not set]{0}
})")) << ToString(p->get_program(), fe.ast_body())
})")) << ToString(p->builder().Symbols(), fe.ast_body())
<< p->error();
}
@ -888,7 +888,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(Assignment{
ArrayAccessor[not set]{
MemberAccessor[not set]{
@ -898,7 +898,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
ScalarConstructor[not set]{1}
}
ScalarConstructor[not set]{0}
})")) << ToString(p->get_program(), fe.ast_body())
})")) << ToString(p->builder().Symbols(), fe.ast_body())
<< p->error();
}
@ -922,7 +922,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_2
@ -942,7 +942,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) {
Assignment{
Identifier[not set]{x_2}
ScalarConstructor[not set]{0}
})")) << ToString(p->get_program(), fe.ast_body())
})")) << ToString(p->builder().Symbols(), fe.ast_body())
<< p->error();
}
@ -978,7 +978,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithHoisting) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{
x_2
@ -1013,7 +1013,7 @@ Assignment{
ScalarConstructor[not set]{0}
}
Return{}
)")) << ToString(p->get_program(), fe.ast_body())
)")) << ToString(p->builder().Symbols(), fe.ast_body())
<< p->error();
}
@ -1066,7 +1066,7 @@ TEST_F(SpvParserTest, ArrayLength) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body_str = ToString(p->get_program(), fe.ast_body());
const auto body_str = ToString(p->builder().Symbols(), fe.ast_body());
EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_1

View File

@ -68,7 +68,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_11
@ -108,7 +108,7 @@ VariableDeclStatement{
ScalarConstructor[not set]{0.000000}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
@ -129,7 +129,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_11
@ -171,7 +171,7 @@ VariableDeclStatement{
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
@ -190,7 +190,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_11
@ -212,7 +212,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
@ -232,7 +232,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_11
@ -246,7 +246,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
@ -265,7 +265,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{
x_11
@ -281,7 +281,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
}
}
}
})")) << ToString(p->get_program(), fe.ast_body());
})")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTestMiscInstruction, OpNop) {
@ -297,8 +297,8 @@ TEST_F(SpvParserTestMiscInstruction, OpNop) {
<< p->error() << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), Eq(R"(Return{}
)")) << ToString(p->get_program(), fe.ast_body());
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), Eq(R"(Return{}
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
// Test swizzle generation.
@ -329,7 +329,7 @@ TEST_P(SpvParserSwizzleTest, Sample) {
ASSERT_NE(result, nullptr);
std::ostringstream ss;
result->to_str(ss, 0);
auto str = Demangler().Demangle(p->get_program().Symbols(), ss.str());
auto str = Demangler().Demangle(p->program().Symbols(), ss.str());
EXPECT_THAT(str, Eq(GetParam().expected_expr));
} else {
EXPECT_EQ(result, nullptr);

View File

@ -91,7 +91,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_AnonymousVars) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_1
@ -130,7 +130,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_NamedVars) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
a
@ -169,7 +169,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MixedTypes) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
a
@ -211,7 +211,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarInitializers) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
a
@ -285,7 +285,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarNullInitializers) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
a
@ -345,7 +345,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -360,7 +360,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) {
@ -384,7 +384,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -431,7 +431,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -446,7 +446,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
@ -466,8 +466,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
auto got = ToString(p->builder().Symbols(), fe.ast_body());
const char* expect = R"(VariableDeclStatement{
Variable{
x_200
function
@ -481,7 +481,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)";
EXPECT_EQ(expect, got);
}
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
@ -500,7 +501,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -515,7 +516,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
@ -535,7 +536,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -550,7 +551,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
@ -570,7 +571,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -590,7 +591,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
@ -610,7 +611,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()),
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{
x_200
@ -630,7 +631,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
}
}
}
)")) << ToString(p->get_program(), fe.ast_body());
)")) << ToString(p->builder().Symbols(), fe.ast_body());
}
TEST_F(SpvParserTest,
@ -655,7 +656,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect =
R"(VariableDeclStatement{
Variable{
@ -703,7 +704,7 @@ TEST_F(SpvParserTest, EmitStatement_CombinatorialValue_Immediate_UsedTwice) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
Variable{
x_25
@ -775,7 +776,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
Variable{
x_25
@ -874,7 +875,7 @@ TEST_F(
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Assignment{
Identifier[not set]{x_1}
ScalarConstructor[not set]{0}
@ -992,7 +993,7 @@ TEST_F(
// We don't hoist x_1 into its own mutable variable. It is emitted as
// a const definition.
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
VariableConst{
x_1
@ -1077,7 +1078,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{true}
@ -1164,7 +1165,7 @@ TEST_F(
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(If{
(
ScalarConstructor[not set]{true}
@ -1247,7 +1248,7 @@ TEST_F(SpvParserTest,
// We don't hoist x_1 into its own mutable variable. It is emitted as
// a const definition.
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
VariableConst{
x_1
@ -1321,7 +1322,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
VariableDeclStatement{
Variable{
@ -1465,7 +1466,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(Loop{
VariableDeclStatement{
Variable{
@ -1623,7 +1624,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_ValueFromLoopBodyAndContinuing) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
VariableConst{
x_101
@ -1792,7 +1793,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromElseAndThen) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
VariableConst{
x_101
@ -1914,7 +1915,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromHeaderAndThen) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
VariableConst{
x_101
@ -2022,7 +2023,7 @@ TEST_F(SpvParserTest, EmitStatement_UseInPhiCountsAsUse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(p->get_program(), fe.ast_body());
auto got = ToString(p->builder().Symbols(), fe.ast_body());
auto* expect = R"(VariableDeclStatement{
Variable{
x_101_phi

View File

@ -40,7 +40,8 @@ class Parser : public Reader {
/// @returns true if the parse was successful, false otherwise.
bool Parse() override;
/// @returns the program. The program in the parser will be reset after this.
/// @returns the program. The program builder in the parser will be reset
/// after this.
Program program() override;
private:

View File

@ -255,7 +255,7 @@ ParserImpl::ParserImpl(const std::vector<uint32_t>& spv_binary)
: Reader(),
spv_binary_(spv_binary),
fail_stream_(&success_, &errors_),
bool_type_(program_.create<type::Bool>()),
bool_type_(builder_.create<type::Bool>()),
namer_(fail_stream_),
enum_converter_(fail_stream_),
tools_context_(kInputEnv) {
@ -310,7 +310,7 @@ bool ParserImpl::Parse() {
Program ParserImpl::program() {
// TODO(dneto): Should we clear out spv_binary_ here, to reduce
// memory usage?
return std::move(program_);
return tint::Program(std::move(builder_));
}
type::Type* ParserImpl::ConvertType(uint32_t type_id) {
@ -344,7 +344,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) {
switch (spirv_type->kind()) {
case spvtools::opt::analysis::Type::kVoid:
return save(program_.create<type::Void>());
return save(builder_.create<type::Void>());
case spvtools::opt::analysis::Type::kBool:
return save(bool_type_);
case spvtools::opt::analysis::Type::kInteger:
@ -374,7 +374,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) {
case spvtools::opt::analysis::Type::kImage:
// Fake it for sampler and texture types. These are handled in an
// entirely different way.
return save(program_.create<type::Void>());
return save(builder_.create<type::Void>());
default:
break;
}
@ -713,8 +713,8 @@ bool ParserImpl::RegisterEntryPoints() {
type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Integer* int_ty) {
if (int_ty->width() == 32) {
type::Type* signed_ty = program_.create<type::I32>();
type::Type* unsigned_ty = program_.create<type::U32>();
type::Type* signed_ty = builder_.create<type::I32>();
type::Type* unsigned_ty = builder_.create<type::U32>();
signed_type_for_[unsigned_ty] = signed_ty;
unsigned_type_for_[signed_ty] = unsigned_ty;
return int_ty->IsSigned() ? signed_ty : unsigned_ty;
@ -726,7 +726,7 @@ type::Type* ParserImpl::ConvertType(
type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Float* float_ty) {
if (float_ty->width() == 32) {
return program_.create<type::F32>();
return builder_.create<type::F32>();
}
Fail() << "unhandled float width: " << float_ty->width();
return nullptr;
@ -739,16 +739,16 @@ type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) {
return nullptr;
}
auto* this_ty = program_.create<type::Vector>(ast_elem_ty, num_elem);
auto* this_ty = builder_.create<type::Vector>(ast_elem_ty, num_elem);
// Generate the opposite-signedness vector type, if this type is integral.
if (unsigned_type_for_.count(ast_elem_ty)) {
auto* other_ty = program_.create<type::Vector>(
auto* other_ty = builder_.create<type::Vector>(
unsigned_type_for_[ast_elem_ty], num_elem);
signed_type_for_[other_ty] = this_ty;
unsigned_type_for_[this_ty] = other_ty;
} else if (signed_type_for_.count(ast_elem_ty)) {
auto* other_ty =
program_.create<type::Vector>(signed_type_for_[ast_elem_ty], num_elem);
builder_.create<type::Vector>(signed_type_for_[ast_elem_ty], num_elem);
unsigned_type_for_[other_ty] = this_ty;
signed_type_for_[this_ty] = other_ty;
}
@ -765,7 +765,7 @@ type::Type* ParserImpl::ConvertType(
if (ast_scalar_ty == nullptr) {
return nullptr;
}
return program_.create<type::Matrix>(ast_scalar_ty, num_rows, num_columns);
return builder_.create<type::Matrix>(ast_scalar_ty, num_rows, num_columns);
}
type::Type* ParserImpl::ConvertType(
@ -947,7 +947,7 @@ type::Type* ParserImpl::ConvertType(
}
const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>(
Source{}, program_.Symbols().Register(member_name), ast_member_ty,
Source{}, builder_.Symbols().Register(member_name), ast_member_ty,
std::move(ast_member_decorations));
ast_members.push_back(ast_struct_member);
}
@ -963,13 +963,13 @@ type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S");
auto name = namer_.GetName(type_id);
auto* result = program_.create<type::Struct>(
program_.Symbols().Register(name), ast_struct);
auto* result = builder_.create<type::Struct>(
builder_.Symbols().Register(name), ast_struct);
id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result);
}
program_.AST().AddConstructedType(result);
builder_.AST().AddConstructedType(result);
return result;
}
@ -1003,7 +1003,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id,
ast_storage_class = ast::StorageClass::kStorage;
remap_buffer_block_type_.insert(type_id);
}
return program_.create<type::Pointer>(ast_elem_ty, ast_storage_class);
return builder_.create<type::Pointer>(ast_elem_ty, ast_storage_class);
}
bool ParserImpl::RegisterTypes() {
@ -1091,7 +1091,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
MakeVariable(inst.result_id(), ast::StorageClass::kNone, ast_type,
true, ast_expr, std::move(spec_id_decos));
if (ast_var) {
program_.AST().AddGlobalVariable(ast_var);
builder_.AST().AddGlobalVariable(ast_var);
scalar_spec_constants_.insert(inst.result_id());
}
}
@ -1129,11 +1129,11 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
return;
}
const auto name = namer_.GetName(type_id);
auto* ast_alias_type = program_.create<type::Alias>(
program_.Symbols().Register(name), ast_underlying_type);
auto* ast_alias_type = builder_.create<type::Alias>(
builder_.Symbols().Register(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type;
program_.AST().AddConstructedType(ast_alias_type);
builder_.AST().AddConstructedType(ast_alias_type);
}
bool ParserImpl::EmitModuleScopeVariables() {
@ -1209,7 +1209,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
ast_constructor, ast::VariableDecorationList{});
// TODO(dneto): initializers (a.k.a. constructor expression)
if (ast_var) {
program_.AST().AddGlobalVariable(ast_var);
builder_.AST().AddGlobalVariable(ast_var);
}
}
@ -1226,7 +1226,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition),
});
program_.AST().AddGlobalVariable(var);
builder_.AST().AddGlobalVariable(var);
}
return success_;
}
@ -1248,7 +1248,7 @@ ast::Variable* ParserImpl::MakeVariable(
auto access = read_only_struct_types_.count(type)
? ast::AccessControl::kReadOnly
: ast::AccessControl::kReadWrite;
type = program_.create<type::AccessControl>(access, type);
type = builder_.create<type::AccessControl>(access, type);
}
for (auto& deco : GetDecorationsFor(id)) {
@ -1307,7 +1307,7 @@ ast::Variable* ParserImpl::MakeVariable(
std::string name = namer_.Name(id);
return create<ast::Variable>(Source{}, // source
program_.Symbols().Register(name), // symbol
builder_.Symbols().Register(name), // symbol
sc, // storage_class
type, // type
is_const, // is_const
@ -1451,7 +1451,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
if (const auto* mat_ty = type->As<type::Matrix>()) {
// Matrix components are columns
auto* column_ty =
program_.create<type::Vector>(mat_ty->type(), mat_ty->rows());
builder_.create<type::Vector>(mat_ty->type(), mat_ty->rows());
ast::ExpressionList ast_components;
for (size_t i = 0; i < mat_ty->columns(); ++i) {
ast_components.emplace_back(MakeNullValue(column_ty));
@ -1546,14 +1546,14 @@ type::Type* ParserImpl::GetSignedIntMatchingShape(type::Type* other) {
if (other == nullptr) {
Fail() << "no type provided";
}
auto* i32 = program_.create<type::I32>();
auto* i32 = builder_.create<type::I32>();
if (other->Is<type::F32>() || other->Is<type::U32>() ||
other->Is<type::I32>()) {
return i32;
}
auto* vec_ty = other->As<type::Vector>();
if (vec_ty) {
return program_.create<type::Vector>(i32, vec_ty->size());
return builder_.create<type::Vector>(i32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
@ -1564,14 +1564,14 @@ type::Type* ParserImpl::GetUnsignedIntMatchingShape(type::Type* other) {
Fail() << "no type provided";
return nullptr;
}
auto* u32 = program_.create<type::U32>();
auto* u32 = builder_.create<type::U32>();
if (other->Is<type::F32>() || other->Is<type::U32>() ||
other->Is<type::I32>()) {
return u32;
}
auto* vec_ty = other->As<type::Vector>();
if (vec_ty) {
return program_.create<type::Vector>(u32, vec_ty->size());
return builder_.create<type::Vector>(u32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
@ -1845,7 +1845,7 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
// Construct the Tint handle type.
type::Type* ast_store_type = nullptr;
if (usage.IsSampler()) {
ast_store_type = program_.create<type::Sampler>(
ast_store_type = builder_.create<type::Sampler>(
usage.IsComparisonSampler() ? type::SamplerKind::kComparisonSampler
: type::SamplerKind::kSampler);
} else if (usage.IsTexture()) {
@ -1876,13 +1876,13 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
// OpImage variable with an OpImage*Dref* instruction. In WGSL we must
// treat that as a depth texture.
if (image_type->depth() || usage.IsDepthTexture()) {
ast_store_type = program_.create<type::DepthTexture>(dim);
ast_store_type = builder_.create<type::DepthTexture>(dim);
} else if (image_type->is_multisampled()) {
// Multisampled textures are never depth textures.
ast_store_type = program_.create<type::MultisampledTexture>(
ast_store_type = builder_.create<type::MultisampledTexture>(
dim, ast_sampled_component_type);
} else {
ast_store_type = program_.create<type::SampledTexture>(
ast_store_type = builder_.create<type::SampledTexture>(
dim, ast_sampled_component_type);
}
} else {
@ -1893,8 +1893,8 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
if (format == type::ImageFormat::kNone) {
return nullptr;
}
ast_store_type = program_.create<type::AccessControl>(
access, program_.create<type::StorageTexture>(dim, format));
ast_store_type = builder_.create<type::AccessControl>(
access, builder_.create<type::StorageTexture>(dim, format));
}
} else {
Fail() << "unsupported: UniformConstant variable is not a recognized "
@ -1904,7 +1904,7 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
}
// Form the pointer type.
auto* result = program_.create<type::Pointer>(
auto* result = builder_.create<type::Pointer>(
ast_store_type, ast::StorageClass::kUniformConstant);
// Remember it for later.
handle_type_[&var] = result;
@ -1922,7 +1922,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) {
case type::ImageFormat::kRg32Uint:
case type::ImageFormat::kRgba16Uint:
case type::ImageFormat::kRgba32Uint:
return program_.create<type::U32>();
return builder_.create<type::U32>();
case type::ImageFormat::kR8Sint:
case type::ImageFormat::kR16Sint:
@ -1933,7 +1933,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) {
case type::ImageFormat::kRg32Sint:
case type::ImageFormat::kRgba16Sint:
case type::ImageFormat::kRgba32Sint:
return program_.create<type::I32>();
return builder_.create<type::I32>();
case type::ImageFormat::kR8Unorm:
case type::ImageFormat::kRg8Unorm:
@ -1952,7 +1952,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) {
case type::ImageFormat::kRg32Float:
case type::ImageFormat::kRgba16Float:
case type::ImageFormat::kRgba32Float:
return program_.create<type::F32>();
return builder_.create<type::F32>();
default:
break;
}
@ -1992,7 +1992,7 @@ type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) {
case type::ImageFormat::kRg8Uint:
case type::ImageFormat::kRg8Unorm:
// Two channels
return program_.create<type::Vector>(component_type, 2);
return builder_.create<type::Vector>(component_type, 2);
case type::ImageFormat::kBgra8Unorm:
case type::ImageFormat::kBgra8UnormSrgb:
@ -2009,7 +2009,7 @@ type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) {
case type::ImageFormat::kRgba8Unorm:
case type::ImageFormat::kRgba8UnormSrgb:
// Four channels
return program_.create<type::Vector>(component_type, 4);
return builder_.create<type::Vector>(component_type, 4);
default:
break;

View File

@ -33,7 +33,7 @@
#include "spirv-tools/libspirv.hpp"
#include "src/ast/expression.h"
#include "src/ast/struct_member_decoration.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/reader/reader.h"
#include "src/reader/spirv/entry_point_info.h"
#include "src/reader/spirv/enum_converter.h"
@ -95,12 +95,13 @@ class ParserImpl : Reader {
/// @returns true if the parse was successful, false otherwise.
bool Parse() override;
/// @returns the program. The program in the parser will be reset after this.
/// @returns the program. The program builder in the parser will be reset
/// after this.
Program program() override;
/// Returns a reference to the program, without resetting it.
/// @returns the program
Program& get_program() { return program_; }
/// @returns a reference to the internal builder, without building the
/// program. To be used only for testing.
ProgramBuilder& builder() { return builder_; }
/// Logs failure, ands return a failure stream to accumulate diagnostic
/// messages. By convention, a failure should only be logged along with
@ -118,14 +119,14 @@ class ParserImpl : Reader {
const std::string error() { return errors_.str(); }
/// Builds an internal representation of the SPIR-V binary,
/// and parses it into a Tint program. Diagnostics are emitted
/// and parses it into a Tint AST module. Diagnostics are emitted
/// to the error stream.
/// @returns true if it was successful.
bool BuildAndParseInternalModule() {
return BuildInternalModule() && ParseInternalModule();
}
/// Builds an internal representation of the SPIR-V binary,
/// and parses the module, except functions, into a Tint program.
/// and parses the module, except functions, into a Tint AST module.
/// Diagnostics are emitted to the error stream.
/// @returns true if it was successful.
bool BuildAndParseInternalModuleExceptFunctions() {
@ -524,20 +525,19 @@ class ParserImpl : Reader {
bool ParseArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
ast::ArrayDecorationList* decorations);
/// Creates a new `ast::Node` owned by the Program. When the Program is
/// destructed, the `ast::Node` will also be destructed.
/// Creates a new `ast::Node` owned by the ProgramBuilder.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
return program_.create<T>(std::forward<ARGS>(args)...);
return builder_.create<T>(std::forward<ARGS>(args)...);
}
// The SPIR-V binary we're parsing
std::vector<uint32_t> spv_binary_;
// The resulting module in Tint AST form.
Program program_;
// The program builder.
ProgramBuilder builder_;
// Is the parse successful?
bool success_ = true;

View File

@ -566,7 +566,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
EXPECT_TRUE(type->Is<type::Struct>());
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(Demangler().Demangle(p->get_program().Symbols(), ss.str()),
EXPECT_THAT(Demangler().Demangle(p->program().Symbols(), ss.str()),
Eq(R"(Struct{
StructMember{field0: __u32}
StructMember{field1: __f32}
@ -588,7 +588,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
EXPECT_TRUE(type->Is<type::Struct>());
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(Demangler().Demangle(p->get_program().Symbols(), ss.str()),
EXPECT_THAT(Demangler().Demangle(p->program().Symbols(), ss.str()),
Eq(R"(Struct{
[[block]]
StructMember{field0: __u32}
@ -614,7 +614,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
EXPECT_TRUE(type->Is<type::Struct>());
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(Demangler().Demangle(p->get_program().Symbols(), ss.str()),
EXPECT_THAT(Demangler().Demangle(p->program().Symbols(), ss.str()),
Eq(R"(Struct{
StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32}

View File

@ -17,6 +17,7 @@
#include <vector>
#include "gmock/gmock.h"
#include "src/ast/module.h"
#include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h"
#include "src/reader/spirv/spirv_tools_helpers_test.h"
@ -53,7 +54,8 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) {
auto p = parser(test::Assemble(CommonTypes()));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
}
@ -64,7 +66,8 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
}
@ -79,9 +82,10 @@ OpFunctionEnd)";
auto p = parser(test::Assemble(input));
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("main").to_str() +
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
StageDecoration{vertex}
()
@ -99,9 +103,10 @@ OpFunctionEnd)";
auto p = parser(test::Assemble(input));
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("main").to_str() +
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
StageDecoration{fragment}
()
@ -119,9 +124,10 @@ OpFunctionEnd)";
auto p = parser(test::Assemble(input));
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("main").to_str() +
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
StageDecoration{compute}
()
@ -141,15 +147,16 @@ OpFunctionEnd)";
auto p = parser(test::Assemble(input));
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("frag_main").to_str() +
Function )" + program.Symbols().Get("frag_main").to_str() +
R"( -> __void
StageDecoration{fragment}
()
{)"));
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("comp_main").to_str() +
Function )" + program.Symbols().Get("comp_main").to_str() +
R"( -> __void
StageDecoration{compute}
()
@ -165,9 +172,10 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = p->get_program().to_str();
Program program = p->program();
const auto program_ast = program.AST().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().Symbols().Get("main").to_str() +
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
()
{)"));
@ -199,7 +207,8 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = Demangler().Demangle(p->get_program());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function leaf -> __u32
()
@ -266,7 +275,8 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = Demangler().Demangle(p->get_program());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function ret_float -> __f32
()
@ -295,7 +305,8 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = Demangler().Demangle(p->get_program());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void
(
@ -334,7 +345,8 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = Demangler().Demangle(p->get_program());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void
(

View File

@ -1129,7 +1129,7 @@ TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->get_program());
const auto program = Demangler().Demangle(p->program());
EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << program;
}
@ -1305,7 +1305,7 @@ TEST_P(SpvParserTest_SampledImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->get_program());
const auto program = Demangler().Demangle(p->program());
EXPECT_THAT(program, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << program;
EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin))
@ -2554,7 +2554,7 @@ TEST_P(SpvParserTest_ImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->get_program());
const auto program = Demangler().Demangle(p->program());
EXPECT_THAT(program, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << program;
EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin))
@ -3706,10 +3706,11 @@ TEST_P(SpvParserTest_ImageCoordsTest, MakeCoordinateOperandsForImageAccess) {
EXPECT_TRUE(fe.success()) << p->error();
EXPECT_TRUE(p->error().empty());
std::vector<std::string> result_strings;
Program program = p->program();
for (auto* expr : result) {
ASSERT_NE(expr, nullptr);
result_strings.push_back(
Demangler().Demangle(p->get_program().Symbols(), expr->str()));
Demangler().Demangle(program.Symbols(), expr->str()));
}
EXPECT_THAT(result_strings,
::testing::ContainerEq(GetParam().expected_expressions));

View File

@ -15,6 +15,7 @@
#include <string>
#include "gmock/gmock.h"
#include "src/ast/module.h"
#include "src/demangler.h"
#include "src/reader/spirv/function.h"
#include "src/reader/spirv/parser_impl.h"
@ -70,8 +71,8 @@ TEST_F(SpvModuleScopeVarParserTest, NoVar) {
auto p = parser(test::Assemble(""));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto program_ast = p->program().to_str();
EXPECT_THAT(program_ast, Not(HasSubstr("Variable")));
const auto module_ast = p->program().AST().to_str();
EXPECT_THAT(module_ast, Not(HasSubstr("Variable")));
}
TEST_F(SpvModuleScopeVarParserTest, BadStorageClass_NotAWebGPUStorageClass) {
@ -143,7 +144,7 @@ TEST_F(SpvModuleScopeVarParserTest, AnonWorkgroupVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
x_52
@ -162,7 +163,7 @@ TEST_F(SpvModuleScopeVarParserTest, NamedWorkgroupVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
the_counter
@ -181,7 +182,7 @@ TEST_F(SpvModuleScopeVarParserTest, PrivateVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
my_own_private_idaho
@ -200,7 +201,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinVertexIndex) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -250,7 +251,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_MapsToModuleScopeVec4Var) {
EXPECT_EQ(position_info.pointer_type_id, 11u);
EXPECT_EQ(position_info.storage_class, SpvStorageClassOutput);
EXPECT_EQ(position_info.per_vertex_var_id, 1u);
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -330,7 +331,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_StorePosition) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
Identifier[not set]{gl_Position}
@ -383,7 +384,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
Identifier[not set]{gl_Position}
@ -414,7 +415,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
MemberAccessor[not set]{
@ -445,7 +446,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
{
Assignment{
@ -475,7 +476,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Write1_IsErased) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Variable{
Decorations{
@ -531,7 +532,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_ReadReplaced) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Variable{
x_900
@ -598,7 +599,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Variable{
Decorations{
@ -649,7 +650,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_Write1_IsErased) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -693,7 +694,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_ReadReplaced) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Variable{
x_900
@ -729,7 +730,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -756,7 +757,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty()) << p->error();
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -860,7 +861,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -917,7 +918,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarNullInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -966,7 +967,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarUndefInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -1010,7 +1011,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1033,7 +1034,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1056,7 +1057,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1079,7 +1080,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1102,7 +1103,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1125,7 +1126,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1148,7 +1149,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1171,7 +1172,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1194,7 +1195,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1223,7 +1224,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1259,7 +1260,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1295,7 +1296,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1332,7 +1333,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1355,7 +1356,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1378,7 +1379,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1403,7 +1404,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1432,7 +1433,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1461,7 +1462,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1492,7 +1493,7 @@ TEST_F(SpvModuleScopeVarParserTest, LocationDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1544,7 +1545,7 @@ TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1598,7 +1599,7 @@ TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1652,7 +1653,7 @@ TEST_F(SpvModuleScopeVarParserTest,
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1683,7 +1684,7 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1712,7 +1713,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Dropped) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1761,7 +1762,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1790,7 +1791,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1822,7 +1823,7 @@ TEST_F(
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1846,7 +1847,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1871,7 +1872,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_False) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1896,7 +1897,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_U32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1921,7 +1922,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_I32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1946,7 +1947,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_F32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1972,7 +1973,7 @@ TEST_F(SpvModuleScopeVarParserTest,
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->get_program());
const auto module_str = Demangler().Demangle(p->program());
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
myconst
@ -2001,7 +2002,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_TRUE(p->error().empty());
EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(
EXPECT_THAT(ToString(p->builder().Symbols(), fe.ast_body()), HasSubstr(R"(
VariableConst{
x_1
none
@ -2014,7 +2015,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) {
}
}
})"))
<< ToString(p->get_program(), fe.ast_body());
<< ToString(p->builder().Symbols(), fe.ast_body());
}
} // namespace

View File

@ -17,6 +17,7 @@
#include <vector>
#include "gmock/gmock.h"
#include "src/ast/module.h"
#include "src/ast/struct.h"
#include "src/demangler.h"
#include "src/reader/spirv/parser_impl.h"
@ -40,7 +41,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) {
%s = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()), HasSubstr("S Struct"));
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr("S Struct"));
}
TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
@ -50,8 +51,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
%s = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
HasSubstr("mystruct Struct"));
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr("mystruct Struct"));
}
TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
@ -61,7 +61,7 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
%s2 = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_THAT(Demangler().Demangle(p->get_program()), HasSubstr(R"(S Struct{
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr(R"(S Struct{
StructMember{field0: __u32}
StructMember{field1: __u32}
}
@ -82,7 +82,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
EXPECT_THAT(Demangler().Demangle(p->program()),
HasSubstr("RTArr -> __array__u32_stride_8\n"));
}
@ -95,7 +95,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) {
%arr2 = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
EXPECT_THAT(Demangler().Demangle(p->program()),
HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> "
"__array__u32_stride_8\n"));
}
@ -108,7 +108,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
EXPECT_THAT(Demangler().Demangle(p->program()),
HasSubstr("myrtarr -> __array__u32_stride_8\n"));
}
@ -122,7 +122,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
EXPECT_THAT(Demangler().Demangle(p->program()),
HasSubstr("myarr -> __array__u32_5_stride_8"));
}
@ -136,7 +136,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->get_program()),
EXPECT_THAT(Demangler().Demangle(p->program()),
HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> "
"__array__u32_5_stride_8"));
}

View File

@ -58,16 +58,16 @@ class SpvParserTestBase : public T {
using SpvParserTest = SpvParserTestBase<::testing::Test>;
/// Returns the string dump of a statement list.
/// @param program the program
/// @param symbols the SymbolTable
/// @param stmts the statement list
/// @returns the string dump of a statement list.
inline std::string ToString(const Program& program,
inline std::string ToString(const SymbolTable& symbols,
const ast::StatementList& stmts) {
std::ostringstream outs;
for (const auto* stmt : stmts) {
stmt->to_str(outs, 0);
}
return Demangler().Demangle(program.Symbols(), outs.str());
return Demangler().Demangle(symbols, outs.str());
}
} // namespace spirv

View File

@ -39,7 +39,8 @@ class Parser : public Reader {
/// @returns true if the parse was successful, false otherwise.
bool Parse() override;
/// @returns the program. The program in the parser will be reset after this.
/// @returns the program. The program builder in the parser will be reset
/// after this.
Program program() override;
private:

View File

@ -293,7 +293,7 @@ void ParserImpl::translation_unit() {
}
}
assert(program_.IsValid());
assert(builder_.IsValid());
}
// global_decl
@ -323,7 +323,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("variable declaration", Token::Type::kSemicolon))
return Failure::kErrored;
program_.AST().AddGlobalVariable(gv.value);
builder_.AST().AddGlobalVariable(gv.value);
return true;
}
@ -335,7 +335,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("constant declaration", Token::Type::kSemicolon))
return Failure::kErrored;
program_.AST().AddGlobalVariable(gc.value);
builder_.AST().AddGlobalVariable(gc.value);
return true;
}
@ -347,7 +347,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("type alias", Token::Type::kSemicolon))
return Failure::kErrored;
program_.AST().AddConstructedType(ta.value);
builder_.AST().AddConstructedType(ta.value);
return true;
}
@ -359,10 +359,9 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("struct declaration", Token::Type::kSemicolon))
return Failure::kErrored;
auto* type = str.value;
register_constructed(
program_.Symbols().NameFor(type->As<type::Struct>()->symbol()), type);
program_.AST().AddConstructedType(type);
register_constructed(builder_.Symbols().NameFor(str.value->symbol()),
str.value);
builder_.AST().AddConstructedType(str.value);
return true;
}
@ -378,7 +377,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (func.errored)
errored = true;
if (func.matched) {
program_.AST().Functions().Add(func.value);
builder_.AST().Functions().Add(func.value);
return true;
}
@ -437,7 +436,7 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
return create<ast::Variable>(
decl->source, // source
program_.Symbols().Register(decl->name), // symbol
builder_.Symbols().Register(decl->name), // symbol
decl->storage_class, // storage_class
decl->type, // type
false, // is_const
@ -466,7 +465,7 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
return create<ast::Variable>(
decl->source, // source
program_.Symbols().Register(decl->name), // symbol
builder_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -516,7 +515,7 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return program_.create<type::SampledTexture>(dim.value, subtype.value);
return builder_.create<type::SampledTexture>(dim.value, subtype.value);
}
auto ms_dim = multisampled_texture_type();
@ -527,7 +526,7 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return program_.create<type::MultisampledTexture>(ms_dim.value,
return builder_.create<type::MultisampledTexture>(ms_dim.value,
subtype.value);
}
@ -541,7 +540,7 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (format.errored)
return Failure::kErrored;
return program_.create<type::StorageTexture>(storage.value, format.value);
return builder_.create<type::StorageTexture>(storage.value, format.value);
}
// DEPRECATED
@ -555,9 +554,9 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (format.errored)
return Failure::kErrored;
return program_.create<type::AccessControl>(
return builder_.create<type::AccessControl>(
ac_storage->second,
program_.create<type::StorageTexture>(ac_storage->first, format.value));
builder_.create<type::StorageTexture>(ac_storage->first, format.value));
}
return Failure::kNoMatch;
@ -568,10 +567,10 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
// | SAMPLER_COMPARISON
Maybe<type::Type*> ParserImpl::sampler_type() {
if (match(Token::Type::kSampler))
return program_.create<type::Sampler>(type::SamplerKind::kSampler);
return builder_.create<type::Sampler>(type::SamplerKind::kSampler);
if (match(Token::Type::kComparisonSampler))
return program_.create<type::Sampler>(
return builder_.create<type::Sampler>(
type::SamplerKind::kComparisonSampler);
return Failure::kNoMatch;
@ -717,17 +716,17 @@ ParserImpl::storage_texture_type_access_control() {
// | TEXTURE_DEPTH_CUBE_ARRAY
Maybe<type::Type*> ParserImpl::depth_texture_type() {
if (match(Token::Type::kTextureDepth2d))
return program_.create<type::DepthTexture>(type::TextureDimension::k2d);
return builder_.create<type::DepthTexture>(type::TextureDimension::k2d);
if (match(Token::Type::kTextureDepth2dArray))
return program_.create<type::DepthTexture>(
return builder_.create<type::DepthTexture>(
type::TextureDimension::k2dArray);
if (match(Token::Type::kTextureDepthCube))
return program_.create<type::DepthTexture>(type::TextureDimension::kCube);
return builder_.create<type::DepthTexture>(type::TextureDimension::kCube);
if (match(Token::Type::kTextureDepthCubeArray))
return program_.create<type::DepthTexture>(
return builder_.create<type::DepthTexture>(
type::TextureDimension::kCubeArray);
return Failure::kNoMatch;
@ -913,7 +912,7 @@ Expect<ParserImpl::TypedIdentifier> ParserImpl::expect_variable_ident_decl(
for (auto* deco : access_decos) {
// If we have an access control decoration then we take it and wrap our
// type up with that decoration
ty = program_.create<type::AccessControl>(
ty = builder_.create<type::AccessControl>(
deco->As<ast::AccessDecoration>()->value(), ty);
}
@ -975,8 +974,8 @@ Maybe<type::Type*> ParserImpl::type_alias() {
if (!type.matched)
return add_error(peek(), "invalid type alias");
auto* alias = program_.create<type::Alias>(
program_.Symbols().Register(name.value), type.value);
auto* alias = builder_.create<type::Alias>(
builder_.Symbols().Register(name.value), type.value);
register_constructed(name.value, alias);
return alias;
@ -1034,16 +1033,16 @@ Maybe<type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
}
if (match(Token::Type::kBool))
return program_.create<type::Bool>();
return builder_.create<type::Bool>();
if (match(Token::Type::kF32))
return program_.create<type::F32>();
return builder_.create<type::F32>();
if (match(Token::Type::kI32))
return program_.create<type::I32>();
return builder_.create<type::I32>();
if (match(Token::Type::kU32))
return program_.create<type::U32>();
return builder_.create<type::U32>();
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
next(); // Consume the peek
@ -1101,7 +1100,7 @@ Expect<type::Type*> ParserImpl::expect_type_decl_pointer() {
if (subtype.errored)
return Failure::kErrored;
return program_.create<type::Pointer>(subtype.value, sc.value);
return builder_.create<type::Pointer>(subtype.value, sc.value);
});
}
@ -1118,7 +1117,7 @@ Expect<type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
if (subtype.errored)
return Failure::kErrored;
return program_.create<type::Vector>(subtype.value, count);
return builder_.create<type::Vector>(subtype.value, count);
}
Expect<type::Type*> ParserImpl::expect_type_decl_array(
@ -1162,7 +1161,7 @@ Expect<type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
if (subtype.errored)
return Failure::kErrored;
return program_.create<type::Matrix>(subtype.value, rows, columns);
return builder_.create<type::Matrix>(subtype.value, rows, columns);
}
// storage_class
@ -1229,7 +1228,7 @@ Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
return Failure::kErrored;
return create<type::Struct>(
program_.Symbols().Register(name.value),
builder_.Symbols().Register(name.value),
create<ast::Struct>(source, std::move(body.value),
std::move(struct_decos.value)));
}
@ -1284,7 +1283,7 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member(
return Failure::kErrored;
return create<ast::StructMember>(decl->source,
program_.Symbols().Register(decl->name),
builder_.Symbols().Register(decl->name),
decl->type, std::move(member_decos.value));
}
@ -1321,7 +1320,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
return Failure::kErrored;
return create<ast::Function>(
header->source, program_.Symbols().Register(header->name), header->params,
header->source, builder_.Symbols().Register(header->name), header->params,
header->return_type, body.value, func_decos.value);
}
@ -1330,7 +1329,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
// | VOID
Maybe<type::Type*> ParserImpl::function_type_decl() {
if (match(Token::Type::kVoid))
return program_.create<type::Void>();
return builder_.create<type::Void>();
return type_decl();
}
@ -1391,7 +1390,7 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
for (;;) {
auto* var = create<ast::Variable>(
decl->source, // source
program_.Symbols().Register(decl->name), // symbol
builder_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -1662,7 +1661,7 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = create<ast::Variable>(
decl->source, // source
program_.Symbols().Register(decl->name), // symbol
builder_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class
decl->type, // type
true, // is_const
@ -1691,7 +1690,7 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var =
create<ast::Variable>(decl->source, // source
program_.Symbols().Register(decl->name), // symbol
builder_.Symbols().Register(decl->name), // symbol
decl->storage_class, // storage_class
decl->type, // type
false, // is_const
@ -2093,7 +2092,7 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
Source{}, create<ast::CallExpression>(
source,
create<ast::IdentifierExpression>(
source, program_.Symbols().Register(name)),
source, builder_.Symbols().Register(name)),
std::move(params)));
}
@ -2166,7 +2165,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (match(Token::Type::kIdentifier))
return create<ast::IdentifierExpression>(
t.source(), program_.Symbols().Register(t.to_str()));
t.source(), builder_.Symbols().Register(t.to_str()));
auto type = type_decl();
if (type.errored)
@ -2242,7 +2241,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, prefix,
create<ast::IdentifierExpression>(
ident.source, program_.Symbols().Register(ident.value))));
ident.source, builder_.Symbols().Register(ident.value))));
}
return prefix;
@ -2742,19 +2741,19 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
Maybe<ast::Literal*> ParserImpl::const_literal() {
auto t = peek();
if (match(Token::Type::kTrue)) {
auto* type = program_.create<type::Bool>();
auto* type = builder_.create<type::Bool>();
return create<ast::BoolLiteral>(Source{}, type, true);
}
if (match(Token::Type::kFalse)) {
auto* type = program_.create<type::Bool>();
auto* type = builder_.create<type::Bool>();
return create<ast::BoolLiteral>(Source{}, type, false);
}
if (match(Token::Type::kSintLiteral)) {
auto* type = program_.create<type::I32>();
auto* type = builder_.create<type::I32>();
return create<ast::SintLiteral>(Source{}, type, t.to_i32());
}
if (match(Token::Type::kUintLiteral)) {
auto* type = program_.create<type::U32>();
auto* type = builder_.create<type::U32>();
return create<ast::UintLiteral>(Source{}, type, t.to_u32());
}
if (match(Token::Type::kFloatLiteral)) {
@ -2763,7 +2762,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
next(); // Consume 'f'
add_error(p.source(), "float literals must not be suffixed with 'f'");
}
auto* type = program_.create<type::F32>();
auto* type = builder_.create<type::F32>();
return create<ast::FloatLiteral>(Source{}, type, t.to_f32());
}
return Failure::kNoMatch;

View File

@ -52,7 +52,7 @@
#include "src/ast/variable_decoration.h"
#include "src/diagnostic/diagnostic.h"
#include "src/diagnostic/formatter.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/reader/wgsl/parser_impl_detail.h"
#include "src/reader/wgsl/token.h"
#include "src/type/storage_texture_type.h"
@ -307,11 +307,12 @@ class ParserImpl {
/// @returns the diagnostic messages
diag::List& diagnostics() { return diags_; }
/// @returns the program. The program in the parser will be reset after this.
Program program() { return std::move(program_); }
/// @returns the Program. The program builder in the parser will be reset
/// after this.
Program program() { return Program(std::move(builder_)); }
/// @returns a pointer to the module, without resetting it.
Program& get_program() { return program_; }
/// @returns the program builder.
ProgramBuilder& builder() { return builder_; }
/// @returns the next token
Token next();
@ -829,7 +830,7 @@ class ParserImpl {
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
return program_.create<T>(std::forward<ARGS>(args)...);
return builder_.create<T>(std::forward<ARGS>(args)...);
}
diag::List diags_;
@ -839,7 +840,7 @@ class ParserImpl {
std::vector<Token::Type> sync_tokens_;
int silence_errors_ = 0;
std::unordered_map<std::string, type::Type*> registered_constructs_;
Program program_;
ProgramBuilder builder_;
size_t max_errors_ = 25;
};

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
ASSERT_TRUE(e->lhs()->Is<ast::IdentifierExpression>());
auto* ident = e->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>());
@ -77,7 +77,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
auto* ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("d"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("d"));
ASSERT_TRUE(mem->structure()->Is<ast::ArrayAccessorExpression>());
auto* ary = mem->structure()->As<ast::ArrayAccessorExpression>();
@ -93,18 +93,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
mem = ary->array()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("c"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("c"));
ASSERT_TRUE(mem->structure()->Is<ast::MemberAccessorExpression>());
mem = mem->structure()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->structure()->Is<ast::IdentifierExpression>());
ident = mem->structure()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("b"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("b"));
}
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, Statement_Call) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
EXPECT_EQ(c->params().size(), 0u);
}
@ -56,7 +56,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(ident->symbol(), p->builder().Symbols().Get("a"));
EXPECT_EQ(c->params().size(), 3u);
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());

Some files were not shown because too many files have changed in this diff Show More