Fix comparison predicates

This commit is contained in:
Sasha Koshka 2023-12-07 17:32:02 -05:00
parent c4df65d189
commit e55d87d378
2 changed files with 22 additions and 0 deletions

View File

@ -68,3 +68,23 @@ testString (test,
}
`)
}
func TestCompare (test *testing.T) {
testString (test,
`%Bool = type i8
define %Bool @main() {
0:
%1 = alloca i64
store i64 32, ptr %1
%2 = load i64, ptr %1
%3 = icmp sgt i64 %2, 1
ret i1 %3
}
`,
`
[main]:Bool = {
x:Int = 32
[> x 1]
}
`)
}

View File

@ -607,6 +607,7 @@ func (this *Block) NewFCmp (predicate FPredicate, x, y Value) *InstructionFCmp {
instruction.Token = "fcmp"
instruction.X = x
instruction.Y = y
instruction.Predicate = predicate
switch xType := x.Type().(type) {
case *TypeFloat:
instruction.Ty = &TypeInt { BitSize: 1 }
@ -879,6 +880,7 @@ func (this *Block) NewICmp (predicate IPredicate, x, y Value) *InstructionICmp {
instruction.Token = "icmp"
instruction.X = x
instruction.Y = y
instruction.Predicate = predicate
switch xType := x.Type().(type) {
case *TypeInt, *TypePointer:
instruction.Ty = &TypeInt { BitSize: 1 }