Comments (8)
I'm not sure that there's anything we can do here as the enum variant is determined by LLVM not inkwell. I think it happens because functions sort of decay into pointers (or maybe inherit from pointers?).
re: your second question. I've only just started to add methods to the traits - but it takes time and writing tests to verify that the method works for all variants and doesn't cause any memory issues.
from inkwell.
Can you clarify this statement?
I've only just started to add methods to the traits - but it takes time and writing tests to verify that the method works for all variants and doesn't cause any memory issues.
For the LLVM functions listed here, the docs say pretty clearly that
Functions in this section work on all LLVMValueRef instances, regardless of their sub-type. They correspond to functions available on llvm::Value.
From this, it seems to me that those methods should be safe to apply to anything with the AnyValue
trait (or more specifically, the AsValueRef
trait). But I fully believe I could be naively missing something - is there a reason to believe that applying these methods to any AsValueRef
object would cause problems?
from inkwell.
I suppose I just meant I haven't had time to add tests to verify they work properly or as expected as a wrapper. Also, I think BasicValue
s are far more useful/common than AnyValue
so I tend to test additions to them first.
from inkwell.
I believe there is a workaround for this issue. It is true that the when a function is created in LLVM, its Type is casted into PointerType, but the ValueType stay the same. Hence we can use that ValueType to infer the function type, like what i do in this code.
pub(crate) unsafe fn new(value: LLVMValueRef) -> Self {
match LLVMGetTypeKind(LLVMTypeOf(value)) {
LLVMTypeKind::LLVMFloatTypeKind
| LLVMTypeKind::LLVMFP128TypeKind
| LLVMTypeKind::LLVMDoubleTypeKind
| LLVMTypeKind::LLVMHalfTypeKind
| LLVMTypeKind::LLVMX86_FP80TypeKind
| LLVMTypeKind::LLVMPPC_FP128TypeKind => AnyValueEnum::FloatValue(FloatValue::new(value)),
LLVMTypeKind::LLVMIntegerTypeKind => AnyValueEnum::IntValue(IntValue::new(value)),
LLVMTypeKind::LLVMStructTypeKind => AnyValueEnum::StructValue(StructValue::new(value)),
LLVMTypeKind::LLVMPointerTypeKind => {
match LLVMGetValueKind(value){
LLVMValueKind::LLVMFunctionValueKind => AnyValueEnum::FunctionValue(FunctionValue::new(value).unwrap()),
_ => AnyValueEnum::PointerValue(PointerValue::new(value)),
}
}
LLVMTypeKind::LLVMArrayTypeKind => AnyValueEnum::ArrayValue(ArrayValue::new(value)),
LLVMTypeKind::LLVMVectorTypeKind => AnyValueEnum::VectorValue(VectorValue::new(value)),
LLVMTypeKind::LLVMFunctionTypeKind => AnyValueEnum::FunctionValue(FunctionValue::new(value).unwrap()),
LLVMTypeKind::LLVMVoidTypeKind => {
if LLVMIsAInstruction(value).is_null() {
panic!("Void value isn't an instruction.");
}
AnyValueEnum::InstructionValue(InstructionValue::new(value))
},
LLVMTypeKind::LLVMMetadataTypeKind => panic!("Metadata values are not supported as AnyValue's."),
_ => panic!("The given type is not supported."),
}
}
from inkwell.
@TheDan64 I want to know if this fix in your codebase is legitimate?
from inkwell.
That might work, yea
from inkwell.
@hardcoresummer Do you plan to put up a PR for this change?
from inkwell.
from inkwell.
Related Issues (20)
- Couldn't compile HOT 5
- Unable to Access Context Dynamically in LLVMManager: Seeking Alternative Approach HOT 2
- `InstructionValue::new` is `pub(crate)` instead of `pub` HOT 2
- Segfaults when builder is called without setting its position first HOT 5
- Add llvm-sys linkage flags
- Question: How to use LLVM `type`? HOT 5
- More examples? HOT 6
- Question: Is there a way to get the BasicValueEnum from the name of the instruction. HOT 6
- Question: What does `get_insert_block` returns. HOT 2
- Question: How can I get all defined structures? HOT 2
- Question: How to get the size of a type during LLVM generation? HOT 4
- Add `typos` to CI
- Create new fine-grained enum for `build_cast` HOT 1
- How to link library to jit? HOT 2
- Support llvm 17 HOT 1
- Add support for `global_ctor` HOT 4
- Add support for `global_ctor` HOT 3
- ORC support HOT 1
- Const struct member access HOT 1
- Segfault when using `module.create_jit_execution_engine()` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inkwell.