From 6a0b557df99f3b36c54ba9cca3d4b39d3f365221 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 30 Jun 2016 18:13:56 +0100 Subject: [PATCH] scc: merge stack adjustments --- Applications/SmallC/TODO | 7 +------ Applications/SmallC/code6801.c | 7 +++++++ Applications/SmallC/code6809.c | 16 +++++++++++++++- Applications/SmallC/code8080.c | 7 +++++++ Applications/SmallC/codegeneric.c | 6 ++++++ Applications/SmallC/codez80.c | 6 ++++++ Applications/SmallC/function.c | 2 ++ Applications/SmallC/prototype.h | 1 + Applications/SmallC/stmt.c | 5 ++++- Applications/SmallC/sym.c | 2 +- 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Applications/SmallC/TODO b/Applications/SmallC/TODO index 27afe622..1604b63d 100644 --- a/Applications/SmallC/TODO +++ b/Applications/SmallC/TODO @@ -1,11 +1,6 @@ -- Debug stack offsets -- Get code generation working and suiting things like as09 - 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 and maybe even get rid of the literal pool (2.5K saving) - Can we split the preprocessor optionally -- Work out what is needed for stack frame based Z80 and 6809 code - -Easy small C fixups worth doing in passing -- \x and \001 style escapes +- Work out what is needed for stack frame based Z80 code diff --git a/Applications/SmallC/code6801.c b/Applications/SmallC/code6801.c index 46688321..54e9890a 100644 --- a/Applications/SmallC/code6801.c +++ b/Applications/SmallC/code6801.c @@ -417,6 +417,13 @@ int gen_modify_stack(int newstkp) { return newstkp; } +/* FIXME */ +int gen_defer_modify_stack(int newstkp) +{ + return gen_modify_stack(newstkp); +} + + /** * multiply the primary register by INTSIZE */ diff --git a/Applications/SmallC/code6809.c b/Applications/SmallC/code6809.c index 948b9587..596452e9 100644 --- a/Applications/SmallC/code6809.c +++ b/Applications/SmallC/code6809.c @@ -368,6 +368,8 @@ void gen_def_word(void) { output_with_tab ("fdb "); } +static int defer; + /** * modify the stack pointer to the new value indicated * @param newstkp new value @@ -375,7 +377,8 @@ void gen_def_word(void) { int gen_modify_stack(int newstkp) { int k; - k = newstkp - stkp; + k = newstkp - stkp + defer; + defer = 0; if (k == 0) return (newstkp); output_with_tab("leas "); @@ -385,6 +388,17 @@ int gen_modify_stack(int newstkp) { return (newstkp); } +/** + * modify the stack pointer to the new value indicated, but + * allow the change to be deferred + */ + +int gen_defer_modify_stack(int newstkp) +{ + defer += newstkp - stkp; + return newstkp + defer; +} + /** * multiply the primary register by INTSIZE */ diff --git a/Applications/SmallC/code8080.c b/Applications/SmallC/code8080.c index 9562075f..5aebcf80 100644 --- a/Applications/SmallC/code8080.c +++ b/Applications/SmallC/code8080.c @@ -432,6 +432,13 @@ int gen_modify_stack(int newstkp) { return (newstkp); } +/* FIXME */ +int gen_defer_modify_stack(int newstkp) +{ + return gen_modify_stack(newstkp); +} + + /** * multiply the primary register by INTSIZE */ diff --git a/Applications/SmallC/codegeneric.c b/Applications/SmallC/codegeneric.c index 9a4f8565..3d8d2ee9 100644 --- a/Applications/SmallC/codegeneric.c +++ b/Applications/SmallC/codegeneric.c @@ -378,6 +378,12 @@ int gen_modify_stack(int newstkp) { return (newstkp); } +/* FIXME */ +int gen_defer_modify_stack(int newstkp) +{ + return gen_modify_stack(newstkp); +} + /** * multiply the primary register by INTSIZE */ diff --git a/Applications/SmallC/codez80.c b/Applications/SmallC/codez80.c index f4c12bde..8212c012 100644 --- a/Applications/SmallC/codez80.c +++ b/Applications/SmallC/codez80.c @@ -458,6 +458,12 @@ int gen_modify_stack(int newstkp) { return (newstkp); } +/* FIXME */ +int gen_defer_modify_stack(int newstkp) +{ + return gen_modify_stack(newstkp); +} + /** * multiply the primary register by INTSIZE */ diff --git a/Applications/SmallC/function.c b/Applications/SmallC/function.c index 3a901abf..04056745 100644 --- a/Applications/SmallC/function.c +++ b/Applications/SmallC/function.c @@ -62,6 +62,7 @@ void newfunc_typed(int storage, char *n, int type) if (find_locale(an) > -1) multidef(an); else { + /* FIXME: struct */ add_local(an, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } @@ -210,6 +211,7 @@ void doLocalAnsiArgument(int type) { ptr = ptr - 1; address = symbol_table[ptr].offset; symbol_table[ptr].offset = address + INTSIZE; + /* Struct etc FIXME */ } } } else { diff --git a/Applications/SmallC/prototype.h b/Applications/SmallC/prototype.h index e65c301b..faa24484 100644 --- a/Applications/SmallC/prototype.h +++ b/Applications/SmallC/prototype.h @@ -30,6 +30,7 @@ extern void gen_test_jump(int label, int ft); extern void gen_def_byte(void); extern void gen_def_storage(void); extern void gen_def_word(void); +extern int gen_defer_modify_stack(int newstkp); extern int gen_modify_stack(int newstkp); extern void gen_multiply_by_two(void); extern void gen_divide_by_two(void); diff --git a/Applications/SmallC/stmt.c b/Applications/SmallC/stmt.c index 771409b1..14ea439e 100644 --- a/Applications/SmallC/stmt.c +++ b/Applications/SmallC/stmt.c @@ -151,8 +151,11 @@ void do_compound(int func) { if (input_eof) return; if (decls) { - if (!statement_declare ()) + if (!statement_declare ()) { + /* Any deferred movement now happens */ + gen_modify_stack(stkp); decls = NO; + } } else do_statement (); } diff --git a/Applications/SmallC/sym.c b/Applications/SmallC/sym.c index ae349c32..a8a13d90 100644 --- a/Applications/SmallC/sym.c +++ b/Applications/SmallC/sym.c @@ -253,7 +253,7 @@ 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); + stkp = gen_defer_modify_stack(stkp - k); add_local(sname, j, typ, stkp, AUTO); } else add_local(sname, j, typ, k, LSTATIC); -- 2.34.1