* src/z80/mappings.i: Added z80asm support.
[fw/sdcc] / src / z80 / main.c
index 2cddd076d16de916d384f9dad16093a021e5727b..8336b0556aa47f01478ef2fb9de9b856aa974dae 100644 (file)
@@ -46,7 +46,8 @@ typedef enum
     /* Must be first */
     ASM_TYPE_ASXXXX,
     ASM_TYPE_RGBDS,
-    ASM_TYPE_ISAS
+    ASM_TYPE_ISAS,
+    ASM_TYPE_Z80ASM
   }
 ASM_TYPE;
 
@@ -71,6 +72,14 @@ extern PORT z80_port;
 
 #include "mappings.i"
 
+static builtins _z80_builtins[] = {
+  /* Disabled for now.
+    { "__builtin_strcpy", "v", 2, {"cg*", "cg*" } },
+    { "__builtin_memcpy", "cg*", 3, {"cg*", "cg*", "ui" } },
+  */
+    { NULL , NULL,0, {NULL}}
+};    
+
 static void
 _z80_init (void)
 {
@@ -151,7 +160,7 @@ _process_pragma (const char *sz)
              wassert (0);
            }
        }
-      gbz80_port.mem.code_name = gc_strdup (buffer);
+      gbz80_port.mem.code_name = Safe_strdup (buffer);
       code->sname = gbz80_port.mem.code_name;
       return 0;
     }
@@ -228,12 +237,12 @@ _parseOptions (int *pargc, char **argv, int *i)
            case 'o':
              /* ROM bank */
              sprintf (buffer, "CODE_%u", bank);
-             gbz80_port.mem.code_name = gc_strdup (buffer);
+             gbz80_port.mem.code_name = Safe_strdup (buffer);
              return TRUE;
            case 'a':
              /* RAM bank */
              sprintf (buffer, "DATA_%u", bank);
-             gbz80_port.mem.data_name = gc_strdup (buffer);
+             gbz80_port.mem.data_name = Safe_strdup (buffer);
              return TRUE;
            }
        }
@@ -261,6 +270,13 @@ _parseOptions (int *pargc, char **argv, int *i)
              _G.asmType = ASM_TYPE_ISAS;
              return TRUE;
            }
+         else if (!strcmp (argv[*i], "--asm=z80asm"))
+           {
+              port->assembler.externGlobal = TRUE;
+             asm_addTree (&_z80asm_z80);
+             _G.asmType = ASM_TYPE_ISAS;
+             return TRUE;
+           }
        }
     }
   return FALSE;
@@ -320,6 +336,7 @@ _setDefaultOptions (void)
   options.mainreturn = 1;
   /* first the options part */
   options.intlong_rent = 1;
+  options.float_rent = 1;
   options.noRegParams = 1;
   /* Default code and data locations. */
   options.code_loc = 0x200;
@@ -372,7 +389,7 @@ _mangleSupportFunctionName(char *original)
           options.noRegParams ? "s" : "bds"
           );
 
-  return gc_strdup(buffer);
+  return Safe_strdup(buffer);
 }
 
 static const char *
@@ -382,10 +399,44 @@ _getRegName (struct regs *reg)
     {
       return reg->name;
     }
-  assert (0);
+  //  assert (0);
   return "err";
 }
 
+static bool
+_hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
+{
+  sym_link *test = NULL;
+  value *val;
+
+  if ( ic->op != '*')
+    {
+      return FALSE;
+    }
+
+  if ( IS_LITERAL (left))
+    {
+      test = left;
+      val = OP_VALUE (IC_LEFT (ic));
+    }
+  else if ( IS_LITERAL (right))
+    {
+      test = left;
+      val = OP_VALUE (IC_RIGHT (ic));
+    }
+  else
+    {
+      return FALSE;
+    }
+
+  if ( getSize (test) <= 2)
+    {
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 #define LINKCMD \
     "{bindir}{sep}link-{port} -n -c -- {z80bases} -m -j" \
     " {z80libspec}" \
@@ -443,6 +494,8 @@ PORT z80_port =
     "OVERLAY",
     "GSFINAL",
     "HOME",
+    NULL, // xidata
+    NULL, // xinit
     NULL,
     NULL,
     1
@@ -464,10 +517,12 @@ PORT z80_port =
   _keywords,
   0,                           /* no assembler preamble */
   0,                           /* no local IVT generation code */
+  0,                            /* no genXINIT code */
   _reset_regparm,
   _reg_parm,
   _process_pragma,
   _mangleSupportFunctionName,
+  _hasNativeMulFor,
   TRUE,
   0,                           /* leave lt */
   0,                           /* leave gt */
@@ -476,6 +531,11 @@ PORT z80_port =
   1,                           /* transform != to !(a == b) */
   0,                           /* leave == */
   TRUE,                         /* Array initializer support. */       
+  0,                            /* no CSE cost estimation yet */
+  _z80_builtins,               /* no builtin functions */
+  GPOINTER,                    /* treat unqualified pointers as "generic" pointers */
+  1,                           /* reset labelKey to 1 */
+  1,                           /* globals & local static allowed */
   PORT_MAGIC
 };
 
@@ -524,6 +584,8 @@ PORT gbz80_port =
     "OVERLAY",
     "GSFINAL",
     "HOME",
+    NULL, // xidata
+    NULL, // xinit
     NULL,
     NULL,
     1
@@ -545,10 +607,12 @@ PORT gbz80_port =
   _keywords,
   0,                           /* no assembler preamble */
   0,                           /* no local IVT generation code */
+  0,                            /* no genXINIT code */
   _reset_regparm,
   _reg_parm,
   _process_pragma,
   _mangleSupportFunctionName,
+  _hasNativeMulFor,
   TRUE,
   0,                           /* leave lt */
   0,                           /* leave gt */
@@ -556,6 +620,11 @@ PORT gbz80_port =
   1,                           /* transform >= to ! < */
   1,                           /* transform != to !(a == b) */
   0,                           /* leave == */
-  FALSE,                        /* No array initializer support. */
+  TRUE,                         /* Array initializer support. */
+  0,                            /* no CSE cost estimation yet */
+  NULL,                        /* no builtin functions */
+  GPOINTER,                    /* treat unqualified pointers as "generic" pointers */
+  1,                           /* reset labelKey to 1 */
+  1,                           /* globals & local static allowed */
   PORT_MAGIC
 };