* device/include/pic16/pic18f*.h: add bit aliases in INTCONbits_t
[fw/sdcc] / src / izt / gen_generic.c
index 1fbdbf0390319933ca6d2c357577d4a2b9f74083..e0618e43ed3463b3614683d1ac2c092271171331 100644 (file)
@@ -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