From 12a4365b56b0609087c5228bdd26fbe02b54f7cf Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Mon, 24 Aug 2020 17:20:17 -0600 Subject: [PATCH] reorder and check to make sure we can invoke the simulator and the associated harness twice --- python_arborist.py | 87 ++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/python_arborist.py b/python_arborist.py index 41dea07..0f46f30 100644 --- a/python_arborist.py +++ b/python_arborist.py @@ -265,9 +265,10 @@ class Cirno(Elaboratable): return m -def run_the_sim(): +def run_the_sim(parse_me): m = Module() m.submodules.baka = nine = Cirno() + trace = [] def process(): while True: @@ -306,6 +307,7 @@ def run_the_sim(): for x in trace: print(x) + return trace top_bit = (1<<16) @@ -366,6 +368,21 @@ def deserializer(serialized_array, last_idx_written): print("physical to logical mapping is", physical_to_logical) return (new_node, random_triggered) +def are_trees_equal(tree_one_root, tree_two_root): # returns True if equal, False otherwise + if (tree_one_root.language_element != tree_two_root.language_element): + return False + if (len(tree_one_root.subnodes) != len(tree_two_root.subnodes)): + return False + + for idx, elem in enumerate(tree_one_root.subnodes): + if(are_trees_equal(elem, tree_two_root.subnodes[idx]) == False): + return False + + if ((len(tree_one_root.subnodes) == 0) and (len(tree_two_root.subnodes) == 0) and (tree_one_root.language_element == tree_two_root.language_element)): + return True + + return True + tokens ={ "BOTTOM": 0x5a00, @@ -418,62 +435,42 @@ list_of_nonterminals = [EXPRESSION, TERM, FACTOR] list_of_terminals = [INTEGER, ADDOP, MULTOP, OPENPAREN, CLOSEPAREN] -z = CFGBoltzmann.CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) -cooked_rules = z.preprocessor() -bgen = z.Gzero_shimmed(EXPRESSION, 5) -parse_me = bgen[0] - - -parse_me.append(ENDOFPARSE) -trace = [] - - -run_the_sim() - -serialized_tree_final = trace[-1] -print() -print("DESER TREE FINAL is " '[{}]'.format(', '.join(hex(x) for x in serialized_tree_final))) - - - - - +z = CFGBoltzmann.CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) +cooked_rules = z.preprocessor() +def do_an_iteration(): + bgen = z.Gzero_shimmed(EXPRESSION, 5) + parse_me = bgen[0] -(parser_output_tree, random_trig) = deserializer(serialized_tree_final, 30) + parse_me.append(ENDOFPARSE) + + trace = run_the_sim(parse_me) -walk_the_tree(parser_output_tree,0) + serialized_tree_final = trace[-1] + print() + print("DESER TREE FINAL is " '[{}]'.format(', '.join(hex(x) for x in serialized_tree_final))) -#print("derivation tree was") -#walk_the_tree(bgen[1]) -print("reversed derivation tree is") -z.reversiflip(bgen[1]) -walk_the_tree(bgen[1]) + (parser_output_tree, random_trig) = deserializer(serialized_tree_final, 30) -print("THE ORIGINAL STRING WAS", [hex_to_name(x) for x in parse_me]) + walk_the_tree(parser_output_tree,0) + #print("derivation tree was") + #walk_the_tree(bgen[1]) -def are_trees_equal(tree_one_root, tree_two_root): # returns True if equal, False otherwise - if (tree_one_root.language_element != tree_two_root.language_element): - return False - if (len(tree_one_root.subnodes) != len(tree_two_root.subnodes)): - return False - - for idx, elem in enumerate(tree_one_root.subnodes): - if(are_trees_equal(elem, tree_two_root.subnodes[idx]) == False): - return False - - if ((len(tree_one_root.subnodes) == 0) and (len(tree_two_root.subnodes) == 0) and (tree_one_root.language_element == tree_two_root.language_element)): - return True - - return True + print("reversed derivation tree is") + z.reversiflip(bgen[1]) + walk_the_tree(bgen[1]) + print("THE ORIGINAL STRING WAS", [hex_to_name(x) for x in parse_me]) + print("WAS RANDOM TRIGGERED??", random_trig) + print("ARE TREES EQUAL???", are_trees_equal(bgen[1], parser_output_tree)) +do_an_iteration() +print("DOING IT A SECOND TIME XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") -print("WAS RANDOM TRIGGERED??", random_trig) -print("ARE TREES EQUAL???", are_trees_equal(bgen[1], parser_output_tree)) +do_an_iteration() \ No newline at end of file -- GitLab