aadl2glueC.py 25.7 KB
Newer Older
1
#!/usr/bin/env python3
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# vim: set expandtab ts=8 sts=4 shiftwidth=4
#
# (C) Semantix Information Technologies.
#
# Semantix Information Technologies is licensing the code of the
# Data Modelling Tools (DMT) in the following dual-license mode:
#
# Commercial Developer License:
#       The DMT Commercial Developer License is the suggested version
# to use for the development of proprietary and/or commercial software.
# This version is for developers/companies who do not want to comply
# with the terms of the GNU Lesser General Public License version 2.1.
#
# GNU LGPL v. 2.1:
#       This version of DMT is the one to use for the development of
# applications, when you are willing to comply with the terms of the
# GNU Lesser General Public License version 2.1.
#
# Note that in both cases, there are no charges (royalties) for the
# generated code.
#
'''
Code Integrator

This is the core of the "glue" generators that Semantix developed for
the European research project ASSERT. It has been enhanced in the
context of Data Modelling and Data Modelling Tuning projects,
and continuous to evolve over the course of other projects.

This code starts by reading the AADL specification of the system.
It then generates the runtime bridge-code that will map the message
data structures from those generated by the Semantix Certified ASN.1
compiler to/from those generated by the modeling tool used to
functionally model the APLC subsystem (e.g. SCADE, ObjectGeode,
Matlab/Simulink, C, Ada, etc).

The code generation is done via user-visible (and editable) backends.

There are three kinds of backends:

1. Synchronous backends
=======================

For these, the working logic is:

for each subprogram implementation
    Load B mapper
    call OnStartup
    for each subprogram param
        Call OnBasic/OnSequence/OnEnumerated etc
    call OnShutdown

That is, there is OnStartup/OnInteger/OnSequence/.../OnShutdown cycle
done PER EACH SUBPROGRAM.

2. Asynchronous backends
========================

Asynchronous backends are only generating standalone encoders and decoders
(they are not doing this per sp.param).

The working logic is therefore different

OnStartup called ONCE for each async backend in use (used by this system's PIs)
Via the asynchronous.py, after visiting all params and collecting them,
for each asn.1 type that is actually used (at least once) as a param:
    Call Encoder and Decoder
Call OnShutdown ONCE for each async backend in use (used by this system's PIs)

3. Special backends
===================

GUI, Python, (VHDL?), etc...

These have custom requirements, so each one is handled by specific AADL2GLUEC
code. As it is now, the pattern follows that of the synchronous backends,
but with an extra call to OnFinal at the end.
'''

import os
import sys
83
import hashlib
84
85
import pickle
import tempfile
86
from distutils import spawn
87

88
from typing import cast, Optional, Dict, List, Tuple, Set, Any  # NOQA pylint: disable=unused-import
89

90
91
92
93
94
95
96
97
98
99
100
101
102
# from importlib import import_module
from .B_mappers import ada_B_mapper
from .B_mappers import c_B_mapper
from .B_mappers import gui_B_mapper
from .B_mappers import og_B_mapper
from .B_mappers import sdl_B_mapper
from .B_mappers import pyside_B_mapper
from .B_mappers import python_B_mapper
from .B_mappers import qgenada_B_mapper
from .B_mappers import qgenc_B_mapper
from .B_mappers import rtds_B_mapper
from .B_mappers import scade6_B_mapper
from .B_mappers import simulink_B_mapper
103
from .B_mappers import micropython_async_B_mapper
104
from .B_mappers import vhdl_B_mapper
105
from .B_mappers import zestSC1_B_mapper
106

107
108
from .B_mappers.module_protos import Sync_B_Mapper, Async_B_Mapper

109
from . import commonPy
110

111
112
from .commonPy.utility import panic, inform
from .commonPy import verify
113
from .commonPy.cleanupNodes import DiscoverBadTypes, SetOfBadTypenames
114
115
from .commonPy.asnParser import Filename, Typename, AST_Lookup, AST_TypesOfFile, AST_Leaftypes  # NOQA pylint: disable=unused-import
from .commonPy.asnAST import AsnNode  # NOQA pylint: disable=unused-import
116
from .commonPy.aadlAST import ApLevelContainer, Param  # NOQA pylint: disable=unused-import
117

