Commit 3e26f7e9 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Merge into feature_buster

parents 54a871cc 770d073a
......@@ -204,7 +204,7 @@ def _process(process, simu=False, instance=False, taste=False, **kwargs):
# taste-properties module-specific flag for the Ada backend:
# import the state data from an external module
import_context = kwargs["ppty_check"] if "ppty_check" in kwargs else ""
stop_condition = kwargs["ppty_check"] if "ppty_check" in kwargs else ""
# When building a shared library (with simu=True), generate a "mini-cv"
# for aadl2glueC to create the code interfacing with asn1scc
......@@ -438,13 +438,13 @@ LD_LIBRARY_PATH=./lib:.:$LD_LIBRARY_PATH opengeode-simulator
# Write the ASN.1 file (not in case of Stop Condition)
if not import_context:
if not stop_condition:
with open(process_name.lower() + '_datamodel.asn', 'w') as asn1_file:
# Generate the code to declare process-level context
context_decl = []
if not import_context:
if not stop_condition:
# but not in stop condition code, since we reuse the context type
# of the state machine being observed
......@@ -472,12 +472,12 @@ LD_LIBRARY_PATH=./lib:.:$LD_LIBRARY_PATH opengeode-simulator
# The choice selections will allow to use the present operator
# together with a variable of the -selection type
if import_context:
if stop_condition:
# code of stop conditions must use the same type as the main process
f'{LPREFIX} : {ASN1SCC}{import_context}_Context '
f'renames {import_context}.{import_context}_ctxt;')
if simu and not import_context:
f'{LPREFIX} : {ASN1SCC}{stop_condition}_Context '
f'renames {stop_condition}.{stop_condition}_ctxt;')
if simu and not stop_condition:
# Export the context, so that it can be manipulated from outside
# (in practice used by the "properties" module.
context_decl.append(f'pragma export (C, {LPREFIX}, "{LPREFIX}");')
......@@ -555,14 +555,15 @@ with Ada.Unchecked_Conversion;
with Ada.Numerics.Generic_Elementary_Functions;
package body {process_name} is'''
if not instance else f"package body {process_name} is"]
if not instance else f'''-- Package body for instance - Generated by OpenGEODE (DO NOT EDIT)
package body {process_name} is''']
generic_spec, instance_decl = "", ""
if generic:
generic_spec = "generic\n"
ri_list = external_ri_list(process)
if ri_list:
generic_spec += u" with " + u";\n with ".join(ri_list) + ';'
generic_spec += " with " + ";\n with ".join(ri_list) + ';'
if instance:
instance_decl = f"with {process.instance_of_name};"
......@@ -572,15 +573,15 @@ package body {process_name} is'''
# Generate the source file (.ads) header
# Stop conditions must import the SDL model they observe
imp_str = f"with {import_context}; use {import_context};" \
if import_context else ''
imp_str = f"with {stop_condition}; use {stop_condition};" \
if stop_condition else ''
imp_datamodel = (f"with {process_name}_Datamodel; "
f"use {process_name}_Datamodel;") \
if not import_context and not instance else (
f"with {import_context}_Datamodel; "
f"use {import_context}_Datamodel;"
if import_context else "")
if not stop_condition and not instance else (
f"with {stop_condition}_Datamodel; "
f"use {stop_condition}_Datamodel;"
if stop_condition else "")
imp_ri = f"with {process_name}_RI;" if not simu and not generic else ""
......@@ -634,7 +635,7 @@ package body {process_name}_RI is''']
if not instance:
if not generic and not instance and not import_context:
if not generic and not instance and not stop_condition:
# Add function allowing to trace current state as a string
f"function Get_State return chars_ptr "
......@@ -644,9 +645,14 @@ package body {process_name}_RI is''']
f'Link_Name => "{process_name.lower()}_state";')
# Declare procedure Startup in .ads
ads_template.append(f'procedure Startup with Export, Convention => C, Link_Name => "{process_name}_startup";')
if simu and not import_context: # import_context = stop condition
if not generic:
ads_template.append(f'procedure Startup'
f' with Export, Convention => C,'
f' Link_Name => "{process_name}_startup";')
else: # function type
ads_template.append(f'procedure Startup;')
if simu and not stop_condition:
ads_template.append('-- API for simulation via DLL')
dll_api.append('-- API to remotely change internal data')
......@@ -713,7 +719,7 @@ package body {process_name}_RI is''']
# Generate the code for each input signal (provided interface) and timers
for signal in process.input_signals + [
{'name': timer} for timer in process.timers]:
if import_context:
if stop_condition:
# dont generate anything in stop_condition functions
......@@ -847,6 +853,14 @@ package body {process_name}_RI is''']
taste_template.append(f'end {signame};')
# add call to startup function for instances
if instance:
taste_template.extend(['procedure Startup is',
'end Startup;',
# for the .ads file, generate the declaration of the required interfaces
# output signals are the asynchronous RI - only one parameter
for signal in process.output_signals:
......@@ -942,7 +956,7 @@ package body {process_name}_RI is''']
# for the .ads file, generate the declaration of timers set/reset functions
for timer in process.timers:
if import_context:
if stop_condition:
# don't generte timer code for stop conditions
ads_template.append(f'-- Timer {timer} SET and RESET functions')
......@@ -1000,19 +1014,18 @@ package body {process_name}_RI is''']
if instance:
# Instance of a process type, all the RIs (including timers) must
# be gathered to instantiate the package
pkg_decl = (u"package {}_Instance is new {}"
.format(process_name, process.instance_of_name))
pkg_decl = (f"package {process_name}_Instance is new {process.instance_of_name}")
ri_list = [f"RI{SEPARATOR}{sig['name']}"
for sig in process.output_signals]
ri_list.extend ([u"RI{sep}{name}".format(sep=SEPARATOR,
for proc in process.procedures if proc.external])
ri_list.extend([u"set_{}".format(timer) for timer in process.timers])
ri_list.extend([u"reset_{}".format(timer) for timer in process.timers])
ri_inst = [u"{ri} => {ri}".format(ri=ri) for ri in ri_list]
ri_list.extend([f"set_{timer}" for timer in process.timers])
ri_list.extend([f"reset_{timer}" for timer in process.timers])
ri_inst = [f"{ri} => {ri}" for ri in ri_list]
if ri_inst:
pkg_decl += u" ({})".format(u", ".join(ri_inst))
ads_template.append(pkg_decl + u";")
pkg_decl += " ({})".format(", ".join(ri_inst))
ads_template.append(pkg_decl + ";")
f"function Get_State return chars_ptr "
f"is (New_String ({process_name}_Instance.{LPREFIX}.State'Img))"
......@@ -1023,12 +1036,12 @@ package body {process_name}_RI is''']
if simu and has_cs:
# Callback registration for Check_Queue
taste_template.append(u'procedure Register_Check_Queue'
u'(Callback: Check_Queue_T) is')
taste_template.append(u'Check_Queue := Callback;')
taste_template.append(u'end Register_Check_Queue;')
taste_template.append('procedure Register_Check_Queue '
'(Callback : Check_Queue_T) is')
taste_template.append('Check_Queue := Callback;')
taste_template.append('end Register_Check_Queue;')
# If the process has no input, output, procedures, or timers, then Ada
# will not compile the body - generate a pragma to fix this
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