Commit 62fcf81c authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Refactoring - using Helper

parent 39c9516f
......@@ -115,6 +115,10 @@ def _process(process):
# In case model has nested states, flatten everything
Helper.flatten(process)
# Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime
mapping = Helper.map_input_state(process)
VARIABLES.update(process.variables)
INNER_PROCEDURES.extend(process.content.inner_procedures)
......@@ -160,20 +164,6 @@ def _process(process):
start_transition = ['begin',
'runTransition(0);']
mapping = {}
# Generate the code for the transitions in a mapping input-state
input_signals = [sig['name'] for sig in process.input_signals]
# Add timers to the mapping
input_signals.extend(process.timers)
for input_signal in input_signals:
mapping[input_signal] = {}
for state_name, input_symbols in process.mapping.viewitems():
if isinstance(input_symbols, list):
# Start symbols have no list of inputs
for i in input_symbols:
if input_signal.lower() in (inp.lower() for
inp in i.inputlist):
mapping[input_signal][state_name] = i
# Generate the TASTE template
try:
......
......@@ -33,6 +33,7 @@ import logging
from singledispatch import singledispatch
import ogAST
import Helper
LOG = logging.getLogger(__name__)
......@@ -66,7 +67,12 @@ def expression(expr):
@generate.register(ogAST.Process)
def _process(process):
''' Generate the code for a complete process (AST Top level) '''
pass
# In case model has nested states, flatten everything
Helper.flatten(process)
# Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime
mapping = Helper.map_input_state(process)
def write_statement(param, newline):
''' Generate the code for the special "write" operator '''
......
......@@ -9,6 +9,8 @@
flatten(ast) : transform a model with nested states to a flat model
rename_everything(ast, from_name, to_name) : rename symbols
inner_labels_to_floating(process) : remove labels from transitions
map_input_state(process) -> mapping: create a mapping
input-state-transition
Copyright (c) 2012-2014 European Space Agency
......@@ -27,7 +29,25 @@ import ogAST
LOG = logging.getLogger(__name__)
__all__ = ['flatten', 'rename_everything', 'inner_labels_to_floating']
__all__ = ['flatten', 'rename_everything', 'inner_labels_to_floating',
'map_input_state']
def map_input_state(process):
''' Create a mapping dict {input1: {state1: transition, ...}, ...} '''
mapping = defaultdict(dict)
input_signals = [sig['name'] for sig in process.input_signals]
# Add timers to the mapping
input_signals.extend(process.timers)
for input_signal in input_signals:
for state_name, input_symbols in process.mapping.viewitems():
if isinstance(input_symbols, list):
# Start symbols have no list of inputs
for i in input_symbols:
if input_signal.lower() in (inp.lower() for
inp in i.inputlist):
mapping[input_signal][state_name] = i
return mapping
def inner_labels_to_floating(process):
......
......@@ -22,6 +22,7 @@ from singledispatch import singledispatch
from llvm import core, passes, ee
import ogAST
import Helper
LOG = logging.getLogger(__name__)
......@@ -56,6 +57,13 @@ def _process(process):
process_name = process.processName
LOG.info('Generating LLVM IR code for process ' + str(process_name))
# In case model has nested states, flatten everything
Helper.flatten(process)
# Make an maping {input: {state: transition...}} in order to easily
# generate the lookup tables for the state machine runtime
mapping = Helper.map_input_state(process)
# Initialise LLVM global structure
LLVM['module'] = core.Module.new(str(process_name))
LLVM['pass_manager'] = passes.FunctionPassManager.new(LLVM['module'])
......@@ -136,14 +144,29 @@ def _task_forloop(task):
'''
pass
# ------ expressions --------
@singledispatch
def expression(expr):
''' Generate the code for Expression-classes, returning 3 things:
- list of statements
- useable string corresponding to the evaluation of the expression,
- list of local declarations
(API can differ depending on the backend)
'''
_ = expr
raise TypeError('Unsupported expression: ' + str(expr))
#return [], '', []
@generate.register(ogAST.PrimVariable)
@expression.register(ogAST.PrimVariable)
def _primary_variable(prim):
''' Single variable reference '''
pass
@generate.register(ogAST.PrimPath)
@expression.register(ogAST.PrimPath)
def _prim_path(primaryId):
'''
Return the string of an element list (path)
......@@ -157,107 +180,107 @@ def _prim_path(primaryId):
pass
@generate.register(ogAST.ExprPlus)
@generate.register(ogAST.ExprMul)
@generate.register(ogAST.ExprMinus)
@generate.register(ogAST.ExprEq)
@generate.register(ogAST.ExprNeq)
@generate.register(ogAST.ExprGt)
@generate.register(ogAST.ExprGe)
@generate.register(ogAST.ExprLt)
@generate.register(ogAST.ExprLe)
@generate.register(ogAST.ExprDiv)
@generate.register(ogAST.ExprMod)
@generate.register(ogAST.ExprRem)
@generate.register(ogAST.ExprAssign)
@expression.register(ogAST.ExprPlus)
@expression.register(ogAST.ExprMul)
@expression.register(ogAST.ExprMinus)
@expression.register(ogAST.ExprEq)
@expression.register(ogAST.ExprNeq)
@expression.register(ogAST.ExprGt)
@expression.register(ogAST.ExprGe)
@expression.register(ogAST.ExprLt)
@expression.register(ogAST.ExprLe)
@expression.register(ogAST.ExprDiv)
@expression.register(ogAST.ExprMod)
@expression.register(ogAST.ExprRem)
@expression.register(ogAST.ExprAssign)
def _basic_operators(expr):
''' Expressions with two sides '''
pass
@generate.register(ogAST.ExprOr)
@generate.register(ogAST.ExprAnd)
@generate.register(ogAST.ExprXor)
@expression.register(ogAST.ExprOr)
@expression.register(ogAST.ExprAnd)
@expression.register(ogAST.ExprXor)
def _bitwise_operators(expr):
''' Logical operators '''
pass
@generate.register(ogAST.ExprAppend)
@expression.register(ogAST.ExprAppend)
def _append(expr):
''' Generate code for the APPEND construct: a // b '''
pass
@generate.register(ogAST.ExprIn)
@expression.register(ogAST.ExprIn)
def _expr_in(expr):
''' IN expressions: check if item is in a SEQUENCE OF '''
pass
@generate.register(ogAST.PrimEnumeratedValue)
@expression.register(ogAST.PrimEnumeratedValue)
def _enumerated_value(primary):
''' Generate code for an enumerated value '''
pass
@generate.register(ogAST.PrimChoiceDeterminant)
@expression.register(ogAST.PrimChoiceDeterminant)
def _choice_determinant(primary):
''' Generate code for a choice determinant (enumerated) '''
pass
@generate.register(ogAST.PrimInteger)
@generate.register(ogAST.PrimReal)
@generate.register(ogAST.PrimBoolean)
@expression.register(ogAST.PrimInteger)
@expression.register(ogAST.PrimReal)
@expression.register(ogAST.PrimBoolean)
def _integer(primary):
''' Generate code for a raw integer/real/boolean value '''
pass
@generate.register(ogAST.PrimEmptyString)
@expression.register(ogAST.PrimEmptyString)
def _empty_string(primary):
''' Generate code for an empty SEQUENCE OF: {} '''
pass
@generate.register(ogAST.PrimStringLiteral)
@expression.register(ogAST.PrimStringLiteral)
def _string_literal(primary):
''' Generate code for a string (Octet String) '''
pass
@generate.register(ogAST.PrimConstant)
@expression.register(ogAST.PrimConstant)
def _constant(primary):
''' Generate code for a reference to an ASN.1 constant '''
pass
@generate.register(ogAST.PrimMantissaBaseExp)
@expression.register(ogAST.PrimMantissaBaseExp)
def _mantissa_base_exp(primary):
''' Generate code for a Real with Mantissa-base-Exponent representation '''
pass
@generate.register(ogAST.PrimIfThenElse)
@expression.register(ogAST.PrimIfThenElse)
def _if_then_else(ifThenElse):
''' Return string and statements for ternary operator '''
pass
@generate.register(ogAST.PrimSequence)
@expression.register(ogAST.PrimSequence)
def _sequence(seq):
''' Return Ada string for an ASN.1 SEQUENCE '''
pass
@generate.register(ogAST.PrimSequenceOf)
@expression.register(ogAST.PrimSequenceOf)
def _sequence_of(seqof):
''' Return Ada string for an ASN.1 SEQUENCE OF '''
pass
@generate.register(ogAST.PrimChoiceItem)
@expression.register(ogAST.PrimChoiceItem)
def _choiceitem(choice):
''' Return the Ada code for a CHOICE expression '''
pass
......
......@@ -29,8 +29,8 @@ D ada.ads 20070406091342 3ffc8e18
D a-charac.ads 20070912115821 2d3ec45b
D a-chlat1.ads 20070912115821 2825df20
D a-unccon.ads 20070406091342 f9eb8f06
D adaasn1rtl.ads 20140513071215 989f6c09
D adaasn1rtl.adb 20140513071215 3a622529
D adaasn1rtl.ads 20140513113246 989f6c09
D adaasn1rtl.adb 20140513113246 3a622529
D interfac.ads 20110906094621 129923ea
D system.ads 20140212114732 bd760655
D s-exnllf.ads 20121004090553 81841eef
......
......@@ -14,12 +14,12 @@ W adaasn1rtl%s adaasn1rtl.adb adaasn1rtl.ali
D ada.ads 20070406091342 3ffc8e18
D a-charac.ads 20070912115821 2d3ec45b
D a-chlat1.ads 20070912115821 2825df20
D adaasn1rtl.ads 20140513071215 989f6c09
D adaasn1rtl.ads 20140513113246 989f6c09
D interfac.ads 20110906094621 129923ea
D system.ads 20140212114732 bd760655
D s-unstyp.ads 20090409150019 6ae15c76
D taste_basictypes.ads 20140513071215 72ec04b4
D taste_basictypes.adb 20140513071215 ad8ecfb4
D taste_basictypes.ads 20140513113246 72ec04b4
D taste_basictypes.adb 20140513113246 ad8ecfb4
X 4 adaasn1rtl.ads
7K9*adaasn1rtl 908e15 8|2w6 2r27 2r57 2r85 11r27 21r75 29r28 39r77 47r26
. 57r73 65r27 75r75 83r29 9|2w6 3r10 4r10 5r10 12r36 21r75 23r11 31r12 47r77
......
......@@ -14,13 +14,13 @@ W taste_basictypes%s taste_basictypes.adb taste_basictypes.ali
D ada.ads 20070406091342 3ffc8e18
D a-charac.ads 20070912115821 2d3ec45b
D a-chlat1.ads 20070912115821 2825df20
D adaasn1rtl.ads 20140513071215 989f6c09
D adaasn1rtl.ads 20140513113246 989f6c09
D interfac.ads 20110906094621 129923ea
D system.ads 20140212114732 bd760655
D s-unstyp.ads 20090409150019 6ae15c76
D taste_basictypes.ads 20140513071215 72ec04b4
D taste_dataview.ads 20140513071215 a40837cf
D taste_dataview.adb 20140513071215 051f7d26
D taste_basictypes.ads 20140513113246 72ec04b4
D taste_dataview.ads 20140513113246 a40837cf
D taste_dataview.adb 20140513113246 051f7d26
X 4 adaasn1rtl.ads
7K9*adaasn1rtl 908e15 9|2w6 2r27 2r57 2r85 10|2w6 4r10 5r10 6r10
20M10*BIT 9|2r96 10|6r21
......
......@@ -21,15 +21,15 @@ W taste_dataview%s taste_dataview.adb taste_dataview.ali
D ada.ads 20070406091342 3ffc8e18
D a-charac.ads 20070912115821 2d3ec45b
D a-chlat1.ads 20070912115821 2825df20
D adaasn1rtl.ads 20140513071215 989f6c09
D adaasn1rtl.ads 20140513113246 989f6c09
D interfac.ads 20110906094621 129923ea
D system.ads 20140212114732 bd760655
D s-io.ads 20090409150019 9e42f74f
D s-unstyp.ads 20090409150019 6ae15c76
D taste_basictypes.ads 20140513071215 72ec04b4
D taste_dataview.ads 20140513071215 a40837cf
D trafficlight.ads 20140513071214 76d3ced9
D trafficlight.adb 20140513071214 95fc595b
D taste_basictypes.ads 20140513113246 72ec04b4
D taste_dataview.ads 20140513113246 a40837cf
D trafficlight.ads 20140513113246 76d3ced9
D trafficlight.adb 20140513113246 95fc595b
X 4 adaasn1rtl.ads
7K9*adaasn1rtl 908e15 12|11w6 12r5
28I13*Asn1Int{5|52I9}
......
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