From: Alan Cox Date: Thu, 23 Jun 2016 21:27:11 +0000 (+0100) Subject: scc: minor fixes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f1c05f25608346f00703c42779ace5da65f82304;p=FUZIX.git scc: minor fixes --- diff --git a/Applications/SmallC/codegeneric.c b/Applications/SmallC/codegeneric.c index fc8f7dca..149b2836 100644 --- a/Applications/SmallC/codegeneric.c +++ b/Applications/SmallC/codegeneric.c @@ -131,7 +131,7 @@ void gen_get_memory(SYMBOL *sym) { output_bracketed(sym->name); newline(); } else { - output_with_tab ("load r1 "); + output_with_tab ("(ggm)load r1 "); output_bracketed(sym->name); newline (); } @@ -151,18 +151,11 @@ int gen_get_locale(SYMBOL *sym) { newline(); return HL_REG; } else { - if (uflag && !(sym->identity == ARRAY)) {// || - //(sym->identity == VARIABLE && sym->type == STRUCT))) { - output_with_tab("ldsi\t"); - output_number(sym->offset - stkp); - newline (); - return DE_REG; - } else { - gen_immediate(); - output_number(sym->offset - stkp); - output_line ("+sp"); - return HL_REG; - } + gen_immediate(); + output_number(sym->offset - stkp); + output_string("+sp"); + newline(); + return HL_REG; } } diff --git a/Applications/SmallC/codez80.c b/Applications/SmallC/codez80.c index 667e9255..24973d0b 100644 --- a/Applications/SmallC/codez80.c +++ b/Applications/SmallC/codez80.c @@ -112,7 +112,6 @@ void fpubext(SYMBOL *scptr) { * @param num */ void output_number(int num) { - output_byte('#'); output_decimal(num); } @@ -140,7 +139,7 @@ void gen_get_memory(SYMBOL *sym) { output_line("ld l,a"); output_line("ld h,0"); } else { - output_with_tab ("ld hl,"); + output_with_tab ("*ld hl,"); output_bracketed(sym->name); newline (); } @@ -160,19 +159,13 @@ int gen_get_locale(SYMBOL *sym) { newline(); return HL_REG; } else { - if (uflag && !(sym->identity == ARRAY)) {// || - //(sym->identity == VARIABLE && sym->type == STRUCT))) { - output_with_tab("ldsi\t"); - output_number(sym->offset - stkp); - newline (); - return DE_REG; - } else { - gen_immediate(); - output_number(sym->offset - stkp); - newline (); - output_line ("add hl, sp"); - return HL_REG; - } + gen_immediate(); + output_number(sym->offset - stkp); +/* output_string(" ; "); + output_number(sym->offset + 2);*/ + newline (); + output_line ("add hl,sp"); + return HL_REG; } } @@ -229,17 +222,10 @@ void gen_get_indirect(char typeobj, int reg) { output_line("ld l,(hl)"); output_line("ld h,0"); } else { // int - if (uflag) { - if (reg & HL_REG) { - gen_swap(); - } - output_line("lhlx"); - } else { - output_line("ld a,(hl)"); - output_line("inc hl"); - output_line("ld h,(hl)"); - output_line("ld l,a"); - } + output_line("ld a,(hl)"); + output_line("inc hl"); + output_line("ld h,(hl)"); + output_line("ld l,a"); } } @@ -302,7 +288,26 @@ void gen_call(char *sname) { void declare_entry_point(char *symbol_name) { output_string(symbol_name); output_label_terminator(); - //newline(); + newline(); +} + +void gen_prologue(void) +{ +#if 0 + output_line("push ix"); + output_line("ld ix,#0"); + output_line("add ix,sp"); + stkp = stkp - INTSIZE; +#endif +} + +void gen_epilogue(void) +{ +#if 0 + output_line("ld sp,ix"); + output_line("pop ix"); + stkp = 0; +#endif } /** diff --git a/Applications/SmallC/function.c b/Applications/SmallC/function.c index ea4dc24d..001f7d33 100644 --- a/Applications/SmallC/function.c +++ b/Applications/SmallC/function.c @@ -75,10 +75,12 @@ void newfunc(void) { } } } + gen_prologue(); statement(YES); print_label(fexitlab); output_label_terminator(); newline(); + gen_epilogue(); gen_modify_stack(0); gen_ret(); stkp = 0; diff --git a/Applications/SmallC/prototype.h b/Applications/SmallC/prototype.h index 608501f7..615049f6 100644 --- a/Applications/SmallC/prototype.h +++ b/Applications/SmallC/prototype.h @@ -62,6 +62,8 @@ extern void gen_unsigned_less_than(void); extern void gen_unsigned_less_or_equal(void); extern void gen_usigned_greater_than(void); extern void gen_unsigned_greater_or_equal(void); +extern void gen_prologue(void); +extern void gen_epilogue(void); extern char *inclib(void); extern void gnargs(int d); extern int assemble(char *s); diff --git a/Applications/SmallC/sym.c b/Applications/SmallC/sym.c index 2a138c9b..c1ddf9ce 100644 --- a/Applications/SmallC/sym.c +++ b/Applications/SmallC/sym.c @@ -239,6 +239,8 @@ void declare_local(int typ, int stclass, int otag) { } } } + /* FIXME: do one gen_modify_stack at the end and + some kind of align method here */ if (stclass != LSTATIC) { stkp = gen_modify_stack(stkp - k); add_local(sname, j, typ, stkp, AUTO); @@ -328,6 +330,7 @@ int add_global (char *sname, int identity, int type, int offset, int storage) { current_symbol_table_idx = global_table_index; symbol = &symbol_table[current_symbol_table_idx]; buffer_ptr = symbol->name; + /* FIXME: only copy so many bytes */ while (alphanumeric(*buffer_ptr++ = *sname++)); symbol->identity = identity; symbol->type = type; @@ -361,6 +364,7 @@ int add_local (char *sname, int identity, int type, int offset, int storage_clas current_symbol_table_idx = local_table_index; symbol = &symbol_table[current_symbol_table_idx]; buffer_ptr = symbol->name; + /* FIXME: only copy so many bytes */ while (alphanumeric(*buffer_ptr++ = *sname++)); symbol->identity = identity; symbol->type = type;