118
from . import B_mappers  # NOQA pylint: disable=unused-import
119

120
121
122
123
124
# To unpickle the Py2/ANTLR2-generated pickle file...
#    http://stackoverflow.com/questions/2121874/python-pickling-after-changing-a-modules-directory
from . import commonPy2
sys.modules['commonPy2'] = commonPy2

125

126
127
g_async_mappers = {
    'C': c_B_mapper,
128
    'MicroPython': micropython_async_B_mapper,
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    'Ada': ada_B_mapper,
    'SDL': sdl_B_mapper,
    'OG': og_B_mapper,
    'QGenAda': qgenada_B_mapper,
    'RTDS': rtds_B_mapper,
}


g_sync_mappers = {
    'Scade6': scade6_B_mapper,
    'Simulink': simulink_B_mapper,
    'gui': gui_B_mapper,
    'python': python_B_mapper,
    'QgenC': qgenc_B_mapper,
    'vhdl': vhdl_B_mapper,
}


147
def ParseAADLfilesAndResolveSignals() -> None:
148
149
150
    '''Invokes the ANTLR generated AADL parser, and resolves
all references to AAADL Data types into the param._signal member
of each SUBPROGRAM param.'''
151
152
153
    projectCache = os.getenv("PROJECT_CACHE")
    if projectCache is not None:
        if not os.path.isdir(projectCache):
154
155
156
157
158
            try:
                os.mkdir(projectCache)
            except:
                panic("The configured cache folder:\n\n\t" + projectCache +
                      "\n\n...is not there!\n")
159
    aadlASTcache = None
160
    astInfo = None
161
162
163
164
165
166
167
168
169
170
171
172
173
    if projectCache is not None:
        filehash = hashlib.md5()
        for each in sorted(sys.argv[1:]):
            filehash.update(open(each).read().encode('utf-8'))
        newHash = filehash.hexdigest()
        # set the name of the Pickle files containing the dumped AST
        aadlASTcache = projectCache + os.sep + newHash + "_aadl_ast.pickle"
        if not os.path.exists(aadlASTcache):
            print("[DMT] No cached AADL model found for",
                  ",".join(sys.argv[1:]))
        else:
            print("[DMT] Reusing cached AADL model for",
                  ",".join(sys.argv[1:]))
174
175
            astInfo = pickle.load(open(aadlASTcache, 'rb'), fix_imports=False)
    if astInfo is None:
176
177
178
179
180
181
182
        f = tempfile.NamedTemporaryFile(delete=False)
        astFile = f.name
        f.close()
        os.unlink(astFile)
        parserUtility = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "parse_aadl.py")
        cmd = "python2 " + parserUtility + " -o " + astFile + ' ' + \
Thanassis Tsiodras's avatar
PEP8    
Thanassis Tsiodras committed
183
            ' '.join(sys.argv[1:])
184
185
186
187
188
189
190
        if os.system(cmd) != 0:
            if os.path.exists(astFile):
                os.unlink(astFile)
            panic("AADL parsing failed. Aborting...")
        astInfo = pickle.load(open(astFile, 'rb'), fix_imports=False)
        if aadlASTcache:
            pickle.dump(astInfo, open(aadlASTcache, 'wb'), fix_imports=False)
191

192
193
    def FixMetaClasses(sp: ApLevelContainer) -> None:
        def patchMe(o: Any) -> None:
194
195
196
197
198
199
200
            try:
                python2className = str(o.__class__).split("'")[1]
                if 'commonPy2' in python2className:
                    klass = commonPy
                    for step in python2className.split('.')[1:]:
                        klass = getattr(klass, step)
                    o.__class__ = klass
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
201
            except Exception:
202
203
204
205
206
207
208
                pass

        patchMe(sp)
        for param in sp._params:
            patchMe(param)
            patchMe(param._signal)
            patchMe(param._sourceElement)
209
210
        # for c in sp._calls:
        #     patchMe(c)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
