Commit 562297f5 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

More STG backend

parent c27217fe
......@@ -139,8 +139,6 @@ def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
process_template['pdecl'] = inner_procedure_decl
process_template['pcode'] = inner_procedures_code
print str(process_template)
return
# Generate the code for each input signal (provided interface) and timers
pi_code = []
......@@ -160,12 +158,6 @@ def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
pi_template['name'] = signal['name']
pi_template['process'] = 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, 'RI'))
# For each input signal, define the possible transition based on the
# current state.
cases = []
......@@ -221,52 +213,20 @@ def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
# for the .ads file, generate the declaration of the required interfaces
# output signals are the asynchronous RI - only one parameter
required_interfaces = []
for signal in process.output_signals:
# TODO, pass the type and name of the parameter (for the Ads)
ri_template = STG.getInstanceOf("required_interface")
ri_template['name'] = signal['name']
ri_template['simu'] = simu
required_interfaces.append(str(ri_template))
param_name = signal.get('param_name') \
or u'{}_param'.format(signal['name'])
# Add (optional) RI parameter
param_spec = '' if not simu else "(tm: chars_ptr)"
if 'type' in signal:
typename = type_name(signal['type'])
param_spec = u'({pName}: access {sort}{shared})' \
.format(pName=param_name,
sort=typename,
shared=u'; Size: Integer'
if SHARED_LIB else '')
ads_template.append(u'-- Required interface "' + signal['name'] + '"')
if simu:
# When generating a shared library, we need a callback mechanism
ads_template.append(u'type {}_T is access procedure{};'
.format(signal['name'], param_spec))
ads_template.append('pragma Convention(Convention => C,'
' Entity => {}_T);'.format(signal['name']))
ads_template.append('{sig} : {sig}_T;'
.format(sig=signal['name']))
ads_template.append('procedure Register_{sig}(Callback: {sig}_T);'
.format(sig=signal['name']))
ads_template.append('pragma Export(C, Register_{sig},'
' "register_{sig}");'
.format(sig=signal['name']))
# 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'))
taste_template.append('procedure Register_{sig}'
'(Callback:{sig}_T) is'
.format(sig=signal['name']))
taste_template.append('begin')
taste_template.append('{} := Callback;'.format(signal['name']))
taste_template.append('end Register_{};'.format(signal['name']))
taste_template.append('')
else:
ads_template.append(u'procedure {}{};'
.format(signal['name'], param_spec))
ads_template.append(u'pragma import(C, {sig}, "{proc}_RI_{sig}");'
.format(sig=signal['name'], proc=process_name))
process_template['arrs_async_ri'] = required_interfaces
print str(process_template)
return
external_proc = []
# for the .ads file, generate the declaration of the external procedures
for proc in (proc for proc in process.procedures if proc.external):
ri_header = u'procedure {sig_name}'.format(sig_name=proc.inputString)
......
......@@ -7,12 +7,13 @@ group adb;
* pcode : inner procedure code (array)
* vars: list of local variables and sort: { name: str, sort: str })
* arrs_inp : code handling the reception of messages (array of <input_signal>)
* arrs_async_ri : code for the required interfaces
* constants: list of start named start transitions (when using substates)
* states: list of states
* asn1_mod : list of ASN.1 modules
* simu, dll : flags set by the user for generation of optional code
*/
process(name, decl, pdecl, pcode vars, arrs_inp, constants, states, asn1_mod, simu, dll) ::= <<
process(name, decl, pdecl, pcode vars, arrs_inp, arrs_async_ri, constants, states, asn1_mod, simu, dll) ::= <<
-- This file was generated automatically: DO NOT MODIFY !
<if(asn1_mod)>
......@@ -91,6 +92,7 @@ end dll_set_l_<each.name>;
<endif>
<pcode; separator="\n">
<arrs_inp; separator = "\n">
<arrs_ri; separator = "\n">
-- Process initialization: execute the START transition)
begin
......@@ -189,6 +191,17 @@ procedure <if(!external)>p<safe_separator()><endif><name>
>>
/* Code for external RI */
required_interface(name, simu) ::= <<
<if(simu)>
procedure Register_<name>(Callback: <name>_T) is
begin
<name> := Callback;
end Register_<name>;
<endif>
>>
/* Template for floating labels */
floating_label(name, traceability, transition) ::= <<
<traceability>
......
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