Chromium Code Reviews| Index: src/IceTypeConverter.h |
| diff --git a/src/IceTypeConverter.h b/src/IceTypeConverter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6723496fa45ed5d2658735149c77310401e5a8aa |
| --- /dev/null |
| +++ b/src/IceTypeConverter.h |
| @@ -0,0 +1,82 @@ |
| +//===- subzero/src/IceTypeConverter.h - Convert ICE/LLVM Types --*- C++ -*-===// |
| +// |
| +// The Subzero Code Generator |
| +// |
| +// This file is distributed under the University of Illinois Open Source |
| +// License. See LICENSE.TXT for details. |
| +// |
| +//===----------------------------------------------------------------------===// |
| +// |
| +// This file defines how to convert LLVM types to ICE types, and ICE types |
| +// to LLVM types. |
| +// |
| +//===----------------------------------------------------------------------===// |
| + |
| +#ifndef SUBZERO_SRC_ICETYPECONVERTER_H |
| +#define SUBZERO_SRC_ICETYPECONVERTER_H |
| + |
| +#include "IceDefs.h" |
| +#include "IceTypes.h" |
| +#include "llvm/IR/DerivedTypes.h" |
| + |
| +namespace llvm { |
| +class LLVMContext; |
| +} // end of llvm namespace. |
| + |
| +namespace Ice { |
| + |
| +/// Converts LLVM types to ICE types, and ICE types to LLVM types. |
| +class TypeConverter { |
| + TypeConverter(const TypeConverter&) LLVM_DELETED_FUNCTION; |
| + TypeConverter &operator=(const TypeConverter&) LLVM_DELETED_FUNCTION; |
| +public: |
| + /// Context is the context to use to build llvm types. |
| + TypeConverter(llvm::LLVMContext &Context); |
| + |
| + /// Returns the LLVM type for the corresponding ICE type Ty. |
| + llvm::Type *convertToLLVMType(Type Ty) const { |
| + // Note: We use "at" here to verify Ty is valid. |
|
Jim Stichnoth
2014/08/01 18:05:33
How about:
We use "at" here in case Ty wasn't re
Karl
2014/08/25 17:46:53
Done.
|
| + return LLVMTypes.at(Ty); |
| + } |
| + |
| + /// Converts LLVM type LLVMTy to an ICE type. Returns |
| + /// Ice::IceType_NUM if unable to convert. |
| + Type convertToIceType(llvm::Type *LLVMTy) const { |
| + std::map<llvm::Type *, Type>::const_iterator |
| + Pos = LLVM2IceMap.find(LLVMTy); |
| + if (Pos == LLVM2IceMap.end()) |
| + return convertToIceTypeOther(LLVMTy); |
| + return Pos->second; |
| + } |
| + |
| + /// Returns ICE model of pointer type. |
| + Type getIcePointerType() const { |
| + return IceType_i32; |
| + } |
| + |
| + /// Returns LLVM integer type with number of bits. Returns NULL |
|
Jim Stichnoth
2014/08/01 18:05:33
with *specified* number
Karl
2014/08/25 17:46:53
Done.
|
| + /// if not a valid PNaCl integer type. |
| + llvm::Type *getLLVMIntegerType(unsigned NumBits) const; |
| + |
| + /// Returns the LLVM vector type for Size and Ty arguments. Returns |
| + /// NULL if not a valid PNaCl vector type. |
| + llvm::Type *getLLVMVectorType(unsigned Size, Type Ty) const; |
| + |
| +private: |
| + // The LLVM context to use to build LLVM types. |
| + llvm::LLVMContext &Context; |
| + // The list of allowable LLVM types. Indexed by ICE type. |
| + std::vector<llvm::Type*> LLVMTypes; |
| + // The inverse mapping of LLVMTypes. |
| + std::map<llvm::Type *, Type> LLVM2IceMap; |
| + |
| + // Add LLVM/ICE pair to internal tables. |
| + void AddLLVMType(Type Ty, llvm::Type *LLVMTy); |
| + |
| + // Converts types not in LLVM2IceMap. |
| + Type convertToIceTypeOther(llvm::Type *LLVMTy) const; |
| +}; |
| + |
| +} // end of Ice namespace. |
| + |
| +#endif // SUBZERO_SRC_ICETYPECONVERTER_H |