From: Alan Cox Date: Thu, 30 Jun 2016 17:00:29 +0000 (+0100) Subject: scc: support processors that support stack relative addressing X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a6093a06ba8ebaab5a9a3f412088b648bf4759de;p=FUZIX.git scc: support processors that support stack relative addressing Also fix LSTATIC to be more efficient --- diff --git a/Applications/SmallC/code6801.c b/Applications/SmallC/code6801.c index eb715f6e..46688321 100644 --- a/Applications/SmallC/code6801.c +++ b/Applications/SmallC/code6801.c @@ -210,6 +210,16 @@ void gen_get_indirect(char typeobj, int reg) { } } +/** + * platform level analysis of whether a symbol access needs to be + * direct or indirect (globals are always direct) + */ +int gen_indirected(SYMBOL *s) +{ + /* TODO */ + return 1; +} + /** * swap the primary and secondary registers */ diff --git a/Applications/SmallC/code6809.c b/Applications/SmallC/code6809.c index f6eddb49..948b9587 100644 --- a/Applications/SmallC/code6809.c +++ b/Applications/SmallC/code6809.c @@ -119,6 +119,18 @@ void output_immediate(int num) { output_decimal(num); } +static void describe_access(SYMBOL *sym) +{ + if (sym->storage == LSTATIC) + print_label(sym->offset); + else if (sym->storage == AUTO || sym->storage == DEFAUTO) { + output_number(sym->offset - stkp); + output_string(",s"); + } else + output_string(sym->name); + newline(); +} + /** * fetch a static memory cell into the primary register * @param sym @@ -126,18 +138,15 @@ void output_immediate(int num) { void gen_get_memory(SYMBOL *sym) { if ((sym->identity != POINTER) && (sym->type == CCHAR)) { output_with_tab("ldb "); - output_string(sym->name); - newline (); + describe_access(sym); output_line("sex"); } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) { output_with_tab("ldb "); - output_string(sym->name); - newline(); + describe_access(sym); output_line("clr a"); } else { output_with_tab ("ldd "); - output_string(sym->name); - newline (); + describe_access(sym); } } @@ -167,14 +176,11 @@ int gen_get_locale(SYMBOL *sym) { * @param sym */ void gen_put_memory(SYMBOL *sym) { - if ((sym->identity != POINTER) && (sym->type & CCHAR)) { + if ((sym->identity != POINTER) && (sym->type & CCHAR)) output_with_tab ("stb "); - output_string(sym->name); - } else { + else output_with_tab("std "); - output_string(sym->name); - } - newline (); + describe_access(sym); } /** @@ -217,6 +223,16 @@ void gen_get_indirect(char typeobj, int reg) { } } +/** + * platform level analysis of whether a symbol access needs to be + * direct or indirect (globals are always direct) + */ +int gen_indirected(SYMBOL *s) +{ + /* Never indirect, use s relative because our CPU rocks */ + return 0; +} + /** * swap the primary and secondary registers */ diff --git a/Applications/SmallC/code8080.c b/Applications/SmallC/code8080.c index a603b203..9562075f 100644 --- a/Applications/SmallC/code8080.c +++ b/Applications/SmallC/code8080.c @@ -238,6 +238,17 @@ void gen_get_indirect(char typeobj, int reg) { } } +/** + * platform level analysis of whether a symbol access needs to be + * direct or indirect (globals are always direct) + */ +int gen_indirected(SYMBOL *s) +{ + /* FIXME: TODO - we can avoid indirecting LSTATIC */ + return 1; +} + + /** * swap the primary and secondary registers */ diff --git a/Applications/SmallC/codegeneric.c b/Applications/SmallC/codegeneric.c index c6306e93..9a4f8565 100644 --- a/Applications/SmallC/codegeneric.c +++ b/Applications/SmallC/codegeneric.c @@ -128,24 +128,32 @@ static void output_bracketed(char *p) output_byte(')'); } +static void describe_access(SYMBOL *sym) +{ + output_byte('('); + if (sym->storage == LSTATIC) { + print_label(sym->offset); + } else if (sym->storage == AUTO || sym->storage == DEFAUTO) { + output_number(sym->offset); + output_string("+fp"); + } else + output_string(sym->name); + output_byte(')'); + newline(); +} + /** * fetch a static memory cell into the primary register * @param sym */ void gen_get_memory(SYMBOL *sym) { - if ((sym->identity != POINTER) && (sym->type == CCHAR)) { + if ((sym->identity != POINTER) && (sym->type == CCHAR)) output_with_tab ("loadsb r1 "); - output_bracketed(sym->name); - newline (); - } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) { + else if ((sym->identity != POINTER) && (sym->type == UCHAR)) output_with_tab("loadub r1 "); - output_bracketed(sym->name); - newline(); - } else { + else output_with_tab ("load r1 "); - output_bracketed(sym->name); - newline (); - } + describe_access(sym); } /** @@ -173,14 +181,11 @@ int gen_get_locale(SYMBOL *sym) { * @param sym */ void gen_put_memory(SYMBOL *sym) { - if ((sym->identity != POINTER) && (sym->type & CCHAR)) { + if ((sym->identity != POINTER) && (sym->type & CCHAR)) output_with_tab ("storeb r1 "); - output_bracketed(sym->name); - } else { + else output_with_tab("store r1 "); - output_bracketed(sym->name); - } - newline (); + describe_access(sym); } /** @@ -220,6 +225,15 @@ void gen_get_indirect(char typeobj, int reg) { } } +/** + * platform level analysis of whether a symbol access needs to be + * direct or indirect (globals are always direct) + */ +int gen_indirected(SYMBOL *s) +{ + return 0; +} + /** * swap the primary and secondary registers */ diff --git a/Applications/SmallC/codez80.c b/Applications/SmallC/codez80.c index cb76fd24..f4c12bde 100644 --- a/Applications/SmallC/codez80.c +++ b/Applications/SmallC/codez80.c @@ -115,6 +115,14 @@ void output_number(int num) { output_decimal(num); } +static void output_number_signed(int num) +{ + if (num > 0) + output_byte('+'); + else + output_decimal(num); +} + static void output_bracketed(char *p) { output_byte('('); @@ -122,6 +130,22 @@ static void output_bracketed(char *p) output_byte(')'); } +static void describe_access(SYMBOL *sym) +{ + if (sym->storage == LSTATIC) { + output_byte('('); + print_label(sym->offset); + output_byte(')'); + } else if (sym->storage == AUTO || sym->storage == DEFAUTO) { + output_string("(ix"); + output_number_signed(sym->offset - stkp); + output_byte(')'); + } else + output_string(sym->name); + newline(); +} + + /** * fetch a static memory cell into the primary register * @param sym @@ -227,6 +251,19 @@ void gen_get_indirect(char typeobj, int reg) { } } +/** + * platform level analysis of whether a symbol access needs to be + * direct or indirect (globals are always direct) + */ +int gen_indirected(SYMBOL *s) +{ + if (s->storage == LSTATIC) + return 0; +/* if (abs(s->offset) < 124 && (s->type == CCHAR || s->type == UCHAR)) + return 0; */ + return 1; +} + /** * swap the primary and secondary registers */ diff --git a/Applications/SmallC/primary.c b/Applications/SmallC/primary.c index 7f0afb23..3c802dda 100644 --- a/Applications/SmallC/primary.c +++ b/Applications/SmallC/primary.c @@ -50,8 +50,26 @@ int primary(LVALUE *lval) { return(0); } if (symname (sname)) { - if ((symbol_table_idx = find_locale(sname)) > -1) { - symbol = &symbol_table[symbol_table_idx]; + int local = 1; + symbol_table_idx = find_locale(sname); + if (symbol_table_idx == -1) { + local = 0; + symbol_table_idx = find_global(sname); + /* Only valid undeclared name is a function reference */ + if (symbol_table_idx == -1) { + blanks(); + if (ch() != '(') + error("undeclared variable"); + symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC); + symbol = &symbol_table[symbol_table_idx]; + lval->symbol = symbol; + lval->indirect = 0; + return 0; + } + } + symbol = &symbol_table[symbol_table_idx]; + + if (local && gen_indirected(symbol)) { reg = gen_get_locale(symbol); lval->symbol = symbol; lval->indirect = symbol->type; @@ -69,37 +87,32 @@ int primary(LVALUE *lval) { } return FETCH | reg; } - if ((symbol_table_idx = find_global(sname)) > -1) { - symbol = &symbol_table[symbol_table_idx]; - if (symbol->identity != FUNCTION) { - lval->symbol = symbol; - lval->indirect = 0; - if (symbol->type == STRUCT) { - lval->tagsym = &tag_table[symbol->tagidx]; - } - if (symbol->identity != ARRAY && - (symbol->identity != VARIABLE || symbol->type != STRUCT)) { - if (symbol->identity == POINTER) { - lval->ptr_type = symbol->type; - } - return FETCH | HL_REG; + /* Globals and anything we can directly access */ + if (symbol->identity != FUNCTION) { + lval->symbol = symbol; + lval->indirect = 0; + if (symbol->type == STRUCT) { + lval->tagsym = &tag_table[symbol->tagidx]; + } + if (symbol->identity != ARRAY && + (symbol->identity != VARIABLE || symbol->type != STRUCT)) { + if (symbol->identity == POINTER) { + lval->ptr_type = symbol->type; } + return FETCH | HL_REG; + } + + if (symbol->storage == LSTATIC) + gen_get_locale(symbol); + else { gen_immediate(); output_string(symbol->name); newline(); - lval->indirect = symbol->type; - lval->ptr_type = symbol->type; - return 0; } + lval->indirect = symbol->type; + lval->ptr_type = symbol->type; + return 0; } - blanks(); - if (ch() != '(') - error("undeclared variable"); - symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC); - symbol = &symbol_table[symbol_table_idx]; - lval->symbol = symbol; - lval->indirect = 0; - return 0; } lval->symbol = 0; lval->indirect = 0; diff --git a/Applications/SmallC/prototype.h b/Applications/SmallC/prototype.h index 3659188d..e65c301b 100644 --- a/Applications/SmallC/prototype.h +++ b/Applications/SmallC/prototype.h @@ -13,6 +13,7 @@ extern void output_number(int num); extern void gen_get_memory(SYMBOL *sym); extern int gen_get_locale(SYMBOL *sym); extern void gen_put_memory(SYMBOL *sym); +extern int gen_indirected(SYMBOL *sym); extern void gen_put_indirect(char typeobj); extern void gen_get_indirect(char typeobj, int reg); extern void gen_swap(void);