You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to implement a switch statement, we ran into the issue of not being able to pass basic blocks into the build_switch method as it requires a slice of (IntegerValue, &BasicBlocks) but we are building these blocks in a loop which will go out of scope, meaning we are not able to pass them as references.
It would seem natural to me that you would expect a BasicBlock in the method, and not a reference to it since it just a copied llvm-sys object anyway.
Could you give an example on how to implement such a build_switch?
Our code looks like this :
letmut cases = Vec::new();//generate a int_value and a BasicBlock for every case-bodyfor i in1..conditional_blocks.len(){let conditional_block = &conditional_blocks[i];let basic_block = self.context.append_basic_block(self.current_function?,"case");let condition = self.generate_statement(&*conditional_block.condition)?;
cases.push((condition.into_int_value(), basic_block));}let else_block = self.context.append_basic_block(self.current_function?,"else");self.builder.build_switch(
selector_statement.into_int_value(),&else_block,
cases.as_slice());// I cannot get this as [(IntegerValue, &BasicBlock)]
Inkwell Branch Used: [e.g. llvm8-0]
The text was updated successfully, but these errors were encountered:
I worked around the issue by mapping the vector like that :
let cases_values :Vec<_> = cases.iter().map(|(value,block)| (value.clone(), block )).collect();
But it somehow feels strange to have to remap my vector and do an extra loop.
I understand that we cannot simply pass the blocks into a build_xxx method since you might want to use them later, but they are small/cheap objects, maybe they should be copied instead of referenced? Or am I missing a bigger picture here?
While trying to implement a switch statement, we ran into the issue of not being able to pass basic blocks into the build_switch method as it requires a slice of (IntegerValue, &BasicBlocks) but we are building these blocks in a loop which will go out of scope, meaning we are not able to pass them as references.
It would seem natural to me that you would expect a BasicBlock in the method, and not a reference to it since it just a copied llvm-sys object anyway.
Could you give an example on how to implement such a build_switch?
Our code looks like this :
The text was updated successfully, but these errors were encountered: