X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fizt%2Fgen_generic.c;h=e0618e43ed3463b3614683d1ac2c092271171331;hb=a24b75e7d87bf0a98c986653268766e8823967a8;hp=1fbdbf0390319933ca6d2c357577d4a2b9f74083;hpb=b4d69dfd516f175255aa87b18b59dcf309d98b46;p=fw%2Fsdcc diff --git a/src/izt/gen_generic.c b/src/izt/gen_generic.c index 1fbdbf03..e0618e43 100644 --- a/src/izt/gen_generic.c +++ b/src/izt/gen_generic.c @@ -1,30 +1,75 @@ #include "izt.h" #include "gen.h" -static void -_genLabel (iCode * ic) +static void _setupPointer(REG *reg, asmop *into, int offset) { - iemit ("!tlabeldef", IC_LABEL (ic)->key + 100); + iemit("; _setupPointer for %s", reg->name); } -static void -_genGoto (iCode * ic) +void izt_putAop(asmop *into, const char *sz, int size, int offset) { - iemit ("jp !tlabel", IC_LABEL (ic)->key + 100); + wassert(offset == 0); + + switch (into->type) { + case AOP_TYPE_REG: + iemit("mov %s,%s", into->u.reg->name, sz); + break; + case AOP_TYPE_CARRY: + // Should support. + wassert(0); + break; + + case AOP_TYPE_SCRATCH_PTR: + _setupPointer(izt_port->scratch, into, offset); + iemit("mov a,%s", sz); + iemit("mov %s,a", izt_port->scratch->name); + break; + + case AOP_TYPE_STACK: + iemit("mov a,%s", sz); + iemit("mov (%s+%d),a", izt_port->base_ptr->name, into->u.stack); + break; + + case AOP_TYPE_LITERAL: + case AOP_TYPE_IMMEDIATE: + default: + wassert(0); + } } -static void -_genFunction (iCode * ic) +char *izt_getAop(asmop *from, int size, int offset) { - symbol *sym = OP_SYMBOL (IC_LEFT (ic)); + return "blah"; +} - // Create the function header - iemit ("!functionheader", sym->name); - iemit ("!functionlabeldef", sym->rname); +/** Perform a generic move operation. + */ +static void _mov(asmop *into, asmop *from) +{ + int size = into->size; + izt_putAop(into, izt_getAop(from, size, 0), size, 0); +} - if (sym->stack) - { - iemit ("!enterx", sym->stack); +static void _genLabel(iCode *ic) +{ + iemit("!tlabeldef", IC_LABEL(ic)->key + 100); +} + +static void _genGoto(iCode *ic) +{ + iemit("jp !tlabel", IC_LABEL(ic)->key+100); +} + +static void _genFunction(iCode *ic) +{ + symbol *sym = OP_SYMBOL(IC_LEFT(ic)); + + // Create the function header + iemit("!functionheader", sym->name); + iemit("!functionlabeldef", sym->rname); + + if (sym->stack) { + iemit("!enterx", sym->stack); } else { @@ -32,13 +77,23 @@ _genFunction (iCode * ic) } } +static void _genEndFunction(iCode *ic) +{ + // symbol *sym = OP_SYMBOL(IC_LEFT(ic)); + + /* PENDING: calleeSave */ + + iemit("!leave"); + iemit("ret"); +} + static void _genReturn (iCode * ic) { - if (IC_LEFT (ic)) - { - // Has a return value. Load it up. - iemit ("; PENDING: call the generic loader to setup the return value."); + if (IC_LEFT(ic)) { + // Has a return value. Load it up. + izt_bindAop(IC_LEFT(ic), ic); + _mov(izt_getAopForReturn(AOP_SIZE(IC_LEFT(ic))), AOP(IC_LEFT(ic))); } if (ic->next && ic->next->op == LABEL && IC_LABEL (ic->next) == returnLabel) @@ -51,13 +106,13 @@ _genReturn (iCode * ic) } } -static EMITTER _base_emitters[] = -{ - {LABEL, _genLabel}, - {GOTO, _genGoto}, - {FUNCTION, _genFunction}, - {RETURN, _genReturn}, - {0, NULL} +static EMITTER _base_emitters[] = { + { LABEL, _genLabel }, + { GOTO, _genGoto }, + { FUNCTION, _genFunction }, + { RETURN, _genReturn }, + { ENDFUNCTION, _genEndFunction }, + { 0, NULL } }; void