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
254f187e
Commit
254f187e
authored
May 10, 2018
by
Paul
Browse files
Validate on eval
parent
c4bc243a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
include/rtg/instruction.hpp
include/rtg/instruction.hpp
+12
-0
include/rtg/program.hpp
include/rtg/program.hpp
+2
-0
src/program.cpp
src/program.cpp
+8
-0
No files found.
include/rtg/instruction.hpp
View file @
254f187e
...
...
@@ -61,6 +61,18 @@ struct instruction
return
std
::
addressof
(
i
)
==
std
::
addressof
(
*
ref
);
}
bool
valid
()
const
{
return
std
::
all_of
(
output
.
begin
(),
output
.
end
(),
[
&
](
instruction_ref
i
)
{
return
std
::
find
(
i
->
arguments
.
begin
(),
i
->
arguments
.
end
(),
*
this
)
!=
i
->
arguments
.
end
();
})
&&
std
::
all_of
(
arguments
.
begin
(),
arguments
.
end
(),
[
&
](
instruction_ref
i
)
{
return
std
::
find
(
i
->
output
.
begin
(),
i
->
output
.
end
(),
*
this
)
!=
i
->
output
.
end
();
});
}
friend
bool
operator
==
(
instruction_ref
ref
,
const
instruction
&
i
)
{
return
i
==
ref
;
}
friend
bool
operator
!=
(
const
instruction
&
i
,
instruction_ref
ref
)
{
return
!
(
i
==
ref
);
}
...
...
include/rtg/program.hpp
View file @
254f187e
...
...
@@ -63,6 +63,8 @@ struct program
instruction_ref
begin
();
instruction_ref
end
();
instruction_ref
validate
()
const
;
private:
std
::
unique_ptr
<
program_impl
>
impl
;
};
...
...
src/program.cpp
View file @
254f187e
...
...
@@ -72,8 +72,16 @@ bool program::has_instruction(instruction_ref ins) const
instruction_ref
program
::
begin
()
{
return
impl
->
instructions
.
begin
();
}
instruction_ref
program
::
end
()
{
return
impl
->
instructions
.
end
();
}
instruction_ref
program
::
validate
()
const
{
return
std
::
find_if
(
impl
->
instructions
.
begin
(),
impl
->
instructions
.
end
(),
[](
const
instruction
&
i
)
{
return
i
.
valid
();
});
}
literal
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
{
assert
(
this
->
validate
()
!=
impl
->
instructions
.
end
());
std
::
unordered_map
<
const
instruction
*
,
argument
>
results
;
argument
result
;
for
(
auto
&
ins
:
impl
->
instructions
)
...
...
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