diff --git a/.github/workflows/go.yml b/.github/workflows/test.yml similarity index 94% rename from .github/workflows/go.yml rename to .github/workflows/test.yml index e12257c..133ee36 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/test.yml @@ -11,14 +11,13 @@ jobs: strategy: matrix: llvm: [14, 15, 16, 17, 18, 19] - go-version: [1.18.x, 1.21.x, 1.22.x] steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go-version }} + go-version: '1.22' #- name: Update Homebrew # if: matrix.llvm == 17 # needed as long as LLVM 17 is still fresh # run: brew update diff --git a/README.markdown b/README.markdown index abcb17a..2e93808 100644 --- a/README.markdown +++ b/README.markdown @@ -1,13 +1,5 @@ # Go bindings to system LLVM -[![Build Status](https://github.com/goplus/llvm/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/llvm/actions/workflows/go.yml) -[![Go Report Card](https://goreportcard.com/badge/github.com/goplus/llvm)](https://goreportcard.com/report/github.com/goplus/llvm) -[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/llvm.svg)](https://pkg.go.dev/github.com/goplus/llvm) - - This library provides bindings to a system-installed LLVM. Currently supported: @@ -24,7 +16,7 @@ to use LLVM 17. If you have a supported LLVM installation, you should be able to do a simple `go get`: - go get github.com/goplus/llvm + go get tinygo.org/x/go-llvm You can use build tags to select a LLVM version. For example, use `-tags=llvm15` to select LLVM 15. Setting a build tag for a LLVM version that is not supported will be ignored. diff --git a/backports.cpp b/backports.cpp index 3bb6797..89811c3 100644 --- a/backports.cpp +++ b/backports.cpp @@ -62,17 +62,3 @@ void LLVMGoDIBuilderInsertDbgValueRecordAtEnd( LLVMDIBuilderInsertDbgValueAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block); #endif } - -void LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd( - LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) { -#if LLVM_VERSION_MAJOR >= 19 - // Note: this returns a LLVMDbgRecordRef. Previously, InsertDeclareAtEnd would - // return a Declare. But since the type changed, and I'd like to keep the API - // consistent across LLVM versions, I decided to drop the return value. - LLVMDIBuilderInsertDeclareRecordAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block); -#else - // Old llvm.dbg.* API. - LLVMDIBuilderInsertDeclareAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block); -#endif -} \ No newline at end of file diff --git a/backports.h b/backports.h index 8b7805a..c25819d 100644 --- a/backports.h +++ b/backports.h @@ -14,10 +14,6 @@ void LLVMGoDIBuilderInsertDbgValueRecordAtEnd( LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block); -void LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd( - LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block); - #ifdef __cplusplus } #endif /* defined(__cplusplus) */ diff --git a/dibuilder.go b/dibuilder.go index cba645e..e5128cf 100644 --- a/dibuilder.go +++ b/dibuilder.go @@ -610,14 +610,6 @@ func (d *DIBuilder) CreateExpression(addr []uint64) Metadata { return Metadata{C: result} } -// InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the -// specified basic block for the given value and associated debug metadata. -func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) { - loc := C.LLVMDIBuilderCreateDebugLocation( - d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C) - C.LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C) -} - // InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the // specified basic block for the given value and associated debug metadata. func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) { diff --git a/go.mod b/go.mod index 19f86ac..81a0559 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/goplus/llvm +module tinygo.org/x/go-llvm go 1.14 diff --git a/llvm_config_windows_llvm20.go b/llvm_config_windows_llvm20.go deleted file mode 100644 index df63bfc..0000000 --- a/llvm_config_windows_llvm20.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !byollvm && windows && !llvm14 && !llvm15 && !llvm16 && !llvm17 && !llvm18 && !llvm19 - -package llvm - -// #cgo CPPFLAGS: -I/usr/include/llvm -I/usr/include/llvm-c -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -// #cgo CXXFLAGS: -std=c++17 -// #cgo LDFLAGS: -Lllvm-20 -lLLVM-20.dll -import "C" - -type run_build_sh int diff --git a/llvm_test.go b/llvm_test.go index ecd3c0a..1ee15e3 100644 --- a/llvm_test.go +++ b/llvm_test.go @@ -1,10 +1,8 @@ package llvm_test -import ( - "testing" +import "tinygo.org/x/go-llvm" - "github.com/goplus/llvm" -) +import "testing" // Dummy test function. // All it does is test whether we can use LLVM at all. diff --git a/z_llvmext.go b/z_llvmext.go deleted file mode 100644 index 8a6a56d..0000000 --- a/z_llvmext.go +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package llvm - -/* -#include "llvm-c/Core.h" -#include -*/ -import "C" -import ( - "runtime" - "unsafe" -) - -func (c Context) Finalize() { - runtime.SetFinalizer(c.C, func(c C.LLVMContextRef) { - Context{c}.Dispose() - }) -} - -func (m Module) Finalize() { - runtime.SetFinalizer(m.C, func(m C.LLVMModuleRef) { - Module{m}.Dispose() - }) -} - -func (b Builder) Finalize() { - runtime.SetFinalizer(b.C, func(b C.LLVMBuilderRef) { - Builder{b}.Dispose() - }) -} - -var ( - emptyCStr [1]C.char -) - -func CreateBinOp(b Builder, op Opcode, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildBinOp(b.C, C.LLVMOpcode(op), lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateNot(b Builder, v Value) (rv Value) { - rv.C = C.LLVMBuildNot(b.C, v.C, &emptyCStr[0]) - return -} - -func CreateNeg(b Builder, v Value) (rv Value) { - rv.C = C.LLVMBuildNeg(b.C, v.C, &emptyCStr[0]) - return -} - -func CreateFNeg(b Builder, v Value) (rv Value) { - rv.C = C.LLVMBuildFNeg(b.C, v.C, &emptyCStr[0]) - return -} - -func CreateShl(b Builder, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildShl(b.C, lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateLShr(b Builder, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildLShr(b.C, lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateAShr(b Builder, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildAShr(b.C, lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateAnd(b Builder, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildAnd(b.C, lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateXor(b Builder, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildXor(b.C, lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreatePHI(b Builder, t Type) (v Value) { - v.C = C.LLVMBuildPhi(b.C, t.C, &emptyCStr[0]) - return -} - -func CreateSelect(b Builder, ifv, thenv, elsev Value) (v Value) { - v.C = C.LLVMBuildSelect(b.C, ifv.C, thenv.C, elsev.C, &emptyCStr[0]) - return -} - -func CreateICmp(b Builder, op IntPredicate, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildICmp(b.C, C.LLVMIntPredicate(op), lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateFCmp(b Builder, op FloatPredicate, lhs, rhs Value) (v Value) { - v.C = C.LLVMBuildFCmp(b.C, C.LLVMRealPredicate(op), lhs.C, rhs.C, &emptyCStr[0]) - return -} - -func CreateBitCast(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildBitCast(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreateIntCast(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildIntCast(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreateTrunc(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildTrunc(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreateZExt(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildZExt(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateSExt(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildSExt(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateFPTrunc(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildFPTrunc(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateFPExt(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildFPExt(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreatePtrToInt(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildPtrToInt(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreateIntToPtr(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildIntToPtr(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreatePointerCast(b Builder, v Value, t Type) (r Value) { - r.C = C.LLVMBuildPointerCast(b.C, v.C, t.C, &emptyCStr[0]) - return -} - -func CreateFPToUI(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildFPToUI(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateFPToSI(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildFPToSI(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateUIToFP(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildUIToFP(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateSIToFP(b Builder, val Value, t Type) (v Value) { - v.C = C.LLVMBuildSIToFP(b.C, val.C, t.C, &emptyCStr[0]) - return -} - -func CreateAlloca(b Builder, t Type) (v Value) { - v.C = C.LLVMBuildAlloca(b.C, t.C, &emptyCStr[0]) - return -} - -func CreateArrayAlloca(b Builder, t Type, n Value) (v Value) { - v.C = C.LLVMBuildArrayAlloca(b.C, t.C, n.C, &emptyCStr[0]) - return -} - -func CreateGEP(b Builder, t Type, p Value, indices []Value) (v Value) { - ptr, nvals := llvmValueRefs(indices) - v.C = C.LLVMBuildGEP2(b.C, t.C, p.C, ptr, nvals, &emptyCStr[0]) - return -} - -func CreateInBoundsGEP(b Builder, t Type, p Value, indices []Value) (v Value) { - ptr, nvals := llvmValueRefs(indices) - v.C = C.LLVMBuildInBoundsGEP2(b.C, t.C, p.C, ptr, nvals, &emptyCStr[0]) - return -} - -func CreateStructGEP(b Builder, t Type, p Value, i int) (v Value) { - v.C = C.LLVMBuildStructGEP2(b.C, t.C, p.C, C.unsigned(i), &emptyCStr[0]) - return -} - -func CreateExtractValue(b Builder, agg Value, i int) (v Value) { - v.C = C.LLVMBuildExtractValue(b.C, agg.C, C.unsigned(i), &emptyCStr[0]) - return -} - -func CreateLoad(b Builder, t Type, p Value) (v Value) { - v.C = C.LLVMBuildLoad2(b.C, t.C, p.C, &emptyCStr[0]) - return -} - -func CreateCall(b Builder, t Type, fn Value, args []Value) (v Value) { - ptr, nvals := llvmValueRefs(args) - v.C = C.LLVMBuildCall2(b.C, t.C, fn.C, ptr, nvals, &emptyCStr[0]) - return -} - -func CreateGlobalStringPtr(b Builder, str string) (v Value) { - cstr := C.CString(str) - defer C.free(unsafe.Pointer(cstr)) - v.C = C.LLVMBuildGlobalStringPtr(b.C, cstr, &emptyCStr[0]) - return -}