1 #ifndef TYPE_UTIL_H
2 #define TYPE_UTIL_H
3 
4 #include <pass.h>
5 #include <magic/support/EDIType.h>
6 
7 using namespace llvm;
8 
9 namespace llvm {
10 
11 #define TypeUtilLog(M) DEBUG(dbgs() << "TypeUtil: " << M << "\n")
12 
13 class TypeUtil {
14   public:
15       static int VERBOSE_LEVEL;
16       static int PRINT_SKIP_UNIONS;
17       static int PRINT_SKIP_STRUCTS;
18       static int PRINT_USE_BUILTIN_PRINTING;
19       static int PRINT_MULTI_NAMES;
20       static const unsigned TYPE_STRUCT = 0x01;
21       static const unsigned TYPE_UNION = 0x02;
22       static const unsigned TYPE_ANONYMOUS = 0x04;
23       static const unsigned TYPE_UNNAMED = 0x08;
24 
25       static bool isPaddedType(TYPECONST Type *type);
26 
27       static TYPECONST Type* lookupTopStructType(TYPECONST Type *type, unsigned index);
28       static void parseTopStructTypes(Module &M, TYPECONST Type *type, std::vector<std::string> *names, std::vector<unsigned> *flags);
29       static int findTopStructTypeIndex(Module &M, TYPECONST Type *type, std::string &name, unsigned flagsToAccept);
30       static TYPECONST Type* getRecursiveElementType(TYPECONST Type *type);
31       static TYPECONST Type* getArrayFreePointerType(TYPECONST Type *type);
32       static bool hasInnerPointers(TYPECONST Type *type);
33       static bool isArrayAsStructTy(TYPECONST Type *type);
34       static bool isOpaqueTy(TYPECONST Type *type);
35 
36       static unsigned getHash(TYPECONST Type* type);
37       static const std::string getDescription(TYPECONST Type* type, size_t max_chars = 0, size_t max_levels = 0);
38       static const std::string getDescription(const EDIType* aEDIType);
39       static const std::string getDescription(TYPECONST Type* type, const EDIType* aEDIType, size_t max_chars = 0, size_t max_levels = 0);
40       static const std::string getFormattedDescription(std::string &description);
41       static void printFormattedTypeString(raw_ostream &OS, std::string &typeStr, int start, int length);
42       static void printTypeString(raw_ostream &OS, TYPECONST Type* type, size_t max_chars = 0, size_t max_levels = 0);
43       static unsigned typeToBits(TYPECONST Type *type);
44 };
45 
46 inline bool TypeUtil::isOpaqueTy(TYPECONST Type *type) {
47       return PassUtil::isOpaqueTy(type);
48 }
49 
50 }
51 
52 #endif
53