Git Product home page Git Product logo

clang.jl's Introduction

Clang.jl

Clang.jl provides a Julia language wrapper for libclang: the stable, C-exported interface to (a subset of) the LLVM Clang compiler. The libclang API documentation provides background on the functionality available through libclang, and thus through the Julia wrapper. The Clang.jl repository also hosts related tools built on top of libclang functionality.

Getting Started

Installation requirements are listed down page.

Clang.jl Documentation

Example notebooks:

Usage Examples

Parsing C with Clang and Julia

C wrapper generator

Clang.jl includes a generator to create Julia wrappers for C libraries from a collection of header files. The following declarations are currently supported:

  • function: translated to Julia ccall, with full type translation

  • typedef: translated to Julia typealias to underlying intrinsic type

  • enum: translated to const value symbol

  • struct: partial struct support may be enabled by setting WrapContext.options.wrap_structs = true

    • note: struct support is limited to intrinsic types. Unsupported constructs presently include: nested structs and unions, as well as fixed-size arrays.

Please see the following repositories for examples of the wrapper driver scripts and generator output:

  • Sundials.jl: interface to the LLNL "SUite of Nonlinear and DIfferential/ALgebraic equation Solvers" package
  • libCURL.jl: wrapper of cURL

Installation

Prerequisites

libclang and libclang-dev (versions >= 3.1) are required. libclang may optionally be built by the Julia build system by setting BUILD_LLVM_CLANG=1 in julia/Make.user.

When using a distribution packaged version, note the latest version may only be available from an optional pre-release archive (e.g. Ubuntu PPA).

Install

To install using the Julia package manager, use: Pkg.add("Clang"). You can use an external LLVM/Clang to build Clang.jl by specifying a llvm-config:

ENV["LLVM_CONFIG"]="/usr/lib/llvm-3.3/bin/llvm-config"
Pkg.add("Clang")

Background Information

libclang wrapper status

The cindex.jl libclang wrapper encompasses most CXType, CXCursor, and C++ related functions. A small convenience API is provided for basic tasks related to index generation, and retrieval of cursor kind and type information.

All testing and development so far has been on Ubuntu 12.04.1 (64-bit)

cindex.jl Usage

using Clang.cindex

julia> topcu = cindex.parse("Index.h") # Parse Index.h, returning the root cursor
julia> topcl = children(topcu)
julia> topcl.size
595

julia> cu = topcl[350]
julia> cu_kind(cu) == CIndex.CurKind.FUNCTIONDECL
true
julia> name(topcl[350])
"clang_parseTranslationUnit(CXIndex, const char *, const char *const *, int, struct CXUnsavedFile *, unsigned int, unsigned int)"

See the examples/ and util/ folders for further usage scenarios. Clang.jl is partially self-generating, including parsing of the enums (util/genCIndex_h.jl)

There is a small convenience API exported by CIndex:

tu_init     # init and parse file to TranslationUnit
tu_cursor   # get top cursor from TranslationUnit
children    # gets CXCursor children; accessed by ref.
cu_kind     # CIndex.CurKind enum
ty_kind     # CIndex.TypKind enum
name        # get the DisplayName of a CXCursor
spelling    # get spelling of a CXCursor or CXType
cu_file     # file in which cursor was declared
is_function # CXCursor or CXType
is_null     # CXCursor

For documentation of wrapped CIndex functions, see:

http://clang.llvm.org/doxygen/group__CINDEX.html

For a nice introduction to some capabilities and limitations (fewer now) of the libclang API, see this post:

http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/

Implementation

Most libclang functions accept and return small structs by value. As Julia does not (yet) have full struct support, the current Clang.jl implementation includes a C++ wrapper. clang functions are wrapped by a C++ function that memcpys data to/from a Julia-owned memory array (passed by pointer)

see src/cindex_base.jl and deps/src/wrapclang.h for generated wrappers.

Some functions are manually wrapped for convenience and ease of implementation, or to provide a more Julia-friendly API.

see src/Clang.jl and deps/src/wrapclang.cpp

License

Clang.jl is licensed under the MIT license.

clang.jl's People

Contributors

amitmurthy avatar ihnorton avatar mlubin avatar simonster avatar timholy avatar vtjnash avatar

Watchers

 avatar  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.