211
212
        for cn in sp._connections:
            patchMe(cn)
213
    try:
214
215
216
        for k in ['g_processImplementations', 'g_apLevelContainers',
                  'g_signals', 'g_systems', 'g_subProgramImplementations',
                  'g_threadImplementations']:
217
            setattr(commonPy.aadlAST, k, astInfo[k])
218
219
220
        for k in ['g_processImplementations',
                  'g_subProgramImplementations', 'g_threadImplementations']:
            for si in astInfo[k]:
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
221
222
                # sp, sp_impl, modelingLanguage, maybeFVname = si[0], si[1], si[2], si[3]
                sp = si[0]
223
224
                sp = commonPy.aadlAST.g_apLevelContainers[sp]
                FixMetaClasses(sp)
225
226
227
228
229
    except Exception as e:
        if os.path.exists(astFile):
            os.unlink(astFile)
        panic(str(e))

230

231
def SpecialCodes(asnFile: str) -> None:
232
233
234
235
    '''This function handles the code generations needs that reside outside
the scope of individual parameters (e.g. it needs access to all ASN.1
types). This used to cover Dumpable C/Ada Types and OG headers.'''
    outputDir = commonPy.configMT.outputDir
236
    asn1SccPath = spawn.find_executable('asn1.exe')
237
    # allow externally-defined flags when calling the asn1 compiler (e.g. to set word size based on target)
238
    extraFlags = os.getenv("ASN1SCC_FLAGS") or ""
239
    if asnFile is not None:
240
        if not asn1SccPath:
241
            panic("ASN1SCC seems not installed on your system (asn1.exe not found in PATH).\n")  # pragma: no cover
242
243
        os.system('mono "{}" -typePrefix asn1Scc {} -Ada -equal -o "{}" "{}"'
                  .format(asn1SccPath, extraFlags, outputDir, '" "'.join([asnFile])))
244
245


246
def getSyncBackend(modelingLanguage: str) -> Sync_B_Mapper:
247
248
    if modelingLanguage not in g_sync_mappers:
        panic("Synchronous modeling language '%s' not supported" % modelingLanguage)
249
250
    if os.getenv("ZESTSC1") is not None and modelingLanguage == 'vhdl':
        return cast(Sync_B_Mapper, zestSC1_B_mapper)
251
    return cast(Sync_B_Mapper, g_sync_mappers[modelingLanguage])
252
253
254
255
256
257
258
259
260


def ProcessSync(
        modelingLanguage: str,
        asnFile: str,
        sp: ApLevelContainer,
        sp_impl: str,
        maybeFVname: str,
        useOSS: bool,
261
262
        badTypes: SetOfBadTypenames) -> Sync_B_Mapper:
    backend = getSyncBackend(modelingLanguage)
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

    # Asynchronous backends are only generating standalone encoders and decoders
    # (they are not doing this per sp.param).
    #
    # They must however do this when they have collected ALL the types they are
    # supposed to handle, so this can only be done when the loop over
    # SystemsAndImplementations has completed. We therefore accumulate them in a
    # container, and call their 'OnShutdown' method (which generates the encoders
    # and decoders) at the end (outside the loop). This of course means that we
    # can only call OnStartup once (when the backend is first loaded)

    # In synchronous tools, always call OnStartup and OnShutdown for each SystemsAndImplementation
    backend.OnStartup(modelingLanguage, asnFile, sp, sp_impl, commonPy.configMT.outputDir, maybeFVname, useOSS)

    for param in sp._params:
        inform("Creating glue for param %s...", param._id)
279
        assert asnFile == param._signal._asnFilename
280
281
282
283
284
285
286
287
288
        names = commonPy.asnParser.g_names
        leafTypeDict = commonPy.asnParser.g_leafTypeDict

        inform("This param uses definitions from %s", asnFile)
        nodeTypename = param._signal._asnNodename

        # Check if this type must be skipped
        if nodeTypename in badTypes:
            continue
