Skip to content

Commit

Permalink
repair: try to fix add guard
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Jan 9, 2024
1 parent 708dbb5 commit 7125565
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 9 additions & 6 deletions rtlrepair.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'conditional_overwrite': conditional_overwrite,
'add_guard': add_guard,
}
#_default_templates = ['replace_literals', 'assign_const', 'add_guard']
# _default_templates = ['replace_literals', 'assign_const', 'add_guard']
_default_templates = ['replace_literals', 'add_guard', 'conditional_overwrite']


Expand Down Expand Up @@ -130,10 +130,13 @@ def find_solver_version(solver: str) -> str:
r = subprocess.run([solver] + arg, check=True, stdout=subprocess.PIPE)
return r.stdout.decode('utf-8').splitlines()[0].strip()


# return this if the synthesizer did not run or did not run properly (i.e. crashed)
NoSynthStat = SynthStats(solver_time_ns=0, past_k=-1, future_k=-1)

def try_template(config: Config, ast, prefix: str, template, statistics: dict, analysis: AnalysisResults) -> (Status, list):

def try_template(config: Config, ast, prefix: str, template, statistics: dict, analysis: AnalysisResults) -> (
Status, list):
if config.opts.per_template_timeout is not None:
signal.alarm(int(math.ceil(config.opts.per_template_timeout)))

Expand All @@ -159,8 +162,8 @@ def try_template(config: Config, ast, prefix: str, template, statistics: dict, a
if config.opts.per_template_timeout is not None:
status, assignments, synth_stats = Status.Timeout, [], NoSynthStat
else:
assert config.opts.timeout is not None # global timeout instead!
raise e # dispatch to top
assert config.opts.timeout is not None # global timeout instead!
raise e # dispatch to top
except subprocess.CalledProcessError:
# something crashed, so we cannot repair this bug
status, assignments, synth_stats = Status.CannotRepair, [], NoSynthStat
Expand Down Expand Up @@ -285,7 +288,7 @@ def check_verilator_version(opts: Options):

def main():
config = parse_args()
assert not (config.opts.timeout and config.opts.per_template_timeout),\
assert not (config.opts.timeout and config.opts.per_template_timeout), \
"timeout and template-timeout options are not compatible!"

check_verilator_version(config.opts)
Expand All @@ -306,7 +309,7 @@ def main():
except TimeoutError:
status, solutions = Status.Timeout, []
delta_time = time.monotonic() - start_time
statistics['total_time'] = delta_time
statistics['total_time'] = delta_time

# save results to disk
success = status in {Status.Success, Status.NoRepair}
Expand Down
7 changes: 6 additions & 1 deletion rtlrepair/templates/add_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ def build_guard_item(self, atoms: list[vast.Node]) -> vast.Node:


def find_atoms(lvars: set[str], a: AnalysisResults) -> list[vast.Node]:
verbose = False
atoms = []
l_deps = set() if len(lvars) == 0 else set.union(*[a.vars[v].depends_on for v in lvars])
if verbose:
print(f"l_deps={l_deps}")
for var in a.vars.values():
# we are only interested in 1-bit vars
if var.width != 1:
Expand All @@ -123,7 +126,9 @@ def find_atoms(lvars: set[str], a: AnalysisResults) -> list[vast.Node]:
if len(lvar_deps) > 0 or var.name in lvars:
continue
# check to see if we would create a new dependency
new_deps = var.depends_on - l_deps
if verbose:
print(f"{var.name}.depends_on = {var.depends_on}")
new_deps = (var.depends_on | {var.name}) - l_deps
if len(new_deps) > 0:
continue
# otherwise this might be a good candidate
Expand Down

0 comments on commit 7125565

Please sign in to comment.