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>
This commit is contained in:
parent
a32315cb73
commit
fa9dbf0dda
|
@ -292,22 +292,27 @@ int main(int argc, const char** argv) {
|
|||
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 @@ int main(int argc, const char** argv) {
|
|||
|
||||
#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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 @@ class TypeDeterminer {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue