Skip to content

Commit

Permalink
fix callprivatearg for malformed .tac
Browse files Browse the repository at this point in the history
  • Loading branch information
ruaronicola committed Apr 15, 2023
1 parent 25d61b7 commit de69f59
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion greed/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import networkx as nx

from collections import defaultdict

from greed.TAC.TAC_parser import TAC_parser
from greed.TAC.gigahorse_ops import TAC_Callprivateargs
from greed.factory import Factory
Expand All @@ -23,10 +25,13 @@ def __init__(self, target_dir: str):
self.function_at = self.tac_parser.parse_functions()

# inject CALLPRIVATEARGS fake statements
_fake_counters = defaultdict(int)
for function in self.function_at.values():
for arg in function.arguments[::-1]:
root_block = self.factory.block(function.id)
fake_statement = TAC_Callprivateargs(block_id=root_block.id, stmt_id=f"fake_{arg}", defs=[arg])
_counter = _fake_counters[arg]
_fake_counters[arg] += 1
fake_statement = TAC_Callprivateargs(block_id=root_block.id, stmt_id=f"fake_{arg}_{_counter}", defs=[arg])
root_block.statements.insert(0, fake_statement)
self.statement_at[fake_statement.id] = fake_statement

Expand Down

0 comments on commit de69f59

Please sign in to comment.