termite2 / Termite

The Termite driver synthesis tool
30 stars 7 forks source link

Generated C code does not compile #13

Open davidcock opened 9 years ago

davidcock commented 9 years ago

Particularly the class.c files, example (from specs/uart):

davec@dwarrowdelf:uart$ cc -I. -I../include -o class.o -c class.c
class.c:4:13: error: redeclaration of enumerator ‘bits5’ bits5, bits6, bits7, bits8 ^ In file included from class.c:1:0: ./class.h:6:13: note: previous definition of ‘bits5’ was here bits5, bits6, bits7, bits8 ^ class.c:4:20: error: redeclaration of enumerator ‘bits6’ bits5, bits6, bits7, bits8 ^ In file included from class.c:1:0: ./class.h:6:20: note: previous definition of ‘bits6’ was here bits5, bits6, bits7, bits8 ^ class.c:4:27: error: redeclaration of enumerator ‘bits7’ bits5, bits6, bits7, bits8 ^ In file included from class.c:1:0: ./class.h:6:27: note: previous definition of ‘bits7’ was here bits5, bits6, bits7, bits8 ^ class.c:4:34: error: redeclaration of enumerator ‘bits8’ bits5, bits6, bits7, bits8 ^ In file included from class.c:1:0: ./class.h:6:34: note: previous definition of ‘bits8’ was here bits5, bits6, bits7, bits8 ^ class.c:5:11: error: conflicting types for ‘wl_t’ } wl_t; ^ In file included from class.c:1:0: ./class.h:7:11: note: previous declaration of ‘wl_t’ was here } wl_t; ^

Nothing in specs/uart_exynos compiles at all.

ryzhyk commented 9 years ago

Thanks, should be fixed now. Also, you should not need to generate a .c file for class.tsl. Normally, you need to generate a .c/.h pair for the synthesised driver, and only .h for all the files that it imports.

davidcock commented 9 years ago

OK, that looks better, but I now can't see how to generate code for a non-root spec. For example, I can synthesis main.tsl with "termite -i main.tsl -g", but I can't call "termite -i drv.tsl -g", as it complains with:

termite: user error (validation error: drv.tsl:5:39: Unknown template name: uart_linux)

In the previous commit I managed it with "termite -i main.tsl -g drv.tsl", but that now gives a command-line error.

ryzhyk commented 9 years ago

This happens due to a mismatch between C #include semantics and TSL imports. In TSL, the contents of all files imported from anywhere in the spec becomes globally visible to all other files. In the hindsight, this was a bas idea, as TSL does not force each file to import all of its dependencies. I should add a check to force this to the TSL compiler. In the meanwhile, the solution is to add the missing imports to drv.tsl. I did this for spi_exynos and uart_exynos specs.