================ @@ -0,0 +1,244 @@ +//===---- ABITypeMapper.cpp - Maps LLVM ABI Types to LLVM IR Types ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Maps LLVM ABI type representations back to corresponding LLVM IR types. +/// This reverse mapper translates low-level ABI-specific types back into +/// LLVM IR types suitable for code generation and optimization passes. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/ABI/ABITypeMapper.h" +#include "llvm/ABI/Types.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Type.h" + +using namespace llvm; + +Type *ABITypeMapper::convertType(const abi::Type *ABIType) { + if (!ABIType) + return nullptr; + + auto It = TypeCache.find(ABIType); + if (It != TypeCache.end()) + return It->second; + + Type *Result = nullptr; + + switch (ABIType->getKind()) { + case abi::TypeKind::Integer: { + const auto *IT = cast<abi::IntegerType>(ABIType); + unsigned Bitwidth = IT->getSizeInBits().getFixedValue(); + Result = IntegerType::get(Context, Bitwidth); + break; + } + case abi::TypeKind::Float: + Result = convertFloatType(cast<abi::FloatType>(ABIType)); + break; + case abi::TypeKind::Pointer: + Result = PointerType::get(Context, + cast<abi::PointerType>(ABIType)->getAddrSpace()); + break; + case abi::TypeKind::Array: + Result = convertArrayType(cast<abi::ArrayType>(ABIType)); + break; + case abi::TypeKind::Vector: + Result = convertVectorType(cast<abi::VectorType>(ABIType)); + break; + case abi::TypeKind::Struct: + Result = convertStructType(cast<abi::StructType>(ABIType)); + break; + case abi::TypeKind::Void: + Result = Type::getVoidTy(Context); + break; + case abi::TypeKind::Complex: + Result = convertComplexType(cast<abi::ComplexType>(ABIType)); + break; + case abi::TypeKind::MemberPointer: + Result = convertMemberPointerType(cast<abi::MemberPointerType>(ABIType)); + break; ---------------- nikic wrote:
We should add a `default: llvm_unreachable()` here. This is supposed to cover all types, right? https://github.com/llvm/llvm-project/pull/140112 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits