reuse symbolic types across transformations to save Z3 syms & memory
MODIFY
tools/alive.cpp
tools/alive.cpp
@@ -75,7 +75,7 @@ int main(int argc, char **argv) {
}
smt::smt_initializer smt_init;
- init_parser();
+ parser_initializer parser_init;
TransformPrintOpts print_opts;
print_opts.print_fn_header = false;

MODIFY
tools/alive_parser.cpp
tools/alive_parser.cpp
@@ -131,6 +131,9 @@ static Type& parse_type(bool optional = true) {
default:
if (optional) {
tokenizer.unget(t);
+ if (sym_num < sym_types.size())
+ return *sym_types[sym_num++].get();
+
auto t = make_unique<SymbolicType>("symty_" + to_string(sym_num++));
return *sym_types.emplace_back(move(t)).get();
} else {
@@ -421,10 +424,10 @@ vector<Transform> parse(string_view buf) {
vector<Transform> ret;
yylex_init(buf);
- sym_num = 0;
while (!tokenizer.empty()) {
auto &t = ret.emplace_back();
+ sym_num = 0;
parse_name(t);
parse_pre(t);
parse_fn(t.src);
@@ -436,7 +439,8 @@ vector<Transform> parse(string_view buf) {
return ret;
}
-void init_parser() {
+
+parser_initializer::parser_initializer() {
int_types.emplace_back(nullptr);
for (unsigned i = 1; i <= 64; ++i) {
@@ -444,4 +448,9 @@ void init_parser() {
}
}
+parser_initializer::~parser_initializer() {
+ int_types.clear();
+ sym_types.clear();
+}
+
}

MODIFY
tools/alive_parser.h
tools/alive_parser.h
namespace tools {
-std::vector<tools::Transform> parse(std::string_view buf);
-void init_parser();
+std::vector<Transform> parse(std::string_view buf);
+
+struct parser_initializer {
+ parser_initializer();
+ ~parser_initializer();
+};
+
struct ParseException {
std::string str;

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -172,7 +172,9 @@ TypingAssignments TransformVerify::getTypings() const {
}
for (auto &i : t.src.getInputs()) {
- c &= i.getType() == tgt_inputs.at(i.getName())->getType();
+ auto tgt_i = tgt_inputs.find(i.getName());
+ if (tgt_i != tgt_inputs.end())
+ c &= i.getType() == tgt_i->second->getType();
}
}

reuse symbolic types across transformations to save Z3 syms & memory