Skip to content

Commit

Permalink
adding get_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
tutugordillo committed Aug 2, 2024
1 parent ada3c1d commit 3264a6e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/parser/utils_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,28 @@ def get_empty_spec():
spec["rules"] = ""

return spec

#It returns the expression that a instruction takes as argument
#It returns a expression of the form:
# op -> opcode_name
# exp -> [int_val] | [input_var] | [op, [exp]]

def get_expression(var, instructions):
if var.startswith("0x"):
return [var]

candidates = list(filter(lambda x: var in x.get_out_args(), instructions))
if len(candidates) == 0:
return [var]

assert(len(candidates) == 1, "[ERROR]: A variable cannot be generated by more than one instruction")

new_instruction = candidates[0]

sub_expression = []
for v in new_instruction.get_in_args():
new_subexp = get_expression(v,instructions)
sub_expression.append(new_subexp)

return [new_instruction.get_op_name(),sub_expression]

0 comments on commit 3264a6e

Please sign in to comment.