Separate signed and unsigned comparisons correctly
This commit is contained in:
parent
e6a16ab667
commit
dab4d47b8e
@ -12,8 +12,8 @@ namespace types {
|
||||
auto bool_ty = std::shared_ptr<types::Type>{
|
||||
new types::FundamentalType{ types::FundamentalTypeKind::Bool } };
|
||||
|
||||
// Integer arithmetic binops
|
||||
for (auto& ty : { int_ty, char_ty, bool_ty }) {
|
||||
// Arithmetic binops
|
||||
definitions.push_back(BinopDefinition{
|
||||
ty, types::BinOp::Add, ty,
|
||||
ty, [](codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs) {
|
||||
@ -25,8 +25,10 @@ namespace types {
|
||||
ty, [](codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs) {
|
||||
return builder.builder->CreateSub(lhs, rhs, "sub");
|
||||
} });
|
||||
}
|
||||
|
||||
// Comparisons
|
||||
// Signed comparisons
|
||||
for (auto& ty : { int_ty }) {
|
||||
definitions.push_back(BinopDefinition{
|
||||
ty, types::BinOp::LessThan, ty,
|
||||
bool_ty, [](codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs) {
|
||||
@ -40,6 +42,21 @@ namespace types {
|
||||
} });
|
||||
}
|
||||
|
||||
// Unsigned comparisons
|
||||
for (auto& ty : { bool_ty, char_ty }) {
|
||||
definitions.push_back(BinopDefinition{
|
||||
ty, types::BinOp::LessThan, ty,
|
||||
bool_ty, [](codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs) {
|
||||
return builder.builder->CreateICmpULT(lhs, rhs, "icmpslt");
|
||||
} });
|
||||
|
||||
definitions.push_back(BinopDefinition{
|
||||
ty, types::BinOp::GreaterThan, ty,
|
||||
bool_ty, [](codegen::Builder& builder, llvm::Value* lhs, llvm::Value* rhs) {
|
||||
return builder.builder->CreateICmpUGT(lhs, rhs, "icmpsgt");
|
||||
} });
|
||||
}
|
||||
|
||||
return definitions;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user