* gen_inst: Use lastmcodeptr instead of last_compiled.
[cacao.git] / src / vm / descriptor.h
index fcf9a1482f8648461f6c0a42ee28be2499d92e3d..dbc8cc35573ec3736bbef3c1b80b20221b8fe7d2 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: descriptor.h 2182 2005-04-01 20:56:33Z edwin $
+   $Id: descriptor.h 2796 2005-06-23 09:42:34Z twisti $
 
 */
 
 /* forward typedefs ***********************************************************/
 
 typedef struct descriptor_pool descriptor_pool;
+typedef struct paramdesc paramdesc;
 
+#include "vm/class.h"
 #include "vm/global.h"
+#include "vm/method.h"
 #include "vm/references.h"
 #include "vm/tables.h"
 
+
 /* data structures ************************************************************/ 
 
 /*----------------------------------------------------------------------------*/
@@ -103,13 +107,37 @@ struct typedesc {
 /*       So short is PRIMITIVETYPE_SHORT, char is PRIMITIVETYPE_CHAR.         */
 /*       For non-primitive types decltype is TYPE_ADR.                        */
 
+struct paramdesc {
+       bool inmemory;              /* argument in register or on stack           */
+       s4   regoff;                /* register index or stack offset             */
+};
+
 struct methoddesc {
-       s2                 paramcount; /* number of parameters                    */
-       s2                 paramslots; /* like above but LONG,DOUBLE count twice  */
-       typedesc           returntype; /* parsed descriptor of the return type    */
-       typedesc           paramtypes[1]; /* parameter types, variable length!    */
+       s2         paramcount;      /* number of parameters                       */
+       s2         paramslots;      /* like above but LONG,DOUBLE count twice     */
+       s4         argintreguse;    /* number of used integer argument registers  */
+       s4         argfltreguse;    /* number of used float argument registers    */
+       s4         memuse;          /* number of stack slots used                 */
+       paramdesc *params;          /* allocated parameter descriptions [3]       */
+       typedesc   returntype;      /* parsed descriptor of the return type       */
+       typedesc   paramtypes[1];   /* parameter types, variable length!          */
 };
 
+/* [3]...If params is NULL, the parameter descriptions have not yet been      */
+/*       allocated. In this case ___the possible 'this' pointer of the method */
+/*       is NOT counted in paramcount/paramslots and it is NOT included in    */
+/*       the paramtypes array___.                                             */
+/*       If params != NULL, the parameter descriptions have been              */
+/*       allocated, and the 'this' pointer of the method, if any, IS included.*/
+/*       In case the method has no parameters at all, the special value       */
+/*       METHODDESC_NO_PARAMS is used (see below).                            */
+
+/* METHODDESC_NO_PARAMS is a special value for the methoddesc.params field    */
+/* indicating that the method is a static method without any parameters.      */
+/* This special value must be != NULL and it may only be set if               */
+/* md->paramcount == 0.                                                       */
+
+#define METHODDESC_NOPARAMS  ((paramdesc*)1)
 
 /* function prototypes ********************************************************/
 
@@ -125,6 +153,7 @@ struct methoddesc {
 
 void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
 
+
 /* descriptor_debug_print_methoddesc *******************************************
  
    Print the given methoddesc to the given stream
@@ -137,6 +166,19 @@ void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
 
 void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
 
+
+/* descriptor_debug_print_paramdesc ********************************************
+   Print the given paramdesc to the given stream
+
+   IN:
+          file.............stream to print to
+          d................the parameter descriptor
+
+*******************************************************************************/
+
+void descriptor_debug_print_paramdesc(FILE *file,paramdesc *d);
+
 /* descriptor_pool_new *********************************************************
  
    Allocate a new descriptor_pool
@@ -151,6 +193,7 @@ void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
 
 descriptor_pool * descriptor_pool_new(classinfo *referer);
 
+
 /* descriptor_pool_add_class ***************************************************
  
    Add the given class reference to the pool
@@ -167,6 +210,7 @@ descriptor_pool * descriptor_pool_new(classinfo *referer);
 
 bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
 
+
 /* descriptor_pool_add *********************************************************
  
    Check the given descriptor and add it to the pool
@@ -187,6 +231,7 @@ bool descriptor_pool_add_class(descriptor_pool *pool,utf *name);
 
 bool descriptor_pool_add(descriptor_pool *pool,utf *desc,int *paramslots);
 
+
 /* descriptor_pool_create_classrefs ********************************************
  
    Create a table containing all the classrefs which were added to the pool
@@ -206,6 +251,7 @@ bool descriptor_pool_add(descriptor_pool *pool,utf *desc,int *paramslots);
 constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
                                                                                                         s4 *count);
 
+
 /* descriptor_pool_lookup_classref *********************************************
  
    Return the constant_classref for the given class name
@@ -222,6 +268,7 @@ constant_classref * descriptor_pool_create_classrefs(descriptor_pool *pool,
 
 constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *classname);
 
+
 /* descriptor_pool_alloc_parsed_descriptors ************************************
  
    Allocate space for the parsed descriptors
@@ -237,6 +284,7 @@ constant_classref * descriptor_pool_lookup_classref(descriptor_pool *pool,utf *c
 
 void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
 
+
 /* descriptor_pool_parse_field_descriptor **************************************
  
    Parse the given field descriptor
@@ -255,7 +303,8 @@ void descriptor_pool_alloc_parsed_descriptors(descriptor_pool *pool);
 
 *******************************************************************************/
 
-typedesc * descriptor_pool_parse_field_descriptor(descriptor_pool *pool,utf *desc);
+typedesc *descriptor_pool_parse_field_descriptor(descriptor_pool *pool, utf *desc);
+
 
 /* descriptor_pool_parse_method_descriptor *************************************
  
@@ -263,7 +312,11 @@ typedesc * descriptor_pool_parse_field_descriptor(descriptor_pool *pool,utf *des
 
    IN:
        pool.............the descriptor_pool
-          desc.............the method descriptor
+       desc.............the method descriptor
+       mflags...........the method flags
+          thisclass........classref to the class containing the method.
+                                               This is ignored if mflags contains ACC_STATIC.
+                                               The classref is stored for inserting the 'this' argument.
 
    RETURN VALUE:
        a pointer to the parsed method descriptor, or
@@ -275,7 +328,32 @@ typedesc * descriptor_pool_parse_field_descriptor(descriptor_pool *pool,utf *des
 
 *******************************************************************************/
 
-methoddesc * descriptor_pool_parse_method_descriptor(descriptor_pool *pool,utf *desc);
+methoddesc *descriptor_pool_parse_method_descriptor(descriptor_pool *pool, utf *desc, s4 mflags,
+                                                                                                       constant_classref *thisclass);
+
+/* descriptor_params_from_paramtypes *******************************************
+   Create the paramdescs for a method descriptor. This function is called
+   when we know whether the method is static or not. This function may only
+   be called once for each methoddesc, and only if md->params == NULL.
+
+   IN:
+       md...............the parsed method descriptor
+                           md->params MUST be NULL.
+          mflags...........the ACC_* access flags of the method. Only the
+                           ACC_STATIC bit is checked.
+                                               The value ACC_UNDEF is NOT allowed.
+
+   RETURN VALUE:
+       true.............the paramdescs were created successfully
+          false............an exception has been thrown
+
+   POSTCONDITION:
+       md->parms != NULL
+
+*******************************************************************************/
+
+bool descriptor_params_from_paramtypes(methoddesc *md, s4 mflags);
 
 /* descriptor_pool_get_parsed_descriptors **************************************
  
@@ -298,8 +376,8 @@ methoddesc * descriptor_pool_parse_method_descriptor(descriptor_pool *pool,utf *
 
 *******************************************************************************/
 
-void * descriptor_pool_get_parsed_descriptors(descriptor_pool *pool,
-                                                                                         s4 *size);
+void *descriptor_pool_get_parsed_descriptors(descriptor_pool *pool, s4 *size);
+
 
 /* descriptor_pool_get_sizes ***************************************************
  
@@ -320,8 +398,9 @@ void * descriptor_pool_get_parsed_descriptors(descriptor_pool *pool,
 
 *******************************************************************************/
 
-void descriptor_pool_get_sizes(descriptor_pool *pool,
-                                                          u4 *classrefsize,u4 *descsize);
+void descriptor_pool_get_sizes(descriptor_pool *pool, u4 *classrefsize,
+                                                          u4 *descsize);
+
 
 /* descriptor_debug_print_typedesc *********************************************
  
@@ -333,7 +412,8 @@ void descriptor_pool_get_sizes(descriptor_pool *pool,
 
 *******************************************************************************/
 
-void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
+void descriptor_debug_print_typedesc(FILE *file, typedesc *d);
+
 
 /* descriptor_debug_print_methoddesc *******************************************
  
@@ -345,7 +425,8 @@ void descriptor_debug_print_typedesc(FILE *file,typedesc *d);
 
 *******************************************************************************/
 
-void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
+void descriptor_debug_print_methoddesc(FILE *file, methoddesc *d);
+
 
 /* descriptor_pool_debug_dump **************************************************
  
@@ -357,49 +438,11 @@ void descriptor_debug_print_methoddesc(FILE *file,methoddesc *d);
 
 *******************************************************************************/
 
-void descriptor_pool_debug_dump(descriptor_pool *pool,FILE *file);
-
-/* macros for descriptor parsing **********************************************/
-
-/* XXX These should be moved to descriptor.c */
+void descriptor_pool_debug_dump(descriptor_pool *pool, FILE *file);
 
-/* SKIP_FIELDDESCRIPTOR:
- * utf_ptr must point to the first character of a field descriptor.
- * After the macro call utf_ptr points to the first character after
- * the field descriptor.
- *
- * CAUTION: This macro does not check for an unexpected end of the
- * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE.
- */
-#define SKIP_FIELDDESCRIPTOR(utf_ptr)                                                  \
-       do { while (*(utf_ptr)=='[') (utf_ptr)++;                                       \
-               if (*(utf_ptr)++=='L')                                                                  \
-                       while(*(utf_ptr)++ != ';') /* skip */; } while(0)
-
-/* SKIP_FIELDDESCRIPTOR_SAFE:
- * utf_ptr must point to the first character of a field descriptor.
- * After the macro call utf_ptr points to the first character after
- * the field descriptor.
- *
- * Input:
- *     utf_ptr....points to first char of descriptor
- *     end_ptr....points to first char after the end of the string
- *     errorflag..must be initialized (to false) by the caller!
- * Output:
- *     utf_ptr....points to first char after the descriptor
- *     errorflag..set to true if the string ended unexpectedly
- */
-#define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag)                   \
-       do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++;     \
-               if ((utf_ptr) == (end_ptr))                                                                             \
-                       (errorflag) = true;                                                                                     \
-               else                                                                                                                    \
-                       if (*(utf_ptr)++=='L') {                                                                        \
-                               while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';')    \
-                                       /* skip */;                                                                                     \
-                               if ((utf_ptr)[-1] != ';')                                                               \
-                                       (errorflag) = true; }} while(0)
 
+/* machine dependent descriptor function */
+void md_param_alloc(methoddesc *md);
 
 #endif /* _DESCRIPTOR_H */