Total Pageviews

Tuesday 30 August 2016

llgo是llvm的一个go前端

LLVM-based compiler for Go.
This project has moved to llvm.org. Any contributions or bug reports should be sent there. Please refer to thellgo readme for more information.
llgo is a Go frontend for LLVM, written in Go.
llgo is under active development. It compiles and passes most of the standard library test suite and a substantial portion of the gc test suite, but there are some corner cases that are known not to be handled correctly yet. Nevertheless it can compile modestly substantial programs (including itself; it is self hosting on x86-64 Linux).
Progress will be reported on the mailing list.

Installation

llgo requires:
Note that Ubuntu Precise is one Linux distribution which does not package a sufficiently new CMake or C++ toolchain.
If you built a newer GCC following the linked instructions above, you will need to set the following environment variables before proceeding:
export PATH=/path/to/gcc-inst/bin:$PATH
export LD_LIBRARY_PATH=/path/to/gcc-inst/lib64:$LD_LIBRARY_PATH
export CC=`which gcc`
export CXX=`which g++`
export LIBGO_CFLAGS=--gcc-toolchain=/path/to/gcc-inst
To build and install llgo:
# Ensure $GOPATH is set.
go get -d github.com/go-llvm/llgo/cmd/gllgo
$GOPATH/src/llvm.org/llvm/bindings/go/build.sh -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=host
cd $GOPATH/src/github.com/go-llvm/llgo
make install prefix=/path/to/prefix j=N  # where N is the number of cores on your machine.

Running

We install two binaries to $prefix/bin: llgo and llgo-go.
llgo is the compiler binary. It has a command line interface that is intended to be compatible to a large extent withgccgo.
llgo-go is a command line wrapper for go. It works like the regular go command except that it uses llgo to build.
from  https://github.com/go-llvm/llgo
---------------

LLVM bindings for the Go programming language 

GoLLVM

This project has moved to llvm.org. Any contributions or bug reports should be sent there. Please refer to the Go bindings readme for more information.
Build Status

Prerequisites

  • Go 1.2+.
  • CMake (to build LLVM).
The author has only built and tested with Linux, but there is no particular reason why GoLLVM should not work with other operating systems.

Building LLVM

The development version of GoLLVM is tied to a specific revision of LLVM SVN trunk. We also make releases which are synchronized with LLVM releases. Those releases are available in branches named vMN, where M is the major number of the LLVM release and N is the minor number.
The script update\_llvm.sh in this directory can be used to build the required revision of LLVM and prepare it to be used by GoLLVM. If you receive an error message from go build like this:
./analysis.go:4:84: fatal error: llvm-c/Analysis.h: No such file or directory
 #include <llvm-c/Analysis.h> // If you are getting an error here read README.md
or like this:
./llvm_dep.go:5: undefined: run_update_llvm_sh_to_get_revision_NNNNNN
it means that LLVM needs to be built or updated by running the script.
$ ./update_llvm.sh
Any command line arguments supplied to the script are passed to LLVM's CMake build system. A good set of arguments to use during development are:
$ ./update_llvm.sh -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD=host -DBUILD_SHARED_LIBS=ON
Note that CMake keeps a cache of build settings so once you have built LLVM there is no need to pass these arguments again after updating.
Alternatively, you can build LLVM yourself or use a version provided by your distribution, but you must then set the CGO_CFLAGS and CGO_LDFLAGS environment variables:
$ export CGO_CFLAGS=`llvm-config --cflags`
$ export CGO_LDFLAGS="`llvm-config --ldflags` -Wl,-L`llvm-config --libdir` -lLLVM-`llvm-config --version`"
$ go get -tags byollvm github.com/go-llvm/llvm
from