Gnimuc / ClangCompiler.jl

Clang compiler infrastructure for Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClangCompiler

CI TagBot codecov

Still WIP...

Installation

Make sure you don't have LIBCLANGEX_INSTALL_PREFIX in your environment variable.

pkg> add https://github.com/Gnimuc/ClangCompiler.jl.git

Development(macOS and Linux)

  1. Build libclangex locally and set ENV["LIBCLANGEX_INSTALL_PREFIX"] to the install directory.
  2. Install and test the package by running:
pkg> dev https://github.com/Gnimuc/ClangCompiler.jl.git

pkg> test ClangCompiler

Examples

Decl Lookup

using ClangCompiler

# source file
src = joinpath(dirname(pathof(ClangCompiler)), "..", "examples", "sample.cpp")

# compilation flags
args = get_compiler_args()

cc = ClangCompiler.IncrementalIRGenerator(src, args)

decl_lookup = DeclFinder(cc.instance)

@assert decl_lookup(cc, "vector", "std::vector")

decl = get_decl(decl_lookup)
dump(decl)

# clean up
dispose(decl_lookup)
dispose(cc)

JIT (experimental)

The following example is only tested on macOS.

using ClangCompiler
using ClangCompiler.LLVM

# source file
src = joinpath(dirname(pathof(ClangCompiler)), "..", "examples", "sample.cpp")

# compilation flags
args = get_compiler_args()

# create JIT
jit = LLJIT(;tm=JITTargetMachine())

# generate LLVM IR
irgen = IRGenerator(src, args)

# compile and link
cc = CXCompiler(irgen, jit)
link_process_symbols(cc)
compile(cc)

# lookup and call the main function 
addr = lookup(jit, "main")
@eval main() = ccall($(pointer(addr)), Cint, ())

main()

# clean up
dispose(cc)

About

Clang compiler infrastructure for Julia

License:MIT License


Languages

Language:Julia 99.8%Language:C 0.1%Language:C++ 0.0%