289

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
        node = names[nodeTypename]
        inform("ASN.1 node is %s", nodeTypename)

        # First, make sure we know what leaf type this node is
        if node._isArtificial:
            continue  # artificially created (inner) type

        leafType = leafTypeDict[nodeTypename]
        if leafType in ['BOOLEAN', 'INTEGER', 'REAL', 'OCTET STRING']:
            processor = backend.OnBasic
        elif leafType == 'SEQUENCE':
            processor = backend.OnSequence
        elif leafType == 'SET':
            processor = backend.OnSet
        elif leafType == 'CHOICE':
            processor = backend.OnChoice
        elif leafType == 'SEQUENCEOF':
            processor = backend.OnSequenceOf
        elif leafType == 'SETOF':
            processor = backend.OnSetOf
        elif leafType == 'ENUMERATED':
            processor = backend.OnEnumerated
        else:  # pragma: no cover
            panic("Unexpected type of element: %s" % leafType)  # pragma: no cover
        processor(nodeTypename, node, sp, sp_impl, param, leafTypeDict, names)

    # For synchronous backend, call OnShutdown once per each sp_impl
    backend.OnShutdown(modelingLanguage, asnFile, sp, sp_impl, maybeFVname)
318
319
320
321
    return backend


def getAsyncBackend(modelingLanguage: str) -> Async_B_Mapper:
322
323
324
    if modelingLanguage not in g_async_mappers:
        panic("Asynchronous modeling language '%s' not supported" % modelingLanguage)
    return cast(Async_B_Mapper, g_async_mappers[modelingLanguage])
325
326
327
328
329
330
331
332
333


def ProcessAsync(  # pylint: disable=dangerous-default-value
        modelingLanguage: str,
        asnFile: str,
        sp: ApLevelContainer,
        maybeFVname: str,
        useOSS: bool,
        badTypes: SetOfBadTypenames,
334
        loaded_languages_cache: List[str] = []) -> Async_B_Mapper:  # pylint: disable=invalid-sequence-index
335

336
    backend = getAsyncBackend(modelingLanguage)
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

    # Asynchronous backends are only generating standalone encoders and decoders
    # (they are not doing this per sp.param).
    #
    # They must however do this when they have collected ALL the types they are
    # supposed to handle, so this can only be done when the loop over
    # SystemsAndImplementations has completed. We therefore accumulate them in a
    # container, and call their 'OnShutdown' method (which generates the encoders
    # and decoders) at the end (outside the loop). This of course means that we
    # can only call OnStartup once (when the backend is first loaded)
    if modelingLanguage not in loaded_languages_cache:
        loaded_languages_cache.append(modelingLanguage)
        # Only call OnStartup ONCE for asynchronous backends
        # Also notice, no SP or SPIMPL are passed. We are asynchronous, so
        # we only generate "generic" encoders and decoders, not SP-specific ones.
        backend.OnStartup(modelingLanguage, asnFile, commonPy.configMT.outputDir, maybeFVname, useOSS)

    for param in sp._params:
        inform("Creating glue for param %s...", param._id)
356
        assert asnFile == param._signal._asnFilename
357
358
359
360
361
362
363
364
365
366
367
        names = commonPy.asnParser.g_names
        leafTypeDict = commonPy.asnParser.g_leafTypeDict

        inform("This param uses definitions from %s", asnFile)
        for nodeTypename in names:
            # Check if this type must be skipped
            if nodeTypename in badTypes:
                continue

            node = names[nodeTypename]
            inform("ASN.1 node is %s", nodeTypename)
368

369
370
371
            # First, make sure we know what leaf type this node is
            if node._isArtificial:
                continue  # artificially created (inner) type
372

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
            leafType = leafTypeDict[nodeTypename]
            if leafType in ['BOOLEAN', 'INTEGER', 'REAL', 'OCTET STRING']:
                processor = backend.OnBasic
            elif leafType == 'SEQUENCE':
                processor = backend.OnSequence
            elif leafType == 'SET':
                processor = backend.OnSet
            elif leafType == 'CHOICE':
                processor = backend.OnChoice
            elif leafType == 'SEQUENCEOF':
                processor = backend.OnSequenceOf
            elif leafType == 'SETOF':
                processor = backend.OnSetOf
            elif leafType == 'ENUMERATED':
                processor = backend.OnEnumerated
            else:  # pragma: no cover
                panic("Unexpected type of element: %s" % leafType)  # pragma: no cover
            processor(nodeTypename, node, leafTypeDict, names)
    return backend


