OLD | NEW |
(Empty) | |
| 1 //===- PNaClABITypeChecker.h - Verify PNaCl ABI rules -----------*- C++ -*-===// |
| 2 // |
| 3 // The LLVM Compiler Infrastructure |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // Common type-checking code for module and function-level passes |
| 11 // |
| 12 // |
| 13 //===----------------------------------------------------------------------===// |
| 14 |
| 15 #ifndef LLVM_ANALYSIS_NACL_PNACLABITYPECHECKER_H |
| 16 #define LLVM_ANALYSIS_NACL_PNACLABITYPECHECKER_H |
| 17 |
| 18 #include "llvm/ADT/DenseSet.h" |
| 19 #include "llvm/IR/Type.h" |
| 20 #include "llvm/Support/raw_ostream.h" |
| 21 |
| 22 namespace llvm { |
| 23 class FunctionType; |
| 24 |
| 25 class PNaClABITypeChecker { |
| 26 PNaClABITypeChecker(const PNaClABITypeChecker&) LLVM_DELETED_FUNCTION; |
| 27 void operator=(const PNaClABITypeChecker&) LLVM_DELETED_FUNCTION; |
| 28 public: |
| 29 // Returns true if Ty is a valid argument or return value type for PNaCl. |
| 30 static bool isValidParamType(const Type *Ty); |
| 31 |
| 32 // Returns true if Ty is a valid function type for PNaCl. |
| 33 static bool isValidFunctionType(const FunctionType *FTy); |
| 34 |
| 35 // Returns true if Ty is a valid non-derived type for PNaCl. |
| 36 static bool isValidScalarType(const Type *Ty); |
| 37 |
| 38 // Returns true if Ty is a valid vector type for PNaCl. |
| 39 static bool isValidVectorType(const Type *Ty); |
| 40 |
| 41 // Returns true if type Ty can be used in (integer) arithmetic operations. |
| 42 static bool isValidIntArithmeticType(const Type *Ty); |
| 43 |
| 44 // Returns true if type Ty can be used to define the test condition of |
| 45 // a switch instruction. |
| 46 static bool isValidSwitchConditionType(const Type *Ty) { |
| 47 return PNaClABITypeChecker::isValidIntArithmeticType(Ty); |
| 48 } |
| 49 // Returns error message showing what was expected when given the |
| 50 // switch condition type Ty. Assumes isValidSwitchConditionType(Ty) |
| 51 // returned false. |
| 52 static const char *ExpectedSwitchConditionType(const Type *Ty) { |
| 53 if (!Ty->isIntegerTy()) |
| 54 return "switch not on integer type"; |
| 55 if (Ty->isIntegerTy(1)) |
| 56 return "switch on i1 not allowed"; |
| 57 return "switch disallowed for integer type"; |
| 58 } |
| 59 |
| 60 // There's no built-in way to get the name of a type, so use a |
| 61 // string ostream to print it. |
| 62 static std::string getTypeName(const Type *T) { |
| 63 std::string TypeName; |
| 64 raw_string_ostream N(TypeName); |
| 65 T->print(N); |
| 66 return N.str(); |
| 67 } |
| 68 |
| 69 // Returns true if T1 is equivalent to T2, converting to i32 if |
| 70 // a pointer type. |
| 71 static bool IsPointerEquivType(Type *T1, Type *T2) { |
| 72 if (T1->isPointerTy()) return T2->isIntegerTy(32); |
| 73 if (T2->isPointerTy()) return T1->isIntegerTy(32); |
| 74 return T1 == T2; |
| 75 } |
| 76 |
| 77 }; |
| 78 } // namespace llvm |
| 79 |
| 80 #endif // LLVM_ANALYSIS_NACL_PNACLABITYPECHECKER_H |
OLD | NEW |