def test_snippets(self): for input, output in self.working_snippets: lexer = interpret.Lexer(input) parser = interpret.Parser(lexer) interpreter = interpret.Interpreter(parser) result = interpreter.interpret() self.assertEqual(result, output)
def result(): try: result = request.args.get('prog', 0, type=str) lexer = interpret.Lexer(result) parser = interpret.Parser(lexer) interpreter = interpret.Interpreter(parser) done = interpreter.interpret() return jsonify(result=done) except Exception as e: return jsonify(result=str(e))
parser.add_argument("--source", dest="source", help="Path to input XML file", default="STDIN") parser.add_argument("--input", dest="input", help="Path a file with inputs used as STDIN inputs", default="STDIN") args = parser.parse_args() if args.source == args.input == "STDIN": print("At least one argument of --input, --source must be specified!", file=sys.stderr) exit(10) # TODO check if args.source exists! interpret = INPR.Interpreter() interpret.get_labels(args.source) xml_tree = XML.parse(args.source) # Get the XML tree root = xml_tree.getroot() instruction_count = len(root.getchildren()) - 1 current = 0 instructions = root.getchildren() instructions = sorted(instructions, key=lambda x: int(x.attrib["order"])) while current <= instruction_count: print("++++++++++++++++++++++++++++++++++++++++++", instructions[current].attrib["opcode"], "****") return_value = interpret.interpret_instruction(instructions[current]) print("++++++++++++++++++++++++++++++++++++++++++",
def generate_generators( self, gen_template_name="templates/generators/12.mako", common_template_name="templates/generators/common2.mako"): """ Generates the generators for the RHS for the invariant/postcondition. """ from mako.template import Template import re common_template = Template(filename=common_template_name) gen_template = Template(filename=gen_template_name) # find candidate expressions for array LDs candidates = ArrLDFinder().find(self.program, self.get_loopvars()) filtered_candidates = list(set(map(tree_to_str, candidates))) logging.debug("Candidate expressions for array LDs: %s", filtered_candidates) ret = common_template.render( loopvar=self.get_loopvars(), int_params=[x[0] for x in self.inputs if x[1] == "int"] + self.get_loopvars(), array_sz_candidates=filtered_candidates, arrays=[x[0] for x in self.inputs if re.search("\[", x[1])]) # find candidate array accesses candidate_accesses = SketchGeneratorLevel5.FindAccesses().find( self.program, self.get_loopvars()) logging.debug("Candidate array accesses: %s", candidate_accesses) # interpret the loop nest to find the overall structure import interpret inputs = [x for x in self.inputs if x[0] not in self.get_out_array()] outputs = [x for x in self.inputs if x[0] in self.get_out_array()] logging.debug("Interpreter inputs: %s", inputs) logging.debug("Interpreter outputs: %s", outputs) interpreter_result = interpret.Interpreter(inputs, outputs).interpret( self.program) pcon_guess = interpret.Guesser( inputs, outputs).guess_postcondition(interpreter_result) logging.debug("Postcondition guess: %s", pcon_guess) # compute aggregates across all loops all_invariants = {} for invariant in self.invariant_names_to_loops.keys(): node = self.invariant_names_to_loops[invariant] thiskey = loop_key(node) var = node.iter_var.name all_invariants[thiskey] = var for arr in self.get_out_array(): # we want all the arrays that are not output # this is because even if we use the output arrays in a RAW manner, we want to # construct our conditions in terms of the inputs arraynames = [ x[0] for x in self.inputs if re.search("\[", x[1]) and x[0] not in self.get_out_array() ] ret += gen_template.render( parameters=self.get_params() + ", " + ','.join(["int " + x for x in self.get_loopvars()]), call_params=self.get_params_without_types() + ", " + ','.join(self.get_loopvars()), outarray=arr, all_invariants=all_invariants, pcon_guess=pcon_guess[arr], candidate_accesses=candidate_accesses, int_params=[x[0] for x in self.inputs if x[1] == "int"] + self.get_loopvars(), float_params=[(x[1], x[0]) for x in self.inputs if x[1] == "double" or x[1] == "float"], arraynames=arraynames, loopvar=self.get_loopvars()) return ret