Trying to debug this segfault
This commit is contained in:
parent
dd4816624c
commit
06a5de6e32
@ -3,5 +3,9 @@ fn hella(a, b) {
|
|||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn paha(x, y, z) {
|
||||||
|
x * y * z
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
2 + 8
|
2 + 8
|
||||||
|
@ -136,6 +136,10 @@ impl CodeGen for Function {
|
|||||||
for expr in body {
|
for expr in body {
|
||||||
ret = expr.codegen(data);
|
ret = expr.codegen(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get basic block of main
|
||||||
|
let main_bb = LLVMWrap::GetBasicBlocks(data.main_function).get(0).expect("Couldn't get first block of main").clone();
|
||||||
|
LLVMWrap::PositionBuilderAtEnd(data.builder, main_bb);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,9 +163,14 @@ impl CodeGen for Prototype {
|
|||||||
&*self.name,
|
&*self.name,
|
||||||
function_type);
|
function_type);
|
||||||
|
|
||||||
for (index, param) in LLVMWrap::GetParams(function).iter().enumerate() {
|
let function_params = LLVMWrap::GetParams(function);
|
||||||
|
println!("Params: {:?}", function_params);
|
||||||
|
for (index, param) in function_params.iter().enumerate() {
|
||||||
let name = self.parameters.get(index).expect(&format!("Failed this check at index {}", index));
|
let name = self.parameters.get(index).expect(&format!("Failed this check at index {}", index));
|
||||||
LLVMWrap::SetValueName(*param, name);
|
println!("Gonna set value name for : {}, value is {:?}", name, param);
|
||||||
|
let new = *param;
|
||||||
|
|
||||||
|
LLVMWrap::SetValueName(new, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function
|
function
|
||||||
@ -198,6 +207,7 @@ impl CodeGen for Expression {
|
|||||||
int_value
|
int_value
|
||||||
}
|
}
|
||||||
Conditional(ref test, ref then_expr, ref else_expr) => {
|
Conditional(ref test, ref then_expr, ref else_expr) => {
|
||||||
|
/*
|
||||||
let condition_value = test.codegen(data);
|
let condition_value = test.codegen(data);
|
||||||
let is_nonzero =
|
let is_nonzero =
|
||||||
LLVMWrap::BuildICmp(data.builder,
|
LLVMWrap::BuildICmp(data.builder,
|
||||||
@ -228,6 +238,8 @@ impl CodeGen for Expression {
|
|||||||
LLVMWrap::BuildBr(data.builder, merge_block);
|
LLVMWrap::BuildBr(data.builder, merge_block);
|
||||||
LLVMWrap::PositionBuilderAtEnd(data.builder, merge_block);
|
LLVMWrap::PositionBuilderAtEnd(data.builder, merge_block);
|
||||||
zero
|
zero
|
||||||
|
*/
|
||||||
|
unreachable!()
|
||||||
}
|
}
|
||||||
Block(ref exprs) => {
|
Block(ref exprs) => {
|
||||||
let mut ret = zero;
|
let mut ret = zero;
|
||||||
|
@ -178,6 +178,7 @@ pub fn AddIncoming(phi: LLVMValueRef, incoming_values: *mut LLVMValueRef, incomi
|
|||||||
|
|
||||||
pub fn SetValueName(value: LLVMValueRef, name: &str) {
|
pub fn SetValueName(value: LLVMValueRef, name: &str) {
|
||||||
let name = CString::new(name).unwrap();
|
let name = CString::new(name).unwrap();
|
||||||
|
println!("Value: {:?}", value);
|
||||||
unsafe {
|
unsafe {
|
||||||
core::LLVMSetValueName(value, name.as_ptr())
|
core::LLVMSetValueName(value, name.as_ptr())
|
||||||
}
|
}
|
||||||
@ -239,6 +240,20 @@ pub fn BuildICmp(builder: LLVMBuilderRef,
|
|||||||
unsafe { core::LLVMBuildICmp(builder, op, lhs, rhs, name.as_ptr()) }
|
unsafe { core::LLVMBuildICmp(builder, op, lhs, rhs, name.as_ptr()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn GetBasicBlocks(function: LLVMValueRef) -> Vec<LLVMBasicBlockRef> {
|
||||||
|
let size = CountBasicBlocks(function);
|
||||||
|
unsafe {
|
||||||
|
let mut container = Vec::with_capacity(size);
|
||||||
|
let p = container.as_mut_ptr();
|
||||||
|
core::LLVMGetBasicBlocks(function, p);
|
||||||
|
Vec::from_raw_parts(p, size, size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn CountBasicBlocks(function: LLVMValueRef) -> usize {
|
||||||
|
unsafe { core::LLVMCountBasicBlocks(function) as usize }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn PrintModuleToFile(module: LLVMModuleRef, filename: &str) -> LLVMBool {
|
pub fn PrintModuleToFile(module: LLVMModuleRef, filename: &str) -> LLVMBool {
|
||||||
let out_file = CString::new(filename).unwrap();
|
let out_file = CString::new(filename).unwrap();
|
||||||
unsafe { core::LLVMPrintModuleToFile(module, out_file.as_ptr(), ptr::null_mut()) }
|
unsafe { core::LLVMPrintModuleToFile(module, out_file.as_ptr(), ptr::null_mut()) }
|
||||||
|
Loading…
Reference in New Issue
Block a user