Commit 92b13e62 authored by Maxime Perrotin's avatar Maxime Perrotin

Generate gpr and Makefile

not complete, the gpr for SDL must call opengeode to generate Ada with
all input files in one go, not one call per file
parent ce83f208
...@@ -242,9 +242,32 @@ def _process(process, simu=False, instance=False, **kwargs): ...@@ -242,9 +242,32 @@ def _process(process, simu=False, instance=False, **kwargs):
pr_path = ' '.join(parent.pr_files) if None not in parent.pr_files else '' pr_path = ' '.join(parent.pr_files) if None not in parent.pr_files else ''
pr_names = ' '.join( pr_names = ' '.join(
os.path.basename(pr_file) for pr_file in parent.pr_files) os.path.basename(pr_file) for pr_file in parent.pr_files)
asn1_modules = (name.lower().replace('-', '_') + '.o' asn1_modules_o = (name.lower().replace('-', '_') + '.o'
for name in process.asn1Modules) for name in process.asn1Modules)
asn1_mods = ("\"{}\"".format(mod.lower().replace('-', '_'))
for mod in process.asn1Modules)
# Create a .gpr to build the library for the simulator
lib_gpr = '''project {pr}_Lib is
for Languages use ("Ada");
for Library_Name use "{pr}";
for Library_Interface use ("{pr}", "adaasn1rtl", {other_asn1_modules});
for Object_Dir use "obj";
for Library_Dir use "lib";
for Library_Standalone use "encapsulated";
for Library_Kind use "dynamic";
for Source_Dirs use (".");
end {pr}_Lib;'''.format(pr=process_name.lower(),
other_asn1_modules=", ".join(asn1_mods))
# Create a .gpr to build the Ada generated code
ada_gpr = '''project {pr}_Ada is
for Languages use ("Ada");
for Source_Dirs use ("code");
for Object_Dir use "obj";
end {pr}_Ada;'''.format(pr=process_name.lower())
simu_script = '''#!/bin/bash -e simu_script = '''#!/bin/bash -e
rm -rf {pr}_simu rm -rf {pr}_simu
mkdir -p {pr}_simu mkdir -p {pr}_simu
...@@ -264,20 +287,17 @@ mono $(which asn1.exe) -c -typePrefix asn1Scc -equal {asn1}'''.format( ...@@ -264,20 +287,17 @@ mono $(which asn1.exe) -c -typePrefix asn1Scc -equal {asn1}'''.format(
asn1=asn1_filenames) asn1=asn1_filenames)
simu_script += ''' simu_script += '''
gnatmake -fPIC -gnat2012 -c *.adb gprbuild -p -P ../{pr}_lib.gpr
gnatbind -n -Llib{pr} {pr}
gnatmake -fPIC -c -gnat2012 b~{pr}.adb
gcc -shared -fPIC -o lib{pr}.so b~{pr}.o {pr}.o {asn1_mod} adaasn1rtl.o -lgnat
rm -f dataview-uniq.c dataview-uniq.h rm -f dataview-uniq.c dataview-uniq.h
asn2aadlPlus dataview-uniq.asn DataView.aadl asn2aadlPlus dataview-uniq.asn DataView.aadl
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)" >>datamodel.py echo "errCodes=$(taste-asn1-errCodes ./dataview-uniq.h)" >>datamodel.py
LD_LIBRARY_PATH=. opengeode-simulator LD_LIBRARY_PATH=../lib:. opengeode-simulator
'''.format(pr=process_name.lower(), '''.format(pr=process_name.lower(),
asn1_files=asn1_filenames, asn1_files=asn1_filenames,
asn1_mod=' '.join(asn1_modules)) asn1_mod=' '.join(asn1_modules_o))
LOG.info('Generating Ada code for process ' + str(process_name)) LOG.info('Generating Ada code for process ' + str(process_name))
...@@ -1089,6 +1109,9 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -1089,6 +1109,9 @@ package {process_name} is'''.format(generic=generic_spec,
ada_file.write( ada_file.write(
u'\n'.join(format_ada_code(ads_template)).encode('latin1')) u'\n'.join(format_ada_code(ads_template)).encode('latin1'))
with open("{}_ada.gpr".format(process_name.lower()), "w") as gprada:
gprada.write(ada_gpr)
if simu: if simu:
with open(u'{}_interface.aadl' with open(u'{}_interface.aadl'
.format(process_name.lower()), 'w') as aadl: .format(process_name.lower()), 'w') as aadl:
...@@ -1096,6 +1119,8 @@ package {process_name} is'''.format(generic=generic_spec, ...@@ -1096,6 +1119,8 @@ package {process_name} is'''.format(generic=generic_spec,
script = '{}_simu.sh'.format(process_name.lower()) script = '{}_simu.sh'.format(process_name.lower())
with open(script, 'w') as bash_script: with open(script, 'w') as bash_script:
bash_script.write(simu_script) bash_script.write(simu_script)
with open("{}_lib.gpr".format(process_name.lower()), 'w') as gprlib:
gprlib.write(lib_gpr)
os.chmod(script, os.stat(script).st_mode | stat.S_IXUSR) os.chmod(script, os.stat(script).st_mode | stat.S_IXUSR)
......
...@@ -85,7 +85,7 @@ except ImportError: ...@@ -85,7 +85,7 @@ except ImportError:
from PySide import QtGui, QtCore from PySide import QtGui, QtCore
from PySide.QtCore import (Qt, QSize, QFile, QIODevice, QRectF, QTimer, QPoint, from PySide.QtCore import (Qt, QSize, QFile, QIODevice, QRectF, QTimer, QPoint,
QPointF, QLineF) QPointF, QLineF, QFileInfo)
from PySide.QtUiTools import QUiLoader from PySide.QtUiTools import QUiLoader
from PySide import QtSvg from PySide import QtSvg
...@@ -1938,6 +1938,7 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -1938,6 +1938,7 @@ class SDL_View(QtGui.QGraphicsView, object):
def save_diagram(self, save_as=False, autosave=False): def save_diagram(self, save_as=False, autosave=False):
''' Save the diagram to a .pr file ''' ''' Save the diagram to a .pr file '''
if (not self.filename or save_as) and not autosave: if (not self.filename or save_as) and not autosave:
save_as = True save_as = True
self.filename = QtGui.QFileDialog.getSaveFileName( self.filename = QtGui.QFileDialog.getSaveFileName(
...@@ -1947,6 +1948,50 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -1947,6 +1948,50 @@ class SDL_View(QtGui.QGraphicsView, object):
filename = ((self.filename or '_opengeode') filename = ((self.filename or '_opengeode')
+ '.autosave') if autosave else self.filename + '.autosave') if autosave else self.filename
prj_name = ''.join(
filename.split(os.path.extsep)[0:-1]).split(os.path.sep)[-1]
template_gpr_sdl = '''with "dataview_ada";
project {pr} is
for Languages use ("SDL");
for Source_Dirs use (".");
for Object_Dir use "code";
package Naming is
for Body_Suffix ("SDL") use ".pr";
end Naming;
package Compiler is
for Driver ("SDL") use "opengeode";
for Object_File_Suffix ("SDL") use ".adb";
for Leading_Required_Switches ("SDL") use ("--toAda");
end Compiler;
end {pr};'''.format(pr=prj_name)
# ASN1 template to be filled with "Ada" or "c"
template_gpr_asn1 = '''project DataView_{lang} is
for Languages use ("ASN1");
for Source_Dirs use (".");
for Object_Dir use "code";
package Naming is
for Body_Suffix ("ASN1") use ".asn";
end Naming;
package Compiler is
for Driver ("ASN1") use "asn1.exe";
for Leading_Required_Switches ("ASN1") use ("-{lang}", "-typePrefix", "Asn1Scc");
end Compiler;
end DataView_{lang};'''
# Template for the Makefile
template_makefile = '''all:
\tgprbuild -p -P {pr}.gpr # generate Ada code from the SDL and ASN.1 models
\tgprbuild -p -P {pr}_ada.gpr # build the Ada code
clean:
\trm -rf obj code'''.format(pr=prj_name)
# If the current scene is a nested one, save the top parent # If the current scene is a nested one, save the top parent
scene = self.top_scene() scene = self.top_scene()
...@@ -2000,6 +2045,7 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -2000,6 +2045,7 @@ class SDL_View(QtGui.QGraphicsView, object):
else: else:
pr_file = QFile(filename) pr_file = QFile(filename)
pr_path = QFileInfo(pr_file).path()
pr_file.open(QIODevice.WriteOnly | QIODevice.Text) pr_file.open(QIODevice.WriteOnly | QIODevice.Text)
if not autosave and save_as: if not autosave and save_as:
scene.name = 'block {}[*]'.format(''.join(filename scene.name = 'block {}[*]'.format(''.join(filename
...@@ -2028,6 +2074,21 @@ class SDL_View(QtGui.QGraphicsView, object): ...@@ -2028,6 +2074,21 @@ class SDL_View(QtGui.QGraphicsView, object):
pr_file.write(pr_data.encode('utf-8')) pr_file.write(pr_data.encode('utf-8'))
pr_file.close() pr_file.close()
if not autosave: if not autosave:
# also create gpr files to compile the model
with open(pr_path + os.sep + prj_name + '.gpr', 'w') as gpr:
gpr.write(template_gpr_sdl)
with open(pr_path + '/dataview_ada.gpr', 'w') as gpr:
gpr.write(template_gpr_asn1.format(lang='Ada'))
# dataview_c.gpr is needed for the simulator
with open(pr_path + '/dataview_c.gpr', 'w') as gpr:
gpr.write(template_gpr_asn1.format(lang='c'))
# and generate a Makefile.project to build everything
with open(pr_path + '/Makefile.{}'.format(prj_name), 'w') as f:
f.write(template_makefile)
self.scene().clear_focus() self.scene().clear_focus()
for each in chain([scene], scene.all_nested_scenes): for each in chain([scene], scene.all_nested_scenes):
each.undo_stack.setClean() each.undo_stack.setClean()
......
all:
gprbuild -p -P orchestrator.gpr # generate Ada code from the SDL and ASN.1 models
gprbuild -p -P orchestrator_ada.gpr # build the Ada code
clean:
rm -rf obj code
\ No newline at end of file
with "dataview_ada";
project orchestrator is
for Languages use ("SDL");
for Source_Dirs use (".");
for Object_Dir use "code";
package Naming is
for Body_Suffix ("SDL") use ".pr";
end Naming;
package Compiler is
for Driver ("SDL") use "opengeode";
for Object_File_Suffix ("SDL") use ".adb";
for Leading_Required_Switches ("SDL") use ("--toAda");
end Compiler;
end orchestrator;
\ No newline at end of file
...@@ -57,11 +57,11 @@ comment 'Hello'; ...@@ -57,11 +57,11 @@ comment 'Hello';
NEXTSTATE Wait; NEXTSTATE Wait;
/* CIF state (1680, 345), (74, 35) */ /* CIF state (1680, 345), (74, 35) */
state next; state next;
/* CIF input (1679, 400), (71, 35) */ /* CIF input (1677, 400), (74, 35) */
input pulse(a); input pulse(a);
/* CIF PROCEDURECALL (1609, 450), (213, 35) */ /* CIF PROCEDURECALL (1607, 450), (213, 35) */
call reset_timer(mytimer); call reset_timer(mytimer);
/* CIF NEXTSTATE (1680, 500), (70, 35) */ /* CIF NEXTSTATE (1679, 500), (70, 35) */
NEXTSTATE wait; NEXTSTATE wait;
endstate; endstate;
/* CIF state (1674, 125), (100, 35) */ /* CIF state (1674, 125), (100, 35) */
...@@ -116,7 +116,7 @@ anint := 478; ...@@ -116,7 +116,7 @@ anint := 478;
NEXTSTATE next; NEXTSTATE next;
/* CIF input (1219, 305), (147, 35) */ /* CIF input (1219, 305), (147, 35) */
input Paramless_TC; input Paramless_TC;
/* CIF task (1180, 360), (223, 35) */ /* CIF task (1175, 360), (234, 35) */
task counter := (counter + 1) mod 500; task counter := (counter + 1) mod 500;
/* CIF PROCEDURECALL (1166, 410), (253, 35) */ /* CIF PROCEDURECALL (1166, 410), (253, 35) */
call writeln('Got Paramless TC'); call writeln('Got Paramless TC');
......
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