diff --git a/CHANGELOG.org b/CHANGELOG.org index 16e3809..13755ed 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -16,9 +16,12 @@ * Current ** Added +Added support for envp in cc_x86.s ** Changed Reduced stack usage thanks to akkartik +Changed argv, argc behavior in cc_x86.s +updated stage3/M2-Planet_x86.c to commit 56db0fcad4b3362d14d20e69a17e45d751c264a5 ** Fixed Add debug label diff --git a/stage3/M2-Planet_x86.c b/stage3/M2-Planet_x86.c index 6fef02b..fe1e2c0 100644 --- a/stage3/M2-Planet_x86.c +++ b/stage3/M2-Planet_x86.c @@ -1004,7 +1004,7 @@ void initialize_types() struct type* d = calloc(1, sizeof(struct type)); d->name = "char**"; d->size = 4; - d->type = c; + d->type = b; d->indirect = d; /*fix up indrects for chars */ @@ -1246,6 +1246,7 @@ char* break_target_num; struct token_list* break_frame; int current_count; struct type* last_type; +int Address_of; /* Imported functions */ char* parse_string(char* string); @@ -1253,8 +1254,6 @@ int escape_lookup(char* c); char* numerate_number(int a); - - struct token_list* emit(char *s, struct token_list* head) { struct token_list* t = calloc(1, sizeof(struct token_list)); @@ -1388,8 +1387,8 @@ void variable_load(struct token_list* a) emit_out("LOAD_BASE_ADDRESS_eax %"); emit_out(numerate_number(a->depth)); emit_out("\n"); + if(TRUE == Address_of) return; if(match("=", global_token->s)) return; - if(match("char**", a->type->name)) return; emit_out("LOAD_INTEGER\n"); } @@ -1597,7 +1596,7 @@ void postfix_expr_arrow() emit_out("\nADD_ebx_to_eax\n"); } - if(!match("=", global_token->s) && !match("char**", current_target->name)) + if((!match("=", global_token->s) && (4 >= i->size))) { emit_out("LOAD_INTEGER\n"); } @@ -1762,6 +1761,16 @@ void bitwise_expr() void primary_expr() { + if(match("&", global_token->s)) + { + Address_of = TRUE; + global_token = global_token->next; + } + else + { + Address_of = FALSE; + } + if(match("sizeof", global_token->s)) unary_expr_sizeof(); else if('-' == global_token->s[0]) { @@ -1817,7 +1826,7 @@ void collect_local() struct token_list* a = sym_declare(global_token->s, type_size, function->locals); if(match("main", function->s) && (NULL == function->locals)) { - a->depth = -4; + a->depth = -20; } else if((NULL == function->arguments) && (NULL == function->locals)) { @@ -2213,12 +2222,7 @@ void collect_arguments() { /* deal with foo(int a, char b) */ struct token_list* a = sym_declare(global_token->s, type_size, function->arguments); - if(match("main", function->s)) - { - if(match("argc", a->s)) a->depth = 4; - if(match("argv", a->s)) a->depth = 8; - } - else if(NULL == function->arguments) + if(NULL == function->arguments) { a->depth = -4; } @@ -2256,10 +2260,6 @@ void declare_function() emit_out(":FUNCTION_"); emit_out(function->s); emit_out("\n"); - if(match("main", function->s)) - { - emit_out("COPY_esp_to_ebp\t# Deal with special case\n"); - } statement(); /* Prevent duplicate RETURNS */ @@ -2292,6 +2292,7 @@ struct token_list* program() { out = NULL; function = NULL; + Address_of = FALSE; struct type* type_size; new_type: