]> git.sur5r.net Git - cc65/blobdiff - src/cc65/datatype.c
Optimization for __bzero.
[cc65] / src / cc65 / datatype.c
index 2080cc95f34d2dd3a941556977ce4ed48d2212ac..1c17c27960007cdb3ad02da11436b774d5b96b78 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -138,7 +138,7 @@ void TypeFree (type* T)
 int SignExtendChar (int C)
 /* Do correct sign extension of a character */
 {
-    if (SignedChars && (C & 0x80) != 0) {
+    if (IS_Get (&SignedChars) && (C & 0x80) != 0) {
                return C | ~0xFF;
     } else {
                return C & 0xFF;
@@ -150,7 +150,7 @@ int SignExtendChar (int C)
 type GetDefaultChar (void)
 /* Return the default char type (signed/unsigned) depending on the settings */
 {
-    return SignedChars? T_SCHAR : T_UCHAR;
+    return IS_Get (&SignedChars)? T_SCHAR : T_UCHAR;
 }
 
 
@@ -327,6 +327,12 @@ void PrintFuncSig (FILE* F, const char* Name, type* Type)
 
     /* Print a comment with the function signature */
     PrintType (F, GetFuncReturn (Type));
+    if (D->Flags & FD_NEAR) {
+        fprintf (F, " __near__");
+    }
+    if (D->Flags & FD_FAR) {
+        fprintf (F, " __far__");
+    }
     if (D->Flags & FD_FASTCALL) {
        fprintf (F, " __fastcall__");
     }
@@ -342,6 +348,9 @@ void PrintFuncSig (FILE* F, const char* Name, type* Type)
            if (I > 0) {
                fprintf (F, ", ");
            }
+            if (SymIsRegVar (E)) {
+                fprintf (F, "register ");
+            }
            PrintType (F, E->Type);
            E = E->NextSym;
        }
@@ -365,7 +374,7 @@ void PrintRawType (FILE* F, const type* Type)
 
 
 void Encode (type* Type, unsigned long Val)
-/* Encode p[0] and p[1] so that neither p[0] nore p[1] is zero */
+/* Encode Val into the given type string */
 {
     int I;
     for (I = 0; I < DECODE_SIZE; ++I) {
@@ -422,18 +431,11 @@ void CopyEncode (const type* Source, type* Target)
 
 
 
-type UnqualifiedType (type T)
-/* Return the unqalified type */
-{
-    return (T & ~T_MASK_QUAL);
-}
-
-
-
 unsigned SizeOf (const type* T)
 /* Compute size of object represented by type array. */
 {
     SymEntry* Entry;
+    long      ElementCount;
 
     switch (UnqualifiedType (T[0])) {
 
@@ -475,11 +477,17 @@ unsigned SizeOf (const type* T)
 
        case T_STRUCT:
        case T_UNION:
-                   Entry = (SymEntry*) DecodePtr (T+1);
+                   Entry = DecodePtr (T+1);
                    return Entry->V.S.Size;
 
        case T_ARRAY:
-           return (Decode (T+ 1) * SizeOf (T + DECODE_SIZE + 1));
+            ElementCount = GetElementCount (T);
+            if (ElementCount < 0) {
+                /* Array with unspecified size */
+                return 0;
+            } else {
+               return ElementCount * SizeOf (T + DECODE_SIZE + 1);
+            }
 
        default:
            Internal ("Unknown type in SizeOf: %04X", *T);
@@ -568,8 +576,13 @@ unsigned TypeOf (const type* T)
                case T_ULONG:
                    return CF_LONG | CF_UNSIGNED;
 
+        case T_FLOAT:
+        case T_DOUBLE:
+            /* These two are identical in the backend */
+            return CF_FLOAT;
+
         case T_FUNC:
-           F = (FuncDesc*) DecodePtr (T+1);
+           F = DecodePtr (T+1);
            return (F->Flags & FD_VARIADIC)? 0 : CF_FIXARGC;
 
         case T_STRUCT:
@@ -603,6 +616,18 @@ type* Indirect (type* T)
 
 
 
+type* ArrayToPtr (const type* T)
+/* Convert an array to a pointer to it's first element */
+{
+    /* Function must only be called for an array */
+    CHECK ((T[0] & T_MASK_TYPE) == T_TYPE_ARRAY);
+
+    /* Return pointer to first element */
+    return PointerTo (T + DECODE_SIZE + 1);
+}
+
+
+
 int IsClassInt (const type* T)
 /* Return true if this is an integer type */
 {
@@ -681,42 +706,6 @@ int IsVariadicFunc (const type* T)
 
 
 
-type GetType (const type* T)
-/* Get the raw type */
-{
-    PRECONDITION (T[0] != T_END);
-    return (T[0] & T_MASK_TYPE);
-}
-
-
-
-type GetClass (const type* T)
-/* Get the class of a type string */
-{
-    PRECONDITION (T[0] != T_END);
-    return (T[0] & T_MASK_CLASS);
-}
-
-
-
-type GetSignedness (const type* T)
-/* Get the sign of a type */
-{
-    PRECONDITION (T[0] != T_END);
-    return (T[0] & T_MASK_SIGN);
-}
-
-
-
-type GetSizeModifier (const type* T)
-/* Get the size modifier of a type */
-{
-    PRECONDITION (T[0] != T_END);
-    return (T[0] & T_MASK_SIZE);
-}
-
-
-
 type GetQualifier (const type* T)
 /* Get the qualifier from the given type string */
 {
@@ -743,7 +732,7 @@ FuncDesc* GetFuncDesc (const type* T)
     CHECK (T[0] == T_FUNC);
 
     /* Decode the function descriptor and return it */
-    return (FuncDesc*) DecodePtr (T+1);
+    return DecodePtr (T+1);
 }
 
 
@@ -766,3 +755,23 @@ type* GetFuncReturn (type* T)
 
 
 
+long GetElementCount (const type* T)
+/* Get the element count of the array specified in T (which must be of
+ * array type).
+ */
+{
+    CHECK (IsTypeArray (T));
+    return (unsigned) Decode (T+1);
+}
+
+
+
+type* GetElementType (type* T)
+/* Return the element type of the given array type. */
+{
+    CHECK (IsTypeArray (T));
+    return T + DECODE_SIZE + 1;
+}
+
+
+