Add type determiner infrastructure. This CL adds the Context object, variable ScopeStack and a Function map into the type determiner. The sample app is also updated to verify the module produced before passing to the type determiner. Bug: tint:5 Change-Id: Ib4af4e4305ee8a306f48e1bd328eaf3ad006fd9a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18823 Reviewed-by: David Neto <dneto@google.com>
diff --git a/samples/main.cc b/samples/main.cc index b4af202..4fc31a4 100644 --- a/samples/main.cc +++ b/samples/main.cc
@@ -292,22 +292,27 @@ return 1; } - auto module = reader->module(); + auto mod = reader->module(); if (options.dump_ast) { - std::cout << std::endl << module.to_str() << std::endl; + std::cout << std::endl << mod.to_str() << std::endl; } if (options.parse_only) { return 1; } - tint::TypeDeterminer td; - if (!td.Determine(&module)) { + if (!mod.IsValid()) { + std::cerr << "Invalid module generated..." << std::endl; + return 1; + } + + tint::TypeDeterminer td(&ctx); + if (!td.Determine(&mod)) { std::cerr << td.error() << std::endl; return 1; } tint::Validator v; - if (!v.Validate(module)) { + if (!v.Validate(mod)) { std::cerr << v.error() << std::endl; return 1; } @@ -316,14 +321,13 @@ #if TINT_BUILD_SPV_WRITER if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) { - writer = - std::make_unique<tint::writer::spirv::Generator>(std::move(module)); + writer = std::make_unique<tint::writer::spirv::Generator>(std::move(mod)); } #endif // TINT_BUILD_SPV_WRITER #if TINT_BUILD_WGSL_WRITER if (options.format == Format::kWgsl) { - writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(module)); + writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(mod)); } #endif // TINT_BUILD_WGSL_WRITER
diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 0faf0af..8abece1 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc
@@ -16,7 +16,10 @@ namespace tint { -TypeDeterminer::TypeDeterminer() = default; +TypeDeterminer::TypeDeterminer(Context* ctx) : ctx_(*ctx) { + // TODO(dsinclair): Temporary usage to avoid compiler warning + static_cast<void>(ctx_.type_mgr()); +} TypeDeterminer::~TypeDeterminer() = default;
diff --git a/src/type_determiner.h b/src/type_determiner.h index 8f2062e..b43f923 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h
@@ -16,16 +16,26 @@ #define SRC_TYPE_DETERMINER_H_ #include <string> +#include <unordered_map> #include "src/ast/module.h" +#include "src/context.h" +#include "src/scope_stack.h" namespace tint { +namespace ast { + +class Function; +class Variable; + +} // namespace ast /// Determines types for all items in the given tint module class TypeDeterminer { public: /// Constructor - TypeDeterminer(); + /// @param ctx the tint context + explicit TypeDeterminer(Context* ctx); ~TypeDeterminer(); /// Runs the type determiner @@ -37,7 +47,10 @@ const std::string& error() { return error_; } private: + Context& ctx_; std::string error_; + ScopeStack<ast::Variable*> variable_stack_; + std::unordered_map<std::string, ast::Function*> name_to_function_; }; } // namespace tint