diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-12-29 16:57:00 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-12-29 16:57:00 +0100 |
commit | 3b685241b74cfe05ba8926df472029d7e87f5de5 (patch) | |
tree | 231809843e1a8088df1f39488165534b66e155eb /minie | |
parent | e7dcf15572104e00b7b7b79a4ccbce28c3467638 (diff) | |
download | compilertests-3b685241b74cfe05ba8926df472029d7e87f5de5.tar.gz compilertests-3b685241b74cfe05ba8926df472029d7e87f5de5.tar.bz2 |
started to fix symbol map
Diffstat (limited to 'minie')
-rwxr-xr-x | minie/build.sh | 10 | ||||
-rw-r--r-- | minie/e2c.c | 39 |
2 files changed, 33 insertions, 16 deletions
diff --git a/minie/build.sh b/minie/build.sh index 441631b..56f0190 100755 --- a/minie/build.sh +++ b/minie/build.sh @@ -1,13 +1,17 @@ #!/bin/bash +set -e + gcc -m32 -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c -#tcc -o e2c e2c.c +tcc -o e2c e2c.c # broken, at least on ArchLinux and CVS version #pcc -o e2c e2c.c -#clang -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c +clang -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c ./e2c < test1.e +set +e ./e2c < test2.e ./e2c < test3.e +set -e ./e2c < test4.e ./e2c < test5.e ./e2c < test6.e @@ -16,7 +20,7 @@ gcc -m32 -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c ./e2c < test5.e > test5.c && gcc -g -o test5 test5.c && ./test5 ./e2c < test6.e > test6.c && gcc -g -o test6 test6.c && ( echo 'Hello' | ./test6 ) -./e2c < test7.e > test7.c && gcc -g -o test7 test7.c && ./test7 +./e2c < test7.e > test7.c && gcc -g -o test7 test7.c && ( echo 'Hello' | ./test7 ) ./e2c < test8.e > test8.c && gcc -g -o test8 test8.c && ./test8 ./e2c < ec.e diff --git a/minie/e2c.c b/minie/e2c.c index 9e1d441..18010de 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -527,18 +527,23 @@ static BasicType strToBasicType( char *name ) return TYPE_UNKNOWN; } +typedef struct Type Type; + typedef struct ArrayType { - BasicType type; + char data[128]; + Type *type; int len; } ArrayType; typedef struct RecordType { - BasicType type[MAX_RECORD_MEMBERS]; + char data[128*MAX_RECORD_MEMBERS]; + struct Type *type[MAX_RECORD_MEMBERS]; int len; } RecordType; typedef struct FunctionType { - BasicType params[MAX_PARAMETERS]; + char data[128*MAX_PARAMETERS]; + struct Type *params[MAX_PARAMETERS]; int len; int internal; } FunctionType; @@ -548,11 +553,12 @@ typedef struct ConstantType { union { int boolean; int integer; + char byte; char character; } value; } ConstantType; -typedef struct Type { +struct Type { BasicType type; char name[MAX_IDENT_LEN]; union { @@ -561,7 +567,7 @@ typedef struct Type { FunctionType function; ConstantType constant; } details; -} Type; +}; static int nof_symbols = 0; static Type symbols[MAX_SYMBOLS]; @@ -648,13 +654,15 @@ static void register_internal_functions( void ) /* register compiler-internal functions */ type.type = TYPE_FUNCTION; type.details.function.len = 1; - type.details.function.params[0] = TYPE_ARRAY; + type.details.function.params[0] = (Type *)&type.details.function.data; + type.details.function.params[0]->type = TYPE_ARRAY; type.details.function.internal = 1; insert_symbol( type, "length" ); type.type = TYPE_FUNCTION; type.details.function.len = 1; - type.details.function.params[0] = TYPE_CHAR; + type.details.function.params[0] = (Type *)&type.details.function.data; + type.details.function.params[0]->type = TYPE_CHAR; type.details.function.internal = 1; insert_symbol( type, "char" ); } @@ -858,13 +866,13 @@ static void assignment( void ) /* precondition: ident is a variable and already parsed */ Expect( S_assign ); type = get_symbol_type( varName ); - if( type.type == TYPE_ARRAY && type.details.array.type == TYPE_CHAR ) { + if( type.type == TYPE_ARRAY && type.details.array.type->type == TYPE_CHAR ) { emit( "strncpy( %s, ", varName ); } else { emit( "%s = ", varName ); } expression( ); - if( type.type == TYPE_ARRAY && type.details.array.type == TYPE_CHAR ) { + if( type.type == TYPE_ARRAY && type.details.array.type->type == TYPE_CHAR ) { emit( ", %d )", type.details.array.len ); } emitLn( ";" ); @@ -1105,7 +1113,8 @@ static void arrayType( void ) type( ); /* type is in ident */ lastType.type = TYPE_ARRAY; - lastType.details.array.type = strToBasicType( ident ); + lastType.details.array.type = (Type *)&lastType.details.array.data; + lastType.details.array.type->type = strToBasicType( ident ); lastType.details.array.len = num; } else { Abort( "of' expected in array definition" ); @@ -1215,9 +1224,13 @@ static void procedureDeclaration( void ) /* TODO: properly map data types from above */ funcType.type = TYPE_FUNCTION; + funcType.details.function.params[0] = (Type *)&funcType.details.function.data; funcType.details.function.len = nof_params; -/* type.details.function.params[0] = TYPE_ARRAY; - */ + /* + type.details.function.params[0]->type = TYPE_ARRAY; + type.details.function.internal = 1; + */ + funcType.details.function.internal = 0; insert_symbol( funcType, procName ); @@ -1299,6 +1312,6 @@ int main( void ) init( ); module( ); epilogue( ); - + exit( EXIT_SUCCESS ); } |