def ProcessCustomBackends(
        # Taking list of tuples made of (spName, sp_impl, language, maybeFVname)
        asnFile: str,
        useOSS: bool,
        SystemsAndImplementations: List[Tuple[str, str, str, str]]) -> None:
399
400
401
402
403
404
405
406
407

    # The code generators for GUIs, Python mappers and VHDL mappers are different: they need access to
    # both ASN.1 types and SP params.
    # Custom code follows...

    # Do we need to handle any special subprograms?
    workedOnGUIs = False
    workedOnVHDL = False

408
    def getCustomBackends(lang: str) -> List[Sync_B_Mapper]:  # pylint: disable=invalid-sequence-index
409
        if lang.lower() in ["gui_pi", "gui_ri"]:
410
            return [cast(Sync_B_Mapper, x) for x in [python_B_mapper, pyside_B_mapper]]  # pragma: no cover
411
        elif lang.lower() == "vhdl":  # pragma: no cover
412
413
414
415
            if os.getenv("ZESTSC1") is not None:
                return [cast(Sync_B_Mapper, zestSC1_B_mapper)]  # pragma: no cover
            else:
                return [cast(Sync_B_Mapper, vhdl_B_mapper)]  # pragma: no cover
416
417
        else:
            panic("Unexpected call of getCustomBackends...")  # pragma: no cover
418
419
420

    for si in [x for x in SystemsAndImplementations if x[2] is not None and x[2].lower() in ["gui_ri", "gui_pi", "vhdl"]]:
        # We do, start the work
421
422
        spName, sp_impl, lang, maybeFVname = si[0], si[1], si[2], si[3]
        sp = commonPy.aadlAST.g_apLevelContainers[spName]
423
        if not sp._params:
424
425
426
427
428
429
430
431
432
            if lang.lower() == "gui_ri":  # pragma: no cover
                if "gui_polling" not in sp._id:  # pragma: no cover
                    panic("Due to wxWidgets limitations, your TCs must have at least one parameter (fix %s)" % sp._id)  # pragma: no cover
            continue  # pragma: no cover
        if lang.lower() in ["gui_pi", "gui_ri"]:
            workedOnGUIs = True
        if lang.lower() == "vhdl":
            workedOnVHDL = True  # pragma: no cover
        inform("Creating %s for %s.%s", lang.upper(), sp._id, sp_impl)
433
434
        for backend in getCustomBackends(lang):
            backend.OnStartup(lang, asnFile, sp, sp_impl, commonPy.configMT.outputDir, maybeFVname, useOSS)
435
436
        for param in sp._params:
            inform("Processing param %s...", param._id)
437
            assert asnFile == param._signal._asnFilename
438
439
440
441
442
            names = commonPy.asnParser.g_names
            leafTypeDict = commonPy.asnParser.g_leafTypeDict
            nodeTypename = param._signal._asnNodename
            node = names[nodeTypename]
            inform("ASN.1 node is %s", nodeTypename)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
443
444
            # if node._isArtificial:
            #     continue # artificially created (inner) type pragma: no cover
445
446
            leafType = leafTypeDict[nodeTypename]
            if leafType in ['BOOLEAN', 'INTEGER', 'REAL', 'OCTET STRING']:
447
448
                for backend in getCustomBackends(lang):
                    backend.OnBasic(nodeTypename, node, sp, sp_impl, param, leafTypeDict, names)
449
            elif leafType in ['SEQUENCE', 'SET', 'CHOICE', 'SEQUENCEOF', 'SETOF', 'ENUMERATED']:
