Commit c2ede186 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Merge pull request #31 from lattuada/master

C Backend
parents 2b77c93e 5c8a87a0
...@@ -7,4 +7,34 @@ install.record ...@@ -7,4 +7,34 @@ install.record
antlr-3.1.3.tar.bz2 antlr-3.1.3.tar.bz2
antlr-3.1.3/ antlr-3.1.3/
test_c
tests/**/*.stg tests/**/*.stg
tests/regression/test-controlflow/controlflow.*
tests/regression/test-debug/orchestrator.*
tests/regression/test-equal/og.*
tests/regression/test-exitnested/challenge.*
tests/regression/test-expressions/expressions.*
tests/regression/test-llvm/orchestrator.*
tests/regression/test-nocif/orchestrator.*
tests/regression/test-operators/operators.*
tests/regression/test-processfpar1/og.*
tests/regression/test-processfpar2/og.*
tests/regression/test-simu/orchestrator.*
tests/regression/test-standalone/og.*
tests/regression/test-strings/og.*
tests/regression/test-substrings/myfunction.*
tests/regression/test-types/function1.*
tests/regression/test1/og.*
tests/regression/test10/challenge.*
tests/regression/test11/og.*
tests/regression/test12/trafficlight.*
tests/regression/test2/orchestrator.*
tests/regression/test3/fce.*
tests/regression/test4/asn1crt.*
tests/regression/test4/orchestrator.*
tests/regression/test5/function0.*
tests/regression/test6/myfunction.*
tests/regression/test7/orchestrator.*
tests/regression/test8/orchestrator.*
tests/regression/test9/challenge.*
This diff is collapsed.
...@@ -98,6 +98,11 @@ try: ...@@ -98,6 +98,11 @@ try:
except ImportError: except ImportError:
graphviz = False graphviz = False
try:
import CGenerator
except ImportError:
CGenerator = None
try: try:
import LlvmGenerator import LlvmGenerator
except ImportError: except ImportError:
...@@ -1977,6 +1982,8 @@ def parse_args(): ...@@ -1977,6 +1982,8 @@ def parse_args():
help='Generate Ada code for the .pr file') help='Generate Ada code for the .pr file')
parser.add_argument('--llvm', dest='llvm', action='store_true', parser.add_argument('--llvm', dest='llvm', action='store_true',
help='Generate LLVM IR code for the .pr file (experimental)') help='Generate LLVM IR code for the .pr file (experimental)')
parser.add_argument('--toC', dest='toC', action='store_true',
help='Generate C code .pr file (experimental)')
parser.add_argument("-O", dest="optimization", metavar="level", type=int, parser.add_argument("-O", dest="optimization", metavar="level", type=int,
action="store", choices=[0, 1, 2, 3], default=0, action="store", choices=[0, 1, 2, 3], default=0,
help="Set optimization level for the generated LLVM IR code") help="Set optimization level for the generated LLVM IR code")
...@@ -2023,6 +2030,7 @@ def init_logging(options): ...@@ -2023,6 +2030,7 @@ def init_logging(options):
TextInteraction, TextInteraction,
Connectors, Connectors,
LlvmGenerator, LlvmGenerator,
CGenerator,
StgBackend StgBackend
) )
for module in modules: for module in modules:
...@@ -2063,7 +2071,14 @@ def generate(process, options): ...@@ -2063,7 +2071,14 @@ def generate(process, options):
LOG.error(str(err)) LOG.error(str(err))
LOG.debug(str(traceback.format_exc())) LOG.debug(str(traceback.format_exc()))
LOG.error('Ada code generation failed') LOG.error('Ada code generation failed')
if options.toC:
LOG.info('Generating C code')
try:
CGenerator.generate(process, simu=options.shared, options=options)
except (TypeError, ValueError, NameError) as err:
LOG.error(str(err))
LOG.debug(str(traceback.format_exc()))
LOG.error('C generation failed')
if options.llvm: if options.llvm:
LOG.info('Generating LLVM code') LOG.info('Generating LLVM code')
try: try:
...@@ -2157,7 +2172,7 @@ def cli(options): ...@@ -2157,7 +2172,7 @@ def cli(options):
export(ast, options) export(ast, options)
if any((options.toAda, options.llvm, options.shared, if any((options.toAda, options.llvm, options.shared,
options.stg, options.dll)): options.stg, options.dll, options.toC)):
if not errors: if not errors:
generate(ast.processes[0], options) generate(ast.processes[0], options)
else: else:
...@@ -2224,7 +2239,7 @@ def opengeode(): ...@@ -2224,7 +2239,7 @@ def opengeode():
LOG.debug('Starting OpenGEODE version ' + __version__) LOG.debug('Starting OpenGEODE version ' + __version__)
if any((options.check, options.toAda, options.png, options.pdf, if any((options.check, options.toAda, options.png, options.pdf,
options.svg, options.llvm, options.shared, options.stg, options.svg, options.llvm, options.shared, options.stg,
options.dll)): options.dll, options.toC)):
return cli(options) return cli(options)
else: else:
return gui(options) return gui(options)
......
...@@ -11,9 +11,15 @@ test-parse: ...@@ -11,9 +11,15 @@ test-parse:
test-ada: test-ada:
@python test.py test-ada $(TEST_CASES) @python test.py test-ada $(TEST_CASES)
test-c:
@python test.py test-c $(TEST_CASES)
test-llvm: test-llvm:
@python test.py test-llvm $(TEST_CASES) @python test.py test-llvm $(TEST_CASES)
test-vhdl:
@python test.py test-c $(TEST_CASES)
benchmark: benchmark:
@python benchmark.py $(BENCHMARK_CASES) @python benchmark.py $(BENCHMARK_CASES)
......
...@@ -18,6 +18,10 @@ clean: ...@@ -18,6 +18,10 @@ clean:
$(LLC) $*.ll $(LLC) $*.ll
$(CC) -O$(O) -c -g $*.s $(CC) -O$(O) -c -g $*.s
%.c: %.pr FORCE
$(OPENGEODE) $< system_structure.pr --toC
$(ASN1SCC) -c dataview-uniq.asn -typePrefix asn1Scc -equal
%.ali: %.pr FORCE %.ali: %.pr FORCE
$(OPENGEODE) $< system_structure.pr --toAda $(OPENGEODE) $< system_structure.pr --toAda
$(ASN1SCC) -Ada dataview-uniq.asn -typePrefix asn1Scc -equal $(ASN1SCC) -Ada dataview-uniq.asn -typePrefix asn1Scc -equal
......
...@@ -13,11 +13,19 @@ test-ada: controlflow.ali dataview-uniq.o | test_ada.o ...@@ -13,11 +13,19 @@ test-ada: controlflow.ali dataview-uniq.o | test_ada.o
$(GNATLINK) test_ada.o controlflow.ali -lgnat -lm -o test_ada $(GNATLINK) test_ada.o controlflow.ali -lgnat -lm -o test_ada
./test_ada | diff expected - ./test_ada | diff expected -
test-c: controlflow.c test_c.o dataview-uniq.o
$(CC) controlflow.c -c -o controlflow.o
$(CC) test_c.o controlflow.c -lm -o test_c
./test_c | diff expected -
test-llvm: controlflow.o dataview-uniq.o | test_llvm.o test-llvm: controlflow.o dataview-uniq.o | test_llvm.o
$(CC) controlflow.o dataview-uniq.o test_llvm.o -o test_llvm -lm $(CC) controlflow.o dataview-uniq.o test_llvm.o -o test_llvm -lm
./test_llvm | diff expected - ./test_llvm | diff expected -
test-vhdl : test-c
bambu controlflow.c test_c.c --experimental-setup=BAMBU --debug-classes=MuxConnectionBinding --print-dot --no-clean --pretty-print=a.c -d2
coverage: coverage:
coverage run -p $(OPENGEODE) controlflow.pr system_structure.pr --toAda coverage run -p $(OPENGEODE) controlflow.pr system_structure.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage .PHONY: all edit test-parse test-ada test-llvm coverage
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "dataview-uniq.h"
extern void run();
void controlflow_RI_assert(asn1SccBoolean *res, asn1SccCharString *msg) {
if (!*res) {
printf("%.*s\n", (int)msg->nCount, msg->arr);
exit(1);
}
}
void controlflow_RI_fail(asn1SccCharString *msg) {
printf("%.*s\n", (int)msg->nCount, msg->arr);
exit(1);
}
int main() {
run();
return 0;
}
...@@ -13,6 +13,11 @@ test-ada: orchestrator.ali dataview-uniq.o | test_ada.o ...@@ -13,6 +13,11 @@ test-ada: orchestrator.ali dataview-uniq.o | test_ada.o
$(GNATLINK) -o test_ada test_ada.o orchestrator.ali -lgnat $(GNATLINK) -o test_ada test_ada.o orchestrator.ali -lgnat
./test_ada ./test_ada
test-c: orchestrator.c test_c.o dataview-uniq.o
$(CC) -include missing.h orchestrator.c -c -o orchestrator.o
$(CC) test_c.o dataview-uniq.o orchestrator.o -lm -o test_c
./test_c | diff expected -
test-llvm: orchestrator.o test-llvm: orchestrator.o
test-python: test-python:
...@@ -24,6 +29,9 @@ test-python: ...@@ -24,6 +29,9 @@ test-python:
$(CC) -shared -fPIC -o liborchestrator.so b~orchestrator.o orchestrator.o taste_basictypes.o adaasn1rtl.o -lgnat $(CC) -shared -fPIC -o liborchestrator.so b~orchestrator.o orchestrator.o taste_basictypes.o adaasn1rtl.o -lgnat
python -c "from ctypes import *; test=CDLL('./liborchestrator.so'); test.liborchestratorinit()" python -c "from ctypes import *; test=CDLL('./liborchestrator.so'); test.liborchestratorinit()"
test-vhdl : test-c
bambu orchestrator.c test_c.c --experimental-setup=BAMBU
coverage: coverage:
coverage run -p $(OPENGEODE) orchestrator.pr system_structure.pr --toAda coverage run -p $(OPENGEODE) orchestrator.pr system_structure.pr --toAda
......
TASTE-BasicTypes DEFINITIONS ::= TASTE-BasicTypes DEFINITIONS ::=
BEGIN BEGIN
Boolean ::= BOOLEAN
TASTE-Peek-id ::= INTEGER (0..4294967295) TASTE-Peek-id ::= INTEGER (0..4294967295)
TASTE-Peek-id-list ::= SEQUENCE (SIZE (1..10)) OF TASTE-Peek-id TASTE-Peek-id-list ::= SEQUENCE (SIZE (1..10)) OF TASTE-Peek-id
......
[C Code] Running test
0
0
0
1
0
0
0
1
FALSE
TRUE
TRUE
FALSE
HELLO!!!
HELLOHELLOHELLO
#include "dataview-uniq.h"
asn1SccMyChoice asn1SccMyChoice_c1_set(asn1SccBoolean itm)
{
asn1SccMyChoice temp;
temp.kind = c1_PRESENT;
temp.u.c1 = itm;
return temp;
}
asn1SccSeqOpt_c asn1SccSeqOpt_c_Init()
{
asn1SccSeqOpt_c temp;
asn1SccSeqOpt_c_Initialize(&temp);
return temp;
}
asn1SccSeqOpt_d asn1SccSeqOpt_d_Init()
{
asn1SccSeqOpt_d temp;
asn1SccSeqOpt_d_Initialize(&temp);
return temp;
}
int asn1SccMyChoice_Kind(asn1SccMyChoice val)
{
return val.kind;
}
#include <math.h>
#include <stdio.h>
#include "dataview-uniq.h"
extern void runTransition(int Id);
void telemetry(asn1SccMyEnum * param){}
int main()
{
printf("[C Code] Running test\n");
CInit();
runTransition(0);
return 0;
}
...@@ -13,11 +13,18 @@ test-ada: og.ali dataview-uniq.o | test_ada.o ...@@ -13,11 +13,18 @@ test-ada: og.ali dataview-uniq.o | test_ada.o
$(GNATLINK) -o test_ada test_ada.o og.ali -lgnat $(GNATLINK) -o test_ada test_ada.o og.ali -lgnat
./test_ada | diff expected - ./test_ada | diff expected -
test-c: og.c test_c.o dataview-uniq.o
$(CC) -include missing.h og.c -c -o og.o
$(CC) test_c.o og.o dataview-uniq.o -lm -o test_c
./test_c | diff expected -
test-llvm: og.o dataview-uniq.o | test_llvm.o test-llvm: og.o dataview-uniq.o | test_llvm.o
$(CC) og.o dataview-uniq.o test_llvm.o -o test_llvm -lm $(CC) og.o dataview-uniq.o test_llvm.o -o test_llvm -lm
./test_llvm ./test_llvm
test-vhdl : test-c
bambu og.c test_c.c --experimental-setup=BAMBU
coverage: coverage:
coverage run -p $(OPENGEODE) og.pr system_structure.pr --toAda coverage run -p $(OPENGEODE) og.pr system_structure.pr --toAda
......
#include "dataview-uniq.h"
asn1SccSeqOf asn1SccSeqOf_Init()
{
asn1SccSeqOf temp;
asn1SccSeqOf_Initialize(&temp);
return temp;
}
asn1SccAChoice asn1SccAChoice_b_set(asn1SccSeqOf itm)
{
asn1SccAChoice temp;
temp.kind = b_PRESENT;
temp.u.b = itm;
return temp;
}
asn1SccAChoice asn1SccAChoice_a_set(asn1SccT_Bool itm)
{
asn1SccAChoice temp;
temp.kind = a_PRESENT;
temp.u.a = itm;
return temp;
}
#include <stdio.h>
#include "dataview-uniq.h"
int main() {
asn1SccMy_OctStr toto;
CInit();
runTransition(0);
go(&toto);
return 0;
}
...@@ -13,11 +13,20 @@ test-ada: challenge.ali dataview-uniq.o | test_ada.o ...@@ -13,11 +13,20 @@ test-ada: challenge.ali dataview-uniq.o | test_ada.o
$(GNATLINK) -o test_ada test_ada.o challenge.ali -lgnat -lm $(GNATLINK) -o test_ada test_ada.o challenge.ali -lgnat -lm
./test_ada | diff expected - ./test_ada | diff expected -
test-c: challenge.c test_c.o dataview-uniq.o
$(CC) challenge.c -c -o challenge.o
$(CC) test_c.o dataview-uniq.o challenge.o -lm -o test_c
./test_c
./test_c | diff expected -
test-llvm: challenge.o dataview-uniq.o | test_llvm.o test-llvm: challenge.o dataview-uniq.o | test_llvm.o
$(CC) challenge.o dataview-uniq.o test_llvm.o -o test_llvm -lm $(CC) challenge.o dataview-uniq.o test_llvm.o -o test_llvm -lm
./test_llvm | diff expected - ./test_llvm | diff expected -
test-vhdl : test-c
bambu challenge.c test_c.c --experimental-setup=BAMBU
coverage: coverage:
coverage run -p $(OPENGEODE) challenge.pr system_structure.pr --toAda coverage run -p $(OPENGEODE) challenge.pr system_structure.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage .PHONY: all edit test-parse test-ada test-llvm coverage
\ No newline at end of file
int main()
{
// CInit();
runTransition(0);
run();
go_off();
return 0;
}
...@@ -13,11 +13,19 @@ test-ada: expressions.ali dataview-uniq.o | test_ada.o ...@@ -13,11 +13,19 @@ test-ada: expressions.ali dataview-uniq.o | test_ada.o
$(GNATLINK) test_ada.o expressions.ali -lgnat -lm -o test_ada $(GNATLINK) test_ada.o expressions.ali -lgnat -lm -o test_ada
./test_ada ./test_ada
test-c: expressions.c test_c.o dataview-uniq.o
$(CC) expressions.c -c -o expressions.o
$(CC) test_c.o dataview-uniq.o expressions.o -lm -o test_c
./test_c
test-llvm: expressions.o dataview-uniq.o | test_llvm.o test-llvm: expressions.o dataview-uniq.o | test_llvm.o
$(CC) expressions.o dataview-uniq.o test_llvm.o -o test_llvm -lm $(CC) expressions.o dataview-uniq.o test_llvm.o -o test_llvm -lm
./test_llvm ./test_llvm
test-vhdl : test-c
bambu expressions.c test_c.c dataview-uniq.c --experimental-setup=BAMBU -v4
coverage: coverage:
coverage run -p $(OPENGEODE) expressions.pr system_structure.pr --toAda coverage run -p $(OPENGEODE) expressions.pr system_structure.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage .PHONY: all edit test-parse test-ada test-llvm coverage
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "dataview-uniq.h"
void expressions_RI_assert(asn1SccBoolean *res, asn1SccCharString *msg) {
if (!*res) {
printf("%.*s\n", (int)msg->nCount, msg->arr);
exit(1);
}
}
int main() {
runTransition(0);
run();
return 0;
}
...@@ -13,6 +13,11 @@ test-ada: orchestrator.ali dataview-uniq.o | test_ada.o ...@@ -13,6 +13,11 @@ test-ada: orchestrator.ali dataview-uniq.o | test_ada.o
$(GNATLINK) -o test_ada test_ada.o orchestrator.ali -lgnat $(GNATLINK) -o test_ada test_ada.o orchestrator.ali -lgnat
./test_ada ./test_ada
test-c: orchestrator.c test_c.o dataview-uniq.o
$(CC) orchestrator.c -c -o orchestrator.o
$(CC) test_c.o orchestrator.c dataview-uniq.o -lm -o test_c
./test_c | diff expected -
test-llvm: orchestrator.o dataview-uniq.o | test_llvm.o test-llvm: orchestrator.o dataview-uniq.o | test_llvm.o
$(CC) orchestrator.o dataview-uniq.o test_llvm.o -o test_llvm -lm $(CC) orchestrator.o dataview-uniq.o test_llvm.o -o test_llvm -lm
./test_llvm ./test_llvm
......
Supports Markdown
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