Commit 8fa9325a authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Generate mini-cv when targetting a shared library

parent 12c036b8
......@@ -108,6 +108,36 @@ def _process(process, simu=False, **kwargs):
# When building a shared library (with simu=True), generate a "mini-cv"
# for aadl2glueC to create the code interfacing with asn1scc
minicv = ['-- Automatically generated by OpenGEODE - do NOT modify!']
def aadl_template(sp_name, io_param, pi_or_ri):
''' AADL mini-cv code in case of shared library
sp_name : name of the PI or RI
io_param : list of (param_name, type_name, direction)
pi_or_ri : string "PI" or "RI" depending on the direction
return a string
res = []
# In case of shared library, generate the AADL "mini-cv" code
res.append('SUBPROGRAM {}'.format(sp_name))
if io_param:
for param_name, sort, direction in io_param:
res.append(' {pname}: {io} PARAMETER DataView::{sort} '
res.append('END {};\n'.format(sp_name))
.format(sp_name, pi_or_ri))
res.append(' FV_Name => "{}";'.format(process_name))
res.append(' Source_Language => GUI_{};'.format(pi_or_ri))
res.append('END {}.GUI_{};\n'.format(sp_name, pi_or_ri))
return '\n'.join(res)'Generating Ada code for process ' + str(process_name))
# In case model has nested states, flatten everything
......@@ -213,19 +243,26 @@ package {process_name} is'''.format(process_name=process_name,
{'name': timer.lower()} for timer in process.timers]:
if signal.get('name', u'START') == u'START':
pi_header = 'procedure {sig_name}'.format(sig_name=signal['name'])
param_name = signal.get('param_name') or '{}_param'.format(signal['name'])
pi_header = u'procedure {sig_name}'.format(sig_name=signal['name'])
param_name = signal.get('param_name') \
or u'{}_param'.format(signal['name'])
# Add (optional) PI parameter (only one is possible in TASTE PI)
if 'type' in signal:
typename = type_name(signal['type'])
pi_header += '({pName}: access {sort})'.format(
pi_header += u'({pName}: access {sort})'.format(
pName=param_name, sort=typename)
# Add declaration of the provided interface in the .ads file
ads_template.append('-- Provided interface "' + signal['name'] + '"')
ads_template.append(u'-- Provided interface "' + signal['name'] + '"')
ads_template.append(pi_header + ';')
ads_template.append('pragma export(C, {name}, "{proc}_{name}");'
.format(name=signal['name'], proc=process_name))
ads_template.append(u'pragma export(C, {name}, "{proc}_{name}");'
.format(name=signal['name'], proc=process_name))
if simu:
# Generate code for the mini-cv template
params = [(param_name, type_name(signal['type'], use_prefix=False),
'IN')] if 'type' in signal else []
minicv.append(aadl_template(signal['name'], params, 'PI'))
pi_header += ' is'
......@@ -303,6 +340,12 @@ package {process_name} is'''.format(process_name=process_name,
ads_template.append('pragma Export(C, Register_{sig},'
' "register_{sig}");'
# Generate code for the mini-cv template
params = [(param_name, type_name(signal['type'], use_prefix=False),
'IN')] if 'type' in signal else []
minicv.append(aadl_template(signal['name'], params, 'RI'))
ads_template.append(u'procedure {}{};'
.format(signal['name'], param_spec))
......@@ -427,6 +470,10 @@ package {process_name} is'''.format(process_name=process_name,
if simu:
with open(u'{}_interface.aadl'.format(process_name), 'w') as aadl:
def write_statement(param, newline):
''' Generate the code for the special "write" operator '''
......@@ -1833,10 +1880,11 @@ def find_basic_type(a_type):
return basic_type
def type_name(a_type):
def type_name(a_type, use_prefix=True):
''' Check the type kind and return an Ada usable type name '''
if a_type.kind == 'ReferenceType':
return u'asn1Scc{}'.format(a_type.ReferencedTypeName.replace('-', '_'))
return u'{}{}'.format('asn1Scc' if use_prefix else '',
a_type.ReferencedTypeName.replace('-', '_'))
elif a_type.kind == 'BooleanType':
return u'Boolean'
elif a_type.kind.startswith('Integer'):
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