450
451
452
453
454
455
456
457
458
459
460
461
462
                for backend in getCustomBackends(lang):
                    if leafType == 'SEQUENCE':
                        processor = backend.OnSequence
                    elif leafType == 'SET':
                        processor = backend.OnSet
                    elif leafType == 'CHOICE':
                        processor = backend.OnChoice
                    elif leafType == 'SEQUENCEOF':
                        processor = backend.OnSequenceOf
                    elif leafType == 'SETOF':
                        processor = backend.OnSetOf
                    elif leafType == 'ENUMERATED':
                        processor = backend.OnEnumerated
463
464
465
                    processor(nodeTypename, node, sp, sp_impl, param, leafTypeDict, names)
            else:  # pragma: no cover
                panic("Unexpected type of element: %s" % leafTypeDict[nodeTypename])  # pragma: no cover
466
467
468
        for backend in getCustomBackends(lang):
            backend.OnShutdown(lang, asnFile, sp, sp_impl, maybeFVname)

469
470
    # if we processed any GUI subprogram, add footers and close files
    if workedOnGUIs:
471
472
        for backend in getCustomBackends('gui_ri'):
            backend.OnFinal()
473
474
    # if we processed any VHDL subprogram, add footers and close files
    if workedOnVHDL:
475
476
477
        for backend in getCustomBackends('vhdl'):  # pragma: no cover
            backend.OnFinal()  # pragma: no cover

478

479
def main() -> None:
480
481
482
483
484
    if "-pdb" in sys.argv:
        sys.argv.remove("-pdb")  # pragma: no cover
        import pdb  # pragma: no cover pylint: disable=wrong-import-position,wrong-import-order
        pdb.set_trace()  # pragma: no cover

485
486
487
488
489
490
491
492
493
    if "-profile" in sys.argv:
        sys.argv.remove("-profile")
        import cProfile
        import pstats
        import io
        pr = cProfile.Profile()
        pr.enable()
        import atexit

494
        def dumpSpeedData() -> None:
495
496
497
498
499
500
501
502
            pr.disable()
            s = io.StringIO()
            sortby = 'cumulative'
            ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
            ps.print_stats()
            print(s.getvalue())
        atexit.register(dumpSpeedData)

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    if "-v" in sys.argv:
        import pkg_resources  # pragma: no cover
        version = pkg_resources.require("dmt")[0].version  # pragma: no cover
        print("aadl2glueC v" + str(version))  # pragma: no cover
        sys.exit(1)  # pragma: no cover

    if sys.argv.count("-o") != 0:
        idx = sys.argv.index("-o")
        try:
            commonPy.configMT.outputDir = os.path.normpath(sys.argv[idx + 1]) + os.sep
        except:  # pragma: no cover
            panic('Usage: %s [-v] [-verbose] [-useOSS] [-o dirname] input1.aadl [input2.aadl] ...\n' % sys.argv[0])  # pragma: no cover
        del sys.argv[idx]
        del sys.argv[idx]
        if not os.path.isdir(commonPy.configMT.outputDir):
            panic("'%s' is not a directory!\n" % commonPy.configMT.outputDir)  # pragma: no cover
    if "-onlySP" in sys.argv:  # pragma: no cover
        commonPy.configMT.g_bOnlySubprograms = True  # pragma: no cover
        sys.argv.remove("-onlySP")  # pragma: no cover
    if "-verbose" in sys.argv:
        commonPy.configMT.verbose = True
        sys.argv.remove("-verbose")
    useOSS = "-useOSS" in sys.argv
    if useOSS:
        sys.argv.remove("-useOSS")

    # No other options must remain in the cmd line...
    if len(sys.argv) < 2:
        panic('Usage: %s [-v] [-verbose] [-useOSS] [-o dirname] input1.aadl [input2.aadl] ...\n' % sys.argv[0])  # pragma: no cover
    commonPy.configMT.showCode = True
    for f in sys.argv[1:]:
        if not os.path.isfile(f):
            panic("'%s' is not a file!\n" % f)  # pragma: no cover

    ParseAADLfilesAndResolveSignals()

    uniqueDataFiles = {}  # type: Dict[Filename, Dict[str, List[ApLevelContainer]]]
    for sp in list(commonPy.aadlAST.g_apLevelContainers.values()):
        for param in sp._params:
            uniqueDataFiles.setdefault(param._signal._asnFilename, {})
            uniqueDataFiles[param._signal._asnFilename].setdefault(sp._language, [])
            uniqueDataFiles[param._signal._asnFilename][sp._language].append(sp)

    asn1files = list(uniqueDataFiles.keys())
    if len(asn1files) == 1:
        asnFile = asn1files[0]
