Comparison operator working

This commit is contained in:
greg 2017-01-14 02:52:52 -08:00
parent afec7e829c
commit 0c7099771f
3 changed files with 15 additions and 12 deletions

View File

@ -1,8 +1,2 @@
a = 1
if a {
a = 42
} else {
a = 23
}
a
8 < 2

View File

@ -162,12 +162,15 @@ impl CodeGen for Expression {
Div => simple_binop!(LLVMWrap::BuildUDiv, "divtemp"),
Mod => simple_binop!(LLVMWrap::BuildSRem, "remtemp"),
Less => {
let pred = LLVMWrap::BuildICmp(data.builder,
let pred: LLVMValueRef = LLVMWrap::BuildICmp(data.builder,
LLVMIntPredicate::LLVMIntULT,
lhs,
rhs,
"tmp");
LLVMWrap::BuildUIToFP(data.builder, pred, int_type, "temp")
LLVMWrap::BuildZExt(data.builder, pred, int_type, "temp")
// god damn it this was probably failing because of the int_type
// this assumes everything is a FP
//LLVMWrap::BuildUIToFP(data.builder, pred, int_type, "temp")
}
_ => panic!("Bad operator {:?}", op),
}

View File

@ -171,15 +171,21 @@ pub fn BuildFCmp(builder: LLVMBuilderRef,
unsafe { core::LLVMBuildFCmp(builder, op, lhs, rhs, name.as_ptr()) }
}
pub fn BuildZExt(builder: LLVMBuilderRef,
val: LLVMValueRef,
dest_type: LLVMTypeRef,
name: &str) -> LLVMValueRef {
let name = CString::new(name).unwrap();
unsafe { core::LLVMBuildZExt(builder, val, dest_type, name.as_ptr()) }
}
pub fn BuildUIToFP(builder: LLVMBuilderRef,
val: LLVMValueRef,
dest_type: LLVMTypeRef,
name: &str) -> LLVMValueRef {
let name = CString::new(name).unwrap();
unsafe { let p = name.as_ptr();
println!("Pointer {:?}", p);
core::LLVMBuildUIToFP(builder, val, dest_type, p) }
unsafe { core::LLVMBuildUIToFP(builder, val, dest_type, name.as_ptr()) }
}
pub fn BuildICmp(builder: LLVMBuilderRef,