From 6370f887af3d16229813020fc6f06ae26ea0d3d5 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 29 Jun 2016 18:58:00 +0100 Subject: [PATCH] scc: fixes for non ANSI headers and 6809 code gen --- Applications/SmallC/code6809.c | 31 +++++++++++++++++-------------- Applications/SmallC/function.c | 9 +++++---- Applications/SmallC/main.c | 24 +++++++++++++----------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Applications/SmallC/code6809.c b/Applications/SmallC/code6809.c index f7ef604f..4f4127eb 100644 --- a/Applications/SmallC/code6809.c +++ b/Applications/SmallC/code6809.c @@ -150,7 +150,7 @@ int gen_get_locale(SYMBOL *sym) { newline(); return HL_REG; } else { - output_line("leay "); + output_with_tab("leay "); output_number(sym->offset - stkp); output_string(",s"); newline (); @@ -180,8 +180,7 @@ void gen_put_memory(SYMBOL *sym) { * @param typeobj */ void gen_put_indirect(char typeobj) { - /* pop ? */ - output_line("tfr d,y"); + output_line("puls d"); if (typeobj & CCHAR) { output_line("stb ,y"); } else { @@ -195,19 +194,23 @@ void gen_put_indirect(char typeobj) { * @param typeobj object type */ void gen_get_indirect(char typeobj, int reg) { - if (typeobj == CCHAR) { - if (reg & DE_REG) { - gen_swap(); + if (typeobj == CCHAR || typeobj == UCHAR) { + if (reg & DE_REG) + output_line("ldb ,x"); + else { + /* TODO work out what we can damage here */ + output_line("tfr d,u"); + output_line("ldb ,u"); } - output_line("loadbs r1 (r1)"); - } else if (typeobj == UCHAR) { - if (reg & DE_REG) { - gen_swap(); - } - //gen_call("cguchar"); - output_line("loadbu r1 (r1)"); + if (typeobj == CCHAR) + output_line("sex"); } else { // int - output_line("load r1 (r1)"); + if (reg & DE_REG) + output_line("ldd ,x"); /* Can't happen ?? */ + else { + output_line("tfr d,u"); + output_line("ldd ,u"); + } } } diff --git a/Applications/SmallC/function.c b/Applications/SmallC/function.c index 917f58cd..3a901abf 100644 --- a/Applications/SmallC/function.c +++ b/Applications/SmallC/function.c @@ -31,6 +31,7 @@ void newfunc_typed(int storage, char *n, int type) { int idx; SYMBOL *symbol; + char an[NAMESIZE]; fexitlab = getlabel(); @@ -57,11 +58,11 @@ void newfunc_typed(int storage, char *n, int type) } else { // K&R style argument declaration while (!match(")")) { - if (symname(n)) { - if (find_locale(n) > -1) - multidef(n); + if (symname(an)) { + if (find_locale(an) > -1) + multidef(an); else { - add_local(n, 0, 0, argstk, AUTO); + add_local(an, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } } else { diff --git a/Applications/SmallC/main.c b/Applications/SmallC/main.c index 801e4a1d..e8f1865a 100644 --- a/Applications/SmallC/main.c +++ b/Applications/SmallC/main.c @@ -144,20 +144,22 @@ void usage(void) { */ void parse(void) { while (!input_eof) { - if (amatch("extern", 6)) + if (match("#")) { + if (match("asm")) + doasm(); + else if (match("include")) + doinclude(); + else if (match("define")) + dodefine(); + else if (match("undef")) + doundef(); + } + else if (amatch("extern", 6)) do_declarations(EXTERN, NULL_TAG, 0); else if (amatch("static", 6)) do_declarations(STATIC, NULL_TAG, 0); - else if (do_declarations(PUBLIC, NULL_TAG, 0)); - else if (match("#asm")) - doasm(); - else if (match("#include")) - doinclude(); - else if (match("#define")) { - dodefine(); - } - else if (match("#undef")) - doundef(); + else if (do_declarations(PUBLIC, NULL_TAG, 0)) + ; else { newfunc(); } -- 2.34.1