* Added z80 blurb.
[fw/sdcc] / src / z80 / main.c
index c22fc0c96c5e947be79c22a3d8da6a0df289b7e7..0e0e932d0bae8c8a80121b1e794649b69f11d16c 100644 (file)
-#include "SDCCglobl.h"
-#include "main.h"
+#include "z80.h"
+
+static char _z80_defaultRules[] =
+{
+#include "peeph.rul"
+#include "peeph-z80.rul"
+};
+
+static char _gbz80_defaultRules[] =
+{
+#include "peeph.rul"
+#include "peeph-gbz80.rul"
+};
+
+Z80_OPTS z80_opts;
+
+static char *_keywords[] = { NULL };
+
+static void _z80_init(void)
+{
+    z80_opts.sub = SUB_Z80;
+}
+
+static void _gbz80_init(void)
+{
+    z80_opts.sub = SUB_GBZ80;
+}
+
+static int regParmFlg = 0; /* determine if we can register a parameter */
+
+static void _reset_regparm()
+{
+    regParmFlg = 0;
+}
+
+static int _reg_parm(link *l)
+{
+        /* for this processor it is simple
+       can pass only the first parameter in a register */
+    if (regParmFlg)
+       return 0;
+
+    regParmFlg = 1;
+    return 1;
+
+}
+
+static int _process_pragma(const char *sz)
+{
+    printf("Got pragma \"%s\"\n", sz);
+    return 1;
+}
+
+static bool _parseOptions(int *pargc, char **argv, int *i)
+{
+    return FALSE;
+}
+
+static void _finaliseOptions(void)
+{
+    port->mem.default_local_map = data;
+    port->mem.default_globl_map = data;
+}
+
+static void _setDefaultOptions(void)
+{    
+    options.genericPtr = 1;   /* default on */
+    options.nopeep    = 0;
+    options.stackAuto = 1;
+    options.mainreturn = 1;
+    options.noregparms = 1;
+    /* first the options part */
+    options.intlong_rent = 1;
+
+    optimize.global_cse = 1;    
+    optimize.label1 = 1;
+    optimize.label2 = 1;
+    optimize.label3 = 1;
+    optimize.label4 = 1;    
+    optimize.loopInvariant = 1;
+    optimize.loopInduction = 0;
+}
+
+static const char *_getRegName(struct regs *reg)
+{
+    if (reg)
+       return reg->name;
+    assert(0);
+    return "err";
+}
+
+/** $1 is always the basename.
+    $2 is always the output file.
+    $3 varies
+    $l is the list of extra options that should be there somewhere...
+    MUST be terminated with a NULL.
+*/
+static const char *_z80_linkCmd[] = {
+    "link-z80", "-nf", "$1", NULL
+};
+
+static const char *_z80_asmCmd[] = {
+    "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
+};
+
+/** $1 is always the basename.
+    $2 is always the output file.
+    $3 varies
+    $l is the list of extra options that should be there somewhere...
+    MUST be terminated with a NULL.
+*/
+static const char *_gbz80_linkCmd[] = {
+    "link-gbz80", "-nf", "$1", NULL
+};
+
+static const char *_gbz80_asmCmd[] = {
+    "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
+};
 
 /* Globals */
-PROCESSOR_CONSTANTS port = {
+PORT z80_port = {
+    "z80",
     "Zilog Z80",               /* Target name */
+    {
+       FALSE,
+    },
     {  
-       "as-z80",               /* Assembler executable name */
+       _z80_asmCmd,
        "-plosgff",             /* Options with debug */
        "-plosgff",             /* Options without debug */
-       TRUE                    /* TRUE if the assembler requires an output name */
     },
     {
-       "link-z80",             /* Linker executable name */
+       _z80_linkCmd
+    },
+    {
+       _z80_defaultRules
     },
     {
        /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
        1, 1, 2, 4, 2, 2, 2, 1, 4, 4
     },
+    {
+       "_XSEG",
+       "_STACK",
+       "_CODE",
+       "_DATA",
+       "_ISEG",
+       "_XSEG",
+       "_BSEG",
+       "_RSEG",
+       "_GSINIT",
+       "_OVERLAY",
+       "_GSFINAL",
+       NULL,
+       NULL,
+       1
+    },
     { 
        -1, 0, 0, 8, 0
     },
     /* Z80 has no native mul/div commands */
     {  
        0
-    }
+    },
+    _z80_init,
+    _parseOptions,
+    _finaliseOptions,
+    _setDefaultOptions,
+    z80_assignRegisters,
+    _getRegName,
+    _keywords,
+    0, /* no assembler preamble */
+    0, /* no local IVT generation code */
+    _reset_regparm,
+    _reg_parm
 };
 
-bool x_parseOptions(char **argv, int *pargc)
-{
-    int i = *pargc;
-    bool fRecognised = FALSE;
-
-    *pargc = i;
-    return fRecognised;
-}
-
-void x_finaliseOptions(void)
-{
-}
-
-void x_setDefaultOptions(void)
-{    
-}
-
+/* Globals */
+PORT gbz80_port = {
+    "gbz80",
+    "Gameboy Z80-like",                /* Target name */
+    {
+       FALSE,
+    },
+    {  
+       _gbz80_asmCmd,
+       "-plosgff",             /* Options with debug */
+       "-plosgff",             /* Options without debug */
+    },
+    {
+       _gbz80_linkCmd
+    },
+    {
+       _gbz80_defaultRules
+    },
+    {
+       /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
+       1, 1, 2, 4, 2, 2, 2, 1, 4, 4
+    },
+    {
+       "_XSEG",
+       "_STACK",
+       "_CODE",
+       "_DATA",
+       "_ISEG",
+       "_XSEG",
+       "_BSEG",
+       "_RSEG",
+       "_GSINIT",
+       "_OVERLAY",
+       "_GSFINAL",
+       NULL,
+       NULL,
+       1
+    },
+    { 
+       -1, 0, 0, 4, 0
+    },
+    /* gbZ80 has no native mul/div commands */
+    {  
+       0
+    },
+    _gbz80_init,
+    _parseOptions,
+    _finaliseOptions,
+    _setDefaultOptions,
+    z80_assignRegisters,
+    _getRegName,
+    _keywords,
+    0, /* no assembler preamble */
+    0, /* no local IVT generation code */
+    _reset_regparm,
+    _reg_parm,
+    _process_pragma
+};