Remove building with NOCRYPTO option
[minix.git] / minix / llvm / passes / include / magic / support / BitFieldAggregation.h
blobac53beba44799a4e9f3f03196445f73e353975fe
1 #ifndef BIT_FIELD_AGGREGATION_H
2 #define BIT_FIELD_AGGREGATION_H
4 #include <magic/support/EDIType.h>
5 #include <magic/support/TypeUtil.h>
7 using namespace llvm;
9 namespace llvm {
11 #define BitFieldAggregationErr(M) errs() << "BitFieldAggregation: " << M << "\n"
13 #define BFA_NAME_PREFIX "__BFA__"
15 class BitFieldAggregation {
16 public:
17 BitFieldAggregation(TYPECONST Type* type, std::vector<EDIType> EDITypes, unsigned typeIndex, unsigned EDITypeIndex, std::vector<DIDerivedType> members, unsigned counter);
18 BitFieldAggregation();
19 void init(TYPECONST Type* type, std::vector<EDIType> EDITypes, unsigned typeIndex, unsigned EDITypeIndex, std::vector<DIDerivedType> members, unsigned counter);
21 const std::string getDescription() const;
23 unsigned getTypeIndex() const;
24 unsigned getEDITypeIndex() const;
25 std::string getName() const;
26 std::vector<DIDerivedType> getMembers() const;
28 unsigned getSize() const;
29 TYPECONST Type *getType() const;
30 std::vector<EDIType> getEDITypes() const;
31 unsigned getRepresentativeEDITypeIndex() const;
33 void print(raw_ostream &OS) const;
35 static bool getBitFieldAggregations(TYPECONST Type *type, const EDIType *aEDIType, std::vector<BitFieldAggregation> &bfas, bool returnOnError=false);
36 static bool hasBitFields(TYPECONST Type *type, const EDIType *aEDIType);
37 static bool isBitField(TYPECONST Type *type, const EDIType *aEDIType, unsigned memberIdx);
39 private:
40 TYPECONST Type *type;
41 std::vector<EDIType> EDITypes;
42 unsigned typeIndex;
43 unsigned EDITypeIndex;
44 std::string name;
45 std::vector<DIDerivedType> members;
46 unsigned size;
48 static std::string bfaNamePrefix;
50 static BitFieldAggregation* getBitFieldAggregation(TYPECONST Type *type, const EDIType *aEDIType, bool returnOnError, unsigned typeIndex, unsigned EDITypeIndex, unsigned lastTypeIndex, unsigned lastEDITypeIndex, unsigned counter);
53 inline raw_ostream &operator<<(raw_ostream &OS, const BitFieldAggregation &bfa) {
54 bfa.print(OS);
55 return OS;
58 inline unsigned BitFieldAggregation::getTypeIndex() const {
59 return typeIndex;
62 inline unsigned BitFieldAggregation::getEDITypeIndex() const {
63 return EDITypeIndex;
66 inline std::string BitFieldAggregation::getName() const {
67 return name;
70 inline std::vector<DIDerivedType> BitFieldAggregation::getMembers() const {
71 return members;
74 inline unsigned BitFieldAggregation::getSize() const {
75 return size;
78 inline TYPECONST Type *BitFieldAggregation::getType() const {
79 return type;
82 inline std::vector<EDIType> BitFieldAggregation::getEDITypes() const {
83 return EDITypes;
86 inline unsigned BitFieldAggregation::getRepresentativeEDITypeIndex() const {
87 return EDITypeIndex;
90 inline void BitFieldAggregation::print(raw_ostream &OS) const {
91 OS << getDescription();
94 inline bool BitFieldAggregation::hasBitFields(TYPECONST Type *type, const EDIType *aEDIType) {
95 if(!aEDIType->isStructTy()) {
96 return false;
98 unsigned numContainedTypes = aEDIType->getNumContainedTypes();
99 for(unsigned i=0;i<numContainedTypes;i++) {
100 if (isBitField(type, aEDIType, i)) {
101 return true;
104 return false;
107 inline bool BitFieldAggregation::isBitField(TYPECONST Type *type, const EDIType *aEDIType, unsigned memberIdx) {
108 const DIDerivedType subDIType = aEDIType->getMember(memberIdx);
109 unsigned EDITypeBits = subDIType.getSizeInBits();
110 const DIType aDIType = PassUtil::getDITypeDerivedFrom(subDIType);
111 unsigned EDITypeOriginalBits = aDIType.getSizeInBits();
112 return (EDITypeBits>0 && EDITypeOriginalBits>0 && EDITypeBits != EDITypeOriginalBits);
117 #endif