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

Generate Ada code for continuous signals

parent 0dc96941
...@@ -743,14 +743,23 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -743,14 +743,23 @@ package {process_name} is'''.format(process_name=process_name,
.format(ctxt=LPREFIX, s1=agg_name, .format(ctxt=LPREFIX, s1=agg_name,
s2=each.statename, sep=UNICODE_SEP, s2=each.statename, sep=UNICODE_SEP,
s3=statename, first='els' if done else '')) s3=statename, first='els' if done else ''))
taste_template.append(u'null;') for provided_clause in cs_item:
trId = process.transitions.index\
(provided_clause.transition)
code, loc = generate(provided_clause.trigger,
branch_to=trId)
taste_template.extend(code)
done.append(statename) done.append(statename)
break break
for statename in process.cs_mapping.viewkeys() - done: for statename in process.cs_mapping.viewkeys() - done:
cs_item = process.cs_mapping[statename] cs_item = process.cs_mapping[statename]
taste_template.append(u'{first}if trId = -1 and {}.state = {} then' taste_template.append(u'{first}if trId = -1 and {}.state = {} then'
.format(LPREFIX, statename, first='els' if done else '')) .format(LPREFIX, statename, first='els' if done else ''))
taste_template.append(u'null;') for provided_clause in cs_item:
trId = process.transitions.index(provided_clause.transition)
code, loc = generate(provided_clause.trigger,
branch_to=trId)
taste_template.extend(code)
if process.cs_mapping: if process.cs_mapping:
taste_template.append(u'end if;') taste_template.append(u'end if;')
...@@ -777,8 +786,6 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -777,8 +786,6 @@ package {process_name} is'''.format(process_name=process_name,
if simu: if simu:
with open(u'{}_interface.aadl'.format(process_name), 'w') as aadl: with open(u'{}_interface.aadl'.format(process_name), 'w') as aadl:
aadl.write(u'\n'.join(minicv).encode('latin1')) aadl.write(u'\n'.join(minicv).encode('latin1'))
if not simu:
with open('{}_simu.sh'.format(process_name), 'w') as bash_script: with open('{}_simu.sh'.format(process_name), 'w') as bash_script:
bash_script.write(simu_script) bash_script.write(simu_script)
...@@ -1872,8 +1879,19 @@ def _choiceitem(choice): ...@@ -1872,8 +1879,19 @@ def _choiceitem(choice):
@generate.register(ogAST.Decision) @generate.register(ogAST.Decision)
def _decision(dec, **kwargs): def _decision(dec, branch_to=None, **kwargs):
''' generate the code for a decision ''' ''' Generate the code for a decision
A decision is made of a question and some answers ; each answer may
be followed by a transition (ogAST.Transition). The code of the
transition is by default generated, but it is possible to generate only
the code of the question and reference a transition Id (trId) if
the reference number is passed to the branch_to parameter.
This option is used for example when generating the code of
continuous signal: the code is generated in the <<next_transition>>
part, while the code of the transition already exists in the
part above. The need is only to set the id of the next transition.
XXX has to be done also in the C backend
'''
code, local_decl = [], [] code, local_decl = [], []
if dec.kind == 'any': if dec.kind == 'any':
LOG.warning('Ada backend does not support the "ANY" statement') LOG.warning('Ada backend does not support the "ANY" statement')
...@@ -1929,12 +1947,15 @@ def _decision(dec, **kwargs): ...@@ -1929,12 +1947,15 @@ def _decision(dec, **kwargs):
op=a.openRangeOp.operand, op=a.openRangeOp.operand,
ans=ans_str) ans=ans_str)
code.append(sep + exp + ' then') code.append(sep + exp + ' then')
if a.transition: if not branch_to:
stmt, tr_decl = generate(a.transition) if a.transition:
stmt, tr_decl = generate(a.transition)
else:
stmt, tr_decl = ['null;'], []
code.extend(stmt)
local_decl.extend(tr_decl)
else: else:
stmt, tr_decl = ['null;'], [] code.append('trId := {};'.format(branch_to))
code.extend(stmt)
local_decl.extend(tr_decl)
sep = 'elsif ' sep = 'elsif '
elif a.kind == 'closed_range': elif a.kind == 'closed_range':
cl0_stmts, cl0_str, cl0_decl = expression(a.closedRange[0]) cl0_stmts, cl0_str, cl0_decl = expression(a.closedRange[0])
...@@ -1945,12 +1966,15 @@ def _decision(dec, **kwargs): ...@@ -1945,12 +1966,15 @@ def _decision(dec, **kwargs):
local_decl.extend(cl1_decl) local_decl.extend(cl1_decl)
code.append('{sep} {dec} >= {cl0} and {dec} <= {cl1} then' code.append('{sep} {dec} >= {cl0} and {dec} <= {cl1} then'
.format(sep=sep, dec=q_str, cl0=cl0_str, cl1=cl1_str)) .format(sep=sep, dec=q_str, cl0=cl0_str, cl1=cl1_str))
if a.transition: if not branch_to:
stmt, tr_decl = generate(a.transition) if a.transition:
stmt, tr_decl = generate(a.transition)
else:
stmt, tr_decl = ['null;'], []
code.extend(stmt)
local_decl.extend(tr_decl)
else: else:
stmt, tr_decl = ['null;'], [] code.append('trId := {};'.format(branch_to))
code.extend(stmt)
local_decl.extend(tr_decl)
sep = 'elsif ' sep = 'elsif '
elif a.kind == 'informal_text': elif a.kind == 'informal_text':
continue continue
......
...@@ -616,7 +616,7 @@ class ContinuousSignal(Input): ...@@ -616,7 +616,7 @@ class ContinuousSignal(Input):
def __init__(self): def __init__(self):
''' Difference with Input: trigger is an expression ''' ''' Difference with Input: trigger is an expression '''
super(ContinuousSignal, self).__init__() super(ContinuousSignal, self).__init__()
# Expression triggering the transition # Decision triggering the transition
self.trigger = None self.trigger = None
# Priority (integer) # Priority (integer)
self.priority = 0 self.priority = 0
......
...@@ -2752,12 +2752,26 @@ def process_definition(root, parent=None, context=None): ...@@ -2752,12 +2752,26 @@ def process_definition(root, parent=None, context=None):
def continuous_signal(root, parent, context): def continuous_signal(root, parent, context):
''' Parse a PROVIDED clause in a continuous signal ''' ''' Parse a PROVIDED clause in a continuous signal '''
i = ogAST.ContinuousSignal() i = ogAST.ContinuousSignal()
dec = ogAST.Decision()
ans = ogAST.Answer()
warnings, errors = [], [] warnings, errors = [], []
# Keep track of the number of terminator statements in the transition # Keep track of the number of terminator statements in the transition
# useful if we want to render graphs from the SDL model # useful if we want to render graphs from the SDL model
terminators = len(context.terminators) terminators = len(context.terminators)
i.trigger, exp_err, exp_warn = expression(root.getChild(0), context) dec.question, exp_err, exp_warn = expression(root.getChild(0), context)
i.inputString = i.trigger.inputString dec.inputString = dec.question.inputString
dec.line = dec.question.line
dec.charPositionInLine = dec.question.charPositionInLine
dec.kind = 'question'
ans.inputString = 'true'
ans.openRangeOp = ogAST.ExprEq
ans.kind = 'constant'
ans.constant = ogAST.PrimBoolean()
ans.constant.value = ['true']
ans.constant.exprType = BOOLEAN
dec.answers = [ans]
i.trigger = dec
i.inputString = dec.inputString
for child in root.children[1:]: for child in root.children[1:]:
if child.type == lexer.CIF: if child.type == lexer.CIF:
# Get symbol coordinates # Get symbol coordinates
...@@ -2770,12 +2784,14 @@ def continuous_signal(root, parent, context): ...@@ -2770,12 +2784,14 @@ def continuous_signal(root, parent, context):
errors.extend(err) errors.extend(err)
warnings.extend(warn) warnings.extend(warn)
i.transition = trans i.transition = trans
ans.transition = trans
# Associate a reference to the transition to the list of inputs # Associate a reference to the transition to the list of inputs
# The reference is an index to process.transitions table # The reference is an index to process.transitions table
context.transitions.append(trans) context.transitions.append(trans)
i.transition_id = len(context.transitions) - 1 i.transition_id = len(context.transitions) - 1
elif child.type == lexer.COMMENT: elif child.type == lexer.COMMENT:
i.comment, _, _ = end(child) i.comment, _, _ = end(child)
dec.comment = i.comment
elif child.type == lexer.HYPERLINK: elif child.type == lexer.HYPERLINK:
i.hyperlink = child.getChild(0).toString()[1:-1] i.hyperlink = child.getChild(0).toString()[1:-1]
elif child.type == 0: elif child.type == 0:
......
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