by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Daniel Kolsoi
    @TheDan64
    hmm const_string does return a vector..
    Manos Pitsidianakis
    @epilys
    @TheDan64 thanks for your review comments. I think I fixed most if not all your suggestions. Can you tell me what should I do for the coverage check? Make a runnable test under the tests/ dir that generates actual IR with debug metadata?
    Hactar
    @HactarCE
    Should I .delete() all my FunctionValues after I'm done with them, or is dropping the Module sufficient?
    Daniel Kolsoi
    @TheDan64
    @HactarCE dropping should be sufficient
    @epilys Correct. Either a single test that tests everything (if that's much easier) or multiple that focus on specific portions of the new changes
    It's also important to write some tests where we fall validation due to invalid debug ir. This should improve confidence that those scenarios don't produce UB as memory corruption will likely crop up now or in the future
    Manos Pitsidianakis
    @epilys
    @TheDan64 thanks, I know what to do now. Debugging has a really big interface so I want to get this basic stuff out of the way first.
    Hactar
    @HactarCE

    I have a StructType that I want to get the size_of, so I called .size_of().unwrap() on that StructType and got this IntValue:

    IntValue { int_value: Value { name: "", address: 0x1a3e494d910, is_const: true, is_null: false, is_undef: false, llvm_value: "i64 mul nuw (i64 ptrtoint (i64* getelementptr (i64, i64* null, i32 1) to i64), i64 2)", llvm_type:  "i64" } }

    It says is_const: true, but when .get_zero_extended_constant() and .get_sign_extended_constant() both return None. Is there something else I should be doing to get the size of this struct?

    (I'm trying to allocate space for this struct and fill it with values from the calling Rust code using Vec<u8>, but I need to know how much space to allocate.)

    Daniel Kolsoi
    @TheDan64
    It might be because LLVM has const and constant which are two different things...
    IIRC constant is a compile time value
    You can check that with IntValue::is_constant_int
    I suppose we should probably update the IntValue debug to list both of those

    IntValue::is_const docs say:

    Constants includes values that are not known at compile time, for example the address of a function casted to an integer.

    IntValue::is_constant_int:

    ConstantInt only includes values that are known at compile time.

    LLVM is so confusing sometimes...
    Daniel Kolsoi
    @TheDan64
    So I assume if the extended constant methods are returning None then LLVM doesn't have a compile-time value to give you
    Either that or there's a bug somewhere
    Daniel Kolsoi
    @TheDan64
    I think const is more like an immutable runtime value (like the docs above say, an address of a function)
    Hactar
    @HactarCE
    Ah ok
    Hactar
    @HactarCE
    I found TargetData::get_store_size(), which I think does what I want. (https://stackoverflow.com/questions/14608250/how-can-i-find-the-size-of-a-type) Thanks!
    mloc
    @mloc
    is there any way to build a (const) GEP on an ArrayValue right now?
    or will that need an inkwell change
    urg. nevermind, again, got my head in a loop
    Sameer Rahmani
    @lxsameer
    hey folks, quick and silly question, is inkwell an active project ? how much of the LLVM api does it cover ?
    mloc
    @mloc
    is there a way to build an arbitrary intrinsic?
    specifically @llvm.pow.f32
    mloc
    @mloc
    is it acceptable to just add an fn with the correct name + types?
    there is LookupIntrinsicID + GetIntrinsicDeclaration but they don't seem necessary if you can do the overloading yourself
    (and it's not exposed by inkwell)
    Daniel Kolsoi
    @TheDan64
    @lxsameer it is indeed active. It covers most of the C API but there are still some gaps.
    @mloc I think you can add a fn with the right name and types so long as it's linked correctly. Newer versions of LLVM have a specific intrinsic getter method which we don't currently support (thanks for reminding me!)
    Sameer Rahmani
    @lxsameer
    @TheDan64 sorry to ask this silly question, but what's you plan for the future of this library ? basically i'm in doubt to use it or not because i'm afraid that this library might not get updates and fall behind llvm halfway through the project
    Daniel Kolsoi
    @TheDan64
    I definitely plan to continue maintaining inkwell and never just abandon it. I see the worst-case scenario (assuming I'm still alive lol) is that I don't have time to add new changes myself, but would still make time to review and accept changes from the community. There are a couple of companies using inkwell in production so they do occasionally submit PRs.
    The biggest blocker to inkwell 0.1.0 is rust-lang/cargo#2980 and there doesn't seem to be any resolution in sight but we do have / will have stopgap crates for specific llvm versions as they release. Adding support for a new LLVM version usually takes a bit of time and effort though
    Sameer Rahmani
    @lxsameer
    cool, thanks a mil
    DGriffin91
    @DGriffin91
    I'm considering using inkwell to implement a DSL compiler. Is there a way to bundle LLVM so the end user only needs to install the rust application I build, and not have to install LLVM separately? Is there an existing project that is already doing this that I could look at to see how they are doing it?
    Sameer Rahmani
    @lxsameer
    but as far as i know, you should be able to use llvm api to compile to the target code as well
    i might be wrong though
    DGriffin91
    @DGriffin91
    @lxsameer Thanks! I'll check it out.
    Daniel Kolsoi
    @TheDan64
    The problem with llvmenv is that it's no longer maintained and hard to use
    I managed to get it to install LLVM 7&8 but not 10...
    Huh, looks like the author released a new version in May. In any case, it was unmaintained and the author was unresponsive to issues for a long while. Hopefully that changes
    DGriffin91
    @DGriffin91
    @TheDan64 Good to know. Are there any other practical ways to accomplish this?
    Daniel Kolsoi
    @TheDan64
    Llvmenv might still be your best bet... LLVM is just a pain in general
    Daniel Kolsoi
    @TheDan64
    Aleksander Litynski
    @AleksLitynski
    Hello. I'm running into the simplest problem imaginable, and I can't get around it. I've spent several days reading about lifetimes and references counting, and it's still not clicking. How am I supposed to write code that does this - https://pastebin.com/yNJYQ2W8
    This breaks because line 10 borrows context, then line 13 returns the context, leaving create_builder with a broken reference. Most examples pass a 'context' into the new/create function so its address won't change when builder is allocated, but I'd really rather the user be able to call a single function to do all the setup for them.
    Ben Konz
    @benkonz

    Hi, I'm trying to create a simple executable with LLVM and Inkwell, but when I run my program, I get cannot execute binary file: Exec format error

    code:

        let context = Context::create();
        let module = context.create_module("brainfrick-rust");
        let builder = context.create_builder();
    
        let i32_type = context.i32_type();
        let i32_one = i32_type.const_int(10, false);
        let main_fn_type = i32_type.fn_type(&[], false);
    
        let main_fn_val = module.add_function("main", main_fn_type, None);
        let basic_block = context.append_basic_block(main_fn_val, "entry");
    
        builder.position_at_end(basic_block);
    
        builder.build_return(Some(&i32_one));
        Target::initialize_all(&InitializationConfig::default());
    
        let target_triple = TargetMachine::get_default_triple();
    
        let target = Target::from_triple(&target_triple).map_err(|e| format!("{:?}", e))?;
        let target_machine = target
            .create_target_machine(
                &target_triple,
                "generic",
                "",
                OptimizationLevel::Default,
                RelocMode::Default,
                CodeModel::Default,
            )
            .ok_or_else(|| "Unable to create target machine!".to_string())?;
    
        let output_filename = matches.value_of("output").unwrap();
        target_machine
            .write_to_file(&module, FileType::Object, output_filename.as_ref())
            .map_err(|e| format!("{:?}", e))?;
    anything I am leaving out?