"src/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "3885c9bc739cc8687eac5766a4b929462310e376"
Commit fb62d6ff authored by Paul's avatar Paul
Browse files

Update to print cpp

parent b20e3d4d
......@@ -21,8 +21,7 @@ auto with_char(F f)
return [=](unsigned char c) -> bool { return f(c); };
}
inline std::string
replace_string(std::string subject, const std::string& search, const std::string& replace)
inline void replace_string_inplace(std::string& subject, const std::string& search, const std::string& replace)
{
size_t pos = 0;
while((pos = subject.find(search, pos)) != std::string::npos)
......@@ -30,6 +29,12 @@ replace_string(std::string subject, const std::string& search, const std::string
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
}
inline std::string
replace_string(std::string subject, const std::string& search, const std::string& replace)
{
replace_string_inplace(subject, search, replace);
return subject;
}
......
......@@ -675,9 +675,23 @@ void module::print_graph(std::ostream& os, bool brief) const
os << "}" << std::endl;
}
static std::string to_c_id(const std::string& name, char rep = '_')
{
std::string id = transform_string(name, [&](auto c) {
if (with_char(::isalnum)(c) or c == '_')
return c;
return rep;
});
while(contains(id, "__"))
replace_string_inplace(id, "__", "_");
return id;
}
static std::string cpp_var_name(const std::string& name)
{
return "m" + replace_string(name, "@", "x");
// Remove the module name
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)
......@@ -685,6 +699,51 @@ static std::string cpp_op_var(const std::string& name, instruction_ref ins)
return replace_string(name, "@", ins->name());
}
static void print_value(std::ostream& os, const value& v)
{
if (not v.get_key().empty())
{
os << "{";
os << enclose_name(v.get_key()) << ", ";
print_value(os, v.without_key());
os << "}";
}
else if (v.is_array() or v.is_object())
{
char delim = '{';
for(const auto& x: v)
{
os << delim;
delim = ',';
print_value(os, x);
}
os << "}";
}
else if (v.is_null())
{
os << "nullptr";
}
else if (v.is_string())
{
os << enclose_name(v.get_string());
}
else
{
os << v.to<std::string>();
}
}
static void print_make_op(std::ostream& os, const operation& op)
{
os << "migraphx::make_op(" << enclose_name(op.name());
auto v = op.to_value();
if (not v.empty())
{
print_value(os, v);
}
os << ")";
}
static void print_op_attributes(std::ostream& os, const std::string& name, const operation& op)
{
std::string x = to_string(op);
......
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