Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
ca2c57c1
Commit
ca2c57c1
authored
Jan 16, 2015
by
Maxime Perrotin
Browse files
Start structuring the stg backend support
parent
597a09ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
opengeode/StgBackend.py
View file @
ca2c57c1
...
...
@@ -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
)
...
...
opengeode/ada_body.st
0 → 100644
View file @
ca2c57c1
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>;"
opengeode/ada_source.st
View file @
ca2c57c1
group
ads
;
process
(
name
)
:
:=
<<
process
(
name
,
decl
,
code
)
:
:=
<<
--
This
file
was
generated
automatically:
DO
NOT
MODIFY
!
package
<
name
>
is
...
...
opengeode/opengeode.py
View file @
ca2c57c1
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment