From 21fc618006e491c06a27ecba187af980d5f2df9a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 24 Jul 2016 01:52:36 -0700 Subject: 3142 Rewrite ingredients for 'trace' instructions just like 'stash' instructions. --- 062rewrite_stash.cc | 67 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/062rewrite_stash.cc b/062rewrite_stash.cc index 5c6f28ca..adac8236 100644 --- a/062rewrite_stash.cc +++ b/062rewrite_stash.cc @@ -11,6 +11,15 @@ recipe main [ +transform: {stash_2_0: ("address" "array" "character")} <- to-text-line {n: "number"} +transform: stash {stash_2_0: ("address" "array" "character")} +:(scenario rewrite_traces_to_text) +recipe main [ + local-scope + n:number <- copy 34 + trace 2, [app], n +] ++transform: {trace_2_2: ("address" "array" "character")} <- to-text-line {n: "number"} ++transform: trace {2: "literal"}, {"app": "literal-string"}, {trace_2_2: ("address" "array" "character")} + //: special case: rewrite attempts to stash contents of most arrays to avoid //: passing addresses around @@ -50,32 +59,16 @@ void rewrite_stashes_to_text(recipe& caller) { instruction& inst = caller.steps.at(i); if (inst.name == "stash") { for (int j = 0; j < SIZE(inst.ingredients); ++j) { - if (!inst.ingredients.at(j).type) { - // error; will be handled elsewhere - continue; - } - if (is_literal(inst.ingredients.at(j))) continue; - if (is_mu_string(inst.ingredients.at(j))) continue; - // don't try to extend static arrays - if (is_static_array(inst.ingredients.at(j))) continue; - instruction def; - if (is_lookup_of_address_of_array(inst.ingredients.at(j))) { - def.name = "array-to-text-line"; - reagent/*copy*/ tmp = inst.ingredients.at(j); - drop_one_lookup(tmp); - def.ingredients.push_back(tmp); - } - else { - def.name = "to-text-line"; - def.ingredients.push_back(inst.ingredients.at(j)); - } ostringstream ingredient_name; ingredient_name << "stash_" << i << '_' << j << ":address:array:character"; - def.products.push_back(reagent(ingredient_name.str())); - trace(9993, "transform") << to_string(def) << end(); - new_instructions.push_back(def); - inst.ingredients.at(j).clear(); // reclaim old memory - inst.ingredients.at(j) = reagent(ingredient_name.str()); + rewrite_stash_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str()); + } + } + else if (inst.name == "trace") { + for (int j = /*skip*/2; j < SIZE(inst.ingredients); ++j) { + ostringstream ingredient_name; + ingredient_name << "trace_" << i << '_' << j << ":address:array:character"; + rewrite_stash_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str()); } } trace(9993, "transform") << to_string(inst) << end(); @@ -84,6 +77,32 @@ void rewrite_stashes_to_text(recipe& caller) { caller.steps.swap(new_instructions); } +// add an instruction to convert reagent 'r' to text in list 'out', then +// replace r with converted text +void rewrite_stash_to_text(reagent& r, vector& out, const string& tmp_var) { + if (!r.type) return; // error; will be handled elsewhere + if (is_literal(r)) return; + if (is_mu_string(r)) return; + // don't try to extend static arrays + if (is_static_array(r)) return; + instruction def; + if (is_lookup_of_address_of_array(r)) { + def.name = "array-to-text-line"; + reagent/*copy*/ tmp = r; + drop_one_lookup(tmp); + def.ingredients.push_back(tmp); + } + else { + def.name = "to-text-line"; + def.ingredients.push_back(r); + } + def.products.push_back(reagent(tmp_var)); + trace(9993, "transform") << to_string(def) << end(); + out.push_back(def); + r.clear(); // reclaim old memory + r = reagent(tmp_var); +} + bool is_lookup_of_address_of_array(reagent/*copy*/ x) { if (x.type->name != "address") return false; if (!canonize_type(x)) return false; -- cgit 1.4.1-2-gfad0