the new rewriter interface supports running patterns over an Op's children matching Ops that conform to a pattern, and rewriting Ops in arbitrary ways.
24 lines
519 B
C
24 lines
519 B
C
#include <mie/rewrite/pattern.h>
|
|
|
|
enum mie_match_result mie_pattern_match(
|
|
const struct mie_pattern *pattern, const struct mie_op *op)
|
|
{
|
|
if (!pattern->p_match) {
|
|
return MIE_NO_MATCH_FOUND;
|
|
}
|
|
|
|
return pattern->p_match(op);
|
|
}
|
|
|
|
struct mie_rewrite_result mie_pattern_rewrite(
|
|
const struct mie_pattern *pattern, struct mie_op *op,
|
|
struct mie_rewriter *rewriter)
|
|
{
|
|
if (!pattern->p_rewrite) {
|
|
return MIE_REWRITE_RESULT(
|
|
MIE_REWRITE_FAILURE, MIE_ERR_NOT_SUPPORTED);
|
|
}
|
|
|
|
return pattern->p_rewrite(op, rewriter);
|
|
}
|