summaryrefslogtreecommitdiff
path: root/ecomp-c/ec.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-c/ec.c')
-rw-r--r--ecomp-c/ec.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c
index fc283e0..c98c766 100644
--- a/ecomp-c/ec.c
+++ b/ecomp-c/ec.c
@@ -675,6 +675,7 @@ typedef struct Symbol {
int *intarr_value;
/* variable */
int size;
+ int offset;
/* array type */
int dim;
/* procedure type */
@@ -796,6 +797,7 @@ static Symbol *insert_symbol( Scope *scope, char *name, SymbolClass class )
sym->name = Allocate( strlen( name ) + 1 );
strlcpy( sym->name, name, strlen( name ) + 1 );
sym->size = 0;
+ sym->offset = 0;
sym->dim = 0;
sym->next = scope->symbol;
sym->string_value = NULL;
@@ -1959,6 +1961,9 @@ static void parseProcedureBlock( Scope *scope )
if( sym == S_const || sym == S_var || sym == S_begin ) {
+ Symbol *sym;
+ int size_locals;
+
Emit( "; PROC %s\n", symbol->name );
Emit( "%s:\n", symbol->label );
@@ -1970,11 +1975,31 @@ static void parseProcedureBlock( Scope *scope )
/* local scope holding all local defitions */
symbol->scope = create_scope( scope, symbol->name );
+
+ /* TODO: parse parameters, assign parameter values to
+ * local variables (when passed by value) or set
+ * addresses for VAR parameters */
parseProcedureDeclarationBlock( symbol->scope );
- /* TODO: allocate space on stack for local variables */
+ size_locals = 0;
+ sym = symbol->scope->symbol;
+ while( sym != NULL ) {
+ if( sym->class == SYMBOL_CLASS_VARIABLE ) {
+ size_locals += get_size( sym );
+ }
+ sym = sym->next;
+ }
+
+ if( size_locals > 0 ) {
+ Emit( "mov eax, %d\n", size_locals );
+ Emit( "sub esp, eax\n" );
+ }
+
+ /* TODO: allocate space on stack for local variables (and
+ * parameters) */
/* TODO: assign symbols to relative addresses (base pointer) */
+ /* TODO: initialize local variables */
parseStatementBlock( symbol->scope );