Code Monkey home page Code Monkey logo

Comments (3)

mewmew avatar mewmew commented on August 12, 2024

I understand that the library allows for the generation of LLVM IR. How can one programmatically compile the IR to machine code?

Hi @kant777!

Happy to see playing around with LLVM IR.

As you mentioned, the llir/llvm library only handles read/write/modify of LLVM IR. So to compile LLVM IR to machine code one would rely on external tools.

The official LLVM toolchain contains tools for both compilation of LLVM IR to machine code and linking of LLVM IR modules.

If you want to do this programmatically, the easiest way would be to simply use the os/exec Go package and invoke the official LLVM toolchain tools to compile the LLVM IR to machine code.

Potentially using a temporary output file for the LLVM IR. If you decide to use a temporary LLVM IR output file, ensure that the permissions are set in such a way that other users cannot modify its content, as otherwise the LLVM IR code could be changed before compilation (race condition) to inject potentially malicious code.

Let me know how it works out.

Happy coding!

Cheers,
Robin

from llvm.

kant777 avatar kant777 commented on August 12, 2024

@mewmew Got it. Also Do you plan to support latest llvm versions since its been a while now? if not, it makes me think I should probably use https://github.com/twitchyliquid64/golang-asm although I loose all the optimizations that comes with the llvm compiler.

from llvm.

mewmew avatar mewmew commented on August 12, 2024

@mewmew Got it. Also Do you plan to support latest llvm versions since its been a while now? if not, it makes me think I should probably use https://github.com/twitchyliquid64/golang-asm although I loose all the optimizations that comes with the llvm compiler.

Hi @kant777!

While we'd love to support the latest LLVM version, as this is a hobby project driven by open source enthusiasts, there are no immediate plans for it as it requires a large amount of dedicated time.

From time to time, we feel the urge to work on the project, and then update to the latest LLVM versions (as we've done in the past).

So, I'd say, if you need anything specific from the newer versions of LLVM, then use the official tools and bindings to the C library of LLVM. Also, look into the tinygo library with bindings for LLVM, https://pkg.go.dev/tinygo.org/x/go-llvm. They should also include the ability to directly target machine code which would suit your needs quite well.

Wish you all the best and happy coding!

Cheerful summer wishes.
Robin

from llvm.

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.