summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-22 14:32:07 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-22 14:32:07 +0100
commit5aa3a8d691c7a0a4b7eda3546b61281bb8638932 (patch)
tree3b320f47714f6c0df2bebba6e4a3c7c09da6afb9
parent74c43f1af8c222256a37f65288e68e9a0fef4886 (diff)
add ptalog to dfa benchmark generation
-rwxr-xr-xbin/generate-dfa-benchmark.py8
-rwxr-xr-xlib/automata.py3
2 files changed, 11 insertions, 0 deletions
diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py
index 8bb8943..1eb5073 100755
--- a/bin/generate-dfa-benchmark.py
+++ b/bin/generate-dfa-benchmark.py
@@ -39,20 +39,28 @@ if __name__ == '__main__':
with open(modelfile, 'r') as f:
pta = PTA.from_json(json.load(f))
+ print('ptalog.startBenchmark(0);')
+
for run in pta.dfs(opt['depth'], with_arguments = True):
+ print('ptalog.reset();')
for transition, arguments in run:
print('// {} -> {}'.format(transition.origin.name, transition.destination.name))
+ print('ptalog.passTransition({:d});'.format(pta.get_transition_id(transition)))
if transition.is_interrupt:
print('// wait for {} interrupt'.format(transition.name))
+ print('// TODO add startTransition / stopTransition calls to interrupt routine')
else:
+ print('ptalog.startTransition();')
if 'instance' in opt:
print('{}.{}({});'.format(opt['instance'], transition.name, ', '.join(arguments)))
else:
print('{}({});'.format(transition.name, ', '.join(arguments)))
+ print('ptalog.stopTransition();')
if 'sleep' in opt:
print('arch.delay_ms({:d});'.format(opt['sleep']))
+ print('ptalog.dump();')
print()
sys.exit(0)
diff --git a/lib/automata.py b/lib/automata.py
index 37b52e1..7db1ebf 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -411,6 +411,9 @@ class PTA:
self.transitions.append(new_transition)
orig_state.add_outgoing_transition(new_transition)
+ def get_transition_id(self, transition: Transition) -> int:
+ return self.transitions.index(transition)
+
def dfs(self, depth: int = 10, orig_state: str = 'UNINITIALIZED', **kwargs):
"""
Return a generator object for depth-first search starting at orig_state.