Skip to content

Commit

Permalink
C code generation ideas as an test.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Dec 15, 2018
1 parent d193159 commit c25d4a4
Show file tree
Hide file tree
Showing 9 changed files with 1,120 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -59,4 +59,5 @@ target/
test_command_line_*
test_cache
compile_methods_cache
/*.[hc]
/*.[hc]
/main
27 changes: 27 additions & 0 deletions Makefile
@@ -1,3 +1,21 @@
ifeq ($(origin CC), default)
CC = gcc
endif

C_SOURCES := \
tests/main.c \
tests/files/c_source/c_source/oer.c

CFLAGS := \
-Wall \
-Wextra \
-Wdouble-promotion \
-Wfloat-equal \
-Wformat=2 \
-Wshadow \
-Werror

.PHONY: test
test:
python2 setup.py test
python3 setup.py test
Expand All @@ -12,8 +30,16 @@ test:
env PYTHONPATH=. python3 examples/compact_extensions_uper/main.py
env PYTHONPATH=. python3 examples/programming_types/main.py
codespell -d $$(git ls-files | grep -v ietf | grep -v 3gpp)
$(MAKE) test-c
python3 -m pycodestyle $$(git ls-files "asn1tools/*.py")

.PHONY: test-c
test-c:
$(CC) $(CFLAGS) -Wpedantic -std=c99 -O3 $(C_SOURCES) \
-o main
./main

.PHONY: test-sdist
test-sdist:
rm -rf dist
python setup.py sdist
Expand All @@ -24,6 +50,7 @@ test-sdist:
cd asn1tools-* && \
python setup.py test

.PHONY: release-to-pypi
release-to-pypi:
python setup.py sdist
python setup.py bdist_wheel --universal
Expand Down
7 changes: 7 additions & 0 deletions asn1tools/__init__.py
Expand Up @@ -261,6 +261,10 @@ def _do_parse(args):

def _do_generate_c_source(args):
name = 'c_source'

if args.namespace is not None:
name = '{}_{}'.format(args.namespace, name)

filename_h = name + '.h'
filename_c = name + '.c'

Expand Down Expand Up @@ -352,6 +356,9 @@ def _main():
choices=('oer', ),
default='oer',
help='Codec to generate code for (default: oer).')
subparser.add_argument(
'-n', '--namespace',
help='Namespace of defines, structs, functions, files, etc.')
subparser.add_argument('specification',
nargs='+',
help='ASN.1 specification as one or more .asn files.')
Expand Down

0 comments on commit c25d4a4

Please sign in to comment.