From b56a7dcbb764ff824685541f500dafc43f93414f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 26 Aug 2016 16:05:22 +0100 Subject: [PATCH] SmallC: minor adjustments --- Applications/SmallC/Makefile | 3 +++ Applications/SmallC/TODO | 2 ++ Applications/SmallC/code6801.c | 29 ++++++++++++++++++++++------- Applications/SmallC/code6809.c | 30 +++++++++++++++--------------- Applications/SmallC/codez80.c | 16 +++++----------- Applications/SmallC/lex.c | 7 +++++-- Applications/SmallC/prototype.h | 2 ++ 7 files changed, 54 insertions(+), 35 deletions(-) diff --git a/Applications/SmallC/Makefile b/Applications/SmallC/Makefile index 37aa9b5a..14870ce5 100644 --- a/Applications/SmallC/Makefile +++ b/Applications/SmallC/Makefile @@ -41,3 +41,6 @@ clean: $(CC) $(COPT) $(CFLAGS) -c $< -o $@ $(OBJS_ALL) : $(INC) + +clean: + rm -f *~ *.rel *.asm *.lst *.sym *.o *.map *.noi *.bin *.lk diff --git a/Applications/SmallC/TODO b/Applications/SmallC/TODO index ed06557b..1f7105b5 100644 --- a/Applications/SmallC/TODO +++ b/Applications/SmallC/TODO @@ -1,3 +1,5 @@ +- Parse assignment to local variables + auto x = 4; etc - Write some copt rules to stop the output sucking so much - Steal the rst tricks done by BDS C - Output mixed code/data so we can flush the literal pool every line of asm diff --git a/Applications/SmallC/code6801.c b/Applications/SmallC/code6801.c index 2dc5ede6..ff0b156c 100644 --- a/Applications/SmallC/code6801.c +++ b/Applications/SmallC/code6801.c @@ -2,11 +2,12 @@ #include "defs.h" #include "data.h" -int nextreg = 0; -int xdirty = 0; -int xsprel = 0; -int xtype = 0; /* 0 = D, 1 = S */ -int regv[8]; +static int nextreg = 0; +static int xdirty = 0; +static int xsprel = 0; +static int xtype = 0; /* 0 = D, 1 = S */ +static int regv[8]; +static int indata; /* * Some predefinitions: @@ -33,6 +34,7 @@ void header (void) { newline (); output_line ("\t;program area SMALLC_GENERATED is RELOCATABLE"); output_line ("\t.module SMALLC_GENERATED"); + gen_code(); } /** @@ -52,7 +54,6 @@ void initmac(void) { * Output internal generated label prefix */ void output_label_prefix(void) { - xdirty = 1; output_byte('$'); } @@ -61,6 +62,8 @@ void output_label_prefix(void) { */ void output_label_terminator (void) { output_byte (':'); + if (!indata) + xdirty = 1; } /** @@ -902,4 +905,16 @@ void gen_multiply(int type, int size) { void gen_statement_end(void) { output_line(";end"); -} \ No newline at end of file +} + +void gen_data(void) +{ + indata = 1; + output_line(".data"); +} + +void gen_code(void) +{ + indata = 0; + output_line(".code"); +} diff --git a/Applications/SmallC/code6809.c b/Applications/SmallC/code6809.c index 001763c7..6430bdf8 100644 --- a/Applications/SmallC/code6809.c +++ b/Applications/SmallC/code6809.c @@ -240,9 +240,8 @@ void gen_get_indirect(char typeobj, int reg) { output_line("ldb ,x"); else { /* TODO work out what we can damage here */ - /* Can we avoid using ,u ?? */ - output_line("tfr d,u"); - output_line("ldb ,u"); + output_line("tfr d,x"); + output_line("ldb ,x"); } if (typeobj == CCHAR) output_line("sex"); @@ -250,9 +249,8 @@ void gen_get_indirect(char typeobj, int reg) { if (reg & DE_REG) output_line("ldd ,x"); /* Can't happen ?? */ else { - output_line("exg d,x"); - output_line("ldx ,x"); - output_line("exg d,x"); + output_line("tfr d,x"); + output_line("ldd ,x"); } } } @@ -310,11 +308,9 @@ void gen_pop(void) { * FIXME: probably want a gen_call_indirect so targets can do sane things */ void gen_swap_stack(void) { - /* FIXME: if we can get rid of u register stuff we can get two - register variables */ - output_line("ldu ,s"); + output_line("ldx ,s"); output_line("std ,s"); - output_line("tfr u,d"); + output_line("tfr x,d"); } /** @@ -360,12 +356,14 @@ void gen_epilogue(void) output_number(i); newline(); } - /* FIXME: need to adjust the stack if there is cruft in the way */ + /* Need to adjust the stack if there is cruft in the way */ if (nextreg > 1) { + gen_modify_stack(regv[1]); output_line("puls y,u"); stkp + 4; } else if (nextreg) { + gen_modify_stack(regv[0]); output_line("puls y"); stkp += 2; } @@ -517,10 +515,8 @@ void gen_jump_case(void) { * @param lval2 */ void gen_add(LVALUE *lval, LVALUE *lval2) { - if (dbltest (lval2, lval)) { - output_line("asl 1,s"); - output_line("rol ,s"); - } + if (dbltest (lval2, lval)) + output_line("addd ,s"); output_line ("addd ,s++"); stkp += INTSIZE; } @@ -849,11 +845,15 @@ void gen_multiply(int type, int size) { gen_multiply_by_two(); break; case STRUCT: + if (nextreg > 1) + output_line("pshs y"); output_with_tab("ldy "); output_immediate(size); newline(); gen_call("__muli "); newline(); + if (nextreg > 1) + output_line("puls y"); break; default: break; diff --git a/Applications/SmallC/codez80.c b/Applications/SmallC/codez80.c index 82fa3429..d7447963 100644 --- a/Applications/SmallC/codez80.c +++ b/Applications/SmallC/codez80.c @@ -527,14 +527,11 @@ void gen_multiply_by_two(void) { } /** - * divide the primary register by INTSIZE, never used + * divide the primary register by INTSIZE */ void gen_divide_by_two(void) { - gen_push(HL_REG); /* push primary in prep for gasr */ - gen_immediate (); - output_number (1); - newline (); - gen_arithm_shift_right (); /* divide by two */ + output_line("srl h"); + output_line("rr l"); } /** @@ -553,11 +550,8 @@ void gen_jump_case(void) { */ void gen_add(LVALUE *lval, LVALUE *lval2) { gen_pop (); - if (dbltest (lval2, lval)) { - gen_swap (); - gen_multiply_by_two(); - gen_swap (); - } + if (dbltest (lval2, lval)) + output_line("add hl,de"); output_line ("add hl,de"); } diff --git a/Applications/SmallC/lex.c b/Applications/SmallC/lex.c index 51e7083a..a2a98d07 100644 --- a/Applications/SmallC/lex.c +++ b/Applications/SmallC/lex.c @@ -204,6 +204,7 @@ int get_type(void) { if (amatch ("void", 4)) { return VOID; } +#if 0 if (amatch ("register", 8)) { if (amatch("char", 4)) return CCHAR; @@ -211,13 +212,15 @@ int get_type(void) { return CINT; else return CINT; - } else if(amatch("unsigned", 8)) { + } else +#endif + if(amatch("unsigned", 8)) { if (amatch("char", 4)) { return UCHAR; } else if (amatch("int", 3)) { return UINT; } - } else if(amatch("signed", 8)) { + } else if(amatch("signed", 6)) { if (amatch("char", 4)) { return CCHAR; } else if (amatch("int", 3)) { diff --git a/Applications/SmallC/prototype.h b/Applications/SmallC/prototype.h index b72495ac..b9334d98 100644 --- a/Applications/SmallC/prototype.h +++ b/Applications/SmallC/prototype.h @@ -68,6 +68,8 @@ extern void gen_prologue(void); extern void gen_epilogue(void); extern int gen_register(int vp, int size, int typ); extern void gen_statement_end(void); +extern void gen_code(void); +extern void gen_data(void); extern char *inclib(void); extern void gnargs(int d); extern int assemble(char *s); -- 2.34.1