Commit c22b3857 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Test instantiation

parent 04f80b2d
...@@ -350,55 +350,56 @@ LD_LIBRARY_PATH=. opengeode-simulator ...@@ -350,55 +350,56 @@ LD_LIBRARY_PATH=. opengeode-simulator
context_decl.append(u'pragma import (C, ctxt, "{}_ctxt");' context_decl.append(u'pragma import (C, ctxt, "{}_ctxt");'
.format(import_context)) .format(import_context))
if not simu: if not simu and not instance:
process_level_decl.extend(context_decl) process_level_decl.extend(context_decl)
# Continuous State transition id
process_level_decl.append('CS_Only : constant Integer := {};'
.format(len(process.transitions)))
for name, val in process.mapping.viewitems():
# Test val, in principle there is a value but if the code targets
# generation of properties, the model may have been cleant up and
# in that case no value would be set..
if name.endswith(u'START') and name != u'START' and val:
process_level_decl.append(u'{name} : constant := {val};'
.format(name=name, val=str(val)))
# Declare start procedure for aggregate states XXX add in C generator
# should create one START per "via" clause, TODO later
aggreg_start_proc = [] aggreg_start_proc = []
for name, substates in aggregates.viewitems(): start_transition = []
proc_name = u'procedure {}{}START'.format(name, UNICODE_SEP) # Continuous State transition id
process_level_decl.append(u'{};'.format(proc_name)) if not instance:
aggreg_start_proc.extend([u'{} is'.format(proc_name), process_level_decl.append('CS_Only : constant Integer := {};'
'begin']) .format(len(process.transitions)))
aggreg_start_proc.extend(u'runTransition({sub}{sep}START);'
.format(sub=subname.statename, for name, val in process.mapping.viewitems():
sep=UNICODE_SEP) # Test val, in principle there is a value but if the code targets
for subname in substates) # generation of properties, the model may have been cleant up and
aggreg_start_proc.extend([u'end {}{}START;' # in that case no value would be set..
.format(name, UNICODE_SEP), if name.endswith(u'START') and name != u'START' and val:
'\n']) process_level_decl.append(u'{name} : constant := {val};'
.format(name=name, val=str(val)))
# Add the declaration of the runTransition procedure
process_level_decl.append('procedure runTransition(Id: Integer);') # Declare start procedure for aggregate states XXX add in C generator
# should create one START per "via" clause, TODO later
# Generate the code of the start transition (if process not empty) for name, substates in aggregates.viewitems():
initDone = u'{ctxt}.initDone := True;'.format(ctxt=LPREFIX) proc_name = u'procedure {}{}START'.format(name, UNICODE_SEP)
if not simu: process_level_decl.append(u'{};'.format(proc_name))
start_transition = [u'begin'] aggreg_start_proc.extend([u'{} is'.format(proc_name),
if process.transitions: 'begin'])
start_transition.append(u'runTransition(0);') aggreg_start_proc.extend(u'runTransition({sub}{sep}START);'
start_transition.append(initDone) .format(sub=subname.statename,
else: sep=UNICODE_SEP)
start_transition = [u'procedure Startup is', for subname in substates)
u'begin', aggreg_start_proc.extend([u'end {}{}START;'
u' runTransition(0);' if process.transitions .format(name, UNICODE_SEP),
else 'null;', '\n'])
initDone,
u'end Startup;'] # Add the declaration of the runTransition procedure
process_level_decl.append('procedure runTransition(Id: Integer);')
# Generate the code of the start transition (if process not empty)
initDone = u'{ctxt}.initDone := True;'.format(ctxt=LPREFIX)
if not simu:
start_transition = [u'begin']
if process.transitions:
start_transition.append(u'runTransition(0);')
start_transition.append(initDone)
else:
start_transition = [u'procedure Startup is',
u'begin',
u' runTransition(0);' if process.transitions
else 'null;',
initDone,
u'end Startup;']
# Generate the TASTE template # Generate the TASTE template
try: try:
...@@ -409,7 +410,7 @@ LD_LIBRARY_PATH=. opengeode-simulator ...@@ -409,7 +410,7 @@ LD_LIBRARY_PATH=. opengeode-simulator
asn1_modules += '\nwith adaasn1rtl;\nuse adaasn1rtl;' asn1_modules += '\nwith adaasn1rtl;\nuse adaasn1rtl;'
except TypeError: except TypeError:
asn1_modules = '-- No ASN.1 data types are used in this model' asn1_modules = '-- No ASN.1 data types are used in this model'
taste_template = ['''\ taste_template = [u'''\
-- This file was generated automatically: DO NOT MODIFY IT ! -- This file was generated automatically: DO NOT MODIFY IT !
with System.IO; with System.IO;
...@@ -427,7 +428,8 @@ package body {process_name} is'''.format(process_name=process_name, ...@@ -427,7 +428,8 @@ package body {process_name} is'''.format(process_name=process_name,
dataview=asn1_modules, dataview=asn1_modules,
C='with Interfaces.C.Strings;\n' C='with Interfaces.C.Strings;\n'
'use Interfaces.C.Strings;' 'use Interfaces.C.Strings;'
if simu else '')] if simu else '') if not instance
else u"package body {} is".format(process_name)]
generic_spec, instance_decl = "", "" generic_spec, instance_decl = "", ""
if generic: if generic:
...@@ -633,7 +635,8 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -633,7 +635,8 @@ package {process_name} is'''.format(generic=generic_spec,
else: else:
taste_template.append('runTransition(CS_Only);') taste_template.append('runTransition(CS_Only);')
taste_template.append('case {}.state is'.format(LPREFIX)) if not instance:
taste_template.append('case {}.state is'.format(LPREFIX))
def case_state(state): def case_state(state):
''' Recursive function (in case of state aggregation) to generate ''' Recursive function (in case of state aggregation) to generate
...@@ -673,11 +676,17 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -673,11 +676,17 @@ package {process_name} is'''.format(generic=generic_spec,
else: else:
execute_transition(state) execute_transition(state)
map(case_state, reduced_statelist) # XXX update C generator if not instance:
map(case_state, reduced_statelist) # XXX update C generator
taste_template.append('when others =>')
taste_template.append('runTransition(CS_Only);')
taste_template.append('end case;')
else:
inst_call = u"{}_Instance.{}".format(process_name, signame)
if 'type' in signal:
inst_call += u"({})".format(param_name)
taste_template.append(inst_call + ";")
taste_template.append('when others =>')
taste_template.append('runTransition(CS_Only);')
taste_template.append('end case;')
taste_template.append(u'end {};'.format(signame)) taste_template.append(u'end {};'.format(signame))
taste_template.append('\n') taste_template.append('\n')
...@@ -859,7 +868,6 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -859,7 +868,6 @@ package {process_name} is'''.format(generic=generic_spec,
if ri_inst: if ri_inst:
pkg_decl += u" ({})".format(u", ".join(ri_inst)) pkg_decl += u" ({})".format(u", ".join(ri_inst))
ads_template.append(pkg_decl + u";") ads_template.append(pkg_decl + u";")
ads_template.append(u"use {}_Instance;".format(process_name))
if simu and process.cs_mapping: if simu and process.cs_mapping:
# Callback registration for Check_Queue # Callback registration for Check_Queue
...@@ -895,7 +903,7 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -895,7 +903,7 @@ package {process_name} is'''.format(generic=generic_spec,
code_labels.extend(code_label) code_labels.extend(code_label)
# Generate the code of the runTransition procedure, if needed # Generate the code of the runTransition procedure, if needed
if process.transitions: if process.transitions and not instance:
taste_template.append('procedure runTransition(Id: Integer) is') taste_template.append('procedure runTransition(Id: Integer) is')
taste_template.append('trId : Integer := Id;') taste_template.append('trId : Integer := Id;')
if process.cs_mapping: if process.cs_mapping:
...@@ -1040,7 +1048,7 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -1040,7 +1048,7 @@ package {process_name} is'''.format(generic=generic_spec,
taste_template.append('end loop;') taste_template.append('end loop;')
taste_template.append('end runTransition;') taste_template.append('end runTransition;')
taste_template.append('\n') taste_template.append('\n')
else: elif not instance:
# No transitions defined, but keep the interface for CS_Only calls # No transitions defined, but keep the interface for CS_Only calls
taste_template.append('procedure runTransition(Id: Integer) is') taste_template.append('procedure runTransition(Id: Integer) is')
taste_template.append('begin') taste_template.append('begin')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment