diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-05-28 01:26:57 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-05-28 01:26:57 +0800 |
| commit | 5fc580a0fe1ef35f0706394ec9ebb2a088deb5e9 (patch) | |
| tree | 8ebc5bf451f73fee141372c18aaf7041fca09254 /TypeManager.cc | |
| parent | c84e212d0de5ff9f14ab14ac5143e56d2839ac82 (diff) | |
add if, while, repeat
fix function call
modify syntax
Diffstat (limited to 'TypeManager.cc')
| -rw-r--r-- | TypeManager.cc | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/TypeManager.cc b/TypeManager.cc index c721df8..d74f3f0 100644 --- a/TypeManager.cc +++ b/TypeManager.cc @@ -89,17 +89,18 @@ std::pair<std::shared_ptr<Type>, Value> std::dynamic_pointer_cast<RealType>(RightType); Value ConvertedLeft, ConvertedRight; std::shared_ptr<Type> CommonType; - if (LeftType != RightType) { + if (op == BinaryOperator::REAL_DIV) { + // we can only set the CommonType to real for REAL_DIV on builtin types, + // for other types, REAL_DIV and DIV are unavaliable. + CommonType = builtins_[ToUnderlying(BuiltinType::REAL)]; + op = BinaryOperator::DIV; + } else if (LeftType != RightType) { // we can cast the boolean, char, integer and real. - if (LeftRealType != nullptr && RightIntegerBaseType != nullptr) { - ConvertedLeft = left; - ConvertedRight = - builder->CreateSIToFP(right, LeftType->GetLLVMType()); + if (op == BinaryOperator::REAL_DIV) { + CommonType = builtins_[ToUnderlying(BuiltinType::REAL)]; + } else if (LeftRealType != nullptr && RightIntegerBaseType != nullptr) { CommonType = LeftType; } else if (RightRealType != nullptr && LeftIntegerBaseType != nullptr) { - ConvertedLeft = - builder->CreateSIToFP(left, RightType->GetLLVMType()); - ConvertedRight = right; CommonType = RightType; } else if (LeftIntegerBaseType != nullptr && RightIntegerBaseType != nullptr) { @@ -107,10 +108,6 @@ std::pair<std::shared_ptr<Type>, Value> RightIntegerBaseType->GetWidth() ? LeftType : RightType); - ConvertedLeft = - builder->CreateSExt(left, CommonType->GetLLVMType()); - ConvertedRight = - builder->CreateSExt(right, CommonType->GetLLVMType()); } else { Log(LogLevel::PCC_ERROR, "can not apply binary operator on two different type %s and %s", @@ -118,10 +115,10 @@ std::pair<std::shared_ptr<Type>, Value> return {nullptr, nullptr}; } } else { - ConvertedLeft = left; - ConvertedRight = right; CommonType = LeftType; } + ConvertedLeft = CreateCast(CommonType, LeftType, left, context); + ConvertedRight = CreateCast(CommonType, RightType, right, context); Value result = CommonType->CreateBinaryOperation(op, ConvertedLeft, ConvertedRight, context); if (result == nullptr) { |
