[PATCH] Initial version of Go bindings.

Chandler Carruth chandlerc at gmail.com
Mon Oct 13 15:08:29 PDT 2014


First pass at the LLVM C++ and build system side.

================
Comment at: bindings/go/llvm/bitwriter.cpp:25
@@ +24,3 @@
+
+LLVMMemoryBufferRef gollvm_WriteBitcodeToMemoryBuffer(LLVMModuleRef M) {
+  std::string Data;
----------------
Is there any particular reason to not add this to the existing C APIs?

Also, if it remains, this file should be named with CamelCase. Probably as GoBitWriter or BitWriterBindings.

================
Comment at: bindings/go/llvm/dibuilder.cpp:18
@@ +17,3 @@
+#include "llvm/IR/DIBuilder.h"
+#include <iostream>
+
----------------
iostreams aren't used in LLVM

================
Comment at: bindings/go/llvm/dibuilder.h:10
@@ +9,3 @@
+//
+// This file defines C bindings for the DIBuilder class.
+//
----------------
This file too should be GoDIBuilderBindings.{h,cpp} or something CamelCased.

Do you think these should be Go-specific, or generic C APIs for bindings? I'm curious how you see this evolving over time.

================
Comment at: bindings/go/llvm/ir.h:24-26
@@ +23,5 @@
+
+void gollvm_AddFunctionAttr(LLVMValueRef Fn, uint64_t PA);
+uint64_t gollvm_GetFunctionAttr(LLVMValueRef Fn);
+void gollvm_RemoveFunctionAttr(LLVMValueRef Fn, uint64_t PA);
+
----------------
I really thought we already had the C APIs for this... If not, they make a lot of sense to just add.

================
Comment at: bindings/go/llvm/support.h:21-24
@@ +20,6 @@
+
+void gollvm_LoadLibraryPermanently(const char *Filename, char **ErrMsg);
+
+void gollvm_ParseCommandLineOptions(int argc, const char *const *argv,
+                                    const char *Overview);
+
----------------
These both seem moderately terrifying to expose in the Go bindings. Why were they needed?

================
Comment at: bindings/go/llvm/transforms_instrumentation.h:23-28
@@ +22,8 @@
+
+void gollvm_AddAddressSanitizerFunctionPass(LLVMPassManagerRef PM);
+void gollvm_AddAddressSanitizerModulePass(LLVMPassManagerRef PM);
+void gollvm_AddThreadSanitizerPass(LLVMPassManagerRef PM);
+void gollvm_AddMemorySanitizerPass(LLVMPassManagerRef PM);
+void gollvm_AddDataFlowSanitizerPass(LLVMPassManagerRef PM,
+                                     const char *ABIListFile);
+
----------------
I think it would be reasonable to add an 'Instrumentation.h' to llvm-c/Transforms with these in it.

================
Comment at: test/Bindings/Go/go.test:1
@@ +1,2 @@
+; RUN: cd %S/../../../bindings/go/llvm && env CGO_CPPFLAGS="$(llvm-config --cppflags)" CGO_CXXFLAGS=-std=c++11 CGO_LDFLAGS="$(llvm-config --ldflags --libs --system-libs $(../build.sh --print-components))" %go test -tags byollvm .
+
----------------
Ow.

Is there any way to factor some of this into the lit.local.cfg?

At the least split it into multiple lines with '\' to smash them together?

http://reviews.llvm.org/D5684






More information about the llvm-commits mailing list