549
        inform("Checking that all base nodes have mandatory ranges set in %s..." % asnFile)
550
        commonPy.asnParser.ParseAsnFileList(asn1files)
551
    elif asn1files:
552
553
        panic("There appear to be more than one ASN.1 files referenced (%s)..." % str(asn1files))

554
555
556
    names = commonPy.asnParser.g_names
    for node in names.values():
        verify.VerifyRanges(node, names)
557
558
559
560
561

    SystemsAndImplementations = commonPy.aadlAST.g_subProgramImplementations[:]
    SystemsAndImplementations.extend(commonPy.aadlAST.g_threadImplementations[:])
    SystemsAndImplementations.extend(commonPy.aadlAST.g_processImplementations[:])

562
563
564
    # If some AST nodes must be skipped (for any reason), go learn about them
    badTypes = DiscoverBadTypes()

565
566
567
568
569
570
571
572
573
    # Update ASN.1 nodes to carry size info (only for Signal params)
    for si in SystemsAndImplementations:
        spName, sp_impl, modelingLanguage = si[0], si[1], si[2]
        sp = commonPy.aadlAST.g_apLevelContainers[spName]
        for param in sp._params:
            # If there is a parameter used, then there MUST be an asnFile referenced!
            assert asnFile == param._signal._asnFilename
            nodeTypename = param._signal._asnNodename
            node = commonPy.asnParser.g_names[nodeTypename]
574
575
576
577
            if node._leafType == "AsciiString" or nodeTypename in badTypes:
                panic("For type %s:\n\tIA5String and types that depend on them cannot "
                      "be used as a parameter.\n\tUse OCTET STRINGs instead!\n\t(%s)" % (
                          nodeTypename, node.Location()))  # pragma: no cover
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
                # (typo?) node._asnSize = param._signal._asnSize

    if {"ada", "qgenada"} & {y[2].lower() for y in SystemsAndImplementations}:
        SpecialCodes(asnFile)

    asynchronousBackends = set([])  # type: Set[Async_B_Mapper]

    # Moving to static typing - no more dynamic imports,
    # so this information must be statically available
    async_languages = list(g_async_mappers.keys())

    for si in SystemsAndImplementations:
        spName, sp_impl, modelingLanguage, maybeFVname = si[0], si[1], si[2], si[3]
        if modelingLanguage is None:
            continue  # pragma: no cover
        sp = commonPy.aadlAST.g_apLevelContainers[spName]
        inform("Creating glue for parameters of %s.%s...", sp._id, sp_impl)

596
597
        if not sp._params:
            # Avoid generating empty glue - no parameters for this APLC
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
            continue

        # All SCADE versions are handled by lustre_B_mapper
        # if modelingLanguage[:6] == "Lustre" or modelingLanguage[:5] == "SCADE":
        #    modelingLanguage = "Lustre"  # pragma: no cover

        # The code for these mappers needs C ASN.1 codecs
        if modelingLanguage.lower() in ["gui_ri", "gui_pi", "vhdl", "rhapsody"]:
            modelingLanguage = "C"

        if modelingLanguage in async_languages:
            m = ProcessAsync(modelingLanguage, asnFile, sp, maybeFVname, useOSS, badTypes)
            asynchronousBackends.add(m)
        else:
            ProcessSync(modelingLanguage, asnFile, sp, sp_impl, maybeFVname, useOSS, badTypes)

    # SystemsAndImplementation loop completed - time to call OnShutdown ONCE for each async backend that we loaded
    for asyncBackend in asynchronousBackends:
        asyncBackend.OnShutdown(modelingLanguage, asnFile, maybeFVname)

    ProcessCustomBackends(asnFile, useOSS, SystemsAndImplementations)


621
if __name__ == "__main__":
622
    main()