Commit ca2c57c1 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Start structuring the stg backend support

parent 597a09ae
......@@ -43,6 +43,9 @@ SHARED_LIB = False
UNICODE_SEP = u'\u00dc'
# STG group file, avoid passing a parameter as it is a module-level shared var
STG = None
@singledispatch
def generate(*args, **kwargs):
''' Generate the code for an item of the AST '''
......@@ -54,66 +57,35 @@ def generate(*args, **kwargs):
@generate.register(ogAST.Process)
def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
''' Generate the code for a complete process (AST Top level) '''
global TYPES
global STG
global SHARED_LIB
if not stg:
LOG.error('Library missing. As root: pip install stringtemplate3')
return
# initialize string template
# will find the group in the file, and then retrieve the functions
# with group.getInstanceOf
group = stringtemplate3.StringTemplateGroup(file=open(stgfile))
template = group.getInstanceOf("process")
# Load the file containing a group of templates
STG = stringtemplate3.StringTemplateGroup(file=open(stgfile))
if not STG:
LOG.error('Could not load StringTemplate group')
return
# Get the template corresponding to a SDL PROCESS
template = STG.getInstanceOf("process")
template['name'] = process.processName
print str(template)
return
process_name = process.processName
global TYPES
TYPES = process.dataview
del OUT_SIGNALS[:]
del PROCEDURES[:]
OUT_SIGNALS.extend(process.output_signals)
PROCEDURES.extend(process.procedures)
global SHARED_LIB
if simu:
SHARED_LIB = True
# 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 = []
if not io_param:
LOG.info('Parameterless interface "{}" will not appear in the'
' AADL file but will be handled directly by the GUI'
.format(sp_name))
return ''
# In case of shared library, generate the AADL "mini-cv" code
res.append('SUBPROGRAM {}'.format(sp_name))
if io_param:
res.append('FEATURES')
for param_name, sort, direction in io_param:
res.append(' {pname}: {io} PARAMETER DataView::{sort} '
'{{encoding=>Native;}};'.format(pname=param_name,
sort=sort,
io=direction))
res.append('END {};\n'.format(sp_name))
res.append('SUBPROGRAM IMPLEMENTATION {}.GUI_{}'
.format(sp_name, pi_or_ri))
res.append('PROPERTIES')
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)
LOG.info('Generating Ada code for process ' + str(process_name))
LOG.info('Generating code for process {}'.format(process_name))
# In case model has nested states, flatten everything
Helper.flatten(process, sep=UNICODE_SEP)
......
group adb;
process(name, decl, code) ::= <<
-- This file was generated automatically: DO NOT MODIFY !
package <name> is
end <name>;
>>
/* just a test */
vardef(type, name) ::= "<type> <name>;"
group ads;
process(name) ::= <<
process(name, decl, code) ::= <<
-- This file was generated automatically: DO NOT MODIFY !
package <name> is
......
......@@ -2072,7 +2072,6 @@ def generate(process, options):
StgBackend.generate(process, simu=options.shared, stgfile=options.stg)
def export(ast, options):
''' Export process '''
# Qt must be initialized before using SDL_Scene
......
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