Skip to content

Commit

Permalink
llvm 17.0.2 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Oct 25, 2023
1 parent 1d8841d commit ab964ce
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NIMFLAGS=--debuginfo --linedir:on

NLVMFLAGS= --debuginfo --linedir:on

LLVM_MAJ=16
LLVM_MAJ=17
LLVM_MIN=0
LLVM_PAT=2

Expand Down
5 changes: 1 addition & 4 deletions llvm/llvm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import strformat

const
LLVMMaj = 16
LLVMMaj = 17
LLVMMin = 0
LLVMPat = 2
LLVMVersion* = fmt"{LLVMMaj}.{LLVMMin}.{LLVMPat}"
Expand Down Expand Up @@ -59,11 +59,9 @@ type
OpaqueBuilder{.pure, final.} = object
OpaqueModuleProvider{.pure, final.} = object
OpaquePassManager{.pure, final.} = object
OpaquePassRegistry{.pure, final.} = object
OpaqueUse{.pure, final.} = object
OpaqueDiagnosticInfo{.pure, final.} = object
OpaqueTargetMachine{.pure, final.} = object
OpaquePassManagerBuilder{.pure, final.} = object
OpaqueMetaData{.pure, final.} = object
OpaqueDIBuilder{.pure, final.} = object
target{.pure, final.} = object
Expand Down Expand Up @@ -143,7 +141,6 @@ include llvm/Linker
include llvm/Target
include llvm/TargetMachine
include llvm/Transforms/PassBuilder
include llvm/Transforms/PassManagerBuilder

include llvm/ExecutionEngine
include llvm/Orc
Expand Down
90 changes: 58 additions & 32 deletions llvm/llvm/Core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ type
##
## @}
##

