Giter VIP home page Giter VIP logo

Comments (8)

TheDan64 avatar TheDan64 commented on May 23, 2024

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.

cdisselkoen avatar cdisselkoen commented on May 23, 2024

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.

TheDan64 avatar TheDan64 commented on May 23, 2024

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 BasicValues are far more useful/common than AnyValue so I tend to test additions to them first.

from inkwell.

thangnguyen-69 avatar thangnguyen-69 commented on May 23, 2024

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.

thangnguyen-69 avatar thangnguyen-69 commented on May 23, 2024

@TheDan64 I want to know if this fix in your codebase is legitimate?

from inkwell.

TheDan64 avatar TheDan64 commented on May 23, 2024

That might work, yea

from inkwell.

TheDan64 avatar TheDan64 commented on May 23, 2024

@hardcoresummer Do you plan to put up a PR for this change?

from inkwell.

thangnguyen-69 avatar thangnguyen-69 commented on May 23, 2024

from inkwell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.