bool variant_compare_less(const variant& lhs, const type& lhs_type, const variant& rhs, const type& rhs_type) { if (lhs_type.is_arithmetic() && rhs_type.is_arithmetic()) { if (is_floating_point(lhs_type) || is_floating_point(rhs_type)) return (lhs.to_double() < rhs.to_double()); else return (lhs.to_int64() < rhs.to_int64()); } else { variant lhs_tmp; if (lhs.convert(rhs_type, lhs_tmp)) return lhs_tmp.compare_less(rhs); if (!lhs.is_nullptr() && rhs.is_nullptr()) return false; // as last try, do a string conversion bool ok1 = false; bool ok2 = false; auto ret = (lhs.to_string(&ok1) < rhs.to_string(&ok2)); if (ok1 && ok2) return ret; else return (lhs_type < rhs_type); } }
bool variant_compare_equal(const variant& lhs, const type& lhs_type, const variant& rhs, const type& rhs_type) { if (is_floating_point(lhs_type) || is_floating_point(rhs_type)) { return almost_equal(lhs.to_double(), rhs.to_double()); } else { return (lhs.to_int64() == rhs.to_int64()); } }
const void* LLVMCodeGenerator::visit(ASTCast* node) { if (node->original->is_constant) { // constant expression if (node->type->type() == SLTypeTypePointer) { return llvm::ConstantExpr::getPointerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type)); } return llvm::ConstantExpr::getIntegerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type), node->original->type->is_signed()); } auto rr_type = SLType::RemoveReference(node->original->type); if (node->type->type() == SLTypeTypePointer) { return _builder.CreatePointerCast(_dereferenced_value(node->original), _llvm_type(node->type)); } if (node->type->type() == SLTypeTypeBool && rr_type->type() == SLTypeTypePointer) { return _builder.CreateIsNotNull(_dereferenced_value(node->original)); } if (node->type->type() == SLTypeTypeBool && rr_type->is_integer()) { return _builder.CreateICmpNE(_dereferenced_value(node->original), llvm::ConstantInt::get(_llvm_type(rr_type), 0)); } if (node->type->type() == SLTypeTypeBool && rr_type->is_floating_point()) { return _builder.CreateFCmpONE(_dereferenced_value(node->original), llvm::ConstantFP::get(_llvm_type(rr_type), 0.0)); } return _builder.CreateIntCast(_dereferenced_value(node->original), _llvm_type(node->type), node->original->type->is_signed()); }
// is the instruction a candidate to be shared? bool BipartiteWeightedMatchingBinding::isInstructionSharable(Instruction *I, Allocation *alloc) { return (share_div(I) || share_rem(I) || share_mem(I) || is_floating_point(I) || share_dsp(I, alloc)); }
bool is_arithmetic( const type &type_ ) { return is_integral( type_ ) || is_floating_point( type_ ); }