Commit 8743826c authored by Paul's avatar Paul
Browse files

Fix compile errors

parent 5eb53a4e
...@@ -156,7 +156,7 @@ struct module ...@@ -156,7 +156,7 @@ struct module
void print_cpp(std::ostream& os) const; void print_cpp(std::ostream& os) const;
std::unordered_map<instruction_ref, std::string> std::unordered_map<instruction_ref, std::string>
print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::string> names) const; print_cpp(std::ostream& os, const std::string& mname, std::unordered_map<instruction_ref, std::string> names) const;
void annotate(std::ostream& os, std::function<void(instruction_ref)> a) const; void annotate(std::ostream& os, std::function<void(instruction_ref)> a) const;
......
...@@ -689,9 +689,7 @@ static std::string to_c_id(const std::string& name, char rep = '_') ...@@ -689,9 +689,7 @@ static std::string to_c_id(const std::string& name, char rep = '_')
static std::string cpp_var_name(const std::string& name) static std::string cpp_var_name(const std::string& name)
{ {
// Remove the module name return to_c_id("x_" + replace_string(name, ":", "_module_"));
std::string s = split_string(name, ':').back();
return to_c_id("m" + replace_string(s, "@", "x"));
} }
static std::string cpp_op_var(const std::string& name, instruction_ref ins) static std::string cpp_op_var(const std::string& name, instruction_ref ins)
...@@ -784,23 +782,22 @@ static void print_cpp_shape(std::ostream& os, const migraphx::shape& s) ...@@ -784,23 +782,22 @@ static void print_cpp_shape(std::ostream& os, const migraphx::shape& s)
} }
std::unordered_map<instruction_ref, std::string> std::unordered_map<instruction_ref, std::string>
module::print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::string> names) const module::print_cpp(std::ostream& os, const std::string& mname, std::unordered_map<instruction_ref, std::string> names) const
{ {
os << "migraphx::module p;" << std::endl;
// cppcheck-suppress variableScope // cppcheck-suppress variableScope
unsigned long seed = 0; unsigned long seed = names.size();
names = this->print( names = this->print(
[&](auto ins, auto ins_names) { [&](auto ins, auto ins_names) {
auto op = cpp_op_var(ins_names.at(ins), ins); auto op = cpp_op_var(ins_names.at(ins), ins);
if(ins->name().front() != '@') std::vector<std::string> input_vars;
{ std::transform(ins->inputs().begin(), ins->inputs().end(), std::back_inserter(input_vars), [&](auto input) {
os << "migraphx::op::" << ins->name() << " " << op << ";" << std::endl; return cpp_var_name(ins_names.at(input));
print_op_attributes(os, op, ins->get_operator()); });
}
os << "auto " << cpp_var_name(ins_names.at(ins)) << " = "; os << "auto " << cpp_var_name(ins_names.at(ins)) << " = ";
if(ins->name() == "@literal") if(ins->name() == "@literal")
{ {
os << "p.add_literal("; os << mname << "->add_literal(";
bool use_abs = false; bool use_abs = false;
ins->get_literal().visit([&](auto v) { ins->get_literal().visit([&](auto v) {
use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; }); use_abs = std::none_of(v.begin(), v.end(), [](auto x) { return x < 0; });
...@@ -818,17 +815,22 @@ module::print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::str ...@@ -818,17 +815,22 @@ module::print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::str
else if(ins->name() == "@param") else if(ins->name() == "@param")
{ {
std::string name = any_cast<builtin::param>(ins->get_operator()).parameter; std::string name = any_cast<builtin::param>(ins->get_operator()).parameter;
os << "p.add_parameter(" << enclose_name(name) << ","; os << mname << "->add_parameter(" << enclose_name(name) << ",";
print_cpp_shape(os, ins->get_shape()); print_cpp_shape(os, ins->get_shape());
os << ");" << std::endl; os << ");" << std::endl;
} }
else else if(ins->name() == "@return")
{
os << "p.add_instruction(" << op;
for(auto input : ins->inputs())
{ {
os << ", " << cpp_var_name(ins_names.at(input)); os << mname << "->add_return({";
os << join_strings(input_vars, ", ");
os << "});" << std::endl;
} }
else
{
assert(ins->name().front() != '@');
os << mname << "->add_instruction(";
print_make_op(os, ins->get_operator());
os << ", " << join_strings(input_vars, ", ");
os << ");" << std::endl; os << ");" << std::endl;
} }
}, },
...@@ -837,7 +839,7 @@ module::print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::str ...@@ -837,7 +839,7 @@ module::print_cpp(std::ostream& os, std::unordered_map<instruction_ref, std::str
return names; return names;
} }
void module::print_cpp(std::ostream& os) const { this->print_cpp(os, {}); } void module::print_cpp(std::ostream& os) const { this->print_cpp(os, this->name(), {}); }
void module::annotate(std::ostream& os, std::function<void(instruction_ref)> a) const void module::annotate(std::ostream& os, std::function<void(instruction_ref)> a) const
{ {
......
...@@ -752,10 +752,17 @@ void program::print_cpp(std::ostream& os) const ...@@ -752,10 +752,17 @@ void program::print_cpp(std::ostream& os) const
{ {
auto vec_modules = this->get_modules(); auto vec_modules = this->get_modules();
std::unordered_map<instruction_ref, std::string> names; std::unordered_map<instruction_ref, std::string> names;
os << "migraphx::program p;\n";
for(auto& mod : vec_modules) for(auto& mod : vec_modules)
{ {
os << "module: \"" << mod->name() << "\"" << std::endl; std::string var_name = "m" + mod->name();
names = mod->print_cpp(os, names); os << "migraphx::module_ref " << var_name << " = ";
if (mod->name() == "main")
os << "p.get_main_module();";
else
os << "p.create_module(\"" << mod->name() << "\");";
os << std::endl;
names = mod->print_cpp(os, var_name, names);
os << std::endl; os << std::endl;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment