summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-05-21 21:02:12 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2020-05-21 21:02:12 +0200
commit102f2a915f8de897e83522a1654b59d8833e8fab (patch)
treef04510941acd6b060877839bfe2f256c2597e6d9
parentc30d5a9904d204c99b727676532bfaaf74bc429e (diff)
downloadcompilertests-102f2a915f8de897e83522a1654b59d8833e8fab.tar.gz
compilertests-102f2a915f8de897e83522a1654b59d8833e8fab.tar.bz2
starting to add size of types
-rwxr-xr-xecomp-c/build.sh1
-rw-r--r--ecomp-c/ec.c26
-rw-r--r--ecomp-c/emul.c2
-rw-r--r--ecomp-c/tests/boolean_variable.e4
-rw-r--r--ecomp-c/tests/boolean_variable.easm2
5 files changed, 28 insertions, 7 deletions
diff --git a/ecomp-c/build.sh b/ecomp-c/build.sh
index 3b9aff0..004d892 100755
--- a/ecomp-c/build.sh
+++ b/ecomp-c/build.sh
@@ -62,4 +62,3 @@ else
cat ${MODULES[@]} | ${COMPILER} ${CFLAGS} -o ${BINARY} -
fi
-rm -f "${BINARY}_tmp.c"
diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c
index f76dbd6..40879d1 100644
--- a/ecomp-c/ec.c
+++ b/ecomp-c/ec.c
@@ -1032,6 +1032,19 @@ static ExpressionNode *parseExpression( void )
return node;
}
+static int get_size( Symbol *symbol )
+{
+ switch( symbol->class ) {
+ case SYMBOL_CLASS_CONSTANT:
+ case SYMBOL_CLASS_VARIABLE:
+ return get_size( symbol->type );
+ case SYMBOL_CLASS_TYPE:
+ return symbol->size;
+ }
+ Abort( "No size for class '%d", symbol->class );
+ return 0;
+}
+
static void parseAssignment( Scope *scope )
{
Symbol *symbol;
@@ -1063,7 +1076,16 @@ static void parseAssignment( Scope *scope )
Emit( "\n" );
emit_expression_code( node, scope );
Emit( "pop eax\n" );
- Emit( "mov [%s], eax\n", symbol->name );
+ switch( get_size( symbol ) ) {
+ case 4:
+ Emit( "mov [%s], eax\n", symbol->name );
+ break;
+ case 1:
+ Emit( "mov [%s], al\n", symbol->name );
+ break;
+ default:
+ Abort( "Unhandled size %d when storing register to memory", symbol->size );
+ }
free_expression_node( node );
}
@@ -1378,7 +1400,7 @@ static void register_internal_types( Scope *scope )
type_symbol->size = 4;
type_symbol = insert_symbol( current_scope, "boolean", SYMBOL_CLASS_TYPE );
- type_symbol->size = 4;
+ type_symbol->size = 1;
const_symbol = insert_symbol( current_scope, "false", SYMBOL_CLASS_CONSTANT );
const_symbol->type = type_symbol;
diff --git a/ecomp-c/emul.c b/ecomp-c/emul.c
index 292002e..cf924ae 100644
--- a/ecomp-c/emul.c
+++ b/ecomp-c/emul.c
@@ -85,7 +85,7 @@ static void dump_memory( uc_engine *uc, uint64_t start_address, uint64_t end_add
printf( "data:\n" );
for( uint64_t a = start_address; a < end_address; a += 4 ) {
uc_mem_read( uc, a, &mem, 4 );
- printf( "%08X: %02X%02X%02X%02X\n", (uint32_t)a, mem[3], mem[2], mem[1], mem[0] );
+ printf( "%08X: %02X%02X%02X%02X\n", (uint32_t)a, mem[0], mem[1], mem[2], mem[3] );
}
}
diff --git a/ecomp-c/tests/boolean_variable.e b/ecomp-c/tests/boolean_variable.e
index 8903205..aa2f53e 100644
--- a/ecomp-c/tests/boolean_variable.e
+++ b/ecomp-c/tests/boolean_variable.e
@@ -9,7 +9,7 @@ var
flag : boolean;
begin
- a := 1;
- b := 2;
+ a := 573785173; // hex $22334455
+ b := 1719109785; // hex $66778899
flag := a <> b; // flag must be false
end
diff --git a/ecomp-c/tests/boolean_variable.easm b/ecomp-c/tests/boolean_variable.easm
index 7b64339..d71cdde 100644
--- a/ecomp-c/tests/boolean_variable.easm
+++ b/ecomp-c/tests/boolean_variable.easm
@@ -31,6 +31,6 @@ push eax
pop eax
mov [flag], eax
hlt
-flag: dd $00000000
+flag: db $00
b: dd $00000000
a: dd $00000000