Commit 695736e3 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Update Ada generator for simulation

parent 736f7150
...@@ -658,24 +658,37 @@ package body {process_name}_RI is'''] ...@@ -658,24 +658,37 @@ package body {process_name}_RI is''']
ads_template.append(save_state_decl) ads_template.append(save_state_decl)
restore_state_decl = 'procedure Restore_Context with Export, Convention => C, Link_Name => "_restore_context";' restore_state_decl = 'procedure Restore_Context with Export, Convention => C, Link_Name => "_restore_context";'
ads_template.append(restore_state_decl) ads_template.append(restore_state_decl)
dll_api.append("procedure Save_Context is") dll_api.extend([
dll_api.append("begin") "procedure Save_Context is",
dll_api.append("{ctxt}_bk := {ctxt};".format(ctxt=LPREFIX)) "begin",
dll_api.append("end Save_Context;") f"{LPREFIX}_bk := {LPREFIX};",
dll_api.append("") "end Save_Context;",
dll_api.append("procedure Restore_Context is".format(restore_state_decl)) "",
dll_api.append("begin") "procedure Restore_Context is",
dll_api.append("{ctxt} := {ctxt}_bk;".format(ctxt=LPREFIX)) "begin",
dll_api.append("end Restore_Context;") f"{LPREFIX} := {LPREFIX}_bk;",
dll_api.append("") "end Restore_Context;",
""])
# Declare procedure Startup in .ads # Declare procedure Startup in .ads
ads_template.append(f'procedure Startup with Export, Convention => C, Link_Name => "{process_name}_startup";') ads_template.append(f'procedure Startup with Export, Convention => C, Link_Name => "{process_name}_startup";')
# Functions to get global context # Functions to get global context
process_level_decl.append( ads_template.append(
f"function Get_Context return access {ASN1SCC}{process_name}_Context is ({LPREFIX}'access)\n" f"function Get_Context return access {ASN1SCC}{process_name}_Context is ({LPREFIX}'access)\n"
f' with Export, Convention => C, Link_Name => "{process_name.lower()}_context";') f' with Export, Convention => C, Link_Name => "{process_name.lower()}_context";')
ads_template.append(
f"procedure Set_Context (Context : access {ASN1SCC}{process_name}_Context)\n"
f' with Export, Convention => C, Link_Name => "set_{process_name.lower()}_context";')
dll_api.extend([
f"procedure Set_Context (Context : access {ASN1SCC}{process_name}_Context) is",
"begin",
f"{LPREFIX} := Context.all;",
'-- System.IO.Put_Line ("Changed context. State = " & Context.state\'Img);',
"end Set_Context;",
""])
# Generate the the code of the procedures # Generate the the code of the procedures
inner_procedures_code = [] inner_procedures_code = []
for proc in process.content.inner_procedures: for proc in process.content.inner_procedures:
...@@ -685,12 +698,10 @@ package body {process_name}_RI is'''] ...@@ -685,12 +698,10 @@ package body {process_name}_RI is''']
if proc.exported: if proc.exported:
# Exported procedures must be declared in the .ads # Exported procedures must be declared in the .ads
pi_header = procedure_header(proc) pi_header = procedure_header(proc)
ads_template.append(u'{};'.format(pi_header)) ads_template.append(f'{pi_header};')
if not proc.external and not generic: if not proc.external and not generic:
ads_template.append(u'pragma Export' ads_template.append(
u'(C, p{sep}{proc_name}, "_{proc_name}");' f'pragma Export (C, p{SEPARATOR}{proc.inputString}, "_{proc.inputString}");')
.format(sep=SEPARATOR,
proc_name=proc.inputString))
# Generate the code for the process-level variable declarations # Generate the code for the process-level variable declarations
taste_template.extend(process_level_decl) taste_template.extend(process_level_decl)
...@@ -712,27 +723,22 @@ package body {process_name}_RI is'''] ...@@ -712,27 +723,22 @@ package body {process_name}_RI is''']
# dont generate anything in stop_condition functions # dont generate anything in stop_condition functions
break break
signame = signal.get('name', u'START') signame = signal.get('name', 'START')
if signame == u'START': if signame == 'START':
continue continue
pi_header = u'procedure {sig_name}'.format(sig_name=signame) pi_header = f'procedure {signame}'
param_name = signal.get('param_name') \ param_name = signal.get('param_name') or f'{signame}_param'
or u'{}_param'.format(signame)
# Add (optional) PI parameter (only one is possible in TASTE PI) # Add (optional) PI parameter (only one is possible in TASTE PI)
if 'type' in signal: if 'type' in signal:
typename = type_name(signal['type']) typename = type_name(signal['type'])
pi_header += u'({pName}: in out {sort})'.format( pi_header += f'({param_name}: in out {typename})'
pName=param_name, sort=typename)
# Add declaration of the provided interface in the .ads file # Add declaration of the provided interface in the .ads file
ads_template.append(u'-- Provided interface "{}"'.format(signame)) ads_template.append(f'-- Provided interface "{signame}"')
ads_template.append(pi_header + ';') ads_template.append(pi_header + ';')
if not generic: if not generic:
ads_template.append( ads_template.append(
u'pragma Export(C, {name}, "{proc}_PI_{name}");' f'pragma Export(C, {signame}, "{process_name.lower()}_PI_{signame}");')
.format(name=signame, proc=process_name.lower()))
# don't lower case the signal name, not for kazoo at least
#.format(name=signame.lower(), proc=process_name.lower()))
if simu: if simu:
# Generate code for the mini-cv template # Generate code for the mini-cv template
......
...@@ -37,6 +37,7 @@ test-ada: ...@@ -37,6 +37,7 @@ test-ada:
./test_ada ./test_ada
simu: simu:
rm -rf orchestrator_simu
$(OPENGEODE) orchestrator.pr system_structure.pr --shared $(OPENGEODE) orchestrator.pr system_structure.pr --shared
taste-properties -s properties orchestrator.pr system_structure.pr taste-properties -s properties orchestrator.pr system_structure.pr
make -f Makefile.properties make -f Makefile.properties
......
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