Commit 9ff9de74 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Generate simulation script properly

parent 72320a54
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
import logging import logging
import traceback import traceback
import os import os
import stat
from itertools import chain, product from itertools import chain, product
from singledispatch import singledispatch from singledispatch import singledispatch
...@@ -155,26 +156,50 @@ def _process(process, simu=False, **kwargs): ...@@ -155,26 +156,50 @@ def _process(process, simu=False, **kwargs):
return '\n'.join(res) return '\n'.join(res)
# bash script to simulate the system (TEMPORARY) # bash script to simulate the system (TEMPORARY)
# go up to the root of the AST to get the list of ASN.1 files
parent = process.parent
while hasattr(parent, 'parent') and parent.parent:
parent = parent.parent
if isinstance(parent, ogAST.System):
parent = parent.ast
asn1_filenames = ' '.join(parent.asn1_filenames)
pr_path = ' '.join(parent.pr_files)
pr_names = ' '.join(
os.path.basename(pr_file) for pr_file in parent.pr_files)
asn1_modules = (name.lower().replace('-', '_') + '.o'
for name in process.asn1Modules)
simu_script = '''#!/bin/bash -e simu_script = '''#!/bin/bash -e
opengeode {pr}.pr --shared rm -rf {pr}_simu
asn1.exe -Ada dataview-uniq.asn -typePrefix asn1Scc -equal mkdir -p {pr}_simu
asn1.exe -c dataview-uniq.asn -typePrefix asn1Scc -equal cp {pr_path} {asn1} {pr}_simu
cd {pr}_simu
opengeode {pr_names} --shared
cat *.asn > dataview-uniq.asn '''.format(pr=process_name,
if asn1_filenames:
simu_script += '''
asn1.exe -Ada -typePrefix asn1Scc -equal {asn1}
asn1.exe -c -typePrefix asn1Scc -equal {asn1}'''.format(asn1=asn1_filenames)
simu_script += '''
gnatmake -gnat2012 -c *.adb gnatmake -gnat2012 -c *.adb
gnatbind -n -Llib{pr} {pr} gnatbind -n -Llib{pr} {pr}
gnatmake -c -gnat2012 b~{pr}.adb gnatmake -c -gnat2012 b~{pr}.adb
gcc -shared -fPIC -o lib{pr}.so b~{pr}.o {pr}.o taste_dataview.o adaasn1rtl.o -lgnat gcc -shared -fPIC -o lib{pr}.so b~{pr}.o {pr}.o {asn1_mod} adaasn1rtl.o -lgnat
rm -rf simu asn2aadlPlus dataview-uniq.asn DataView.aadl
mkdir -p simu
asn2aadlPlus dataview-uniq.asn simu/DataView.aadl
cp lib{pr}.so dataview-uniq.asn *.pr simu
mv *.aadl simu
cd simu
aadl2glueC DataView.aadl {pr}_interface.aadl aadl2glueC DataView.aadl {pr}_interface.aadl
asn2dataModel -toPython dataview-uniq.asn asn2dataModel -toPython dataview-uniq.asn
make -f Makefile.python make -f Makefile.python
echo "errCodes=$(taste-asn1-errCodes ./dataview-uniq.h)" >> echo "errCodes=$(taste-asn1-errCodes ./dataview-uniq.h)" >>
LD_LIBRARY_PATH=. taste-gui -l LD_LIBRARY_PATH=. opengeode-simulator
'''.format(pr=process_name) '''.format(pr=process_name,
asn1_mod=' '.join(asn1_modules))'Generating Ada code for process ' + str(process_name))'Generating Ada code for process ' + str(process_name))
...@@ -794,8 +819,10 @@ package {process_name} is'''.format(process_name=process_name, ...@@ -794,8 +819,10 @@ 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'))
with open('{}'.format(process_name), 'w') as bash_script: script = '{}'.format(process_name)
with open(script, 'w') as bash_script:
bash_script.write(simu_script) bash_script.write(simu_script)
os.chmod(script, os.stat(script).st_mode | stat.S_IXUSR)
def write_statement(param, newline): def write_statement(param, newline):
#!/bin/bash -e
make test-python
rm -rf simu
mkdir -p simu
asn2aadlPlus dataview.asn simu/DataView.aadl
cp dataview.asn *.pr simu
mv *.aadl simu
cd simu
aadl2glueC DataView.aadl og_interface.aadl
asn2dataModel -toPython dataview.asn
make -f Makefile.python
echo "errCodes=$(taste-asn1-errCodes ./dataview.h)" >>
LD_LIBRARY_PATH=. opengeode-simulator
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