Commit 8e74a764 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Introduce cache-ing of AADL ASTs created by ANTLR-based parser.

parent b7f5c79b
...@@ -80,6 +80,7 @@ but with an extra call to OnFinal at the end. ...@@ -80,6 +80,7 @@ but with an extra call to OnFinal at the end.
import os import os
import sys import sys
import hashlib
from distutils import spawn from distutils import spawn
from typing import cast, Optional, Dict, List, Tuple, Set, Any # NOQA pylint: disable=unused-import from typing import cast, Optional, Dict, List, Tuple, Set, Any # NOQA pylint: disable=unused-import
...@@ -145,19 +146,48 @@ def ParseAADLfilesAndResolveSignals() -> None: ...@@ -145,19 +146,48 @@ def ParseAADLfilesAndResolveSignals() -> None:
'''Invokes the ANTLR generated AADL parser, and resolves '''Invokes the ANTLR generated AADL parser, and resolves
all references to AAADL Data types into the param._signal member all references to AAADL Data types into the param._signal member
of each SUBPROGRAM param.''' of each SUBPROGRAM param.'''
import tempfile projectCache = os.getenv("PROJECT_CACHE")
f = tempfile.NamedTemporaryFile(delete=False) if projectCache is not None:
astFile = f.name if not os.path.isdir(projectCache):
f.close() panic("The configured cache folder:\n\n\t" + projectCache +
os.unlink(astFile) "\n\n...is not there!\n")
parserUtility = os.path.join( cachedModelExists = False
os.path.abspath(os.path.dirname(__file__)), "parse_aadl.py") aadlASTcache = None
cmd = "python2 " + parserUtility + " -o " + astFile + ' ' + \ 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:
cachedModelExists = True
print("[DMT] Reusing cached AADL model for",
",".join(sys.argv[1:]))
import pickle
if cachedModelExists:
astInfo = pickle.load(open(aadlASTcache, 'rb'), fix_imports=False)
else:
import tempfile
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 + ' ' + \
' '.join(sys.argv[1:]) ' '.join(sys.argv[1:])
if os.system(cmd) != 0: if os.system(cmd) != 0:
if os.path.exists(astFile): if os.path.exists(astFile):
os.unlink(astFile) os.unlink(astFile)
panic("AADL parsing failed. Aborting...") 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)
def FixMetaClasses(sp: ApLevelContainer) -> None: def FixMetaClasses(sp: ApLevelContainer) -> None:
def patchMe(o: Any) -> None: def patchMe(o: Any) -> None:
...@@ -181,8 +211,6 @@ of each SUBPROGRAM param.''' ...@@ -181,8 +211,6 @@ of each SUBPROGRAM param.'''
for cn in sp._connections: for cn in sp._connections:
patchMe(cn) patchMe(cn)
try: try:
import pickle
astInfo = pickle.load(open(astFile, 'rb'), fix_imports=False)
for k in ['g_processImplementations', 'g_apLevelContainers', for k in ['g_processImplementations', 'g_apLevelContainers',
'g_signals', 'g_systems', 'g_subProgramImplementations', 'g_signals', 'g_systems', 'g_subProgramImplementations',
'g_threadImplementations']: 'g_threadImplementations']:
......
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