GithubHelp home page GithubHelp logo

llvm-d's Introduction

llvm-d

-Build Status

llvm-d provides bindings to LLVM for the D programming language.

It does so by automatically loading the LLVM dynamic library at program startup and binding to LLVM's C API functions.

This was forked from the llvm-d project, as the original has a few issues with the API and does not version its releases.

Usage

To use llvm-d you just need to import it and then you can use the functions defined by LLVM's C API. For example:

module samples.multithreaded;

import std.stdio;

import llvm.d.llvm_c;

void main(string[] args)
{
	LLVM.load();
	
	static if((LLVMDVersion(3, 3, 0) <= LLVM_Version) && (LLVM_Version < LLVMDVersion(3, 5, 0)))
	{
		writefln("LLVM multithreading on? %s", cast(bool) LLVMIsMultithreaded());
		writefln("Turning it on"); LLVMStartMultithreaded();
		writefln("LLVM multithreading on? %s", cast(bool) LLVMIsMultithreaded());
		writefln("Turning it off"); LLVMStopMultithreaded();
		writefln("LLVM multithreading on? %s", cast(bool) LLVMIsMultithreaded());
	}
}

Note that a static if is used to assure that the function calls are only compiled in if llvm-d is set to compile for at least the LLVM version that is needed (the multithreaded functions where added to LLVM's C API in the 3.3 development cycle and removed in the 3.5 development cycle; thus they are only available in versions 3.3 and 3.4).

A more complex example showing how to calculate the fibonacci series; see the samples/fibonacci.d file for an example.

LLVM versions

The LLVM version to be used is selected via version statements. For DMD, this is the -version argument; for dub, it is the "version" field.

The identifier to set the LLVM version is defined as LLVM_{MAJOR_VERSION}_{MINOR_VERSION}_{PATCH_VERSION}, so to get LLVM version 3.1.0 use LLVM_3_1_0.

Current supported versions are 3.1.0 - 3.7.1 and if no version is given at compile time, 3.7.1 will be assumed.

Documentation

llvm-d exposes C function pointers, constants, and types with the same names as LLVM's C API. See the LLVM Doxygen pages for a reference.

Changes from llvm-d

  • The LLVM library is no longer automatically loaded at startup; this causes issues when loading from paths other than the hardcoded one.
  • The LLVM library loading functions now throw exceptions on failure.
  • llvm.util.memory was removed; there are better options for what it contained in Phobos now.
  • Releases are tagged, so that clients do not need to use the deprecated "~master" version.
  • Patch-level versioning is supported; LLVM_Version is a ulong instead of a float

License

llvm-d is released under the MIT license, see LICENSE.txt.

llvm-d uses source code from LLVM that has been ported to D for accessing LLVM's C API. The above paragraph does not apply to that source code - it is a redistribution of LLVM source code.

LLVM is Copyright (c) 2003-2015 University of Illinois at Urbana-Champaign. All rights reserved.

LLVM is distributed under the University of Illinois Open Source License. See http://opensource.org/licenses/UoI-NCSA.php for details.

llvm-d's People

Contributors

1100110 avatar blm768 avatar buggins avatar colonelthirtytwo avatar moritzmaxeiner avatar

Watchers

 avatar  avatar

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.