summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-06-21 16:18:14 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2020-06-21 16:18:14 +0200
commit1a72b91cfda9a0232443a1c36515ca1449862099 (patch)
treebae71f3ebecafb2a420154d93c6eaee84d30469c
parentc35a3209434122adfce3159210cdaef380c1e952 (diff)
downloadcompilertests-1a72b91cfda9a0232443a1c36515ca1449862099.tar.gz
compilertests-1a72b91cfda9a0232443a1c36515ca1449862099.tar.bz2
- build.sh: better error handling
- ec: fix some memory leaks und UMRs
-rwxr-xr-xecomp-c/build.sh18
-rw-r--r--ecomp-c/ec.c58
2 files changed, 50 insertions, 26 deletions
diff --git a/ecomp-c/build.sh b/ecomp-c/build.sh
index 004d892..1fce90b 100755
--- a/ecomp-c/build.sh
+++ b/ecomp-c/build.sh
@@ -23,6 +23,11 @@ case "${COMPILER}" in
;;
tcc)
CFLAGS="-m32 -march=i386 -Werror -Wall -std=c89"
+ ;;
+ *)
+ echo "ERROR: Unknown compiler '${COMPILER}' (use gcc, clang, pcc or tcc)" 1>&2
+ exit 1
+ ;;
esac
case "${LEVEL}" in
@@ -33,6 +38,19 @@ case "${LEVEL}" in
CFLAGS+=" -g -O0"
DEBUG=1
;;
+ *)
+ echo "ERROR: Unknown compilation level '${LEVEL}' (use one of 0123 for -O<n>, or d for -O0 and debugging)" 1>&2
+ exit 1
+ ;;
+esac
+
+case "${MODE}" in
+ freestanding|hosted)
+ ;;
+ *)
+ echo "ERROR: Unknown environment '${MODE}' (use 'freestanding' or 'hosted')" 1>&2
+ exit 1
+ ;;
esac
case "${COMPILER}:${MODE}" in
diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c
index ac1632f..217c7e1 100644
--- a/ecomp-c/ec.c
+++ b/ecomp-c/ec.c
@@ -697,7 +697,7 @@ static void free_symbol( Symbol *sym )
free( sym );
}
-static void delete_scope( Scope *scope )
+static void free_scope( Scope *scope )
{
Symbol *sym, *next;
Scope *next_scope;
@@ -711,7 +711,7 @@ static void delete_scope( Scope *scope )
}
next_scope = scope->parent;
if( scope->parent != NULL ) {
- delete_scope( scope->parent );
+ free_scope( scope->parent );
}
free( scope->name );
free( scope );
@@ -1105,10 +1105,6 @@ static void emit_expression_code( ExpressionNode *node, Scope *scope )
Emit( "push eax\n" );
} break;
case S_lbracket:
- if( !is_compatible_type( node->symbol->type->type, node->actual_type ) ) {
- Abort( "Incompatible assignment of expression of type '%s' to variable '%s' of type '%s'",
- node->actual_type->name, node->symbol->name, node->symbol->type->name );
- }
emit_expression_code( node->left, scope );
EmitArrayDereference( node->symbol );
break;
@@ -1159,28 +1155,30 @@ static ExpressionNode *parseFactor( Scope *scope )
} else {
Abort( "Unhandled expression assignment from identifier with type '%s'", node->actual_type->name );
}
+ sym = getSym( );
} else if( symbol->class == SYMBOL_CLASS_VARIABLE ) {
- node = create_expression_node( );
- node->type = EXPRESSION_NODE_TYPE_VAR;
- node->symbol = symbol;
- node->actual_type = symbol->type;
+ sym = getSym( );
+ if( sym == S_lbracket ) {
+ Expect( S_lbracket );
+ if( symbol->type->class != SYMBOL_CLASS_ARRAY_TYPE ) {
+ Abort( "Dereferencing non-array '%s'", symbol->name );
+ }
+ node = create_expression_node( );
+ node->type = EXPRESSION_NODE_TYPE_OP;
+ node->op = S_lbracket;
+ node->left = parseExpression( scope );
+ node->symbol = symbol;
+ node->actual_type = symbol->type->type;
+ Expect( S_rbracket );
+ } else {
+ node = create_expression_node( );
+ node->type = EXPRESSION_NODE_TYPE_VAR;
+ node->symbol = symbol;
+ node->actual_type = symbol->type;
+ }
} else {
Abort( "'%s' is the name for a type and not a constant or variable as expected", ident );
}
- sym = getSym( );
- if( sym == S_lbracket ) {
- Expect( S_lbracket );
- if( symbol->type->class != SYMBOL_CLASS_ARRAY_TYPE ) {
- Abort( "Dereferencing non-array '%s'", symbol->name );
- }
- node = create_expression_node( );
- node->type = EXPRESSION_NODE_TYPE_OP;
- node->op = S_lbracket;
- node->left = parseExpression( scope );
- node->symbol = symbol;
- node->actual_type = symbol->type->type;
- Expect( S_rbracket );
- }
} else if( sym == S_lparen ) {
sym = getSym( );
node = parseExpression( scope );
@@ -1951,10 +1949,18 @@ static void reserve_initialize( Symbol *symbol )
i++;
}
Emit( "\n" );
- } else {
+ } else if( symbol->type->type == integer_type ) {
+ for( i = 0; i < symbol->type->dim; i++ ) {
+ Emit( "dd $0\n" );
+ }
+ } else {
+ /* TODO: this can not work */
+ Abort( "Unhandled generic array case" );
+ /*
for( i = 0; i < symbol->type->dim; i++ ) {
reserve_initialize( symbol->type );
}
+ */
}
break;
@@ -1981,7 +1987,7 @@ static void epilogue( void )
static void deinit( void )
{
- delete_scope( current_scope );
+ free_scope( current_scope );
}
int main( void )