New utility to get the proper replacement type for passing structs/unions by value.
New utility to get basic type names such as 'struct', 'union' and so on.
This commit is contained in:
@@ -78,6 +78,33 @@ Type type_double[] = { TYPE(T_DOUBLE), TYPE(T_END) };
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char* GetBasicTypeName (const Type* T)
|
||||||
|
/* Return a const name string of the basic type.
|
||||||
|
** Return "type" for unknown basic types.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
switch (GetType (T)) {
|
||||||
|
case T_TYPE_CHAR: return "char";
|
||||||
|
case T_TYPE_SHORT: return "short";
|
||||||
|
case T_TYPE_INT: return "integer";
|
||||||
|
case T_TYPE_LONG: return "long";
|
||||||
|
case T_TYPE_LONGLONG: return "long long";
|
||||||
|
case T_TYPE_ENUM: return "enum";
|
||||||
|
case T_TYPE_FLOAT: return "poinfloatter";
|
||||||
|
case T_TYPE_DOUBLE: return "double";
|
||||||
|
case T_TYPE_VOID: return "void";
|
||||||
|
case T_TYPE_STRUCT: return "struct";
|
||||||
|
case T_TYPE_UNION: return "union";
|
||||||
|
case T_TYPE_ARRAY: return "array";
|
||||||
|
case T_TYPE_PTR: return "pointer";
|
||||||
|
case T_TYPE_FUNC: return "function";
|
||||||
|
case T_TYPE_NONE: /* FALLTHROUGH */
|
||||||
|
default: return "type";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned TypeLen (const Type* T)
|
unsigned TypeLen (const Type* T)
|
||||||
/* Return the length of the type string */
|
/* Return the length of the type string */
|
||||||
{
|
{
|
||||||
@@ -198,6 +225,26 @@ Type* GetImplicitFuncType (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const Type* GetReplacementType (const Type* SType)
|
||||||
|
/* Get a replacement type for passing a struct/union in the primary register */
|
||||||
|
{
|
||||||
|
const Type* NewType;
|
||||||
|
/* If the size is less than or equal to that of a long, we will copy the
|
||||||
|
** struct using the primary register, otherwise we will use memcpy.
|
||||||
|
*/
|
||||||
|
switch (SizeOf (SType)) {
|
||||||
|
case 1: NewType = type_uchar; break;
|
||||||
|
case 2: NewType = type_uint; break;
|
||||||
|
case 3: /* FALLTHROUGH */
|
||||||
|
case 4: NewType = type_ulong; break;
|
||||||
|
default: NewType = SType; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Type* PointerTo (const Type* T)
|
Type* PointerTo (const Type* T)
|
||||||
/* Return a type string that is "pointer to T". The type string is allocated
|
/* Return a type string that is "pointer to T". The type string is allocated
|
||||||
** on the heap and may be freed after use.
|
** on the heap and may be freed after use.
|
||||||
|
|||||||
@@ -209,6 +209,11 @@ struct SymEntry;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char* GetBasicTypeName (const Type* T);
|
||||||
|
/* Return a const name string of the basic type.
|
||||||
|
** Return "type" for unknown basic types.
|
||||||
|
*/
|
||||||
|
|
||||||
unsigned TypeLen (const Type* T);
|
unsigned TypeLen (const Type* T);
|
||||||
/* Return the length of the type string */
|
/* Return the length of the type string */
|
||||||
|
|
||||||
@@ -238,6 +243,9 @@ Type* GetCharArrayType (unsigned Len);
|
|||||||
Type* GetImplicitFuncType (void);
|
Type* GetImplicitFuncType (void);
|
||||||
/* Return a type string for an inplicitly declared function */
|
/* Return a type string for an inplicitly declared function */
|
||||||
|
|
||||||
|
const Type* GetReplacementType (const Type* SType);
|
||||||
|
/* Get a replacement type for passing a struct/union in the primary register */
|
||||||
|
|
||||||
Type* PointerTo (const Type* T);
|
Type* PointerTo (const Type* T);
|
||||||
/* Return a type string that is "pointer to T". The type string is allocated
|
/* Return a type string that is "pointer to T". The type string is allocated
|
||||||
** on the heap and may be freed after use.
|
** on the heap and may be freed after use.
|
||||||
|
|||||||
Reference in New Issue
Block a user