home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / kaffe-0.5p4-src.tgz / tar.out / contrib / kaffe / kaffevm / constants.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  92 lines

  1. /*
  2.  * constants.h
  3.  * Manage constants.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. /* COPYRIGHT */
  15.  
  16. #ifndef __constant_h
  17. #define __constant_h
  18.  
  19. /*
  20.  * Constant pool definitions.
  21.  */
  22. #define    CONSTANT_Class            7
  23. #define    CONSTANT_Fieldref        9
  24. #define    CONSTANT_Methodref        10
  25. #define    CONSTANT_InterfaceMethodref    11
  26. #define    CONSTANT_String            8
  27. #define    CONSTANT_Integer        3
  28. #define    CONSTANT_Float            4
  29. #define    CONSTANT_Long            5
  30. #define    CONSTANT_Double            6
  31. #define    CONSTANT_NameAndType        12
  32. #define    CONSTANT_Utf8            1
  33. #define    CONSTANT_Unicode        2
  34.  
  35. #define    CONSTANT_LongC            129
  36. #define    CONSTANT_DoubleC        130
  37.  
  38. #define    CONSTANT_Unknown        0
  39. #define    CONSTANT_Chararray        128
  40.  
  41. typedef u2    constIndex;
  42.  
  43. struct _slots;
  44.  
  45. typedef struct _constants {
  46.     u2        size;
  47.     u1*        tags;
  48.     struct _slots*    data;
  49. } constants;
  50.  
  51. #define    STRHASHSZ        128
  52.  
  53. typedef struct _strconst {
  54.     struct _strconst*    next;
  55.     struct _stringClass*    string;
  56.     object            obj;
  57.     char            data[1];
  58. } strconst;
  59.  
  60. #define    STRING_DATA2BASE(i)    (strconst*)(((int)i) - (sizeof(object)+sizeof(strconst*)+sizeof(strconst*)))
  61. #define    STRING_DATA2OBJECT(i)    (object*)(((int)i) - sizeof(object))
  62. #define    STRING_OBJ2DATA(i)    (char*)(((int)i) + sizeof(object))
  63.  
  64. typedef struct _strpair {
  65.     struct _strpair*    next;
  66.     uint32            hash;
  67.     char*            s1;
  68.     char*            s2;
  69. } strpair;
  70.  
  71. /*
  72.  * Macros to take constant pools apart.
  73.  */
  74. #define    METHODREF_CLASS(idx, pool)        (pool->data[idx].v.tint & 0xFFFF)
  75. #define    METHODREF_NAMEANDTYPE(idx, pool)    (pool->data[idx].v.tint >> 16)
  76. #define    CLASS_NAME(idx, pool)            (pool->data[idx].v.tint)
  77. #define    FIELDREF_CLASS(idx, pool)        METHODREF_CLASS(idx, pool)
  78. #define    FIELDREF_NAMEANDTYPE(idx, pool)        METHODREF_NAMEANDTYPE(idx, pool)
  79. #define    NAMEANDTYPE_NAME(idx, pool)        METHODREF_CLASS(idx, pool)
  80. #define    NAMEANDTYPE_SIGNATURE(idx, pool)    METHODREF_NAMEANDTYPE(idx, pool)
  81. #define    STRING_NAME(idx, pool)            CLASS_NAME(idx, pool)
  82.  
  83. struct _classFile;
  84.  
  85. constants*    readConstantPool(struct _classFile*);
  86.  
  87. char*        addStringConstant(strconst*);
  88. strpair*    addStringConstantPair(char*, char*);
  89. strpair*    lookupStringPair(char*, char*);
  90.  
  91. #endif
  92.