Chromium Code Reviews| Index: src/IceTypeConverter.h |
| diff --git a/src/IceTypeConverter.h b/src/IceTypeConverter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17674a1ff95f99f0b8e78c06c1bb12e224927655 |
| --- /dev/null |
| +++ b/src/IceTypeConverter.h |
| @@ -0,0 +1,88 @@ |
| +//===- subzero/src/IceTypeConverter.h - Convert Ice/LLVm Types --*- C++ -*-===// |
|
Jim Stichnoth
2014/07/17 23:00:33
ICE/LLVM
jvoung (off chromium)
2014/07/17 23:57:55
LLVm -> LLVM
Karl
2014/07/18 20:27:42
Done.
Karl
2014/07/18 20:27:43
Done.
|
| +// |
| +// 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" |
| + |
| +#include <map> |
|
jvoung (off chromium)
2014/07/17 23:57:55
Currently, src/IceDefs.h is the one place where <m
Karl
2014/07/18 20:27:43
Talked with Jim. Agreed to let IceDefs.h do the in
Jim Stichnoth
2014/07/21 22:25:21
Karl and I discussed offline. I agree it's a good
|
| + |
| +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 { |
| + 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 void type. |
| + llvm::Type *getLlvmVoidType() const { |
|
jvoung (off chromium)
2014/07/17 23:57:55
This doesn't appear to be used anywhere?
Karl
2014/07/18 20:27:42
Removed.
|
| + return LlvmTypes.at(IceType_void); |
| + } |
| + |
| + /// Returns LLVM integer type with number of bits. Returns NULL |
| + /// 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 |