Began adding the code generation framework.
[fw/sdcc] / src / izt / gen_generic.c
1 #include "izt.h"
2 #include "gen.h"
3
4 static void _genLabel(iCode *ic)
5 {
6     iemit("!tlabeldef", IC_LABEL(ic)->key + 100);
7 }
8
9 static void _genGoto(iCode *ic)
10 {
11     iemit("jp !tlabel", IC_LABEL(ic)->key+100);
12 }
13
14 static void _genFunction(iCode *ic)
15 {
16     symbol *sym = OP_SYMBOL(IC_LEFT(ic));
17
18     // Create the function header
19     iemit("!functionheader", sym->name);
20     iemit("!functionlabeldef", sym->rname);
21
22     if (sym->stack) {
23         iemit("!enterx", sym->stack);
24     }
25     else {
26         iemit("!enter");
27     }
28 }
29
30 static void _genReturn(iCode *ic)
31 {
32     if (IC_LEFT(ic)) {
33         // Has a return value.  Load it up.
34         iemit("; PENDING: call the generic loader to setup the return value.");
35     }
36
37     if (ic->next && ic->next->op == LABEL && IC_LABEL(ic->next) == returnLabel) {
38         // The next label is the return label.  Dont bother emitting a jump.
39     }
40     else {
41         iemit("jp !tlabel", returnLabel->key+100);
42     }
43 }
44
45 static EMITTER _base_emitters[] = {
46     { LABEL,            _genLabel },
47     { GOTO,             _genGoto },
48     { FUNCTION,         _genFunction },
49     { RETURN,           _genReturn },
50     { 0,                NULL }
51 };
52
53 void izt_initBaseEmitters(hTab **into)
54 {
55     izt_addEmittersToHTab(into, _base_emitters);
56 }