proc initializeCore*(r: PassRegistryRef) {.importc: "LLVMInitializeCore",
dynlib: LLVMLib.}
## Deallocate and destroy all ManagedStatic variables.
## @see llvm::llvm_shutdown
## @see ManagedStatic
Expand Down Expand Up @@ -393,14 +390,6 @@ proc contextShouldDiscardValueNames*(c: ContextRef): Bool {.
proc contextSetDiscardValueNames*(c: ContextRef; `discard`: Bool) {.
importc: "LLVMContextSetDiscardValueNames", dynlib: LLVMLib.}
##
## Set whether the given context is in opaque pointer mode.
##
## @see LLVMContext::setOpaquePointers()
##

proc contextSetOpaquePointers*(c: ContextRef; opaquePointers: Bool) {.
importc: "LLVMContextSetOpaquePointers", dynlib: LLVMLib.}
##
## Destroy a context instance.
##
## This should be called for every call to LLVMContextCreate() or memory
Expand Down Expand Up @@ -1316,8 +1305,6 @@ proc isLiteralStruct*(structTy: TypeRef): Bool {.importc: "LLVMIsLiteralStruct",
##
## Obtain the element type of an array or vector type.
##
## This currently also works for pointer types, but this usage is deprecated.
##
## @see llvm::SequentialType::getElementType()
##

Expand Down Expand Up @@ -1345,22 +1332,47 @@ proc getNumContainedTypes*(tp: TypeRef): cuint {.
## The created type will exist in the context that its element type
## exists in.
##
## @deprecated LLVMArrayType is deprecated in favor of the API accurate
## LLVMArrayType2
## @see llvm::ArrayType::get()
##

proc arrayType*(elementType: TypeRef; elementCount: cuint): TypeRef {.
importc: "LLVMArrayType", dynlib: LLVMLib.}
##
## Create a fixed size array type that refers to a specific type.
##
## The created type will exist in the context that its element type
## exists in.
##
## @see llvm::ArrayType::get()
##

proc arrayType2*(elementType: TypeRef; elementCount: uint64): TypeRef {.
importc: "LLVMArrayType2", dynlib: LLVMLib.}
##
## Obtain the length of an array type.
##
## This only works on types that represent arrays.
##
## @deprecated LLVMGetArrayLength is deprecated in favor of the API accurate
## LLVMGetArrayLength2
## @see llvm::ArrayType::getNumElements()
##

proc getArrayLength*(arrayTy: TypeRef): cuint {.importc: "LLVMGetArrayLength",
dynlib: LLVMLib.}
##
## Obtain the length of an array type.
##
## This only works on types that represent arrays.
##
## @see llvm::ArrayType::getNumElements()
##

proc getArrayLength2*(arrayTy: TypeRef): uint64 {.
importc: "LLVMGetArrayLength2", dynlib: LLVMLib.}
##
## Create a pointer type that points to a defined type.
##
## The created type will exist in the context that its pointee type
Expand Down Expand Up @@ -1624,6 +1636,8 @@ template declare_Value_Cast*(name: untyped): untyped =
## !!!Ignored construct: [NewLine] LLVM_FOR_EACH_VALUE_SUBCLASS ( LLVM_DECLARE_VALUE_CAST ) LLVMValueRef LLVMIsAMDNode ( LLVMValueRef Val ) ;
## Error: did not expect [NewLine]!!!

proc isAValueAsMetadata*(val: ValueRef): ValueRef {.
importc: "LLVMIsAValueAsMetadata", dynlib: LLVMLib.}
proc isAMDString*(val: ValueRef): ValueRef {.importc: "LLVMIsAMDString",
dynlib: LLVMLib.}
## Deprecated: Use LLVMGetValueName2 instead.
Expand Down Expand Up @@ -1970,12 +1984,22 @@ proc constStruct*(constantVals: ptr ValueRef; count: cuint; packed: Bool): Value
##
## Create a ConstantArray from values.
##
## @deprecated LLVMConstArray is deprecated in favor of the API accurate
## LLVMConstArray2
## @see llvm::ConstantArray::get()
##

proc constArray*(elementTy: TypeRef; constantVals: ptr ValueRef; length: cuint): ValueRef {.
importc: "LLVMConstArray", dynlib: LLVMLib.}
##
## Create a ConstantArray from values.
##
## @see llvm::ConstantArray::get()
##

proc constArray2*(elementTy: TypeRef; constantVals: ptr ValueRef; length: uint64): ValueRef {.
importc: "LLVMConstArray2", dynlib: LLVMLib.}
##
## Create a non-anonymous ConstantStruct from values.
##
## @see llvm::ConstantStruct::get()
Expand Down Expand Up @@ -2117,9 +2141,6 @@ proc constIntCast*(constantVal: ValueRef; toType: TypeRef; isSigned: Bool): Valu
importc: "LLVMConstIntCast", dynlib: LLVMLib.}
proc constFPCast*(constantVal: ValueRef; toType: TypeRef): ValueRef {.
importc: "LLVMConstFPCast", dynlib: LLVMLib.}
proc constSelect*(constantCondition: ValueRef; constantIfTrue: ValueRef;
constantIfFalse: ValueRef): ValueRef {.
importc: "LLVMConstSelect", dynlib: LLVMLib.}
proc constExtractElement*(vectorConstant: ValueRef; indexConstant: ValueRef): ValueRef {.
importc: "LLVMConstExtractElement", dynlib: LLVMLib.}
proc constInsertElement*(vectorConstant: ValueRef;
Expand Down Expand Up @@ -2866,6 +2887,15 @@ proc getMDNodeNumOperands*(v: ValueRef): cuint {.

proc getMDNodeOperands*(v: ValueRef; dest: ptr ValueRef) {.
importc: "LLVMGetMDNodeOperands", dynlib: LLVMLib.}
##
## Replace an operand at a specific index in a llvm::MDNode value.
##
## @see llvm::MDNode::replaceOperandWith()
##

proc replaceMDNodeOperandWith*(v: ValueRef; index: cuint;
replacement: MetadataRef) {.
importc: "LLVMReplaceMDNodeOperandWith", dynlib: LLVMLib.}
## Deprecated: Use LLVMMDStringInContext2 instead.

proc mDStringInContext*(c: ContextRef; str: cstring; sLen: cuint): ValueRef {.
Expand Down Expand Up @@ -3918,6 +3948,16 @@ proc buildFNeg*(a1: BuilderRef; v: ValueRef; name: cstring): ValueRef {.
importc: "LLVMBuildFNeg", dynlib: LLVMLib.}
proc buildNot*(a1: BuilderRef; v: ValueRef; name: cstring): ValueRef {.
importc: "LLVMBuildNot", dynlib: LLVMLib.}
proc getNUW*(arithInst: ValueRef): Bool {.importc: "LLVMGetNUW", dynlib: LLVMLib.}
proc setNUW*(arithInst: ValueRef; hasNUW: Bool) {.importc: "LLVMSetNUW",
dynlib: LLVMLib.}
proc getNSW*(arithInst: ValueRef): Bool {.importc: "LLVMGetNSW", dynlib: LLVMLib.}
proc setNSW*(arithInst: ValueRef; hasNSW: Bool) {.importc: "LLVMSetNSW",
dynlib: LLVMLib.}
proc getExact*(divOrShrInst: ValueRef): Bool {.importc: "LLVMGetExact",
dynlib: LLVMLib.}
proc setExact*(divOrShrInst: ValueRef; isExact: Bool) {.importc: "LLVMSetExact",
dynlib: LLVMLib.}
## Memory

proc buildMalloc*(a1: BuilderRef; ty: TypeRef; name: cstring): ValueRef {.
Expand Down Expand Up @@ -4122,8 +4162,8 @@ proc getUndefMaskElem*(): cint {.importc: "LLVMGetUndefMaskElem",
## Get the mask value at position Elt in the mask of a ShuffleVector
## instruction.
##
## \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef
## at that position.
## \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is
## poison at that position.
##

proc getMaskValue*(shuffleVectorInst: ValueRef; elt: cuint): cint {.
Expand Down Expand Up @@ -4194,20 +4234,6 @@ proc disposeMemoryBuffer*(memBuf: MemoryBufferRef) {.
## @}
##
##
## @defgroup LLVMCCorePassRegistry Pass Registry
## @ingroup LLVMCCore
##
## @{
##
## Return the global pass registry, for use with initialization functions.
## @see llvm::PassRegistry::getPassRegistry

proc getGlobalPassRegistry*(): PassRegistryRef {.
importc: "LLVMGetGlobalPassRegistry", dynlib: LLVMLib.}
##
## @}
##
##
## @defgroup LLVMCCorePassManagers Pass Managers
## @ingroup LLVMCCore
##
Expand Down
9 changes: 8 additions & 1 deletion llvm/llvm/DebugInfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ type
DWARFSourceLanguageKotlin, DWARFSourceLanguageZig,
DWARFSourceLanguageCrystal, DWARFSourceLanguageC_plusPlus17,
DWARFSourceLanguageC_plusPlus20, DWARFSourceLanguageC17,
DWARFSourceLanguageFortran18, DWARFSourceLanguageAda2005, DWARFSourceLanguageAda2012, ## Vendor extensions:
DWARFSourceLanguageFortran18, DWARFSourceLanguageAda2005,
DWARFSourceLanguageAda2012, DWARFSourceLanguageMojo, ## Vendor extensions:
DWARFSourceLanguageMipsAssembler, DWARFSourceLanguageGOOGLE_RenderScript,
DWARFSourceLanguageBORLAND_Delphi

Expand Down Expand Up @@ -1125,6 +1126,12 @@ proc dIBuilderCreateGlobalVariableExpression*(builder: DIBuilderRef;
localToUnit: Bool; expr: MetadataRef; decl: MetadataRef; alignInBits: uint32): MetadataRef {.
importc: "LLVMDIBuilderCreateGlobalVariableExpression", dynlib: LLVMLib.}
##
## Get the dwarf::Tag of a DINode
##

proc getDINodeTag*(md: MetadataRef): uint16 {.importc: "LLVMGetDINodeTag",
dynlib: LLVMLib.}
##
## Retrieves the \c DIVariable associated with this global variable expression.
## \param GVE The global variable expression.
##
Expand Down
3 changes: 3 additions & 0 deletions llvm/llvm/Transforms/PassBuilder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ proc passBuilderOptionsSetCallGraphProfile*(options: PassBuilderOptionsRef;
proc passBuilderOptionsSetMergeFunctions*(options: PassBuilderOptionsRef;
mergeFunctions: Bool) {.importc: "LLVMPassBuilderOptionsSetMergeFunctions",
dynlib: LLVMLib.}
proc passBuilderOptionsSetInlinerThreshold*(options: PassBuilderOptionsRef;
threshold: cint) {.importc: "LLVMPassBuilderOptionsSetInlinerThreshold",
dynlib: LLVMLib.}
##
## Dispose of a heap-allocated PassBuilderOptions instance
##
Expand Down
70 changes: 0 additions & 70 deletions llvm/llvm/Transforms/PassManagerBuilder.nim

This file was deleted.

5 changes: 0 additions & 5 deletions llvm/llvm/Types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ type
type
PassManagerRef* = ptr OpaquePassManager

## @see llvm::PassRegistry

type
PassRegistryRef* = ptr OpaquePassRegistry

##
## Used to get the users and usees of a Value.
##
Expand Down
4 changes: 2 additions & 2 deletions llvm/rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
LLVM_INC=../ext/llvm-16.0.2.src/include
LLVM_INC=../ext/llvm-17.0.2.src/include

C2NIM="../../c2nim/c2nim"
C2NIMFLAGS="--nep1 --skipinclude --prefix:LLVM --dynlib:LLVMLib --def:LLVM_C_EXTERN_C_BEGIN= --def:LLVM_C_EXTERN_C_END= --stdints"

HEADERS="BitReader.h BitWriter.h Comdat.h Core.h Error.h ExecutionEngine.h DebugInfo.h IRReader.h Linker.h LLJIT.h OrcEE.h Orc.h Target.h TargetMachine.h Support.h Types.h Transforms/PassBuilder.h Transforms/PassManagerBuilder.h"
HEADERS="BitReader.h BitWriter.h Comdat.h Core.h Error.h ExecutionEngine.h DebugInfo.h IRReader.h Linker.h LLJIT.h OrcEE.h Orc.h Target.h TargetMachine.h Support.h Types.h Transforms/PassBuilder.h"

for a in $HEADERS; do
OUT="llvm/${a%.h}.nim"
Expand Down
2 changes: 2 additions & 0 deletions llvm/wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ extern "C" void LLVMNimSetMetadataGlobal(LLVMValueRef Global,
unwrap<GlobalObject>(Global)->setMetadata(KindID, N);
}

LLD_HAS_DRIVER(elf)
extern "C" bool LLVMNimLLDLinkElf(const char **args, size_t arg_count) {
ArrayRef<const char *> array_ref_args(args, arg_count);
return lld::elf::link(array_ref_args, llvm::outs(), llvm::errs(), false, false);
}

LLD_HAS_DRIVER(wasm)
extern "C" bool LLVMNimLLDLinkWasm(const char **args, size_t arg_count) {
ArrayRef<const char *> array_ref_args(args, arg_count);
return lld::wasm::link(array_ref_args, llvm::outs(), llvm::errs(), false, false);
Expand Down

0 comments on commit ab964ce

Please sign in to comment.