From 0c7099771f5a86c041d3ce01699697fda88230c4 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 14 Jan 2017 02:52:52 -0800 Subject: [PATCH] Comparison operator working --- compile.schala | 8 +------- src/compilation.rs | 7 +++++-- src/llvm_wrap.rs | 12 +++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/compile.schala b/compile.schala index 183d747..89c351d 100644 --- a/compile.schala +++ b/compile.schala @@ -1,8 +1,2 @@ -a = 1 -if a { - a = 42 -} else { - a = 23 -} -a +8 < 2 diff --git a/src/compilation.rs b/src/compilation.rs index 22ef6c1..e32f1c5 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -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), } diff --git a/src/llvm_wrap.rs b/src/llvm_wrap.rs index 5ecf1b0..1619381 100644 --- a/src/llvm_wrap.rs +++ b/src/llvm_wrap.rs @@ -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,