Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit dd52ec40 authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Fixed bootstrap's codegen specs

parent 8aed50ec
No related merge requests found
...@@ -64,8 +64,21 @@ module Crystal ...@@ -64,8 +64,21 @@ module Crystal
puts "TODO: codegen #{node}" puts "TODO: codegen #{node}"
end end
def visit(node : IntLiteral) def visit(node : NumberLiteral)
@last = LLVM::Int32.from_i(node.value.to_i) case node.kind
when :i8, :u8
@last = LLVM::Int8.from_i(node.value.to_i)
when :i16, :u16
@last = LLVM::Int16.from_i(node.value.to_i)
when :i32, :u32
@last = LLVM::Int32.from_i(node.value.to_i)
when :i64, :u64
@last = LLVM::Int32.from_i(node.value.to_i64)
when :f32
@last = LLVM::Float.from_s(node.value)
when :f64
@last = LLVM::Double.from_s(node.value)
end
end end
def visit(node : BoolLiteral) def visit(node : BoolLiteral)
...@@ -75,15 +88,7 @@ module Crystal ...@@ -75,15 +88,7 @@ module Crystal
def visit(node : LongLiteral) def visit(node : LongLiteral)
@last = LLVM::Int64.from_i(node.value.to_i) @last = LLVM::Int64.from_i(node.value.to_i)
end end
def visit(node : FloatLiteral)
@last = LLVM::Float.from_s(node.value)
end
def visit(node : DoubleLiteral)
@last = LLVM::Double.from_s(node.value)
end
def visit(node : CharLiteral) def visit(node : CharLiteral)
@last = LLVM::Int8.from_i(node.value[0].ord) @last = LLVM::Int8.from_i(node.value[0].ord)
end end
......
...@@ -24,7 +24,7 @@ lib LibLLVM("LLVM-3.1") ...@@ -24,7 +24,7 @@ lib LibLLVM("LLVM-3.1")
fun int_type = LLVMIntType(bits : Int32) : TypeRef fun int_type = LLVMIntType(bits : Int32) : TypeRef
fun float_type = LLVMFloatType() : TypeRef fun float_type = LLVMFloatType() : TypeRef
fun double_type = LLVMDoubleType() : TypeRef fun double_type = LLVMDoubleType() : TypeRef
fun const_int = LLVMConstInt(int_type : TypeRef, value : Int32, sign_extend : Int32) : ValueRef fun const_int = LLVMConstInt(int_type : TypeRef, value : UInt64, sign_extend : Int32) : ValueRef
fun const_real_of_string = LLVMConstRealOfString(real_type : TypeRef, value : Char*) : ValueRef fun const_real_of_string = LLVMConstRealOfString(real_type : TypeRef, value : Char*) : ValueRef
fun create_jit_compiler_for_module = LLVMCreateJITCompilerForModule (jit : ExecutionEngineRef*, m : ModuleRef, opt_level : Int32, error : Char**) : Int32 fun create_jit_compiler_for_module = LLVMCreateJITCompilerForModule (jit : ExecutionEngineRef*, m : ModuleRef, opt_level : Int32, error : Char**) : Int32
fun run_function = LLVMRunFunction (ee : ExecutionEngineRef, f : ValueRef, num_args : Int32, args : Int32) : GenericValueRef fun run_function = LLVMRunFunction (ee : ExecutionEngineRef, f : ValueRef, num_args : Int32, args : Int32) : GenericValueRef
...@@ -142,7 +142,7 @@ module LLVM ...@@ -142,7 +142,7 @@ module LLVM
end end
def from_i(value) def from_i(value)
LibLLVM.const_int(@type, value, 0) LibLLVM.const_int(@type, value.to_u64, 0)
end end
end end
......
...@@ -22,10 +22,10 @@ describe "Code gen: primitives" do ...@@ -22,10 +22,10 @@ describe "Code gen: primitives" do
end end
it "codegens f32" do it "codegens f32" do
run("1; 2.5_f32").to_f32.should eq(2.5_f32) run("2.5_f32").to_f32.should eq(2.5_f32)
end end
it "codegens f64" do it "codegens f64" do
run("1; 2.5_f64").to_f64.should eq(2.5_f64) run("2.5_f64").to_f64.should eq(2.5_f64)
end end
end end
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment