diff --git a/ir/expression.def b/ir/expression.def index d2130453f8f..7c58a4d6d81 100644 --- a/ir/expression.def +++ b/ir/expression.def @@ -12,6 +12,7 @@ abstract Operation_Unary : Operation { if (!srcInfo && expr) srcInfo = expr->srcInfo; if (type->is<Type::Unknown>() && expr) type = expr->type; } precedence = DBPrint::Prec_Prefix; + toString{ return getStringOp() + expr->toString(); } } class Neg : Operation_Unary { @@ -37,6 +38,11 @@ abstract Operation_Binary : Operation { if (!srcInfo && left && right) srcInfo = left->srcInfo + right->srcInfo; if (type->is<Type::Unknown>() && left && right && left->type == right->type) type = left->type; } + toString { + std::stringstream tmp; + tmp << DBPrint::Prec_Low << *this; + return tmp.str(); + } } abstract Operation_Ternary : Operation { @@ -374,7 +380,7 @@ class Cast : Operation_Unary { /// type, and 'type' will only be updated later when type inferencing occurs precedence = DBPrint::Prec_Prefix; stringOp = "(cast)"; - toString{ return "cast"; } + toString{ return "(" + destType->toString() + ")" + expr->toString(); } validate{ BUG_CHECK(!destType->is<Type_Unknown>(), "%1%: Cannot cast to unknown type", this); } } diff --git a/ir/json_generator.h b/ir/json_generator.h index e9a43367fe9..69076009716 100644 --- a/ir/json_generator.h +++ b/ir/json_generator.h @@ -195,29 +195,7 @@ class JSONGenerator { void generate(cstring v) { if (v) { - out << "\""; - for (auto ch : v) { - switch (ch) { - case '\n': - out << "\\n"; - break; - case '\r': - out << "\\r"; - break; - case '\t': - out << "\\t"; - break; - case '\"': - out << "\\\""; - break; - case '\\': - out << "\\\\"; - break; - default: - out << ch; - } - } - out << "\""; + out << "\"" << v.escapeJson() << "\""; } else { out << "null"; } diff --git a/midend/local_copyprop.h b/midend/local_copyprop.h index f53832ecd56..6a335a518a0 100644 --- a/midend/local_copyprop.h +++ b/midend/local_copyprop.h @@ -150,6 +150,9 @@ class LocalCopyPropagation : public PassManager { passes.push_back(typeChecking); passes.push_back(new DoLocalCopyPropagation(refMap, typeMap, policy, elimUnusedTables)); } + LocalCopyPropagation(ReferenceMap *refMap, TypeMap *typeMap, + std::function<bool(const Context *, const IR::Expression *)> policy) + : LocalCopyPropagation(refMap, typeMap, nullptr, policy) {} }; } // namespace P4