diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-05 08:04:40 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-05 08:04:40 +0100 |
commit | 965b35d6ae356a0aed8b7a044af62e868f1fab4e (patch) | |
tree | 6caf2dc628947f27a99f391bfb66c69cc933168e | |
parent | 4e37798145fa03bd90880f4ac315529190472eaf (diff) |
read instance name from PTA/DFA yaml file
-rwxr-xr-x | bin/generate-dfa-benchmark.py | 11 | ||||
-rwxr-xr-x | lib/automata.py | 8 |
2 files changed, 14 insertions, 5 deletions
diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py index 87cb662..4789ad7 100755 --- a/bin/generate-dfa-benchmark.py +++ b/bin/generate-dfa-benchmark.py @@ -51,6 +51,12 @@ if __name__ == '__main__': print(harness.start_benchmark()) + class_prefix = '' + if 'instance' in opt: + class_prefix = '{}.'.format(opt['instance']) + elif pta.instance: + class_prefix = '{}.'.format(pta.instance) + for run in pta.dfs(opt['depth'], with_arguments = True): print(harness.start_run()) for transition, arguments in run: @@ -59,10 +65,7 @@ if __name__ == '__main__': print('// wait for {} interrupt'.format(transition.name)) transition_code = '// TODO add startTransition / stopTransition calls to interrupt routine' else: - if 'instance' in opt: - transition_code = '{}.{}({});'.format(opt['instance'], transition.name, ', '.join(map(str, arguments))) - else: - transition_code = '{}({});'.format(transition.name, ', '.join(arguments)) + transition_code = '{}{}({});'.format(class_prefix, transition.name, ', '.join(map(str, arguments))) print(harness.pass_transition(pta.get_transition_id(transition), transition_code)) if 'sleep' in opt: diff --git a/lib/automata.py b/lib/automata.py index 96a724e..2d5c27c 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -258,7 +258,8 @@ class PTA: def __init__(self, state_names: list = [], accepting_states: list = None, - parameters: list = [], initial_param_values: list = None): + parameters: list = [], initial_param_values: list = None, + instance: str = None): """ Return a new PTA object. @@ -268,10 +269,12 @@ class PTA: accepting_states -- names of accepting states. By default, all states are accepting parameters -- names of PTA parameters initial_param_values -- initial value for each parameter + instance -- class used for generated C++ code """ self.state = dict([[state_name, State(state_name)] for state_name in state_names]) self.accepting_states = accepting_states.copy() if accepting_states else None self.parameters = parameters.copy() + self.instance = instance if initial_param_values: self.initial_param_values = initial_param_values.copy() else: @@ -380,6 +383,9 @@ class PTA: if 'states' in yaml_input: kwargs['state_names'] = yaml_input['states'] + if 'instance' in yaml_input: + kwargs['instance'] = yaml_input['instance'] + pta = cls(**kwargs) for trans_name in sorted(yaml_input['transition'].keys()): |