[msl-writer] Refactor some entry point variable code.
This CL cleans up some of the entry point variable code. Bug: tint:8 Change-Id: Ic89ff3608d34af26eeb9fe9408cdbd5c7de22dda Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24782 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
df415a8919
commit
d1684ed287
|
@ -278,6 +278,27 @@ bool GeneratorImpl::EmitBreak(ast::BreakStatement*) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GeneratorImpl::current_ep_var_name(VarType type) {
|
||||||
|
std::string name = "";
|
||||||
|
switch (type) {
|
||||||
|
case VarType::kIn: {
|
||||||
|
auto in_it = ep_name_to_in_data_.find(current_ep_name_);
|
||||||
|
if (in_it != ep_name_to_in_data_.end()) {
|
||||||
|
name = in_it->second.var_name;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case VarType::kOut: {
|
||||||
|
auto out_it = ep_name_to_out_data_.find(current_ep_name_);
|
||||||
|
if (out_it != ep_name_to_out_data_.end()) {
|
||||||
|
name = out_it->second.var_name;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
if (!expr->func()->IsIdentifier()) {
|
if (!expr->func()->IsIdentifier()) {
|
||||||
error_ = "invalid function name";
|
error_ = "invalid function name";
|
||||||
|
@ -301,19 +322,18 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
out_ << name << "(";
|
out_ << name << "(";
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
auto var_name = current_ep_var_name(VarType::kIn);
|
||||||
auto in_it = ep_name_to_in_data_.find(current_ep_name_);
|
if (!var_name.empty()) {
|
||||||
if (in_it != ep_name_to_in_data_.end()) {
|
out_ << var_name;
|
||||||
out_ << in_it->second.var_name;
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out_it = ep_name_to_out_data_.find(current_ep_name_);
|
var_name = current_ep_var_name(VarType::kOut);
|
||||||
if (out_it != ep_name_to_out_data_.end()) {
|
if (!var_name.empty()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out_ << ", ";
|
out_ << ", ";
|
||||||
}
|
}
|
||||||
out_ << out_it->second.var_name;
|
out_ << var_name;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,23 +852,18 @@ bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
|
||||||
|
|
||||||
ast::Variable* var = nullptr;
|
ast::Variable* var = nullptr;
|
||||||
if (global_variables_.get(ident->name(), &var)) {
|
if (global_variables_.get(ident->name(), &var)) {
|
||||||
if (var->storage_class() == ast::StorageClass::kInput &&
|
if (var->IsDecorated() && var->AsDecorated()->HasLocationDecoration() &&
|
||||||
var->IsDecorated() && var->AsDecorated()->HasLocationDecoration()) {
|
(var->storage_class() == ast::StorageClass::kInput ||
|
||||||
auto it = ep_name_to_in_data_.find(current_ep_name_);
|
var->storage_class() == ast::StorageClass::kOutput)) {
|
||||||
if (it == ep_name_to_in_data_.end()) {
|
auto var_type = var->storage_class() == ast::StorageClass::kInput
|
||||||
error_ = "unable to find entry point data for input";
|
? VarType::kIn
|
||||||
|
: VarType::kOut;
|
||||||
|
auto name = current_ep_var_name(var_type);
|
||||||
|
if (name.empty()) {
|
||||||
|
error_ = "unable to find entry point data for variable";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << it->second.var_name << ".";
|
out_ << name << ".";
|
||||||
} else if (var->storage_class() == ast::StorageClass::kOutput &&
|
|
||||||
var->IsDecorated() &&
|
|
||||||
var->AsDecorated()->HasLocationDecoration()) {
|
|
||||||
auto it = ep_name_to_out_data_.find(current_ep_name_);
|
|
||||||
if (it == ep_name_to_out_data_.end()) {
|
|
||||||
error_ = "unable to find entry point data for output";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
out_ << it->second.var_name << ".";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_ << namer_.NameFor(ident->name());
|
out_ << namer_.NameFor(ident->name());
|
||||||
|
|
|
@ -202,6 +202,9 @@ class GeneratorImpl : public TextGenerator {
|
||||||
Namer* namer_for_testing() { return &namer_; }
|
Namer* namer_for_testing() { return &namer_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class VarType { kIn, kOut };
|
||||||
|
std::string current_ep_var_name(VarType type);
|
||||||
|
|
||||||
Namer namer_;
|
Namer namer_;
|
||||||
ScopeStack<ast::Variable*> global_variables_;
|
ScopeStack<ast::Variable*> global_variables_;
|
||||||
std::string current_ep_name_;
|
std::string current_ep_name_;
|
||||||
|
|
Loading…
Reference in New Issue