little cleanup
[libfirm] / ir / tr / type.h
index 38d0bb3..98989dd 100644 (file)
@@ -35,8 +35,6 @@
 # ifndef _TYPE_H_
 # define _TYPE_H_
 
-#include <stdbool.h>
-
 # include "firm_types.h"
 # include "tpop.h"
 # include "firm_common.h"
  */
 #ifndef _TYPE_TYPEDEF_
 #define _TYPE_TYPEDEF_
-typedef struct type type;
+typedef struct ir_type type;
 #endif
 
 # include "type_or_entity.h"
@@ -771,23 +769,23 @@ void set_method_first_variadic_param_index(type *method, int index);
  */
 typedef enum {
   mtp_no_property        = 0x00000000, /**< no additional properties, default */
-  mtp_property_const     = 0x00000001, /**< This graph did not access memory and calculates
+  mtp_property_const     = 0x00000001, /**< This method did not access memory and calculates
                                          its return values solely from its parameters.
                                          GCC: __attribute__((const)). */
-  mtp_property_pure      = 0x00000002, /**< This graph did NOT write to memory and calculates
+  mtp_property_pure      = 0x00000002, /**< This method did NOT write to memory and calculates
                                          its return values solely form its parameters and
                                          the memory they points to (or global vars).
                                          GCC: __attribute__((pure)). */
-  mtp_property_noreturn  = 0x00000004, /**< This graph did not return due to an aborting system
+  mtp_property_noreturn  = 0x00000004, /**< This method did not return due to an aborting system
                                          call.
                                          GCC: __attribute__((noreturn)). */
-  mtp_property_nothrow   = 0x00000008, /**< This graph cannot throw an exception.
+  mtp_property_nothrow   = 0x00000008, /**< This method cannot throw an exception.
                                          GCC: __attribute__((nothrow)). */
-  mtp_property_naked     = 0x00000010, /**< This graph is naked.
+  mtp_property_naked     = 0x00000010, /**< This method is naked.
                                          GCC: __attribute__((naked)). */
-  mtp_property_malloc    = 0x00000020, /**< This graph returns newly allocate memory.
+  mtp_property_malloc    = 0x00000020, /**< This method returns newly allocate memory.
                                          GCC: __attribute__((malloc)). */
-  mtp_property_inherited = 0x40000000  /**< used only in irgs, means property is inherited
+  mtp_property_inherited = 0x40000000  /**< used only in irg's, means property is inherited
                                          from type. */
 } mtp_additional_property;
 
@@ -801,40 +799,61 @@ void set_method_additional_properties(type *method, unsigned property_mask);
 void set_method_additional_property(type *method, mtp_additional_property flag);
 
 /**
- * calling conventions
+ * calling conventions: lower 24 bits are the number of register parameters,
+ * upper 8 encode the calling conventions
  */
 typedef enum {
-  cc_reg_param        = 0x00000001, /**< Transmit parameters in registers, else the stack is used.
-                                             This flag may be set as default on some architectures. */
-  cc_last_on_top      = 0x00000002, /**< The last non-register parameter is transmitted on top of
+  cc_reg_param        = 0x01000000, /**< Transmit parameters in registers, else the stack is used.
+                                         This flag may be set as default on some architectures. */
+  cc_last_on_top      = 0x02000000, /**< The last non-register parameter is transmitted on top of
                                              the stack. This is equivalent to the stdcall or pascal
                                              calling convention. If this flag is not set, the first
                                              non-register parameter is used (cdecl calling convention) */
-  cc_callee_clear_stk = 0x00000004, /**< The callee clears the stack. This forbids variadic
-                                             function calls (stdcall). */
-  cc_this_call        = 0x00000008  /**< The first parameter is a this pointer and is transmitted
-                                        in a special way. */
+  cc_callee_clear_stk = 0x04000000, /**< The callee clears the stack. This forbids variadic
+                                         function calls (stdcall). */
+  cc_this_call        = 0x08000000, /**< The first parameter is a this pointer and is transmitted
+                                         in a special way. */
+
+  /* some often used cases */
+  cc_cdecl_set        = 0,                                /**< cdecl calling convention */
+  cc_stdcall_set      = cc_callee_clear_stk,              /**< stdcall calling convention */
+  cc_fastcall_set     = cc_reg_param|cc_callee_clear_stk, /**< fastcall calling convention */
+
+  cc_bits             = (0xFF << 24)                      /**< the calling convention bits */
 } calling_convention;
 
+/** return the default calling convention for method types */
+unsigned get_default_cc_mask(void);
+
 /**
  * check for the CDECL calling convention
  */
-#define IS_CDECL(cc_mask)     (((cc_mask) & (cc_callee_clear_stk|cc_last_on_top)) == 0)
+#define IS_CDECL(cc_mask)     (((cc_mask) & cc_bits) == cc_cdecl_set)
 
 /**
  * check for the STDCALL calling convention
  */
-#define IS_STDCALL(cc_mask)   (((cc_mask) & (cc_callee_clear_stk|cc_last_on_top)) == cc_callee_clear_stk)
+#define IS_STDCALL(cc_mask)   (((cc_mask) & cc_bits) == cc_stdcall_set)
+
+/**
+ * check for the FASTCALL calling convention
+ */
+#define IS_FASTCALL(cc_mask)  (((cc_mask) & cc_bits) == cc_fastcall_set)
+
+/**
+ * set the CDECL convention bits
+ */
+#define SET_CDECL(cc_mask)    (((cc_mask) & ~cc_bits) | cc_cdecl_set)
 
 /**
- * add the CDECL convention bits
+ * set the STDCALL convention bits
  */
-#define SET_CDECL(cc_mask)    ((cc_mask) & ~(cc_callee_clear_stk|cc_last_on_top))
+#define SET_STDCALL(cc_mask)  (((cc_mask) & ~cc_bits) | cc_stdcall_set)
 
 /**
- * add the STDCALL convention bits
+ * set the FASTCALL convention bits
  */
-#define SET_STDCALL(cc_mask)  (((cc_mask) & ~cc_last_on_top) | cc_callee_clear_stk)
+#define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
 
 /** Returns the calling convention of an entities graph. */
 unsigned get_method_calling_convention(const type *method);
@@ -842,6 +861,12 @@ unsigned get_method_calling_convention(const type *method);
 /** Sets the calling convention of an entities graph. */
 void set_method_calling_convention(type *method, unsigned cc_mask);
 
+/** Returns the number of registers parameters, 0 means default. */
+unsigned get_method_n_regparams(type *method);
+
+/** Sets the number of registers parameters, 0 means default. */
+void set_method_n_regparams(type *method, unsigned n_regs);
+
 /** Returns true if a type is a method type. */
 int   is_Method_type     (const type *method);