Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
8fa9325a
Commit
8fa9325a
authored
Nov 17, 2014
by
Maxime Perrotin
Browse files
Generate mini-cv when targetting a shared library
parent
12c036b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
AdaGenerator.py
View file @
8fa9325a
...
...
@@ -108,6 +108,36 @@ def _process(process, simu=False, **kwargs):
OUT_SIGNALS
.
extend
(
process
.
output_signals
)
PROCEDURES
.
extend
(
process
.
procedures
)
# 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
=
[]
# 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
))
# In case model has nested states, flatten everything
...
...
@@ -213,19 +243,26 @@ package {process_name} is'''.format(process_name=process_name,
{
'name'
:
timer
.
lower
()}
for
timer
in
process
.
timers
]:
if
signal
.
get
(
'name'
,
u
'START'
)
==
u
'START'
:
continue
pi_header
=
'procedure {sig_name}'
.
format
(
sig_name
=
signal
[
'name'
])
param_name
=
signal
.
get
(
'param_name'
)
or
'{}_param'
.
format
(
signal
[
'name'
])
pi_header
=
u
'procedure {sig_name}'
.
format
(
sig_name
=
signal
[
'name'
])
param_name
=
signal
.
get
(
'param_name'
)
\
or
u
'{}_param'
.
format
(
signal
[
'name'
])
# Add (optional) PI parameter (only one is possible in TASTE PI)
if
'type'
in
signal
:
typename
=
type_name
(
signal
[
'type'
])
pi_header
+=
'({pName}: access {sort})'
.
format
(
pi_header
+=
u
'({pName}: access {sort})'
.
format
(
pName
=
param_name
,
sort
=
typename
)
# Add declaration of the provided interface in the .ads file
ads_template
.
append
(
'-- Provided interface "'
+
signal
[
'name'
]
+
'"'
)
ads_template
.
append
(
u
'-- Provided interface "'
+
signal
[
'name'
]
+
'"'
)
ads_template
.
append
(
pi_header
+
';'
)
ads_template
.
append
(
'pragma export(C, {name}, "{proc}_{name}");'
.
format
(
name
=
signal
[
'name'
],
proc
=
process_name
))
ads_template
.
append
(
u
'pragma export(C, {name}, "{proc}_{name}");'
.
format
(
name
=
signal
[
'name'
],
proc
=
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
,
'PI'
))
pi_header
+=
' is'
taste_template
.
append
(
pi_header
)
...
...
@@ -303,6 +340,12 @@ package {process_name} is'''.format(process_name=process_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
,
'RI'
))
else
:
ads_template
.
append
(
u
'procedure {}{};'
.
format
(
signal
[
'name'
],
param_spec
))
...
...
@@ -427,6 +470,10 @@ package {process_name} is'''.format(process_name=process_name,
ada_file
.
write
(
u
'
\n
'
.
join
(
format_ada_code
(
ads_template
)).
encode
(
'latin1'
))
if
simu
:
with
open
(
u
'{}_interface.aadl'
.
format
(
process_name
),
'w'
)
as
aadl
:
aadl
.
write
(
u
'
\n
'
.
join
(
minicv
).
encode
(
'latin1'
))
def
write_statement
(
param
,
newline
):
''' Generate the code for the special "write" operator '''
...
...
@@ -1833,10 +1880,11 @@ def find_basic_type(a_type):
return
basic_type
def
type_name
(
a_type
):
def
type_name
(
a_type
,
use_prefix
=
True
):
''' Check the type kind and return an Ada usable type name '''
if
a_type
.
kind
==
'ReferenceType'
:
return
u
'asn1Scc{}'
.
format
(
a_type
.
ReferencedTypeName
.
replace
(
'-'
,
'_'
))
return
u
'{}{}'
.
format
(
'asn1Scc'
if
use_prefix
else
''
,
a_type
.
ReferencedTypeName
.
replace
(
'-'
,
'_'
))
elif
a_type
.
kind
==
'BooleanType'
:
return
u
'Boolean'
elif
a_type
.
kind
.
startswith
(
'Integer'
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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