Commit ebf11fb3 authored by Maxime Perrotin's avatar Maxime Perrotin

Generate iterators for SEQUENCE

parent f1cfa191
...@@ -5,11 +5,10 @@ all: ...@@ -5,11 +5,10 @@ all:
@echo A testcase can be build from source with "make test" @echo A testcase can be build from source with "make test"
install: uninstall install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \ mkdir -p obj && cp src/taste-asn1-iterators.py obj/taste-asn1-iterators
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
rm -rf obj
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr @echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install test_build: clean install
......
PREFIX?=$(HOME)/.local
all:
@echo You can install with "make install"
@echo A testcase can be build from source with "make test"
install: uninstall
mkdir -p obj && rm -f obj/taste-asn1-iterators && \
sed 's,$$PREFIX,$(PREFIX),g' src/taste-asn1-iterators > obj/taste-asn1-iterators && \
chmod +x obj/taste-asn1-iterators
gprbuild -p asn1_iterators.gpr
gprinstall -p -XLIBRARY_TYPE=dynamic --build-name=shared --prefix=$(PREFIX) asn1_iterators.gpr
@echo Do not forget to export ADA_PROJECT_PATH=$(PREFIX)/share/gpr
test_build: clean install
mkdir -p build_test
cp test/DataView.asn build_test
cd build_test && taste-asn1-iterators DataView.asn
gprbuild -p -P test_generic.gpr
test: test_build
build_test/test_generic
uninstall:
gprinstall --uninstall --prefix=$(PREFIX) asn1_iterators || :
clean:
gprclean test_generic.gpr || :
gprclean asn1_iterators.gpr || :
.PHONY: all clean install test test_build
asn1-iterators asn1-iterators
============== ==============
(c) 2016-2017 European Space Agency (c) 2016-2019 European Space Agency
Author/Contact: Maxime.Perrotin@esa.int Author/Contact: Maxime.Perrotin@esa.int
Generic iterator functions in Ada for generating all combinations of values of ASN.1 data types Generic iterator functions in Ada for generating all combinations of values of ASN.1 data types
v0.1 support for INTEGER with a range and SEQUENCE OF INTEGER (fixed and variable size arrays) Support integer, enumerated, sequence, sequence of (fixed and variable sizes)
test:
cd src
make
Work in progress... Part of the TASTE project. Work in progress... Part of the TASTE project.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
""" """
__version__ = "3.0.0" __version__ = "3.0.0"
import os
import signal import signal
import argparse import argparse
import traceback import traceback
...@@ -265,6 +266,21 @@ def sequence_adb_template (sort: str, fields: dict) -> str: ...@@ -265,6 +266,21 @@ def sequence_adb_template (sort: str, fields: dict) -> str:
end {sort}_Pkg;''' end {sort}_Pkg;'''
def top_ads_template(modules: List[str]) -> str:
''' Template for asn1_ada_iterators.ads '''
withs = (f'''with {module}; use {module}; pragma Unreferenced ({module});'''
for module in modules)
withs_str = '\n'.join(withs)
return f'''-- This file was generated by TASTE: DO NOT EDIT
{withs_str}
package ASN1_Ada_Iterators is
end;'''
def ads_template(packages: List[str]) -> str: def ads_template(packages: List[str]) -> str:
''' Top-level template to generate the .ads file ''' ''' Top-level template to generate the .ads file '''
return f'''-- This file was generated by TASTE: DO NOT EDIT return f'''-- This file was generated by TASTE: DO NOT EDIT
...@@ -434,6 +450,13 @@ def parse_args(): ...@@ -434,6 +450,13 @@ def parse_args():
action='store_true', action='store_true',
default=False, default=False,
help='Display debug information') help='Display debug information')
parser.add_argument(
'-o',
'--output',
type=str,
metavar='folder',
default='iterators',
help='Set the output folder')
parser.add_argument( parser.add_argument(
'files', 'files',
metavar='file.asn', metavar='file.asn',
...@@ -465,7 +488,7 @@ def run(options): ...@@ -465,7 +488,7 @@ def run(options):
# Parse the ASN.1 AST to know the types and generate the corresponding code # Parse the ASN.1 AST to know the types and generate the corresponding code
sorts = {} sorts = {}
for module, types in ast.exportedTypes.items(): for module, types in ast.exportedTypes.items():
modules.append(module) modules.append(module.replace('-', '_'))
for sort in types: for sort in types:
sort_def = ast.types[sort] sort_def = ast.types[sort]
basic = parser.find_basic_type (sort_def.type) basic = parser.find_basic_type (sort_def.type)
...@@ -518,14 +541,20 @@ def run(options): ...@@ -518,14 +541,20 @@ def run(options):
ads = ads_template(packages_ads) ads = ads_template(packages_ads)
adb = adb_template(packages_adb) adb = adb_template(packages_adb)
top_ads = top_ads_template(modules)
out_folder = options.output if options.output else '.'
os.makedirs(out_folder, exist_ok=True)
# Write the .ads # Write the .ads
with open ("asn1_ada_iterators-iterators.ads", "wb") as source: with open (f"{out_folder}/asn1_ada_iterators-iterators.ads", "wb") as source:
source.write(ads.encode('latin1')) source.write(ads.encode('latin1'))
with open ("asn1_ada_iterators-iterators.adb", "wb") as source: with open (f"{out_folder}/asn1_ada_iterators-iterators.adb", "wb") as source:
source.write(adb.encode('latin1')) source.write(adb.encode('latin1'))
with open (f"{out_folder}/asn1_ada_iterators.ads", "wb") as source:
source.write(top_ads.encode('latin1'))
def main(): def main():
''' Tool entry point ''' ''' Tool entry point '''
# Catch Ctrl-C to stop the app from the console # Catch Ctrl-C to stop the app from the console
......
this folder is DEPRECATED, the code is now generated from python
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