diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 0990396af..fe0b9e0a3 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -590,25 +590,6 @@ static unsigned GetBitFieldMinimalTypeSize (unsigned BitWidth) } -static unsigned TypeOfBySize (unsigned Size) -/* Get the code generator replacement type of the object by its size */ -{ - unsigned NewType; - /* If the size is less than or equal to that of a a long, we will copy - ** the struct using the primary register, otherwise we use memcpy. - */ - switch (Size) { - case 1: NewType = CF_CHAR; break; - case 2: NewType = CF_INT; break; - case 3: /* FALLTHROUGH */ - case 4: NewType = CF_LONG; break; - default: NewType = CF_NONE; break; - } - - return NewType; -} - - const Type* GetUnderlyingType (const Type* Type) /* Get the underlying type of an enum or other integer class type */ @@ -858,80 +839,6 @@ unsigned CheckedPSizeOf (const Type* T) -unsigned TypeOf (const Type* T) -/* Get the code generator base type of the object */ -{ - unsigned NewType; - - switch (GetUnderlyingTypeCode (T)) { - - case T_SCHAR: - return CF_CHAR; - - case T_UCHAR: - return CF_CHAR | CF_UNSIGNED; - - case T_SHORT: - case T_INT: - return CF_INT; - - case T_USHORT: - case T_UINT: - case T_PTR: - case T_ARRAY: - return CF_INT | CF_UNSIGNED; - - case T_LONG: - return CF_LONG; - - 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: - /* Treat this as a function pointer */ - return CF_INT | CF_UNSIGNED; - - case T_STRUCT: - case T_UNION: - NewType = TypeOfBySize (SizeOf (T)); - if (NewType != CF_NONE) { - return NewType; - } - /* Address of ... */ - return CF_INT | CF_UNSIGNED; - - case T_VOID: - case T_ENUM: - /* Incomplete enum type */ - Error ("Incomplete type '%s'", GetFullTypeName (T)); - return CF_INT; - - default: - Error ("Illegal type %04lX", T->C); - return CF_INT; - } -} - - - -unsigned FuncTypeOf (const Type* T) -/* Get the code generator flag for calling the function */ -{ - if (GetUnderlyingTypeCode (T) == T_FUNC) { - return (T->A.F->Flags & FD_VARIADIC) ? 0 : CF_FIXARGC; - } else { - Error ("Illegal function type %04lX", T->C); - return 0; - } -} - - - const Type* Indirect (const Type* T) /* Do one indirection for the given type, that is, return the type where the ** given type points to. diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index d7e8d2e99..be5b4a31c 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -333,12 +333,6 @@ unsigned CheckedPSizeOf (const Type* T); ** rest of the compiler doesn't have to work with invalid sizes). */ -unsigned TypeOf (const Type* T); -/* Get the code generator base type of the object */ - -unsigned FuncTypeOf (const Type* T); -/* Get the code generator flag for calling the function */ - const Type* Indirect (const Type* T); /* Do one indirection for the given type, that is, return the type where the ** given type points to. diff --git a/src/cc65/expr.c b/src/cc65/expr.c index c95a5a401..8f493ad03 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -103,6 +103,100 @@ unsigned GlobalModeFlags (const ExprDesc* Expr) +static unsigned TypeOfBySize (unsigned Size) +/* Get the code generator replacement type of the object by its size */ +{ + unsigned NewType; + /* If the size is less than or equal to that of a a long, we will copy + ** the struct using the primary register, otherwise we use memcpy. + */ + switch (Size) { + case 1: NewType = CF_CHAR; break; + case 2: NewType = CF_INT; break; + case 3: /* FALLTHROUGH */ + case 4: NewType = CF_LONG; break; + default: NewType = CF_NONE; break; + } + + return NewType; +} + + + +unsigned TypeOf (const Type* T) +/* Get the code generator base type of the object */ +{ + unsigned NewType; + + switch (GetUnderlyingTypeCode (T)) { + + case T_SCHAR: + return CF_CHAR; + + case T_UCHAR: + return CF_CHAR | CF_UNSIGNED; + + case T_SHORT: + case T_INT: + return CF_INT; + + case T_USHORT: + case T_UINT: + case T_PTR: + case T_ARRAY: + return CF_INT | CF_UNSIGNED; + + case T_LONG: + return CF_LONG; + + 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: + /* Treat this as a function pointer */ + return CF_INT | CF_UNSIGNED; + + case T_STRUCT: + case T_UNION: + NewType = TypeOfBySize (SizeOf (T)); + if (NewType != CF_NONE) { + return NewType; + } + /* Address of ... */ + return CF_INT | CF_UNSIGNED; + + case T_VOID: + case T_ENUM: + /* Incomplete enum type */ + Error ("Incomplete type '%s'", GetFullTypeName (T)); + return CF_INT; + + default: + Error ("Illegal type %04lX", T->C); + return CF_INT; + } +} + + + +unsigned FuncTypeOf (const Type* T) +/* Get the code generator flag for calling the function */ +{ + if (GetUnderlyingTypeCode (T) == T_FUNC) { + return (T->A.F->Flags & FD_VARIADIC) ? 0 : CF_FIXARGC; + } else { + Error ("Illegal function type %04lX", T->C); + return 0; + } +} + + + void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr) /* Call an expression function with checks. */ { diff --git a/src/cc65/expr.h b/src/cc65/expr.h index 7c2f426d7..5644fb82d 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -51,6 +51,12 @@ typedef struct GenDesc { unsigned GlobalModeFlags (const ExprDesc* Expr); /* Return the addressing mode flags for the given expression */ +unsigned TypeOf (const Type* T); +/* Get the code generator base type of the object */ + +unsigned FuncTypeOf (const Type* T); +/* Get the code generator flag for calling the function */ + void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr); /* Call an expression function with checks. */ diff --git a/src/cc65/function.c b/src/cc65/function.c index 44d566de8..737b068a3 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -42,6 +42,7 @@ #include "asmlabel.h" #include "codegen.h" #include "error.h" +#include "expr.h" #include "funcdesc.h" #include "global.h" #include "litpool.h" diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index ccd694e35..c5ac43f78 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -36,6 +36,7 @@ /* cc65 */ #include "codegen.h" #include "error.h" +#include "expr.h" #include "exprdesc.h" #include "global.h" #include "loadexpr.h"