Commit c22b3857 authored by Maxime Perrotin's avatar Maxime Perrotin

Test instantiation

parent 04f80b2d
......@@ -350,55 +350,56 @@ LD_LIBRARY_PATH=. opengeode-simulator
context_decl.append(u'pragma import (C, ctxt, "{}_ctxt");'
.format(import_context))
if not simu:
if not simu and not instance:
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 = []
for name, substates in aggregates.viewitems():
proc_name = u'procedure {}{}START'.format(name, UNICODE_SEP)
process_level_decl.append(u'{};'.format(proc_name))
aggreg_start_proc.extend([u'{} is'.format(proc_name),
'begin'])
aggreg_start_proc.extend(u'runTransition({sub}{sep}START);'
.format(sub=subname.statename,
sep=UNICODE_SEP)
for subname in substates)
aggreg_start_proc.extend([u'end {}{}START;'
.format(name, UNICODE_SEP),
'\n'])
# 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;']
start_transition = []
# Continuous State transition id
if not instance:
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
for name, substates in aggregates.viewitems():
proc_name = u'procedure {}{}START'.format(name, UNICODE_SEP)
process_level_decl.append(u'{};'.format(proc_name))
aggreg_start_proc.extend([u'{} is'.format(proc_name),
'begin'])
aggreg_start_proc.extend(u'runTransition({sub}{sep}START);'
.format(sub=subname.statename,
sep=UNICODE_SEP)
for subname in substates)
aggreg_start_proc.extend([u'end {}{}START;'
.format(name, UNICODE_SEP),
'\n'])
# 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
try:
......@@ -409,7 +410,7 @@ LD_LIBRARY_PATH=. opengeode-simulator
asn1_modules += '\nwith adaasn1rtl;\nuse adaasn1rtl;'
except TypeError:
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 !
with System.IO;
......@@ -427,7 +428,8 @@ package body {process_name} is'''.format(process_name=process_name,
dataview=asn1_modules,
C='with Interfaces.C.Strings;\n'
'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 = "", ""
if generic:
......@@ -633,7 +635,8 @@ package {process_name} is'''.format(generic=generic_spec,
else:
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):
''' Recursive function (in case of state aggregation) to generate
......@@ -673,11 +676,17 @@ package {process_name} is'''.format(generic=generic_spec,
else:
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('\n')
......@@ -859,7 +868,6 @@ package {process_name} is'''.format(generic=generic_spec,
if ri_inst:
pkg_decl += u" ({})".format(u", ".join(ri_inst))
ads_template.append(pkg_decl + u";")
ads_template.append(u"use {}_Instance;".format(process_name))
if simu and process.cs_mapping:
# Callback registration for Check_Queue
......@@ -895,7 +903,7 @@ package {process_name} is'''.format(generic=generic_spec,
code_labels.extend(code_label)
# 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('trId : Integer := Id;')
if process.cs_mapping:
......@@ -1040,7 +1048,7 @@ package {process_name} is'''.format(generic=generic_spec,
taste_template.append('end loop;')
taste_template.append('end runTransition;')
taste_template.append('\n')
else:
elif not instance:
# No transitions defined, but keep the interface for CS_Only calls
taste_template.append('procedure runTransition(Id: Integer) is')
taste_template.append('begin')
......
Markdown is supported
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