diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-05-30 12:10:38 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-05-30 12:10:38 +0800 |
| commit | 4c9d2d541c90968db2065260dc94c3be9e8adef9 (patch) | |
| tree | d9c67d89bb7709bd76ea4809101efbd55dd1a9b0 /TypeManager.cc | |
| parent | 63d2a1c552b0d190a0131c2db2045d154b9ec138 (diff) | |
use llvm::Function* to call a function for backward compatibility
Diffstat (limited to 'TypeManager.cc')
| -rw-r--r-- | TypeManager.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/TypeManager.cc b/TypeManager.cc index c4c9c10..55b172e 100644 --- a/TypeManager.cc +++ b/TypeManager.cc @@ -1,5 +1,6 @@ #include "TypeManager.hh" #include "Context.hh" +#include "ExprNode.hh" #include "Log.hh" namespace pcc { @@ -195,6 +196,35 @@ std::shared_ptr<PointerType> return NewType; } +std::shared_ptr<ArrayType> + TypeManager::CreateArrayType(std::shared_ptr<Type> ElementType, + std::shared_ptr<ExprNode> start, + std::shared_ptr<ExprNode> end) { + llvm::Constant* StartValue = llvm::cast<llvm::Constant>(start->CodeGen()); + llvm::Constant* EndValue = llvm::cast<llvm::Constant>(end->CodeGen()); + std::shared_ptr<Type> IndexType = start->GetType(); + if (IndexType != end->GetType()) { + Log(LogLevel::PCC_ERROR, + "the start and end indices of an array type must be same " + "(start=%s, end=%s)", + IndexType->GetCommonName(), end->GetType()->GetCommonName()); + return nullptr; + } + if (std::dynamic_pointer_cast<IntegerBaseType>(IndexType) == nullptr) { + Log(LogLevel::PCC_ERROR, + "array index must have a integer-like type (i.e. integer, char)"); + return nullptr; + } + uint64_t StartIndex = StartValue->getUniqueInteger().getZExtValue(); + uint64_t ElementNumber = + EndValue->getUniqueInteger().getZExtValue() - StartIndex + 1; + std::shared_ptr<ArrayType> NewType = std::make_shared<ArrayType>( + ElementType, ElementNumber, IndexType, StartValue, EndValue, + std::string(ElementType->GetCommonName()) + "[]", StartIndex == 0); + ArrayTypes_.push_back(NewType); + return NewType; +} + std::shared_ptr<FunctionType> TypeManager::CreateFunctionType( std::shared_ptr<Type> ReturnType, std::vector<std::shared_ptr<Type>> ArgTypes) { |
