moritzmaxeiner / llvm-d Goto Github PK
View Code? Open in Web Editor NEWD bindings for LLVM
License: MIT License
D bindings for LLVM
License: MIT License
There's no
LLVMLinkInMCJIT
LLVMLinkInInterpreter
functions(maybe others ?).
Hello,
When I clone this code and compile it, I get the following error:
LINK : fatal error LNK1104: cannot open file 'LLVM.lib'
Error: linker exited with status 1104
Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.
I use ldc2, version: 1.33.0-beta1.
For example on windows there's no way official way buiding llvm as a shared library.
I made some change to your example for a simple sum
function:
sum(10, 25) = 35
but it turns out
sum(10, 25) = 10
seems that the second parameter is not passed in when calling LLVMRunFunction.
Can you help me identify the issue? this code is almost identical to a C version code I found at https://github.com/paulsmith/getting-started-llvm-c-api, which works fine.
import std.stdio;
import std.string: toStringz, fromStringz;
import llvm;
void main()
{
LLVMInitializeNativeTarget();
LLVMInitializeNativeAsmPrinter();
LLVMInitializeNativeAsmParser();
auto _module = LLVMModuleCreateWithName("hello".toStringz());
auto f_args = [LLVMInt32Type(), LLVMInt32Type()];
auto f_ret = LLVMFunctionType(LLVMInt32Type(), f_args.ptr, 2, cast(LLVMBool) false);
auto f = LLVMAddFunction(_module, "sum", f_ret);
LLVMSetFunctionCallConv(f, LLVMCCallConv);
auto p1 = LLVMGetParam(f, 0);
auto p2 = LLVMGetParam(f, 1);
auto entry = LLVMAppendBasicBlock(f, "entry".toStringz());
auto builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(builder, entry);
//auto c = LLVMConstInt(LLVMInt32Type(), 3, cast(LLVMBool)false);
//auto tmp = LLVMBuildAdd(builder, p2, c, "tmp".toStringz());
auto tmp = LLVMBuildAdd(builder, p1, p2, "tmp".toStringz());
LLVMBuildRet(builder, tmp);
char* error;
LLVMVerifyModule(_module, LLVMAbortProcessAction, &error);
LLVMDisposeMessage(error);
LLVMExecutionEngineRef engine;
LLVMMCJITCompilerOptions options;
LLVMInitializeMCJITCompilerOptions(&options, options.sizeof);
error = null;
LLVMCreateMCJITCompilerForModule(&engine, _module, &options, options.sizeof, &error);
auto pass = LLVMCreatePassManager();
if (error) {
scope(exit) LLVMDisposeMessage(error);
writefln("%s", error.fromStringz());
}
// LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass);
LLVMAddConstantPropagationPass(pass);
LLVMAddInstructionCombiningPass(pass);
LLVMAddGVNPass(pass);
LLVMRunPassManager(pass, _module);
LLVMDumpModule(_module);
int x = 10;
int y = 25;
auto args = [
LLVMCreateGenericValueOfInt(LLVMInt32Type(), x, cast(LLVMBool)0),
LLVMCreateGenericValueOfInt(LLVMInt32Type(), y, cast(LLVMBool)0)
];
auto res = LLVMRunFunction(engine, f, 2, args.ptr);
writefln("sum(%d, %d) = %d", x, y, LLVMGenericValueToInt(res, 0));
LLVMDisposePassManager(pass);
LLVMDisposeBuilder(builder);
LLVMDisposeExecutionEngine(engine);
}
https://github.com/Calrama/llvm-d/blob/master/source/llvm/functions.d#LC1488 conflicts with the declaration two lines below it. That causes a build failure when compiled with ldc 1.1.0 and llvm >= 3.7.0.
The C API isn't currently configured to allow linking to recent LLVM releases (i.e. 3.7). I can add the new versions (at least in versions.d) and submit a pull request if you'd like.
C:\Users\knopp\AppData\Local\dub\packages\llvm-d-2.4.0\llvm-d\source\llvm\functions\load.d-mixin-126(126,20): Error: variable llvm.functions.load.core
conflicts with import llvm.functions.load.core at C:\Users\knopp\AppData\Local\dub\packages\llvm-d-2.4.0\llvm-d\source\llvm\functions\load.d(33,12)
C:\Users\knopp\AppData\Local\dub\packages\llvm-d-2.4.0\llvm-d\source\llvm\functions\load.d-mixin-126(126,12): Error: package core has no type.
Platform: Windows 7 x86_64
Compiler: dmd 2.063.2
Compiled as dub dependency:
Building configuration "application", build type debug
Running dmd (compile)...
C:\Users\NCrashed\AppData\Roaming\dub\packages\llvm-d-master\llvm\d\ir\derivedty
pes.d(275): Error: not a property this.getNumElements
C:\Users\NCrashed\AppData\Roaming\dub\packages\llvm-d-master\llvm\d\ir\globalval
ue.d(79): Error: not a property this.getVisibility
C:\Users\NCrashed\AppData\Roaming\dub\packages\llvm-d-master\llvm\d\ir\globalval
ue.d(82): Error: not a property this.getVisibility
C:\Users\NCrashed\AppData\Roaming\dub\packages\llvm-d-master\llvm\d\ir\globalval
ue.d(85): Error: not a property this.getVisibility
Error: Build command failed with exit code 1
There has been quite a few version releases since 7.0.0, and i'm getting missing symbol errors with LLVM 7.0.1 (which is in the arch linux repos)
Could llvm-d be updated to support newer LLVM releases?
Hi!
Are there any plans to support newer versions of LLVM? Specifically I'm hoping for v10.0.1, but even v9 would be great.
Hi Moritz,
I'd like to use your library to learn about LLVM and make a small language of my own. I tried llvm-d on dub but failed: the new dub system requires that a library needs to have a release tag.
Do you plan to update this library to make it work in the newest version of dub/dmd?
Hi!
Great job with this project! Is the binding complete? I've been trying to translate this line of code into D for about an hour now with no luck. Any ideas? Sorry for creating an issue, did not know where to ask for support.
Thanks for the work!
It looks like there's a small bug.
import llvm.all; //public imports llvm.d.llvm_c;
//which doesn't work as shown...
I feel like it should instead import llvm.c.all; since everything compiles nicely that way.
Thank you
Hello.
I have a problem with the load function - it just doesn't find libLLVM.so .
I even moved libLLVM.so to the project folder - nothing works.
llvm.functions.load.SharedLibException@../../.dub/packages/llvm-d-3.0.0/llvm-d/source/llvm/functions/load.d(112): Failed to load library libLLVM.so: libLLVM.so: cannot open shared object file: No such file or directory
----------------
../../.dub/packages/llvm-d-3.0.0/llvm-d/source/llvm/functions/load.d:58 ref llvm.functions.load.SharedLib llvm.functions.load.SharedLib.__ctor(immutable(char)[]) [0x55b5557f8caf]
/usr/include/dmd/druntime/import/core/internal/lifetime.d:38 ref core.internal.lifetime.emplaceRef!(llvm.functions.load.SharedLib, llvm.functions.load.SharedLib, immutable(char)[]).emplaceRef(ref llvm.functions.load.SharedLib, ref immutable(char)[]).S core.internal.lifetime.emplaceRef!(llvm.functions.load.SharedLib, llvm.functions.load.SharedLib, immutable(char)[]).emplaceRef(ref llvm.functions.load.SharedLib, ref immutable(char)[]).S.__ctor!().__ctor(ref immutable(char)[]) [0x55b5557f8b7b]
/usr/include/dmd/druntime/import/core/internal/lifetime.d:57 void core.internal.lifetime.emplaceRef!(llvm.functions.load.SharedLib, llvm.functions.load.SharedLib, immutable(char)[]).emplaceRef(ref llvm.functions.load.SharedLib, ref immutable(char)[]) [0x55b5557f8ac5]
/usr/include/dmd/druntime/import/core/lifetime.d:64 llvm.functions.load.SharedLib* core.lifetime.emplace!(llvm.functions.load.SharedLib, immutable(char)[]).emplace(llvm.functions.load.SharedLib*, ref immutable(char)[]) [0x55b5557f8a84]
/usr/include/dmd/phobos/std/typecons.d:6509 void std.typecons.RefCounted!(llvm.functions.load.SharedLib, 1).RefCounted.RefCountedStore.initialize!(immutable(char)[]).initialize(ref immutable(char)[]) [0x55b5557f8a18]
/usr/include/dmd/phobos/std/typecons.d:6609 ref std.typecons.RefCounted!(llvm.functions.load.SharedLib, 1).RefCounted std.typecons.RefCounted!(llvm.functions.load.SharedLib, 1).RefCounted.__ctor!(immutable(char)[]).__ctor(ref immutable(char)[]) [0x55b5557f89b7]
../../.dub/packages/llvm-d-3.0.0/llvm-d/source/llvm/functions/load.d:177 void llvm.functions.load.LLVM.load(immutable(char)[][]...) [0x55b5557f04a0]
source/app.d:110 _Dmain [0x55b55572feb1]
I'm getting the following build error whenever I run dub
or dub build
:
Error executing command build:
Invalid SemVer format: LLVM_3_6_2
My dub.json file:
{
"name": "project",
"description": "A minimal D application.",
"copyright": "Copyright © 2016, bennetleff",
"authors": ["bennetleff"],
"dependencies": {
"llvm-d": "~>1.0.0",
},
"version": "LLVM_3_6_2",
}
Am I specifying the LLVM version wrong?
I have to manually add lflags after libs in dub.json
"libs": ["LLVM"],
"lflags": ["-L/usr/lib/llvm-3.8/lib/"]
for it to compile.
In release mode the build freezes and over time uses more and more memory (over 2 GB before i stopped it). Is that normal?
The version on my system is simply libLLVM-3.3.so.1.
Maybe need some way to explicitly choose the name?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.