Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
fb62d6ff
Commit
fb62d6ff
authored
Feb 07, 2022
by
Paul
Browse files
Update to print cpp
parent
b20e3d4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
3 deletions
+67
-3
src/include/migraphx/stringutils.hpp
src/include/migraphx/stringutils.hpp
+7
-2
src/module.cpp
src/module.cpp
+60
-1
No files found.
src/include/migraphx/stringutils.hpp
View file @
fb62d6ff
...
@@ -21,8 +21,7 @@ auto with_char(F f)
...
@@ -21,8 +21,7 @@ auto with_char(F f)
return
[
=
](
unsigned
char
c
)
->
bool
{
return
f
(
c
);
};
return
[
=
](
unsigned
char
c
)
->
bool
{
return
f
(
c
);
};
}
}
inline
std
::
string
inline
void
replace_string_inplace
(
std
::
string
&
subject
,
const
std
::
string
&
search
,
const
std
::
string
&
replace
)
replace_string
(
std
::
string
subject
,
const
std
::
string
&
search
,
const
std
::
string
&
replace
)
{
{
size_t
pos
=
0
;
size_t
pos
=
0
;
while
((
pos
=
subject
.
find
(
search
,
pos
))
!=
std
::
string
::
npos
)
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
...
@@ -30,6 +29,12 @@ replace_string(std::string subject, const std::string& search, const std::string
subject
.
replace
(
pos
,
search
.
length
(),
replace
);
subject
.
replace
(
pos
,
search
.
length
(),
replace
);
pos
+=
replace
.
length
();
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
;
return
subject
;
}
}
...
...
src/module.cpp
View file @
fb62d6ff
...
@@ -675,9 +675,23 @@ void module::print_graph(std::ostream& os, bool brief) const
...
@@ -675,9 +675,23 @@ void module::print_graph(std::ostream& os, bool brief) const
os
<<
"}"
<<
std
::
endl
;
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
)
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
)
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)
...
@@ -685,6 +699,51 @@ static std::string cpp_op_var(const std::string& name, instruction_ref ins)
return
replace_string
(
name
,
"@"
,
ins
->
name
());
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
)
static
void
print_op_attributes
(
std
::
ostream
&
os
,
const
std
::
string
&
name
,
const
operation
&
op
)
{
{
std
::
string
x
=
to_string
(
op
);
std
::
string
x
=
to_string
(
op
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment