core.go raw

   1  package llvmpure
   2  
   3  import (
   4  	"fmt"
   5  	"runtime"
   6  	"unsafe"
   7  
   8  	"github.com/ebitengine/purego"
   9  )
  10  
  11  // Function pointers resolved at init time.
  12  var (
  13  	// Context
  14  	symContextCreate  uintptr
  15  	symContextDispose uintptr
  16  	symGetGlobalCtx   uintptr
  17  	symGetMDKindIDCtx uintptr
  18  	symGetMDKindID    uintptr
  19  
  20  	// Attribute
  21  	symGetEnumAttrKindForName uintptr
  22  	symCreateEnumAttr         uintptr
  23  	symCreateTypeAttr         uintptr
  24  	symCreateStringAttr       uintptr
  25  	symGetEnumAttrKind        uintptr
  26  	symGetEnumAttrValue       uintptr
  27  	symGetStringAttrKind      uintptr
  28  	symGetStringAttrValue     uintptr
  29  
  30  	// Module
  31  	symModuleCreateWithNameInCtx uintptr
  32  	symDisposeModule             uintptr
  33  	symGetDataLayout             uintptr
  34  	symSetDataLayout             uintptr
  35  	symGetTarget                 uintptr
  36  	symSetTarget                 uintptr
  37  	symGetModuleContext          uintptr
  38  	symGetTypeByName             uintptr
  39  	symPrintModuleToString       uintptr
  40  	symDisposeMessage            uintptr
  41  	symSetModuleInlineAsm        uintptr
  42  	symDumpModule                uintptr
  43  
  44  	// Integer types
  45  	symInt1TypeInCtx  uintptr
  46  	symInt8TypeInCtx  uintptr
  47  	symInt16TypeInCtx uintptr
  48  	symInt32TypeInCtx uintptr
  49  	symInt64TypeInCtx uintptr
  50  	symIntTypeInCtx   uintptr
  51  	symGetIntTypeWidth uintptr
  52  
  53  	// Float types
  54  	symFloatTypeInCtx    uintptr
  55  	symDoubleTypeInCtx   uintptr
  56  	symX86FP80TypeInCtx  uintptr
  57  	symFP128TypeInCtx    uintptr
  58  	symPPCFP128TypeInCtx uintptr
  59  
  60  	// Function types
  61  	symFunctionType     uintptr
  62  	symIsFunctionVarArg uintptr
  63  	symGetReturnType    uintptr
  64  	symCountParamTypes  uintptr
  65  	symGetParamTypes    uintptr
  66  
  67  	// Struct types
  68  	symStructTypeInCtx         uintptr
  69  	symStructCreateNamed       uintptr
  70  	symGetStructName           uintptr
  71  	symStructSetBody           uintptr
  72  	symIsPackedStruct          uintptr
  73  	symCountStructElementTypes uintptr
  74  	symGetStructElementTypes   uintptr
  75  
  76  	// Sequence types
  77  	symArrayType             uintptr
  78  	symPointerType           uintptr
  79  	symVectorType            uintptr
  80  	symGetElementType        uintptr
  81  	symGetArrayLength        uintptr
  82  	symGetPointerAddressSpace uintptr
  83  	symGetVectorSize         uintptr
  84  	symGetNumContainedTypes  uintptr
  85  	symGetSubtypes           uintptr
  86  
  87  	// Other types
  88  	symVoidTypeInCtx  uintptr
  89  	symLabelTypeInCtx uintptr
  90  	symTokenTypeInCtx uintptr
  91  
  92  	// Type inspection
  93  	symGetTypeKind    uintptr
  94  	symGetTypeContext  uintptr
  95  
  96  	// Value operations
  97  	symTypeOf              uintptr
  98  	symGetValueName        uintptr
  99  	symSetValueName        uintptr
 100  	symDumpValue           uintptr
 101  	symReplaceAllUsesWith  uintptr
 102  	symHasMetadata         uintptr
 103  	symGetMetadata         uintptr
 104  	symPrintValueToString  uintptr
 105  
 106  	// Constant scalars
 107  	symConstInt          uintptr
 108  	symConstFloat        uintptr
 109  	symConstNull         uintptr
 110  	symConstAllOnes      uintptr
 111  	symGetUndef          uintptr
 112  	symConstPointerNull  uintptr
 113  	symIsConstant        uintptr
 114  	symIsNull            uintptr
 115  	symIsUndef           uintptr
 116  	symConstIntGetZExt   uintptr
 117  	symConstIntGetSExt   uintptr
 118  	symConstFloatGetDouble uintptr
 119  
 120  	// Constant expressions
 121  	symConstNeg          uintptr
 122  	symConstNSWNeg       uintptr
 123  	symConstNot          uintptr
 124  	symConstAdd          uintptr
 125  	symConstNSWAdd       uintptr
 126  	symConstSub          uintptr
 127  	symConstNSWSub       uintptr
 128  	symConstMul          uintptr
 129  	symConstNSWMul       uintptr
 130  	symConstXor          uintptr
 131  	symConstGEP2         uintptr
 132  	symConstInBoundsGEP2 uintptr
 133  	symConstTrunc        uintptr
 134  	symConstSExt         uintptr
 135  	symConstZExt         uintptr
 136  	symConstFPTrunc      uintptr
 137  	symConstFPExt        uintptr
 138  	symConstUIToFP       uintptr
 139  	symConstSIToFP       uintptr
 140  	symConstFPToUI       uintptr
 141  	symConstFPToSI       uintptr
 142  	symConstPtrToInt     uintptr
 143  	symConstIntToPtr     uintptr
 144  	symConstBitCast      uintptr
 145  	symConstICmp         uintptr
 146  	symConstFCmp         uintptr
 147  	symConstExtractValue uintptr
 148  	symConstInsertValue  uintptr
 149  
 150  	// Constant aggregates
 151  	symConstStringInCtx uintptr
 152  	symConstStructInCtx uintptr
 153  	symConstArray        uintptr
 154  	symConstNamedStruct  uintptr
 155  
 156  	// Global values
 157  	symGetLinkage     uintptr
 158  	symSetLinkage     uintptr
 159  	symGetSection     uintptr
 160  	symSetSection     uintptr
 161  	symGetVisibility  uintptr
 162  	symSetVisibility  uintptr
 163  	symGetAlignment   uintptr
 164  	symSetAlignment   uintptr
 165  
 166  	// Global variables
 167  	symAddGlobal           uintptr
 168  	symGetNamedGlobal      uintptr
 169  	symGetFirstGlobal      uintptr
 170  	symGetNextGlobal       uintptr
 171  	symGetInitializer      uintptr
 172  	symSetInitializer      uintptr
 173  	symIsGlobalConstant    uintptr
 174  	symSetGlobalConstant   uintptr
 175  	symSetThreadLocal      uintptr
 176  	symIsThreadLocal       uintptr
 177  	symSetExternallyInit   uintptr
 178  	symIsExternallyInit    uintptr
 179  	symDeleteGlobal        uintptr
 180  	symSetUnnamedAddr      uintptr
 181  	symGetUnnamedAddr      uintptr
 182  
 183  	// Functions
 184  	symAddFunction       uintptr
 185  	symGetNamedFunction  uintptr
 186  	symGetFirstFunction  uintptr
 187  	symGetNextFunction   uintptr
 188  	symDeleteFunction    uintptr
 189  	symCountParams       uintptr
 190  	symGetParams         uintptr
 191  	symGetParam          uintptr
 192  	symSetFunctionCallConv uintptr
 193  	symGetFunctionCallConv uintptr
 194  	symAddFuncAttr        uintptr
 195  	symGetEnumFuncAttr    uintptr
 196  	symRemoveEnumFuncAttr uintptr
 197  	symAddTargetDepFuncAttr uintptr
 198  
 199  	// Basic blocks
 200  	symAppendBasicBlockInCtx uintptr
 201  	symInsertBasicBlockInCtx uintptr
 202  	symGetBasicBlockParent   uintptr
 203  	symGetEntryBasicBlock    uintptr
 204  	symGetFirstBasicBlock    uintptr
 205  	symGetLastBasicBlock     uintptr
 206  	symGetNextBasicBlock     uintptr
 207  	symGetPreviousBasicBlock uintptr
 208  	symCountBasicBlocks      uintptr
 209  	symMoveBasicBlockAfter   uintptr
 210  	symMoveBasicBlockBefore  uintptr
 211  	symDeleteBasicBlock      uintptr
 212  	symBasicBlockAsValue     uintptr
 213  
 214  	// Instructions
 215  	symGetFirstInstruction  uintptr
 216  	symGetLastInstruction   uintptr
 217  	symGetNextInstruction   uintptr
 218  	symGetInstructionOpcode uintptr
 219  	symInstructionEraseFromParent uintptr
 220  	symGetInstructionParent uintptr
 221  	symIsATerminatorInst    uintptr
 222  
 223  	// Builder
 224  	symCreateBuilderInCtx     uintptr
 225  	symPositionBuilderAtEnd   uintptr
 226  	symPositionBuilderBefore  uintptr
 227  	symGetInsertBlock         uintptr
 228  	symDisposeBuilder         uintptr
 229  
 230  	// Builder - terminators
 231  	symBuildRetVoid    uintptr
 232  	symBuildRet        uintptr
 233  	symBuildBr         uintptr
 234  	symBuildCondBr     uintptr
 235  	symBuildSwitch     uintptr
 236  	symBuildUnreachable uintptr
 237  
 238  	// Builder - arithmetic
 239  	symBuildAdd     uintptr
 240  	symBuildNSWAdd  uintptr
 241  	symBuildNUWAdd  uintptr
 242  	symBuildFAdd    uintptr
 243  	symBuildSub     uintptr
 244  	symBuildNSWSub  uintptr
 245  	symBuildNUWSub  uintptr
 246  	symBuildFSub    uintptr
 247  	symBuildMul     uintptr
 248  	symBuildNSWMul  uintptr
 249  	symBuildNUWMul  uintptr
 250  	symBuildFMul    uintptr
 251  	symBuildUDiv    uintptr
 252  	symBuildSDiv    uintptr
 253  	symBuildExactSDiv uintptr
 254  	symBuildFDiv    uintptr
 255  	symBuildURem    uintptr
 256  	symBuildSRem    uintptr
 257  	symBuildFRem    uintptr
 258  	symBuildShl     uintptr
 259  	symBuildLShr    uintptr
 260  	symBuildAShr    uintptr
 261  	symBuildAnd     uintptr
 262  	symBuildOr      uintptr
 263  	symBuildXor     uintptr
 264  	symBuildNeg     uintptr
 265  	symBuildNSWNeg  uintptr
 266  	symBuildNot     uintptr
 267  	symBuildFNeg    uintptr
 268  
 269  	// Builder - memory
 270  	symBuildAlloca   uintptr
 271  	symBuildLoad2    uintptr
 272  	symBuildStore    uintptr
 273  	symBuildGEP2     uintptr
 274  	symBuildInBoundsGEP2 uintptr
 275  	symBuildStructGEP2   uintptr
 276  
 277  	// Builder - casts
 278  	symBuildTrunc        uintptr
 279  	symBuildZExt         uintptr
 280  	symBuildSExt         uintptr
 281  	symBuildFPToUI       uintptr
 282  	symBuildFPToSI       uintptr
 283  	symBuildUIToFP       uintptr
 284  	symBuildSIToFP       uintptr
 285  	symBuildFPTrunc      uintptr
 286  	symBuildFPExt        uintptr
 287  	symBuildPtrToInt     uintptr
 288  	symBuildIntToPtr     uintptr
 289  	symBuildBitCast      uintptr
 290  	symBuildPointerCast  uintptr
 291  
 292  	// Builder - comparisons
 293  	symBuildICmp uintptr
 294  	symBuildFCmp uintptr
 295  
 296  	// Builder - misc
 297  	symBuildPhi          uintptr
 298  	symBuildCall2        uintptr
 299  	symBuildSelect       uintptr
 300  	symBuildExtractValue uintptr
 301  	symBuildInsertValue  uintptr
 302  
 303  	// PHI
 304  	symAddIncoming uintptr
 305  
 306  	// Call site
 307  	symSetInstructionCallConv  uintptr
 308  	symGetInstructionCallConv  uintptr
 309  	symAddCallSiteAttribute    uintptr
 310  	symSetInstrParamAlignment  uintptr
 311  
 312  	// Metadata (glue functions)
 313  	symMDString2               uintptr
 314  	symMDNode2                 uintptr
 315  	symConstantAsMetadata      uintptr
 316  	symSetMetadata2            uintptr
 317  	symAddNamedMetadataOperand2 uintptr
 318  	symGlobalObjectAddMetadata uintptr
 319  
 320  	// Switch
 321  	symAddCase uintptr
 322  
 323  	// Landing pad
 324  	symBuildLandingPad uintptr
 325  	symSetCleanup      uintptr
 326  	symAddClause       uintptr
 327  
 328  	// Invoke
 329  	symBuildInvoke2 uintptr
 330  
 331  	// Resume
 332  	symBuildResume uintptr
 333  
 334  	// Atomics
 335  	symBuildFence     uintptr
 336  	symBuildAtomicRMW uintptr
 337  	symBuildAtomicCmpXchg uintptr
 338  	symSetOrdering    uintptr
 339  	symSetAtomicSingleThread uintptr
 340  
 341  	// Inline asm (glue)
 342  	symGoGetInlineAsm uintptr
 343  
 344  	// Debug location (glue)
 345  	symGoSetCurrentDebugLocation uintptr
 346  	symGoGetCurrentDebugLocation uintptr
 347  
 348  	// Module print/verify
 349  	symVerifyModule uintptr
 350  	symVerifyFunction uintptr
 351  
 352  	// Comdat
 353  	symGetOrInsertComdat     uintptr
 354  	symComdatSetSelectionKind uintptr
 355  	symSetComdat             uintptr
 356  
 357  	// Value type checks (IsA*)
 358  	symIsAAllocaInst  uintptr
 359  	symIsAConstant    uintptr
 360  	symIsAConstantInt uintptr
 361  	symIsAFunction    uintptr
 362  	symIsAGlobalValue uintptr
 363  	symIsAInstruction uintptr
 364  	symIsAPHINode     uintptr
 365  	symIsAUndefValue  uintptr
 366  
 367  	// Value misc
 368  	symIsDeclaration    uintptr
 369  	symGlobalGetValType uintptr
 370  	symGetLastParam     uintptr
 371  	symGetOperand       uintptr
 372  	symGetNumOperands   uintptr
 373  	symSetVolatile      uintptr
 374  	symInstructionRemoveFromParent uintptr
 375  	symInstructionGetDebugLoc     uintptr
 376  	symCountIncoming    uintptr
 377  	symGetIncomingValue uintptr
 378  	symGetIncomingBlock uintptr
 379  
 380  	// Builder misc
 381  	symInsertIntoBuilder uintptr
 382  	symBuildBinOp        uintptr
 383  
 384  	// Const misc
 385  	symConstPointerCast uintptr
 386  )
 387  
 388  func registerAll() {
 389  	registerTarget()
 390  	registerDIBuilder()
 391  
 392  	// Context
 393  	symContextCreate = mustSym(libLLVM, "LLVMContextCreate")
 394  	symContextDispose = mustSym(libLLVM, "LLVMContextDispose")
 395  	symGetGlobalCtx = mustSym(libLLVM, "LLVMGetGlobalContext")
 396  	symGetMDKindIDCtx = mustSym(libLLVM, "LLVMGetMDKindIDInContext")
 397  	symGetMDKindID = mustSym(libLLVM, "LLVMGetMDKindID")
 398  
 399  	// Attribute
 400  	symGetEnumAttrKindForName = mustSym(libLLVM, "LLVMGetEnumAttributeKindForName")
 401  	symCreateEnumAttr = mustSym(libLLVM, "LLVMCreateEnumAttribute")
 402  	symCreateTypeAttr = mustSym(libLLVM, "LLVMCreateTypeAttribute")
 403  	symCreateStringAttr = mustSym(libLLVM, "LLVMCreateStringAttribute")
 404  	symGetEnumAttrKind = mustSym(libLLVM, "LLVMGetEnumAttributeKind")
 405  	symGetEnumAttrValue = mustSym(libLLVM, "LLVMGetEnumAttributeValue")
 406  	symGetStringAttrKind = mustSym(libLLVM, "LLVMGetStringAttributeKind")
 407  	symGetStringAttrValue = mustSym(libLLVM, "LLVMGetStringAttributeValue")
 408  
 409  	// Module
 410  	symModuleCreateWithNameInCtx = mustSym(libLLVM, "LLVMModuleCreateWithNameInContext")
 411  	symDisposeModule = mustSym(libLLVM, "LLVMDisposeModule")
 412  	symGetDataLayout = mustSym(libLLVM, "LLVMGetDataLayout")
 413  	symSetDataLayout = mustSym(libLLVM, "LLVMSetDataLayout")
 414  	symGetTarget = mustSym(libLLVM, "LLVMGetTarget")
 415  	symSetTarget = mustSym(libLLVM, "LLVMSetTarget")
 416  	symGetModuleContext = mustSym(libLLVM, "LLVMGetModuleContext")
 417  	symGetTypeByName = mustSym(libLLVM, "LLVMGetTypeByName")
 418  	symPrintModuleToString = mustSym(libLLVM, "LLVMPrintModuleToString")
 419  	symDisposeMessage = mustSym(libLLVM, "LLVMDisposeMessage")
 420  	symSetModuleInlineAsm = mustSym(libLLVM, "LLVMSetModuleInlineAsm")
 421  	symDumpModule = mustSym(libLLVM, "LLVMDumpModule")
 422  
 423  	// Integer types
 424  	symInt1TypeInCtx = mustSym(libLLVM, "LLVMInt1TypeInContext")
 425  	symInt8TypeInCtx = mustSym(libLLVM, "LLVMInt8TypeInContext")
 426  	symInt16TypeInCtx = mustSym(libLLVM, "LLVMInt16TypeInContext")
 427  	symInt32TypeInCtx = mustSym(libLLVM, "LLVMInt32TypeInContext")
 428  	symInt64TypeInCtx = mustSym(libLLVM, "LLVMInt64TypeInContext")
 429  	symIntTypeInCtx = mustSym(libLLVM, "LLVMIntTypeInContext")
 430  	symGetIntTypeWidth = mustSym(libLLVM, "LLVMGetIntTypeWidth")
 431  
 432  	// Float types
 433  	symFloatTypeInCtx = mustSym(libLLVM, "LLVMFloatTypeInContext")
 434  	symDoubleTypeInCtx = mustSym(libLLVM, "LLVMDoubleTypeInContext")
 435  	symX86FP80TypeInCtx = mustSym(libLLVM, "LLVMX86FP80TypeInContext")
 436  	symFP128TypeInCtx = mustSym(libLLVM, "LLVMFP128TypeInContext")
 437  	symPPCFP128TypeInCtx = mustSym(libLLVM, "LLVMPPCFP128TypeInContext")
 438  
 439  	// Function types
 440  	symFunctionType = mustSym(libLLVM, "LLVMFunctionType")
 441  	symIsFunctionVarArg = mustSym(libLLVM, "LLVMIsFunctionVarArg")
 442  	symGetReturnType = mustSym(libLLVM, "LLVMGetReturnType")
 443  	symCountParamTypes = mustSym(libLLVM, "LLVMCountParamTypes")
 444  	symGetParamTypes = mustSym(libLLVM, "LLVMGetParamTypes")
 445  
 446  	// Struct types
 447  	symStructTypeInCtx = mustSym(libLLVM, "LLVMStructTypeInContext")
 448  	symStructCreateNamed = mustSym(libLLVM, "LLVMStructCreateNamed")
 449  	symGetStructName = mustSym(libLLVM, "LLVMGetStructName")
 450  	symStructSetBody = mustSym(libLLVM, "LLVMStructSetBody")
 451  	symIsPackedStruct = mustSym(libLLVM, "LLVMIsPackedStruct")
 452  	symCountStructElementTypes = mustSym(libLLVM, "LLVMCountStructElementTypes")
 453  	symGetStructElementTypes = mustSym(libLLVM, "LLVMGetStructElementTypes")
 454  
 455  	// Sequence types
 456  	symArrayType = mustSym(libLLVM, "LLVMArrayType")
 457  	symPointerType = mustSym(libLLVM, "LLVMPointerType")
 458  	symVectorType = mustSym(libLLVM, "LLVMVectorType")
 459  	symGetElementType = mustSym(libLLVM, "LLVMGetElementType")
 460  	symGetArrayLength = mustSym(libLLVM, "LLVMGetArrayLength")
 461  	symGetPointerAddressSpace = mustSym(libLLVM, "LLVMGetPointerAddressSpace")
 462  	symGetVectorSize = mustSym(libLLVM, "LLVMGetVectorSize")
 463  	symGetNumContainedTypes = mustSym(libLLVM, "LLVMGetNumContainedTypes")
 464  	symGetSubtypes = mustSym(libLLVM, "LLVMGetSubtypes")
 465  
 466  	// Other types
 467  	symVoidTypeInCtx = mustSym(libLLVM, "LLVMVoidTypeInContext")
 468  	symLabelTypeInCtx = mustSym(libLLVM, "LLVMLabelTypeInContext")
 469  	symTokenTypeInCtx = mustSym(libLLVM, "LLVMTokenTypeInContext")
 470  
 471  	// Type inspection
 472  	symGetTypeKind = mustSym(libLLVM, "LLVMGetTypeKind")
 473  	symGetTypeContext = mustSym(libLLVM, "LLVMGetTypeContext")
 474  
 475  	// Value operations
 476  	symTypeOf = mustSym(libLLVM, "LLVMTypeOf")
 477  	symGetValueName = mustSym(libLLVM, "LLVMGetValueName")
 478  	symSetValueName = mustSym(libLLVM, "LLVMSetValueName")
 479  	symDumpValue = mustSym(libLLVM, "LLVMDumpValue")
 480  	symReplaceAllUsesWith = mustSym(libLLVM, "LLVMReplaceAllUsesWith")
 481  	symHasMetadata = mustSym(libLLVM, "LLVMHasMetadata")
 482  	symGetMetadata = mustSym(libLLVM, "LLVMGetMetadata")
 483  	symPrintValueToString = mustSym(libLLVM, "LLVMPrintValueToString")
 484  
 485  	// Constant scalars
 486  	symConstInt = mustSym(libLLVM, "LLVMConstInt")
 487  	symConstFloat = mustSym(libLLVM, "LLVMConstReal")
 488  	symConstNull = mustSym(libLLVM, "LLVMConstNull")
 489  	symConstAllOnes = mustSym(libLLVM, "LLVMConstAllOnes")
 490  	symGetUndef = mustSym(libLLVM, "LLVMGetUndef")
 491  	symConstPointerNull = mustSym(libLLVM, "LLVMConstPointerNull")
 492  	symIsConstant = mustSym(libLLVM, "LLVMIsConstant")
 493  	symIsNull = mustSym(libLLVM, "LLVMIsNull")
 494  	symIsUndef = mustSym(libLLVM, "LLVMIsUndef")
 495  	symConstIntGetZExt = mustSym(libLLVM, "LLVMConstIntGetZExtValue")
 496  	symConstIntGetSExt = mustSym(libLLVM, "LLVMConstIntGetSExtValue")
 497  	symConstFloatGetDouble = mustSym(libLLVM, "LLVMConstRealGetDouble")
 498  
 499  	// Constant expressions
 500  	symConstNeg = mustSym(libLLVM, "LLVMConstNeg")
 501  	symConstNSWNeg = mustSym(libLLVM, "LLVMConstNSWNeg")
 502  	symConstNot = mustSym(libLLVM, "LLVMConstNot")
 503  	symConstAdd = mustSym(libLLVM, "LLVMConstAdd")
 504  	symConstNSWAdd = mustSym(libLLVM, "LLVMConstNSWAdd")
 505  	symConstSub = mustSym(libLLVM, "LLVMConstSub")
 506  	symConstNSWSub = mustSym(libLLVM, "LLVMConstNSWSub")
 507  	symConstMul = mustSym(libLLVM, "LLVMConstMul")
 508  	symConstNSWMul = mustSym(libLLVM, "LLVMConstNSWMul")
 509  	symConstXor = mustSym(libLLVM, "LLVMConstXor")
 510  	symConstGEP2 = mustSym(libLLVM, "LLVMConstGEP2")
 511  	symConstInBoundsGEP2 = mustSym(libLLVM, "LLVMConstInBoundsGEP2")
 512  	symConstTrunc = mustSym(libLLVM, "LLVMConstTrunc")
 513  	symConstSExt = trySym(libLLVM, "LLVMConstSExt")
 514  	symConstZExt = trySym(libLLVM, "LLVMConstZExt")
 515  	symConstFPTrunc = trySym(libLLVM, "LLVMConstFPTrunc")
 516  	symConstFPExt = trySym(libLLVM, "LLVMConstFPExt")
 517  	symConstUIToFP = trySym(libLLVM, "LLVMConstUIToFP")
 518  	symConstSIToFP = trySym(libLLVM, "LLVMConstSIToFP")
 519  	symConstFPToUI = trySym(libLLVM, "LLVMConstFPToUI")
 520  	symConstFPToSI = trySym(libLLVM, "LLVMConstFPToSI")
 521  	symConstPtrToInt = mustSym(libLLVM, "LLVMConstPtrToInt")
 522  	symConstIntToPtr = mustSym(libLLVM, "LLVMConstIntToPtr")
 523  	symConstBitCast = mustSym(libLLVM, "LLVMConstBitCast")
 524  	symConstICmp = trySym(libLLVM, "LLVMConstICmp")
 525  	symConstFCmp = trySym(libLLVM, "LLVMConstFCmp")
 526  	symConstExtractValue = trySym(libLLVM, "LLVMConstExtractValue")
 527  	symConstInsertValue = trySym(libLLVM, "LLVMConstInsertValue")
 528  
 529  	// Constant aggregates
 530  	symConstStringInCtx = mustSym(libLLVM, "LLVMConstStringInContext")
 531  	symConstStructInCtx = mustSym(libLLVM, "LLVMConstStructInContext")
 532  	symConstArray = mustSym(libLLVM, "LLVMConstArray")
 533  	symConstNamedStruct = mustSym(libLLVM, "LLVMConstNamedStruct")
 534  
 535  	// Global values
 536  	symGetLinkage = mustSym(libLLVM, "LLVMGetLinkage")
 537  	symSetLinkage = mustSym(libLLVM, "LLVMSetLinkage")
 538  	symGetSection = mustSym(libLLVM, "LLVMGetSection")
 539  	symSetSection = mustSym(libLLVM, "LLVMSetSection")
 540  	symGetVisibility = mustSym(libLLVM, "LLVMGetVisibility")
 541  	symSetVisibility = mustSym(libLLVM, "LLVMSetVisibility")
 542  	symGetAlignment = mustSym(libLLVM, "LLVMGetAlignment")
 543  	symSetAlignment = mustSym(libLLVM, "LLVMSetAlignment")
 544  
 545  	// Global variables
 546  	symAddGlobal = mustSym(libLLVM, "LLVMAddGlobal")
 547  	symGetNamedGlobal = mustSym(libLLVM, "LLVMGetNamedGlobal")
 548  	symGetFirstGlobal = mustSym(libLLVM, "LLVMGetFirstGlobal")
 549  	symGetNextGlobal = mustSym(libLLVM, "LLVMGetNextGlobal")
 550  	symGetInitializer = mustSym(libLLVM, "LLVMGetInitializer")
 551  	symSetInitializer = mustSym(libLLVM, "LLVMSetInitializer")
 552  	symIsGlobalConstant = mustSym(libLLVM, "LLVMIsGlobalConstant")
 553  	symSetGlobalConstant = mustSym(libLLVM, "LLVMSetGlobalConstant")
 554  	symSetThreadLocal = mustSym(libLLVM, "LLVMSetThreadLocal")
 555  	symIsThreadLocal = mustSym(libLLVM, "LLVMIsThreadLocal")
 556  	symSetExternallyInit = mustSym(libLLVM, "LLVMSetExternallyInitialized")
 557  	symIsExternallyInit = mustSym(libLLVM, "LLVMIsExternallyInitialized")
 558  	symDeleteGlobal = mustSym(libLLVM, "LLVMDeleteGlobal")
 559  	symSetUnnamedAddr = mustSym(libLLVM, "LLVMSetUnnamedAddress")
 560  	symGetUnnamedAddr = mustSym(libLLVM, "LLVMGetUnnamedAddress")
 561  
 562  	// Functions
 563  	symAddFunction = mustSym(libLLVM, "LLVMAddFunction")
 564  	symGetNamedFunction = mustSym(libLLVM, "LLVMGetNamedFunction")
 565  	symGetFirstFunction = mustSym(libLLVM, "LLVMGetFirstFunction")
 566  	symGetNextFunction = mustSym(libLLVM, "LLVMGetNextFunction")
 567  	symDeleteFunction = mustSym(libLLVM, "LLVMDeleteFunction")
 568  	symCountParams = mustSym(libLLVM, "LLVMCountParams")
 569  	symGetParams = mustSym(libLLVM, "LLVMGetParams")
 570  	symGetParam = mustSym(libLLVM, "LLVMGetParam")
 571  	symSetFunctionCallConv = mustSym(libLLVM, "LLVMSetFunctionCallConv")
 572  	symGetFunctionCallConv = mustSym(libLLVM, "LLVMGetFunctionCallConv")
 573  	symAddFuncAttr = mustSym(libLLVM, "LLVMAddAttributeAtIndex")
 574  	symGetEnumFuncAttr = mustSym(libLLVM, "LLVMGetEnumAttributeAtIndex")
 575  	symRemoveEnumFuncAttr = mustSym(libLLVM, "LLVMRemoveEnumAttributeAtIndex")
 576  	symAddTargetDepFuncAttr = mustSym(libLLVM, "LLVMAddTargetDependentFunctionAttr")
 577  
 578  	// Basic blocks
 579  	symAppendBasicBlockInCtx = mustSym(libLLVM, "LLVMAppendBasicBlockInContext")
 580  	symInsertBasicBlockInCtx = mustSym(libLLVM, "LLVMInsertBasicBlockInContext")
 581  	symGetBasicBlockParent = mustSym(libLLVM, "LLVMGetBasicBlockParent")
 582  	symGetEntryBasicBlock = mustSym(libLLVM, "LLVMGetEntryBasicBlock")
 583  	symGetFirstBasicBlock = mustSym(libLLVM, "LLVMGetFirstBasicBlock")
 584  	symGetLastBasicBlock = mustSym(libLLVM, "LLVMGetLastBasicBlock")
 585  	symGetNextBasicBlock = mustSym(libLLVM, "LLVMGetNextBasicBlock")
 586  	symGetPreviousBasicBlock = mustSym(libLLVM, "LLVMGetPreviousBasicBlock")
 587  	symCountBasicBlocks = mustSym(libLLVM, "LLVMCountBasicBlocks")
 588  	symMoveBasicBlockAfter = mustSym(libLLVM, "LLVMMoveBasicBlockAfter")
 589  	symMoveBasicBlockBefore = mustSym(libLLVM, "LLVMMoveBasicBlockBefore")
 590  	symDeleteBasicBlock = mustSym(libLLVM, "LLVMDeleteBasicBlock")
 591  	symBasicBlockAsValue = mustSym(libLLVM, "LLVMBasicBlockAsValue")
 592  
 593  	// Instructions
 594  	symGetFirstInstruction = mustSym(libLLVM, "LLVMGetFirstInstruction")
 595  	symGetLastInstruction = mustSym(libLLVM, "LLVMGetLastInstruction")
 596  	symGetNextInstruction = mustSym(libLLVM, "LLVMGetNextInstruction")
 597  	symGetInstructionOpcode = mustSym(libLLVM, "LLVMGetInstructionOpcode")
 598  	symInstructionEraseFromParent = mustSym(libLLVM, "LLVMInstructionEraseFromParent")
 599  	symGetInstructionParent = mustSym(libLLVM, "LLVMGetInstructionParent")
 600  	symIsATerminatorInst = mustSym(libLLVM, "LLVMIsATerminatorInst")
 601  
 602  	// Builder
 603  	symCreateBuilderInCtx = mustSym(libLLVM, "LLVMCreateBuilderInContext")
 604  	symPositionBuilderAtEnd = mustSym(libLLVM, "LLVMPositionBuilderAtEnd")
 605  	symPositionBuilderBefore = mustSym(libLLVM, "LLVMPositionBuilder")
 606  	symGetInsertBlock = mustSym(libLLVM, "LLVMGetInsertBlock")
 607  	symDisposeBuilder = mustSym(libLLVM, "LLVMDisposeBuilder")
 608  
 609  	// Builder - terminators
 610  	symBuildRetVoid = mustSym(libLLVM, "LLVMBuildRetVoid")
 611  	symBuildRet = mustSym(libLLVM, "LLVMBuildRet")
 612  	symBuildBr = mustSym(libLLVM, "LLVMBuildBr")
 613  	symBuildCondBr = mustSym(libLLVM, "LLVMBuildCondBr")
 614  	symBuildSwitch = mustSym(libLLVM, "LLVMBuildSwitch")
 615  	symBuildUnreachable = mustSym(libLLVM, "LLVMBuildUnreachable")
 616  
 617  	// Builder - arithmetic
 618  	symBuildAdd = mustSym(libLLVM, "LLVMBuildAdd")
 619  	symBuildNSWAdd = mustSym(libLLVM, "LLVMBuildNSWAdd")
 620  	symBuildNUWAdd = mustSym(libLLVM, "LLVMBuildNUWAdd")
 621  	symBuildFAdd = mustSym(libLLVM, "LLVMBuildFAdd")
 622  	symBuildSub = mustSym(libLLVM, "LLVMBuildSub")
 623  	symBuildNSWSub = mustSym(libLLVM, "LLVMBuildNSWSub")
 624  	symBuildNUWSub = mustSym(libLLVM, "LLVMBuildNUWSub")
 625  	symBuildFSub = mustSym(libLLVM, "LLVMBuildFSub")
 626  	symBuildMul = mustSym(libLLVM, "LLVMBuildMul")
 627  	symBuildNSWMul = mustSym(libLLVM, "LLVMBuildNSWMul")
 628  	symBuildNUWMul = mustSym(libLLVM, "LLVMBuildNUWMul")
 629  	symBuildFMul = mustSym(libLLVM, "LLVMBuildFMul")
 630  	symBuildUDiv = mustSym(libLLVM, "LLVMBuildUDiv")
 631  	symBuildSDiv = mustSym(libLLVM, "LLVMBuildSDiv")
 632  	symBuildExactSDiv = mustSym(libLLVM, "LLVMBuildExactSDiv")
 633  	symBuildFDiv = mustSym(libLLVM, "LLVMBuildFDiv")
 634  	symBuildURem = mustSym(libLLVM, "LLVMBuildURem")
 635  	symBuildSRem = mustSym(libLLVM, "LLVMBuildSRem")
 636  	symBuildFRem = mustSym(libLLVM, "LLVMBuildFRem")
 637  	symBuildShl = mustSym(libLLVM, "LLVMBuildShl")
 638  	symBuildLShr = mustSym(libLLVM, "LLVMBuildLShr")
 639  	symBuildAShr = mustSym(libLLVM, "LLVMBuildAShr")
 640  	symBuildAnd = mustSym(libLLVM, "LLVMBuildAnd")
 641  	symBuildOr = mustSym(libLLVM, "LLVMBuildOr")
 642  	symBuildXor = mustSym(libLLVM, "LLVMBuildXor")
 643  	symBuildNeg = mustSym(libLLVM, "LLVMBuildNeg")
 644  	symBuildNSWNeg = mustSym(libLLVM, "LLVMBuildNSWNeg")
 645  	symBuildNot = mustSym(libLLVM, "LLVMBuildNot")
 646  	symBuildFNeg = mustSym(libLLVM, "LLVMBuildFNeg")
 647  
 648  	// Builder - memory
 649  	symBuildAlloca = mustSym(libLLVM, "LLVMBuildAlloca")
 650  	symBuildLoad2 = mustSym(libLLVM, "LLVMBuildLoad2")
 651  	symBuildStore = mustSym(libLLVM, "LLVMBuildStore")
 652  	symBuildGEP2 = mustSym(libLLVM, "LLVMBuildGEP2")
 653  	symBuildInBoundsGEP2 = mustSym(libLLVM, "LLVMBuildInBoundsGEP2")
 654  	symBuildStructGEP2 = mustSym(libLLVM, "LLVMBuildStructGEP2")
 655  
 656  	// Builder - casts
 657  	symBuildTrunc = mustSym(libLLVM, "LLVMBuildTrunc")
 658  	symBuildZExt = mustSym(libLLVM, "LLVMBuildZExt")
 659  	symBuildSExt = mustSym(libLLVM, "LLVMBuildSExt")
 660  	symBuildFPToUI = mustSym(libLLVM, "LLVMBuildFPToUI")
 661  	symBuildFPToSI = mustSym(libLLVM, "LLVMBuildFPToSI")
 662  	symBuildUIToFP = mustSym(libLLVM, "LLVMBuildUIToFP")
 663  	symBuildSIToFP = mustSym(libLLVM, "LLVMBuildSIToFP")
 664  	symBuildFPTrunc = mustSym(libLLVM, "LLVMBuildFPTrunc")
 665  	symBuildFPExt = mustSym(libLLVM, "LLVMBuildFPExt")
 666  	symBuildPtrToInt = mustSym(libLLVM, "LLVMBuildPtrToInt")
 667  	symBuildIntToPtr = mustSym(libLLVM, "LLVMBuildIntToPtr")
 668  	symBuildBitCast = mustSym(libLLVM, "LLVMBuildBitCast")
 669  	symBuildPointerCast = mustSym(libLLVM, "LLVMBuildPointerCast")
 670  
 671  	// Builder - comparisons
 672  	symBuildICmp = mustSym(libLLVM, "LLVMBuildICmp")
 673  	symBuildFCmp = mustSym(libLLVM, "LLVMBuildFCmp")
 674  
 675  	// Builder - misc
 676  	symBuildPhi = mustSym(libLLVM, "LLVMBuildPhi")
 677  	symBuildCall2 = mustSym(libLLVM, "LLVMBuildCall2")
 678  	symBuildSelect = mustSym(libLLVM, "LLVMBuildSelect")
 679  	symBuildExtractValue = mustSym(libLLVM, "LLVMBuildExtractValue")
 680  	symBuildInsertValue = mustSym(libLLVM, "LLVMBuildInsertValue")
 681  
 682  	// PHI
 683  	symAddIncoming = mustSym(libLLVM, "LLVMAddIncoming")
 684  
 685  	// Call site
 686  	symSetInstructionCallConv = mustSym(libLLVM, "LLVMSetInstructionCallConv")
 687  	symGetInstructionCallConv = mustSym(libLLVM, "LLVMGetInstructionCallConv")
 688  	symAddCallSiteAttribute = mustSym(libLLVM, "LLVMAddCallSiteAttribute")
 689  	symSetInstrParamAlignment = mustSym(libLLVM, "LLVMSetInstrParamAlignment")
 690  
 691  	// Switch
 692  	symAddCase = mustSym(libLLVM, "LLVMAddCase")
 693  
 694  	// Landing pad
 695  	symBuildLandingPad = mustSym(libLLVM, "LLVMBuildLandingPad")
 696  	symSetCleanup = mustSym(libLLVM, "LLVMSetCleanup")
 697  	symAddClause = mustSym(libLLVM, "LLVMAddClause")
 698  
 699  	// Invoke
 700  	symBuildInvoke2 = mustSym(libLLVM, "LLVMBuildInvoke2")
 701  
 702  	// Resume
 703  	symBuildResume = mustSym(libLLVM, "LLVMBuildResume")
 704  
 705  	// Atomics
 706  	symBuildFence = mustSym(libLLVM, "LLVMBuildFence")
 707  	symBuildAtomicRMW = mustSym(libLLVM, "LLVMBuildAtomicRMW")
 708  	symBuildAtomicCmpXchg = mustSym(libLLVM, "LLVMBuildAtomicCmpXchg")
 709  	symSetOrdering = mustSym(libLLVM, "LLVMSetOrdering")
 710  	symSetAtomicSingleThread = mustSym(libLLVM, "LLVMSetAtomicSingleThread")
 711  
 712  	// Module verify
 713  	symVerifyModule = mustSym(libLLVM, "LLVMVerifyModule")
 714  	symVerifyFunction = mustSym(libLLVM, "LLVMVerifyFunction")
 715  
 716  	// Comdat
 717  	symGetOrInsertComdat = mustSym(libLLVM, "LLVMGetOrInsertComdat")
 718  	symComdatSetSelectionKind = mustSym(libLLVM, "LLVMSetComdatSelectionKind")
 719  	symSetComdat = mustSym(libLLVM, "LLVMSetComdat")
 720  
 721  	// Value type checks
 722  	symIsAAllocaInst = mustSym(libLLVM, "LLVMIsAAllocaInst")
 723  	symIsAConstant = mustSym(libLLVM, "LLVMIsAConstant")
 724  	symIsAConstantInt = mustSym(libLLVM, "LLVMIsAConstantInt")
 725  	symIsAFunction = mustSym(libLLVM, "LLVMIsAFunction")
 726  	symIsAGlobalValue = mustSym(libLLVM, "LLVMIsAGlobalValue")
 727  	symIsAInstruction = mustSym(libLLVM, "LLVMIsAInstruction")
 728  	symIsAPHINode = mustSym(libLLVM, "LLVMIsAPHINode")
 729  	symIsAUndefValue = mustSym(libLLVM, "LLVMIsAUndefValue")
 730  
 731  	// Value misc
 732  	symIsDeclaration = mustSym(libLLVM, "LLVMIsDeclaration")
 733  	symGlobalGetValType = mustSym(libLLVM, "LLVMGlobalGetValueType")
 734  	symGetLastParam = mustSym(libLLVM, "LLVMGetLastParam")
 735  	symGetOperand = mustSym(libLLVM, "LLVMGetOperand")
 736  	symGetNumOperands = mustSym(libLLVM, "LLVMGetNumOperands")
 737  	symSetVolatile = mustSym(libLLVM, "LLVMSetVolatile")
 738  	symInstructionRemoveFromParent = mustSym(libLLVM, "LLVMInstructionRemoveFromParent")
 739  	symInstructionGetDebugLoc = mustSym(libLLVM, "LLVMInstructionGetDebugLoc")
 740  	symCountIncoming = mustSym(libLLVM, "LLVMCountIncoming")
 741  	symGetIncomingValue = mustSym(libLLVM, "LLVMGetIncomingValue")
 742  	symGetIncomingBlock = mustSym(libLLVM, "LLVMGetIncomingBlock")
 743  
 744  	// Builder misc
 745  	symInsertIntoBuilder = mustSym(libLLVM, "LLVMInsertIntoBuilder")
 746  	symBuildBinOp = mustSym(libLLVM, "LLVMBuildBinOp")
 747  
 748  	// Const misc
 749  	symConstPointerCast = trySym(libLLVM, "LLVMConstPointerCast")
 750  
 751  	// Glue functions (from libmoxie-llvm-glue.so)
 752  	if libGlue != 0 {
 753  		symMDString2 = mustSym(libGlue, "LLVMMDString2")
 754  		symMDNode2 = mustSym(libGlue, "LLVMMDNode2")
 755  		symConstantAsMetadata = mustSym(libGlue, "LLVMConstantAsMetadata")
 756  		symSetMetadata2 = mustSym(libGlue, "LLVMSetMetadata2")
 757  		symAddNamedMetadataOperand2 = mustSym(libGlue, "LLVMAddNamedMetadataOperand2")
 758  		symGlobalObjectAddMetadata = mustSym(libGlue, "LLVMGlobalObjectAddMetadata")
 759  		symGoGetInlineAsm = mustSym(libGlue, "LLVMGoGetInlineAsm")
 760  		symGoSetCurrentDebugLocation = mustSym(libGlue, "LLVMGoSetCurrentDebugLocation")
 761  		symGoGetCurrentDebugLocation = mustSym(libGlue, "LLVMGoGetCurrentDebugLocation")
 762  	}
 763  }
 764  
 765  // ---- Context ----
 766  
 767  func NewContext() Context {
 768  	r, _, _ := purego.SyscallN(symContextCreate)
 769  	return Context{r}
 770  }
 771  
 772  func GlobalContext() Context {
 773  	r, _, _ := purego.SyscallN(symGetGlobalCtx)
 774  	return Context{r}
 775  }
 776  
 777  func (c Context) Dispose() {
 778  	purego.SyscallN(symContextDispose, c.ref)
 779  }
 780  
 781  func (c Context) MDKindID(name string) int {
 782  	cname := cString(name)
 783  	r, _, _ := purego.SyscallN(symGetMDKindIDCtx, c.ref, cname, uintptr(len(name)))
 784  	runtime.KeepAlive(name)
 785  	return int(r)
 786  }
 787  
 788  func MDKindID(name string) int {
 789  	cname := cString(name)
 790  	r, _, _ := purego.SyscallN(symGetMDKindID, cname, uintptr(len(name)))
 791  	runtime.KeepAlive(name)
 792  	return int(r)
 793  }
 794  
 795  // ---- Attributes ----
 796  
 797  func AttributeKindID(name string) uint {
 798  	cname := cString(name)
 799  	r, _, _ := purego.SyscallN(symGetEnumAttrKindForName, cname, uintptr(len(name)))
 800  	runtime.KeepAlive(name)
 801  	return uint(r)
 802  }
 803  
 804  func (c Context) CreateEnumAttribute(kind uint, val uint64) Attribute {
 805  	r, _, _ := purego.SyscallN(symCreateEnumAttr, c.ref, uintptr(kind), uintptr(val))
 806  	return Attribute{r}
 807  }
 808  
 809  func (c Context) CreateTypeAttribute(kind uint, t Type) Attribute {
 810  	r, _, _ := purego.SyscallN(symCreateTypeAttr, c.ref, uintptr(kind), t.ref)
 811  	return Attribute{r}
 812  }
 813  
 814  func (c Context) CreateStringAttribute(kind string, val string) Attribute {
 815  	ckind := cString(kind)
 816  	cval := cString(val)
 817  	r, _, _ := purego.SyscallN(symCreateStringAttr, c.ref, ckind, uintptr(len(kind)), cval, uintptr(len(val)))
 818  	runtime.KeepAlive(kind)
 819  	runtime.KeepAlive(val)
 820  	return Attribute{r}
 821  }
 822  
 823  func (a Attribute) GetEnumKind() uint {
 824  	r, _, _ := purego.SyscallN(symGetEnumAttrKind, a.ref)
 825  	return uint(r)
 826  }
 827  
 828  func (a Attribute) GetEnumValue() uint64 {
 829  	r, _, _ := purego.SyscallN(symGetEnumAttrValue, a.ref)
 830  	return uint64(r)
 831  }
 832  
 833  func (a Attribute) GetStringKind() string {
 834  	var length uintptr
 835  	r, _, _ := purego.SyscallN(symGetStringAttrKind, a.ref, uintptr(unsafe.Pointer(&length)))
 836  	return goStringN(r, int(length))
 837  }
 838  
 839  func (a Attribute) GetStringValue() string {
 840  	var length uintptr
 841  	r, _, _ := purego.SyscallN(symGetStringAttrValue, a.ref, uintptr(unsafe.Pointer(&length)))
 842  	return goStringN(r, int(length))
 843  }
 844  
 845  func goStringN(ptr uintptr, n int) string {
 846  	if ptr == 0 || n == 0 {
 847  		return ""
 848  	}
 849  	return string(unsafe.Slice((*byte)(unsafe.Pointer(ptr)), n))
 850  }
 851  
 852  // ---- Module ----
 853  
 854  func (c Context) NewModule(name string) Module {
 855  	cname := cString(name)
 856  	r, _, _ := purego.SyscallN(symModuleCreateWithNameInCtx, cname, c.ref)
 857  	runtime.KeepAlive(name)
 858  	return Module{r}
 859  }
 860  
 861  func (m Module) Dispose() {
 862  	purego.SyscallN(symDisposeModule, m.ref)
 863  }
 864  
 865  func (m Module) DataLayout() string {
 866  	r, _, _ := purego.SyscallN(symGetDataLayout, m.ref)
 867  	return goString(r)
 868  }
 869  
 870  func (m Module) SetDataLayout(layout string) {
 871  	cl := cString(layout)
 872  	purego.SyscallN(symSetDataLayout, m.ref, cl)
 873  	runtime.KeepAlive(layout)
 874  }
 875  
 876  func (m Module) Target() string {
 877  	r, _, _ := purego.SyscallN(symGetTarget, m.ref)
 878  	return goString(r)
 879  }
 880  
 881  func (m Module) SetTarget(target string) {
 882  	ct := cString(target)
 883  	purego.SyscallN(symSetTarget, m.ref, ct)
 884  	runtime.KeepAlive(target)
 885  }
 886  
 887  func (m Module) Context() Context {
 888  	r, _, _ := purego.SyscallN(symGetModuleContext, m.ref)
 889  	return Context{r}
 890  }
 891  
 892  func (m Module) GetTypeByName(name string) Type {
 893  	cname := cString(name)
 894  	r, _, _ := purego.SyscallN(symGetTypeByName, m.ref, cname)
 895  	runtime.KeepAlive(name)
 896  	return Type{r}
 897  }
 898  
 899  func (m Module) String() string {
 900  	r, _, _ := purego.SyscallN(symPrintModuleToString, m.ref)
 901  	s := goString(r)
 902  	purego.SyscallN(symDisposeMessage, r)
 903  	return s
 904  }
 905  
 906  func (m Module) Dump() {
 907  	purego.SyscallN(symDumpModule, m.ref)
 908  }
 909  
 910  func (m Module) SetInlineAsm(asm string) {
 911  	casm := cString(asm)
 912  	purego.SyscallN(symSetModuleInlineAsm, m.ref, casm)
 913  	runtime.KeepAlive(asm)
 914  }
 915  
 916  func (m Module) AddNamedMetadataOperand(name string, operand Metadata) {
 917  	if symAddNamedMetadataOperand2 == 0 {
 918  		return
 919  	}
 920  	cname := cString(name)
 921  	purego.SyscallN(symAddNamedMetadataOperand2, m.ref, cname, operand.ref)
 922  	runtime.KeepAlive(name)
 923  }
 924  
 925  // ---- Type inspection ----
 926  
 927  func (t Type) TypeKind() TypeKind {
 928  	r, _, _ := purego.SyscallN(symGetTypeKind, t.ref)
 929  	return TypeKind(r)
 930  }
 931  
 932  func (t Type) Context() Context {
 933  	r, _, _ := purego.SyscallN(symGetTypeContext, t.ref)
 934  	return Context{r}
 935  }
 936  
 937  // ---- Integer types ----
 938  
 939  func (c Context) Int1Type() Type {
 940  	r, _, _ := purego.SyscallN(symInt1TypeInCtx, c.ref)
 941  	return Type{r}
 942  }
 943  
 944  func (c Context) Int8Type() Type {
 945  	r, _, _ := purego.SyscallN(symInt8TypeInCtx, c.ref)
 946  	return Type{r}
 947  }
 948  
 949  func (c Context) Int16Type() Type {
 950  	r, _, _ := purego.SyscallN(symInt16TypeInCtx, c.ref)
 951  	return Type{r}
 952  }
 953  
 954  func (c Context) Int32Type() Type {
 955  	r, _, _ := purego.SyscallN(symInt32TypeInCtx, c.ref)
 956  	return Type{r}
 957  }
 958  
 959  func (c Context) Int64Type() Type {
 960  	r, _, _ := purego.SyscallN(symInt64TypeInCtx, c.ref)
 961  	return Type{r}
 962  }
 963  
 964  func (c Context) IntType(numbits int) Type {
 965  	r, _, _ := purego.SyscallN(symIntTypeInCtx, c.ref, uintptr(numbits))
 966  	return Type{r}
 967  }
 968  
 969  func (t Type) IntTypeWidth() int {
 970  	r, _, _ := purego.SyscallN(symGetIntTypeWidth, t.ref)
 971  	return int(r)
 972  }
 973  
 974  // ---- Float types ----
 975  
 976  func (c Context) FloatType() Type {
 977  	r, _, _ := purego.SyscallN(symFloatTypeInCtx, c.ref)
 978  	return Type{r}
 979  }
 980  
 981  func (c Context) DoubleType() Type {
 982  	r, _, _ := purego.SyscallN(symDoubleTypeInCtx, c.ref)
 983  	return Type{r}
 984  }
 985  
 986  func (c Context) X86FP80Type() Type {
 987  	r, _, _ := purego.SyscallN(symX86FP80TypeInCtx, c.ref)
 988  	return Type{r}
 989  }
 990  
 991  func (c Context) FP128Type() Type {
 992  	r, _, _ := purego.SyscallN(symFP128TypeInCtx, c.ref)
 993  	return Type{r}
 994  }
 995  
 996  func (c Context) PPCFP128Type() Type {
 997  	r, _, _ := purego.SyscallN(symPPCFP128TypeInCtx, c.ref)
 998  	return Type{r}
 999  }
1000  
1001  // ---- Function types ----
1002  
1003  func FunctionType(returnType Type, paramTypes []Type, isVarArg bool) Type {
1004  	r, _, _ := purego.SyscallN(symFunctionType, returnType.ref, typeRefPtr(paramTypes), uintptr(len(paramTypes)), boolToInt(isVarArg))
1005  	return Type{r}
1006  }
1007  
1008  func (t Type) IsFunctionVarArg() bool {
1009  	r, _, _ := purego.SyscallN(symIsFunctionVarArg, t.ref)
1010  	return r != 0
1011  }
1012  
1013  func (t Type) ReturnType() Type {
1014  	r, _, _ := purego.SyscallN(symGetReturnType, t.ref)
1015  	return Type{r}
1016  }
1017  
1018  func (t Type) ParamTypesCount() int {
1019  	r, _, _ := purego.SyscallN(symCountParamTypes, t.ref)
1020  	return int(r)
1021  }
1022  
1023  func (t Type) ParamTypes() []Type {
1024  	count := t.ParamTypesCount()
1025  	if count == 0 {
1026  		return nil
1027  	}
1028  	out := make([]Type, count)
1029  	purego.SyscallN(symGetParamTypes, t.ref, uintptr(unsafe.Pointer(&out[0])))
1030  	return out
1031  }
1032  
1033  // ---- Struct types ----
1034  
1035  func (c Context) StructType(elementTypes []Type, packed bool) Type {
1036  	r, _, _ := purego.SyscallN(symStructTypeInCtx, c.ref, typeRefPtr(elementTypes), uintptr(len(elementTypes)), boolToInt(packed))
1037  	return Type{r}
1038  }
1039  
1040  func (c Context) StructCreateNamed(name string) Type {
1041  	cname := cString(name)
1042  	r, _, _ := purego.SyscallN(symStructCreateNamed, c.ref, cname)
1043  	runtime.KeepAlive(name)
1044  	return Type{r}
1045  }
1046  
1047  func (t Type) StructName() string {
1048  	r, _, _ := purego.SyscallN(symGetStructName, t.ref)
1049  	return goString(r)
1050  }
1051  
1052  func (t Type) StructSetBody(elementTypes []Type, packed bool) {
1053  	purego.SyscallN(symStructSetBody, t.ref, typeRefPtr(elementTypes), uintptr(len(elementTypes)), boolToInt(packed))
1054  }
1055  
1056  func (t Type) IsStructPacked() bool {
1057  	r, _, _ := purego.SyscallN(symIsPackedStruct, t.ref)
1058  	return r != 0
1059  }
1060  
1061  func (t Type) StructElementTypesCount() int {
1062  	r, _, _ := purego.SyscallN(symCountStructElementTypes, t.ref)
1063  	return int(r)
1064  }
1065  
1066  func (t Type) StructElementTypes() []Type {
1067  	count := t.StructElementTypesCount()
1068  	if count == 0 {
1069  		return nil
1070  	}
1071  	out := make([]Type, count)
1072  	purego.SyscallN(symGetStructElementTypes, t.ref, uintptr(unsafe.Pointer(&out[0])))
1073  	return out
1074  }
1075  
1076  // ---- Sequence types ----
1077  
1078  func ArrayType(elementType Type, elementCount int) Type {
1079  	r, _, _ := purego.SyscallN(symArrayType, elementType.ref, uintptr(elementCount))
1080  	return Type{r}
1081  }
1082  
1083  func PointerType(elementType Type, addressSpace int) Type {
1084  	r, _, _ := purego.SyscallN(symPointerType, elementType.ref, uintptr(addressSpace))
1085  	return Type{r}
1086  }
1087  
1088  func VectorType(elementType Type, elementCount int) Type {
1089  	r, _, _ := purego.SyscallN(symVectorType, elementType.ref, uintptr(elementCount))
1090  	return Type{r}
1091  }
1092  
1093  func (t Type) ElementType() Type {
1094  	r, _, _ := purego.SyscallN(symGetElementType, t.ref)
1095  	return Type{r}
1096  }
1097  
1098  func (t Type) ArrayLength() int {
1099  	r, _, _ := purego.SyscallN(symGetArrayLength, t.ref)
1100  	return int(r)
1101  }
1102  
1103  func (t Type) PointerAddressSpace() int {
1104  	r, _, _ := purego.SyscallN(symGetPointerAddressSpace, t.ref)
1105  	return int(r)
1106  }
1107  
1108  func (t Type) VectorSize() int {
1109  	r, _, _ := purego.SyscallN(symGetVectorSize, t.ref)
1110  	return int(r)
1111  }
1112  
1113  func (t Type) Subtypes() []Type {
1114  	n, _, _ := purego.SyscallN(symGetNumContainedTypes, t.ref)
1115  	if n == 0 {
1116  		return nil
1117  	}
1118  	out := make([]Type, int(n))
1119  	purego.SyscallN(symGetSubtypes, t.ref, uintptr(unsafe.Pointer(&out[0])))
1120  	return out
1121  }
1122  
1123  // ---- Other types ----
1124  
1125  func (c Context) VoidType() Type {
1126  	r, _, _ := purego.SyscallN(symVoidTypeInCtx, c.ref)
1127  	return Type{r}
1128  }
1129  
1130  func (c Context) LabelType() Type {
1131  	r, _, _ := purego.SyscallN(symLabelTypeInCtx, c.ref)
1132  	return Type{r}
1133  }
1134  
1135  func (c Context) TokenType() Type {
1136  	r, _, _ := purego.SyscallN(symTokenTypeInCtx, c.ref)
1137  	return Type{r}
1138  }
1139  
1140  // ---- Value operations ----
1141  
1142  func (v Value) Type() Type {
1143  	r, _, _ := purego.SyscallN(symTypeOf, v.ref)
1144  	return Type{r}
1145  }
1146  
1147  func (v Value) Name() string {
1148  	r, _, _ := purego.SyscallN(symGetValueName, v.ref)
1149  	return goString(r)
1150  }
1151  
1152  func (v Value) SetName(name string) {
1153  	cname := cString(name)
1154  	purego.SyscallN(symSetValueName, v.ref, cname)
1155  	runtime.KeepAlive(name)
1156  }
1157  
1158  func (v Value) Dump() {
1159  	purego.SyscallN(symDumpValue, v.ref)
1160  }
1161  
1162  func (v Value) ReplaceAllUsesWith(nv Value) {
1163  	purego.SyscallN(symReplaceAllUsesWith, v.ref, nv.ref)
1164  }
1165  
1166  func (v Value) HasMetadata() bool {
1167  	r, _, _ := purego.SyscallN(symHasMetadata, v.ref)
1168  	return r != 0
1169  }
1170  
1171  func (v Value) InstructionDebugLoc() Metadata {
1172  	r, _, _ := purego.SyscallN(symInstructionGetDebugLoc, v.ref)
1173  	return Metadata{r}
1174  }
1175  
1176  func (v Value) SetMetadata(kind int, node Metadata) {
1177  	if symSetMetadata2 == 0 {
1178  		return
1179  	}
1180  	purego.SyscallN(symSetMetadata2, v.ref, uintptr(kind), node.ref)
1181  }
1182  
1183  func (v Value) String() string {
1184  	r, _, _ := purego.SyscallN(symPrintValueToString, v.ref)
1185  	s := goString(r)
1186  	purego.SyscallN(symDisposeMessage, r)
1187  	return s
1188  }
1189  
1190  // ---- Constant scalars ----
1191  
1192  func ConstInt(t Type, n uint64, signExtend bool) Value {
1193  	r, _, _ := purego.SyscallN(symConstInt, t.ref, uintptr(n), boolToInt(signExtend))
1194  	return Value{r}
1195  }
1196  
1197  func ConstFloat(t Type, n float64) Value {
1198  	r, _, _ := purego.SyscallN(symConstFloat, t.ref, *(*uintptr)(unsafe.Pointer(&n)))
1199  	return Value{r}
1200  }
1201  
1202  func ConstNull(t Type) Value {
1203  	r, _, _ := purego.SyscallN(symConstNull, t.ref)
1204  	return Value{r}
1205  }
1206  
1207  func ConstAllOnes(t Type) Value {
1208  	r, _, _ := purego.SyscallN(symConstAllOnes, t.ref)
1209  	return Value{r}
1210  }
1211  
1212  func Undef(t Type) Value {
1213  	r, _, _ := purego.SyscallN(symGetUndef, t.ref)
1214  	return Value{r}
1215  }
1216  
1217  func ConstPointerNull(t Type) Value {
1218  	r, _, _ := purego.SyscallN(symConstPointerNull, t.ref)
1219  	return Value{r}
1220  }
1221  
1222  func (v Value) IsConstant() bool {
1223  	r, _, _ := purego.SyscallN(symIsConstant, v.ref)
1224  	return r != 0
1225  }
1226  
1227  func (v Value) IsNull() bool {
1228  	r, _, _ := purego.SyscallN(symIsNull, v.ref)
1229  	return r != 0
1230  }
1231  
1232  func (v Value) IsUndef() bool {
1233  	r, _, _ := purego.SyscallN(symIsUndef, v.ref)
1234  	return r != 0
1235  }
1236  
1237  func (v Value) ZExtValue() uint64 {
1238  	r, _, _ := purego.SyscallN(symConstIntGetZExt, v.ref)
1239  	return uint64(r)
1240  }
1241  
1242  func (v Value) SExtValue() int64 {
1243  	r, _, _ := purego.SyscallN(symConstIntGetSExt, v.ref)
1244  	return int64(r)
1245  }
1246  
1247  func (v Value) DoubleValue() (float64, bool) {
1248  	var lossy uintptr
1249  	r, _, _ := purego.SyscallN(symConstFloatGetDouble, v.ref, uintptr(unsafe.Pointer(&lossy)))
1250  	return *(*float64)(unsafe.Pointer(&r)), lossy != 0
1251  }
1252  
1253  // ---- Constant expressions ----
1254  
1255  func (v Value) ConstNeg() Value {
1256  	r, _, _ := purego.SyscallN(symConstNeg, v.ref)
1257  	return Value{r}
1258  }
1259  
1260  func (v Value) ConstNSWNeg() Value {
1261  	r, _, _ := purego.SyscallN(symConstNSWNeg, v.ref)
1262  	return Value{r}
1263  }
1264  
1265  func ConstNot(v Value) Value {
1266  	r, _, _ := purego.SyscallN(symConstNot, v.ref)
1267  	return Value{r}
1268  }
1269  
1270  func ConstAdd(lhs, rhs Value) Value {
1271  	r, _, _ := purego.SyscallN(symConstAdd, lhs.ref, rhs.ref)
1272  	return Value{r}
1273  }
1274  
1275  func ConstNSWAdd(lhs, rhs Value) Value {
1276  	r, _, _ := purego.SyscallN(symConstNSWAdd, lhs.ref, rhs.ref)
1277  	return Value{r}
1278  }
1279  
1280  func ConstSub(lhs, rhs Value) Value {
1281  	r, _, _ := purego.SyscallN(symConstSub, lhs.ref, rhs.ref)
1282  	return Value{r}
1283  }
1284  
1285  func ConstNSWSub(lhs, rhs Value) Value {
1286  	r, _, _ := purego.SyscallN(symConstNSWSub, lhs.ref, rhs.ref)
1287  	return Value{r}
1288  }
1289  
1290  func ConstMul(lhs, rhs Value) Value {
1291  	r, _, _ := purego.SyscallN(symConstMul, lhs.ref, rhs.ref)
1292  	return Value{r}
1293  }
1294  
1295  func ConstNSWMul(lhs, rhs Value) Value {
1296  	r, _, _ := purego.SyscallN(symConstNSWMul, lhs.ref, rhs.ref)
1297  	return Value{r}
1298  }
1299  
1300  func ConstXor(lhs, rhs Value) Value {
1301  	r, _, _ := purego.SyscallN(symConstXor, lhs.ref, rhs.ref)
1302  	return Value{r}
1303  }
1304  
1305  func ConstGEP(pointeeType Type, val Value, indices []Value) Value {
1306  	r, _, _ := purego.SyscallN(symConstGEP2, pointeeType.ref, val.ref, valueRefPtr(indices), uintptr(len(indices)))
1307  	return Value{r}
1308  }
1309  
1310  func ConstInBoundsGEP(pointeeType Type, val Value, indices []Value) Value {
1311  	r, _, _ := purego.SyscallN(symConstInBoundsGEP2, pointeeType.ref, val.ref, valueRefPtr(indices), uintptr(len(indices)))
1312  	return Value{r}
1313  }
1314  
1315  func ConstTrunc(val Value, t Type) Value {
1316  	r, _, _ := purego.SyscallN(symConstTrunc, val.ref, t.ref)
1317  	return Value{r}
1318  }
1319  
1320  func ConstSExt(val Value, t Type) Value {
1321  	r, _, _ := purego.SyscallN(symConstSExt, val.ref, t.ref)
1322  	return Value{r}
1323  }
1324  
1325  func ConstZExt(val Value, t Type) Value {
1326  	r, _, _ := purego.SyscallN(symConstZExt, val.ref, t.ref)
1327  	return Value{r}
1328  }
1329  
1330  func ConstFPTrunc(val Value, t Type) Value {
1331  	r, _, _ := purego.SyscallN(symConstFPTrunc, val.ref, t.ref)
1332  	return Value{r}
1333  }
1334  
1335  func ConstFPExt(val Value, t Type) Value {
1336  	r, _, _ := purego.SyscallN(symConstFPExt, val.ref, t.ref)
1337  	return Value{r}
1338  }
1339  
1340  func ConstUIToFP(val Value, t Type) Value {
1341  	r, _, _ := purego.SyscallN(symConstUIToFP, val.ref, t.ref)
1342  	return Value{r}
1343  }
1344  
1345  func ConstSIToFP(val Value, t Type) Value {
1346  	r, _, _ := purego.SyscallN(symConstSIToFP, val.ref, t.ref)
1347  	return Value{r}
1348  }
1349  
1350  func ConstFPToUI(val Value, t Type) Value {
1351  	r, _, _ := purego.SyscallN(symConstFPToUI, val.ref, t.ref)
1352  	return Value{r}
1353  }
1354  
1355  func ConstFPToSI(val Value, t Type) Value {
1356  	r, _, _ := purego.SyscallN(symConstFPToSI, val.ref, t.ref)
1357  	return Value{r}
1358  }
1359  
1360  func ConstPtrToInt(val Value, t Type) Value {
1361  	r, _, _ := purego.SyscallN(symConstPtrToInt, val.ref, t.ref)
1362  	return Value{r}
1363  }
1364  
1365  func ConstIntToPtr(val Value, t Type) Value {
1366  	r, _, _ := purego.SyscallN(symConstIntToPtr, val.ref, t.ref)
1367  	return Value{r}
1368  }
1369  
1370  func ConstBitCast(val Value, t Type) Value {
1371  	r, _, _ := purego.SyscallN(symConstBitCast, val.ref, t.ref)
1372  	return Value{r}
1373  }
1374  
1375  func ConstPointerCast(val Value, t Type) Value {
1376  	if symConstPointerCast == 0 {
1377  		return ConstBitCast(val, t)
1378  	}
1379  	r, _, _ := purego.SyscallN(symConstPointerCast, val.ref, t.ref)
1380  	return Value{r}
1381  }
1382  
1383  func ConstICmp(pred IntPredicate, lhs, rhs Value) Value {
1384  	r, _, _ := purego.SyscallN(symConstICmp, uintptr(pred), lhs.ref, rhs.ref)
1385  	return Value{r}
1386  }
1387  
1388  func ConstFCmp(pred FloatPredicate, lhs, rhs Value) Value {
1389  	r, _, _ := purego.SyscallN(symConstFCmp, uintptr(pred), lhs.ref, rhs.ref)
1390  	return Value{r}
1391  }
1392  
1393  func ConstExtractValue(agg Value, indices []uint32) Value {
1394  	r, _, _ := purego.SyscallN(symConstExtractValue, agg.ref, uintptr(unsafe.Pointer(&indices[0])), uintptr(len(indices)))
1395  	return Value{r}
1396  }
1397  
1398  func ConstInsertValue(agg, val Value, indices []uint32) Value {
1399  	r, _, _ := purego.SyscallN(symConstInsertValue, agg.ref, val.ref, uintptr(unsafe.Pointer(&indices[0])), uintptr(len(indices)))
1400  	return Value{r}
1401  }
1402  
1403  // ---- Constant aggregates ----
1404  
1405  func (c Context) ConstString(str string, addnull bool) Value {
1406  	cstr := cString(str)
1407  	r, _, _ := purego.SyscallN(symConstStringInCtx, c.ref, cstr, uintptr(len(str)), boolToInt(!addnull))
1408  	runtime.KeepAlive(str)
1409  	return Value{r}
1410  }
1411  
1412  func (c Context) ConstStruct(constVals []Value, packed bool) Value {
1413  	r, _, _ := purego.SyscallN(symConstStructInCtx, c.ref, valueRefPtr(constVals), uintptr(len(constVals)), boolToInt(packed))
1414  	return Value{r}
1415  }
1416  
1417  func ConstArray(t Type, constVals []Value) Value {
1418  	r, _, _ := purego.SyscallN(symConstArray, t.ref, valueRefPtr(constVals), uintptr(len(constVals)))
1419  	return Value{r}
1420  }
1421  
1422  func ConstNamedStruct(t Type, constVals []Value) Value {
1423  	r, _, _ := purego.SyscallN(symConstNamedStruct, t.ref, valueRefPtr(constVals), uintptr(len(constVals)))
1424  	return Value{r}
1425  }
1426  
1427  // ---- Global values ----
1428  
1429  func (v Value) Linkage() Linkage {
1430  	r, _, _ := purego.SyscallN(symGetLinkage, v.ref)
1431  	return Linkage(r)
1432  }
1433  
1434  func (v Value) SetLinkage(l Linkage) {
1435  	purego.SyscallN(symSetLinkage, v.ref, uintptr(l))
1436  }
1437  
1438  func (v Value) Section() string {
1439  	r, _, _ := purego.SyscallN(symGetSection, v.ref)
1440  	return goString(r)
1441  }
1442  
1443  func (v Value) SetSection(s string) {
1444  	cs := cString(s)
1445  	purego.SyscallN(symSetSection, v.ref, cs)
1446  	runtime.KeepAlive(s)
1447  }
1448  
1449  func (v Value) Visibility() Visibility {
1450  	r, _, _ := purego.SyscallN(symGetVisibility, v.ref)
1451  	return Visibility(r)
1452  }
1453  
1454  func (v Value) SetVisibility(vis Visibility) {
1455  	purego.SyscallN(symSetVisibility, v.ref, uintptr(vis))
1456  }
1457  
1458  func (v Value) Alignment() int {
1459  	r, _, _ := purego.SyscallN(symGetAlignment, v.ref)
1460  	return int(r)
1461  }
1462  
1463  func (v Value) SetAlignment(a int) {
1464  	purego.SyscallN(symSetAlignment, v.ref, uintptr(a))
1465  }
1466  
1467  // ---- Global variables ----
1468  
1469  func (m Module) AddGlobal(t Type, name string) Value {
1470  	cname := cString(name)
1471  	r, _, _ := purego.SyscallN(symAddGlobal, m.ref, t.ref, cname)
1472  	runtime.KeepAlive(name)
1473  	return Value{r}
1474  }
1475  
1476  func (m Module) NamedGlobal(name string) Value {
1477  	cname := cString(name)
1478  	r, _, _ := purego.SyscallN(symGetNamedGlobal, m.ref, cname)
1479  	runtime.KeepAlive(name)
1480  	return Value{r}
1481  }
1482  
1483  func (m Module) FirstGlobal() Value {
1484  	r, _, _ := purego.SyscallN(symGetFirstGlobal, m.ref)
1485  	return Value{r}
1486  }
1487  
1488  func (v Value) NextGlobal() Value {
1489  	r, _, _ := purego.SyscallN(symGetNextGlobal, v.ref)
1490  	return Value{r}
1491  }
1492  
1493  func (v Value) Initializer() Value {
1494  	r, _, _ := purego.SyscallN(symGetInitializer, v.ref)
1495  	return Value{r}
1496  }
1497  
1498  func (v Value) SetInitializer(c Value) {
1499  	purego.SyscallN(symSetInitializer, v.ref, c.ref)
1500  }
1501  
1502  func (v Value) IsGlobalConstant() bool {
1503  	r, _, _ := purego.SyscallN(symIsGlobalConstant, v.ref)
1504  	return r != 0
1505  }
1506  
1507  func (v Value) SetGlobalConstant(b bool) {
1508  	purego.SyscallN(symSetGlobalConstant, v.ref, boolToInt(b))
1509  }
1510  
1511  func (v Value) SetThreadLocal(b bool) {
1512  	purego.SyscallN(symSetThreadLocal, v.ref, boolToInt(b))
1513  }
1514  
1515  func (v Value) IsThreadLocal() bool {
1516  	r, _, _ := purego.SyscallN(symIsThreadLocal, v.ref)
1517  	return r != 0
1518  }
1519  
1520  func (v Value) SetExternallyInitialized(b bool) {
1521  	purego.SyscallN(symSetExternallyInit, v.ref, boolToInt(b))
1522  }
1523  
1524  func (v Value) IsExternallyInitialized() bool {
1525  	r, _, _ := purego.SyscallN(symIsExternallyInit, v.ref)
1526  	return r != 0
1527  }
1528  
1529  func (v Value) EraseFromParentAsGlobal() {
1530  	purego.SyscallN(symDeleteGlobal, v.ref)
1531  }
1532  
1533  func (v Value) SetUnnamedAddr(b bool) {
1534  	val := uintptr(0)
1535  	if b {
1536  		val = 1 // LLVMGlobalUnnamedAddr
1537  	}
1538  	purego.SyscallN(symSetUnnamedAddr, v.ref, val)
1539  }
1540  
1541  func (v Value) UnnamedAddr() bool {
1542  	r, _, _ := purego.SyscallN(symGetUnnamedAddr, v.ref)
1543  	return r != 0
1544  }
1545  
1546  // ---- Functions ----
1547  
1548  func (m Module) AddFunction(name string, t Type) Value {
1549  	cname := cString(name)
1550  	r, _, _ := purego.SyscallN(symAddFunction, m.ref, cname, t.ref)
1551  	runtime.KeepAlive(name)
1552  	return Value{r}
1553  }
1554  
1555  func AddFunction(m Module, name string, ft Type) Value {
1556  	return m.AddFunction(name, ft)
1557  }
1558  
1559  func AddGlobal(m Module, t Type, name string) Value {
1560  	return m.AddGlobal(t, name)
1561  }
1562  
1563  func (m Module) NamedFunction(name string) Value {
1564  	cname := cString(name)
1565  	r, _, _ := purego.SyscallN(symGetNamedFunction, m.ref, cname)
1566  	runtime.KeepAlive(name)
1567  	return Value{r}
1568  }
1569  
1570  func (m Module) FirstFunction() Value {
1571  	r, _, _ := purego.SyscallN(symGetFirstFunction, m.ref)
1572  	return Value{r}
1573  }
1574  
1575  func (v Value) NextFunction() Value {
1576  	r, _, _ := purego.SyscallN(symGetNextFunction, v.ref)
1577  	return Value{r}
1578  }
1579  
1580  func (v Value) EraseFromParentAsFunction() {
1581  	purego.SyscallN(symDeleteFunction, v.ref)
1582  }
1583  
1584  func (v Value) ParamsCount() int {
1585  	r, _, _ := purego.SyscallN(symCountParams, v.ref)
1586  	return int(r)
1587  }
1588  
1589  func (v Value) Params() []Value {
1590  	count := v.ParamsCount()
1591  	if count == 0 {
1592  		return nil
1593  	}
1594  	out := make([]Value, count)
1595  	purego.SyscallN(symGetParams, v.ref, uintptr(unsafe.Pointer(&out[0])))
1596  	return out
1597  }
1598  
1599  func (v Value) Param(i int) Value {
1600  	r, _, _ := purego.SyscallN(symGetParam, v.ref, uintptr(i))
1601  	return Value{r}
1602  }
1603  
1604  func (v Value) SetFunctionCallConv(cc CallConv) {
1605  	purego.SyscallN(symSetFunctionCallConv, v.ref, uintptr(cc))
1606  }
1607  
1608  func (v Value) FunctionCallConv() CallConv {
1609  	r, _, _ := purego.SyscallN(symGetFunctionCallConv, v.ref)
1610  	return CallConv(r)
1611  }
1612  
1613  func (v Value) AddFunctionAttr(attr Attribute) {
1614  	// LLVMAttributeFunctionIndex = -1, but passed as unsigned = 0xFFFFFFFF
1615  	purego.SyscallN(symAddFuncAttr, v.ref, ^uintptr(0), attr.ref)
1616  }
1617  
1618  func (v Value) GetEnumFunctionAttribute(index int, kindID uint) Attribute {
1619  	r, _, _ := purego.SyscallN(symGetEnumFuncAttr, v.ref, uintptr(index), uintptr(kindID))
1620  	return Attribute{r}
1621  }
1622  
1623  func (v Value) RemoveEnumFunctionAttribute(index int, kindID uint) {
1624  	purego.SyscallN(symRemoveEnumFuncAttr, v.ref, uintptr(index), uintptr(kindID))
1625  }
1626  
1627  func (v Value) AddTargetDependentFunctionAttr(attr, val string) {
1628  	cattr := cString(attr)
1629  	cval := cString(val)
1630  	purego.SyscallN(symAddTargetDepFuncAttr, v.ref, cattr, cval)
1631  	runtime.KeepAlive(attr)
1632  	runtime.KeepAlive(val)
1633  }
1634  
1635  // ---- Basic blocks ----
1636  
1637  func (c Context) AddBasicBlock(f Value, name string) BasicBlock {
1638  	cname := cString(name)
1639  	r, _, _ := purego.SyscallN(symAppendBasicBlockInCtx, c.ref, f.ref, cname)
1640  	runtime.KeepAlive(name)
1641  	return BasicBlock{r}
1642  }
1643  
1644  func AddBasicBlock(f Value, name string) BasicBlock {
1645  	return GlobalContext().AddBasicBlock(f, name)
1646  }
1647  
1648  func (c Context) InsertBasicBlock(ref BasicBlock, name string) BasicBlock {
1649  	cname := cString(name)
1650  	r, _, _ := purego.SyscallN(symInsertBasicBlockInCtx, c.ref, ref.ref, cname)
1651  	runtime.KeepAlive(name)
1652  	return BasicBlock{r}
1653  }
1654  
1655  func (bb BasicBlock) Parent() Value {
1656  	r, _, _ := purego.SyscallN(symGetBasicBlockParent, bb.ref)
1657  	return Value{r}
1658  }
1659  
1660  func (v Value) EntryBasicBlock() BasicBlock {
1661  	r, _, _ := purego.SyscallN(symGetEntryBasicBlock, v.ref)
1662  	return BasicBlock{r}
1663  }
1664  
1665  func (v Value) FirstBasicBlock() BasicBlock {
1666  	r, _, _ := purego.SyscallN(symGetFirstBasicBlock, v.ref)
1667  	return BasicBlock{r}
1668  }
1669  
1670  func (v Value) LastBasicBlock() BasicBlock {
1671  	r, _, _ := purego.SyscallN(symGetLastBasicBlock, v.ref)
1672  	return BasicBlock{r}
1673  }
1674  
1675  func (bb BasicBlock) NextBasicBlock() BasicBlock {
1676  	r, _, _ := purego.SyscallN(symGetNextBasicBlock, bb.ref)
1677  	return BasicBlock{r}
1678  }
1679  
1680  func (bb BasicBlock) PrevBasicBlock() BasicBlock {
1681  	r, _, _ := purego.SyscallN(symGetPreviousBasicBlock, bb.ref)
1682  	return BasicBlock{r}
1683  }
1684  
1685  func (v Value) BasicBlocksCount() int {
1686  	r, _, _ := purego.SyscallN(symCountBasicBlocks, v.ref)
1687  	return int(r)
1688  }
1689  
1690  func (bb BasicBlock) MoveAfter(other BasicBlock) {
1691  	purego.SyscallN(symMoveBasicBlockAfter, bb.ref, other.ref)
1692  }
1693  
1694  func (bb BasicBlock) MoveBefore(other BasicBlock) {
1695  	purego.SyscallN(symMoveBasicBlockBefore, bb.ref, other.ref)
1696  }
1697  
1698  func (bb BasicBlock) EraseFromParent() {
1699  	purego.SyscallN(symDeleteBasicBlock, bb.ref)
1700  }
1701  
1702  func (bb BasicBlock) AsValue() Value {
1703  	r, _, _ := purego.SyscallN(symBasicBlockAsValue, bb.ref)
1704  	return Value{r}
1705  }
1706  
1707  // ---- Instructions ----
1708  
1709  func (bb BasicBlock) FirstInstruction() Value {
1710  	r, _, _ := purego.SyscallN(symGetFirstInstruction, bb.ref)
1711  	return Value{r}
1712  }
1713  
1714  func (bb BasicBlock) LastInstruction() Value {
1715  	r, _, _ := purego.SyscallN(symGetLastInstruction, bb.ref)
1716  	return Value{r}
1717  }
1718  
1719  func (v Value) NextInstruction() Value {
1720  	r, _, _ := purego.SyscallN(symGetNextInstruction, v.ref)
1721  	return Value{r}
1722  }
1723  
1724  func (v Value) InstructionOpcode() Opcode {
1725  	r, _, _ := purego.SyscallN(symGetInstructionOpcode, v.ref)
1726  	return Opcode(r)
1727  }
1728  
1729  func (v Value) EraseFromParentAsInstruction() {
1730  	purego.SyscallN(symInstructionEraseFromParent, v.ref)
1731  }
1732  
1733  func (v Value) InstructionParent() BasicBlock {
1734  	r, _, _ := purego.SyscallN(symGetInstructionParent, v.ref)
1735  	return BasicBlock{r}
1736  }
1737  
1738  func (v Value) IsATerminatorInst() Value {
1739  	r, _, _ := purego.SyscallN(symIsATerminatorInst, v.ref)
1740  	return Value{r}
1741  }
1742  
1743  func (v Value) IsAAllocaInst() Value {
1744  	r, _, _ := purego.SyscallN(symIsAAllocaInst, v.ref)
1745  	return Value{r}
1746  }
1747  
1748  func (v Value) IsAConstant() Value {
1749  	r, _, _ := purego.SyscallN(symIsAConstant, v.ref)
1750  	return Value{r}
1751  }
1752  
1753  func (v Value) IsAConstantInt() Value {
1754  	r, _, _ := purego.SyscallN(symIsAConstantInt, v.ref)
1755  	return Value{r}
1756  }
1757  
1758  func (v Value) IsAFunction() Value {
1759  	r, _, _ := purego.SyscallN(symIsAFunction, v.ref)
1760  	return Value{r}
1761  }
1762  
1763  func (v Value) IsAGlobalValue() Value {
1764  	r, _, _ := purego.SyscallN(symIsAGlobalValue, v.ref)
1765  	return Value{r}
1766  }
1767  
1768  func (v Value) IsAInstruction() Value {
1769  	r, _, _ := purego.SyscallN(symIsAInstruction, v.ref)
1770  	return Value{r}
1771  }
1772  
1773  func (v Value) IsAPHINode() Value {
1774  	r, _, _ := purego.SyscallN(symIsAPHINode, v.ref)
1775  	return Value{r}
1776  }
1777  
1778  func (v Value) IsAUndefValue() Value {
1779  	r, _, _ := purego.SyscallN(symIsAUndefValue, v.ref)
1780  	return Value{r}
1781  }
1782  
1783  func (v Value) IsDeclaration() bool {
1784  	r, _, _ := purego.SyscallN(symIsDeclaration, v.ref)
1785  	return r != 0
1786  }
1787  
1788  func (v Value) GlobalValueType() Type {
1789  	r, _, _ := purego.SyscallN(symGlobalGetValType, v.ref)
1790  	return Type{r}
1791  }
1792  
1793  func (v Value) LastParam() Value {
1794  	r, _, _ := purego.SyscallN(symGetLastParam, v.ref)
1795  	return Value{r}
1796  }
1797  
1798  func (v Value) Operand(i int) Value {
1799  	r, _, _ := purego.SyscallN(symGetOperand, v.ref, uintptr(i))
1800  	return Value{r}
1801  }
1802  
1803  func (v Value) OperandsCount() int {
1804  	r, _, _ := purego.SyscallN(symGetNumOperands, v.ref)
1805  	return int(r)
1806  }
1807  
1808  func (v Value) SetVolatile(volatile bool) {
1809  	purego.SyscallN(symSetVolatile, v.ref, boolToInt(volatile))
1810  }
1811  
1812  func (v Value) RemoveFromParentAsInstruction() {
1813  	purego.SyscallN(symInstructionRemoveFromParent, v.ref)
1814  }
1815  
1816  func (v Value) IncomingCount() int {
1817  	r, _, _ := purego.SyscallN(symCountIncoming, v.ref)
1818  	return int(r)
1819  }
1820  
1821  func (v Value) IncomingValue(i int) Value {
1822  	r, _, _ := purego.SyscallN(symGetIncomingValue, v.ref, uintptr(i))
1823  	return Value{r}
1824  }
1825  
1826  func (v Value) IncomingBlock(i int) BasicBlock {
1827  	r, _, _ := purego.SyscallN(symGetIncomingBlock, v.ref, uintptr(i))
1828  	return BasicBlock{r}
1829  }
1830  
1831  func (v Value) AddAttributeAtIndex(i int, a Attribute) {
1832  	purego.SyscallN(symAddFuncAttr, v.ref, uintptr(i), a.ref)
1833  }
1834  
1835  func (v Value) AddMetadata(kind int, md Metadata) {
1836  	if symGlobalObjectAddMetadata == 0 {
1837  		return
1838  	}
1839  	purego.SyscallN(symGlobalObjectAddMetadata, v.ref, uintptr(kind), md.ref)
1840  }
1841  
1842  // Free-function wrappers for iteration (compiler uses these)
1843  
1844  func NextInstruction(v Value) Value         { return v.NextInstruction() }
1845  func NextBasicBlock(bb BasicBlock) BasicBlock { return bb.NextBasicBlock() }
1846  func NextFunction(v Value) Value            { return v.NextFunction() }
1847  func NextGlobal(v Value) Value              { return v.NextGlobal() }
1848  
1849  // ---- Builder ----
1850  
1851  func (c Context) NewBuilder() Builder {
1852  	r, _, _ := purego.SyscallN(symCreateBuilderInCtx, c.ref)
1853  	return Builder{r}
1854  }
1855  
1856  func (b Builder) SetInsertPointAtEnd(bb BasicBlock) {
1857  	purego.SyscallN(symPositionBuilderAtEnd, b.ref, bb.ref)
1858  }
1859  
1860  func (b Builder) SetInsertPointBefore(instr Value) {
1861  	parent := instr.InstructionParent()
1862  	purego.SyscallN(symPositionBuilderBefore, b.ref, parent.ref, instr.ref)
1863  }
1864  
1865  func (b Builder) GetInsertBlock() BasicBlock {
1866  	r, _, _ := purego.SyscallN(symGetInsertBlock, b.ref)
1867  	return BasicBlock{r}
1868  }
1869  
1870  func (b Builder) Dispose() {
1871  	purego.SyscallN(symDisposeBuilder, b.ref)
1872  }
1873  
1874  func (b Builder) Insert(instr Value) {
1875  	purego.SyscallN(symInsertIntoBuilder, b.ref, instr.ref)
1876  }
1877  
1878  func (b Builder) CreateBinOp(op Opcode, lhs, rhs Value, name string) Value {
1879  	cname := cString(name)
1880  	r, _, _ := purego.SyscallN(symBuildBinOp, b.ref, uintptr(op), lhs.ref, rhs.ref, cname)
1881  	runtime.KeepAlive(name)
1882  	return Value{r}
1883  }
1884  
1885  // Builder - terminators
1886  
1887  func (b Builder) CreateRetVoid() Value {
1888  	r, _, _ := purego.SyscallN(symBuildRetVoid, b.ref)
1889  	return Value{r}
1890  }
1891  
1892  func (b Builder) CreateRet(v Value) Value {
1893  	r, _, _ := purego.SyscallN(symBuildRet, b.ref, v.ref)
1894  	return Value{r}
1895  }
1896  
1897  func (b Builder) CreateBr(dest BasicBlock) Value {
1898  	r, _, _ := purego.SyscallN(symBuildBr, b.ref, dest.ref)
1899  	return Value{r}
1900  }
1901  
1902  func (b Builder) CreateCondBr(cond Value, thenBB, elseBB BasicBlock) Value {
1903  	r, _, _ := purego.SyscallN(symBuildCondBr, b.ref, cond.ref, thenBB.ref, elseBB.ref)
1904  	return Value{r}
1905  }
1906  
1907  func (b Builder) CreateSwitch(v Value, elseBB BasicBlock, numCases int) Value {
1908  	r, _, _ := purego.SyscallN(symBuildSwitch, b.ref, v.ref, elseBB.ref, uintptr(numCases))
1909  	return Value{r}
1910  }
1911  
1912  func (b Builder) CreateUnreachable() Value {
1913  	r, _, _ := purego.SyscallN(symBuildUnreachable, b.ref)
1914  	return Value{r}
1915  }
1916  
1917  // Builder - arithmetic
1918  
1919  func (b Builder) CreateAdd(lhs, rhs Value, name string) Value {
1920  	cname := cString(name)
1921  	r, _, _ := purego.SyscallN(symBuildAdd, b.ref, lhs.ref, rhs.ref, cname)
1922  	runtime.KeepAlive(name)
1923  	return Value{r}
1924  }
1925  
1926  func (b Builder) CreateNSWAdd(lhs, rhs Value, name string) Value {
1927  	cname := cString(name)
1928  	r, _, _ := purego.SyscallN(symBuildNSWAdd, b.ref, lhs.ref, rhs.ref, cname)
1929  	runtime.KeepAlive(name)
1930  	return Value{r}
1931  }
1932  
1933  func (b Builder) CreateNUWAdd(lhs, rhs Value, name string) Value {
1934  	cname := cString(name)
1935  	r, _, _ := purego.SyscallN(symBuildNUWAdd, b.ref, lhs.ref, rhs.ref, cname)
1936  	runtime.KeepAlive(name)
1937  	return Value{r}
1938  }
1939  
1940  func (b Builder) CreateFAdd(lhs, rhs Value, name string) Value {
1941  	cname := cString(name)
1942  	r, _, _ := purego.SyscallN(symBuildFAdd, b.ref, lhs.ref, rhs.ref, cname)
1943  	runtime.KeepAlive(name)
1944  	return Value{r}
1945  }
1946  
1947  func (b Builder) CreateSub(lhs, rhs Value, name string) Value {
1948  	cname := cString(name)
1949  	r, _, _ := purego.SyscallN(symBuildSub, b.ref, lhs.ref, rhs.ref, cname)
1950  	runtime.KeepAlive(name)
1951  	return Value{r}
1952  }
1953  
1954  func (b Builder) CreateNSWSub(lhs, rhs Value, name string) Value {
1955  	cname := cString(name)
1956  	r, _, _ := purego.SyscallN(symBuildNSWSub, b.ref, lhs.ref, rhs.ref, cname)
1957  	runtime.KeepAlive(name)
1958  	return Value{r}
1959  }
1960  
1961  func (b Builder) CreateNUWSub(lhs, rhs Value, name string) Value {
1962  	cname := cString(name)
1963  	r, _, _ := purego.SyscallN(symBuildNUWSub, b.ref, lhs.ref, rhs.ref, cname)
1964  	runtime.KeepAlive(name)
1965  	return Value{r}
1966  }
1967  
1968  func (b Builder) CreateFSub(lhs, rhs Value, name string) Value {
1969  	cname := cString(name)
1970  	r, _, _ := purego.SyscallN(symBuildFSub, b.ref, lhs.ref, rhs.ref, cname)
1971  	runtime.KeepAlive(name)
1972  	return Value{r}
1973  }
1974  
1975  func (b Builder) CreateMul(lhs, rhs Value, name string) Value {
1976  	cname := cString(name)
1977  	r, _, _ := purego.SyscallN(symBuildMul, b.ref, lhs.ref, rhs.ref, cname)
1978  	runtime.KeepAlive(name)
1979  	return Value{r}
1980  }
1981  
1982  func (b Builder) CreateNSWMul(lhs, rhs Value, name string) Value {
1983  	cname := cString(name)
1984  	r, _, _ := purego.SyscallN(symBuildNSWMul, b.ref, lhs.ref, rhs.ref, cname)
1985  	runtime.KeepAlive(name)
1986  	return Value{r}
1987  }
1988  
1989  func (b Builder) CreateNUWMul(lhs, rhs Value, name string) Value {
1990  	cname := cString(name)
1991  	r, _, _ := purego.SyscallN(symBuildNUWMul, b.ref, lhs.ref, rhs.ref, cname)
1992  	runtime.KeepAlive(name)
1993  	return Value{r}
1994  }
1995  
1996  func (b Builder) CreateFMul(lhs, rhs Value, name string) Value {
1997  	cname := cString(name)
1998  	r, _, _ := purego.SyscallN(symBuildFMul, b.ref, lhs.ref, rhs.ref, cname)
1999  	runtime.KeepAlive(name)
2000  	return Value{r}
2001  }
2002  
2003  func (b Builder) CreateUDiv(lhs, rhs Value, name string) Value {
2004  	cname := cString(name)
2005  	r, _, _ := purego.SyscallN(symBuildUDiv, b.ref, lhs.ref, rhs.ref, cname)
2006  	runtime.KeepAlive(name)
2007  	return Value{r}
2008  }
2009  
2010  func (b Builder) CreateSDiv(lhs, rhs Value, name string) Value {
2011  	cname := cString(name)
2012  	r, _, _ := purego.SyscallN(symBuildSDiv, b.ref, lhs.ref, rhs.ref, cname)
2013  	runtime.KeepAlive(name)
2014  	return Value{r}
2015  }
2016  
2017  func (b Builder) CreateExactSDiv(lhs, rhs Value, name string) Value {
2018  	cname := cString(name)
2019  	r, _, _ := purego.SyscallN(symBuildExactSDiv, b.ref, lhs.ref, rhs.ref, cname)
2020  	runtime.KeepAlive(name)
2021  	return Value{r}
2022  }
2023  
2024  func (b Builder) CreateFDiv(lhs, rhs Value, name string) Value {
2025  	cname := cString(name)
2026  	r, _, _ := purego.SyscallN(symBuildFDiv, b.ref, lhs.ref, rhs.ref, cname)
2027  	runtime.KeepAlive(name)
2028  	return Value{r}
2029  }
2030  
2031  func (b Builder) CreateURem(lhs, rhs Value, name string) Value {
2032  	cname := cString(name)
2033  	r, _, _ := purego.SyscallN(symBuildURem, b.ref, lhs.ref, rhs.ref, cname)
2034  	runtime.KeepAlive(name)
2035  	return Value{r}
2036  }
2037  
2038  func (b Builder) CreateSRem(lhs, rhs Value, name string) Value {
2039  	cname := cString(name)
2040  	r, _, _ := purego.SyscallN(symBuildSRem, b.ref, lhs.ref, rhs.ref, cname)
2041  	runtime.KeepAlive(name)
2042  	return Value{r}
2043  }
2044  
2045  func (b Builder) CreateFRem(lhs, rhs Value, name string) Value {
2046  	cname := cString(name)
2047  	r, _, _ := purego.SyscallN(symBuildFRem, b.ref, lhs.ref, rhs.ref, cname)
2048  	runtime.KeepAlive(name)
2049  	return Value{r}
2050  }
2051  
2052  func (b Builder) CreateShl(lhs, rhs Value, name string) Value {
2053  	cname := cString(name)
2054  	r, _, _ := purego.SyscallN(symBuildShl, b.ref, lhs.ref, rhs.ref, cname)
2055  	runtime.KeepAlive(name)
2056  	return Value{r}
2057  }
2058  
2059  func (b Builder) CreateLShr(lhs, rhs Value, name string) Value {
2060  	cname := cString(name)
2061  	r, _, _ := purego.SyscallN(symBuildLShr, b.ref, lhs.ref, rhs.ref, cname)
2062  	runtime.KeepAlive(name)
2063  	return Value{r}
2064  }
2065  
2066  func (b Builder) CreateAShr(lhs, rhs Value, name string) Value {
2067  	cname := cString(name)
2068  	r, _, _ := purego.SyscallN(symBuildAShr, b.ref, lhs.ref, rhs.ref, cname)
2069  	runtime.KeepAlive(name)
2070  	return Value{r}
2071  }
2072  
2073  func (b Builder) CreateAnd(lhs, rhs Value, name string) Value {
2074  	cname := cString(name)
2075  	r, _, _ := purego.SyscallN(symBuildAnd, b.ref, lhs.ref, rhs.ref, cname)
2076  	runtime.KeepAlive(name)
2077  	return Value{r}
2078  }
2079  
2080  func (b Builder) CreateOr(lhs, rhs Value, name string) Value {
2081  	cname := cString(name)
2082  	r, _, _ := purego.SyscallN(symBuildOr, b.ref, lhs.ref, rhs.ref, cname)
2083  	runtime.KeepAlive(name)
2084  	return Value{r}
2085  }
2086  
2087  func (b Builder) CreateXor(lhs, rhs Value, name string) Value {
2088  	cname := cString(name)
2089  	r, _, _ := purego.SyscallN(symBuildXor, b.ref, lhs.ref, rhs.ref, cname)
2090  	runtime.KeepAlive(name)
2091  	return Value{r}
2092  }
2093  
2094  func (b Builder) CreateNeg(v Value, name string) Value {
2095  	cname := cString(name)
2096  	r, _, _ := purego.SyscallN(symBuildNeg, b.ref, v.ref, cname)
2097  	runtime.KeepAlive(name)
2098  	return Value{r}
2099  }
2100  
2101  func (b Builder) CreateNSWNeg(v Value, name string) Value {
2102  	cname := cString(name)
2103  	r, _, _ := purego.SyscallN(symBuildNSWNeg, b.ref, v.ref, cname)
2104  	runtime.KeepAlive(name)
2105  	return Value{r}
2106  }
2107  
2108  func (b Builder) CreateNot(v Value, name string) Value {
2109  	cname := cString(name)
2110  	r, _, _ := purego.SyscallN(symBuildNot, b.ref, v.ref, cname)
2111  	runtime.KeepAlive(name)
2112  	return Value{r}
2113  }
2114  
2115  func (b Builder) CreateFNeg(v Value, name string) Value {
2116  	cname := cString(name)
2117  	r, _, _ := purego.SyscallN(symBuildFNeg, b.ref, v.ref, cname)
2118  	runtime.KeepAlive(name)
2119  	return Value{r}
2120  }
2121  
2122  // Builder - memory
2123  
2124  func (b Builder) CreateAlloca(t Type, name string) Value {
2125  	cname := cString(name)
2126  	r, _, _ := purego.SyscallN(symBuildAlloca, b.ref, t.ref, cname)
2127  	runtime.KeepAlive(name)
2128  	return Value{r}
2129  }
2130  
2131  func (b Builder) CreateLoad(t Type, ptr Value, name string) Value {
2132  	cname := cString(name)
2133  	r, _, _ := purego.SyscallN(symBuildLoad2, b.ref, t.ref, ptr.ref, cname)
2134  	runtime.KeepAlive(name)
2135  	return Value{r}
2136  }
2137  
2138  func (b Builder) CreateStore(val, ptr Value) Value {
2139  	r, _, _ := purego.SyscallN(symBuildStore, b.ref, val.ref, ptr.ref)
2140  	return Value{r}
2141  }
2142  
2143  func (b Builder) CreateGEP(t Type, ptr Value, indices []Value, name string) Value {
2144  	cname := cString(name)
2145  	r, _, _ := purego.SyscallN(symBuildGEP2, b.ref, t.ref, ptr.ref, valueRefPtr(indices), uintptr(len(indices)), cname)
2146  	runtime.KeepAlive(name)
2147  	return Value{r}
2148  }
2149  
2150  func (b Builder) CreateInBoundsGEP(t Type, ptr Value, indices []Value, name string) Value {
2151  	cname := cString(name)
2152  	r, _, _ := purego.SyscallN(symBuildInBoundsGEP2, b.ref, t.ref, ptr.ref, valueRefPtr(indices), uintptr(len(indices)), cname)
2153  	runtime.KeepAlive(name)
2154  	return Value{r}
2155  }
2156  
2157  func (b Builder) CreateStructGEP(t Type, ptr Value, idx int, name string) Value {
2158  	cname := cString(name)
2159  	r, _, _ := purego.SyscallN(symBuildStructGEP2, b.ref, t.ref, ptr.ref, uintptr(idx), cname)
2160  	runtime.KeepAlive(name)
2161  	return Value{r}
2162  }
2163  
2164  // Builder - casts
2165  
2166  func (b Builder) CreateTrunc(val Value, t Type, name string) Value {
2167  	cname := cString(name)
2168  	r, _, _ := purego.SyscallN(symBuildTrunc, b.ref, val.ref, t.ref, cname)
2169  	runtime.KeepAlive(name)
2170  	return Value{r}
2171  }
2172  
2173  func (b Builder) CreateZExt(val Value, t Type, name string) Value {
2174  	cname := cString(name)
2175  	r, _, _ := purego.SyscallN(symBuildZExt, b.ref, val.ref, t.ref, cname)
2176  	runtime.KeepAlive(name)
2177  	return Value{r}
2178  }
2179  
2180  func (b Builder) CreateSExt(val Value, t Type, name string) Value {
2181  	cname := cString(name)
2182  	r, _, _ := purego.SyscallN(symBuildSExt, b.ref, val.ref, t.ref, cname)
2183  	runtime.KeepAlive(name)
2184  	return Value{r}
2185  }
2186  
2187  func (b Builder) CreateFPToUI(val Value, t Type, name string) Value {
2188  	cname := cString(name)
2189  	r, _, _ := purego.SyscallN(symBuildFPToUI, b.ref, val.ref, t.ref, cname)
2190  	runtime.KeepAlive(name)
2191  	return Value{r}
2192  }
2193  
2194  func (b Builder) CreateFPToSI(val Value, t Type, name string) Value {
2195  	cname := cString(name)
2196  	r, _, _ := purego.SyscallN(symBuildFPToSI, b.ref, val.ref, t.ref, cname)
2197  	runtime.KeepAlive(name)
2198  	return Value{r}
2199  }
2200  
2201  func (b Builder) CreateUIToFP(val Value, t Type, name string) Value {
2202  	cname := cString(name)
2203  	r, _, _ := purego.SyscallN(symBuildUIToFP, b.ref, val.ref, t.ref, cname)
2204  	runtime.KeepAlive(name)
2205  	return Value{r}
2206  }
2207  
2208  func (b Builder) CreateSIToFP(val Value, t Type, name string) Value {
2209  	cname := cString(name)
2210  	r, _, _ := purego.SyscallN(symBuildSIToFP, b.ref, val.ref, t.ref, cname)
2211  	runtime.KeepAlive(name)
2212  	return Value{r}
2213  }
2214  
2215  func (b Builder) CreateFPTrunc(val Value, t Type, name string) Value {
2216  	cname := cString(name)
2217  	r, _, _ := purego.SyscallN(symBuildFPTrunc, b.ref, val.ref, t.ref, cname)
2218  	runtime.KeepAlive(name)
2219  	return Value{r}
2220  }
2221  
2222  func (b Builder) CreateFPExt(val Value, t Type, name string) Value {
2223  	cname := cString(name)
2224  	r, _, _ := purego.SyscallN(symBuildFPExt, b.ref, val.ref, t.ref, cname)
2225  	runtime.KeepAlive(name)
2226  	return Value{r}
2227  }
2228  
2229  func (b Builder) CreatePtrToInt(val Value, t Type, name string) Value {
2230  	cname := cString(name)
2231  	r, _, _ := purego.SyscallN(symBuildPtrToInt, b.ref, val.ref, t.ref, cname)
2232  	runtime.KeepAlive(name)
2233  	return Value{r}
2234  }
2235  
2236  func (b Builder) CreateIntToPtr(val Value, t Type, name string) Value {
2237  	cname := cString(name)
2238  	r, _, _ := purego.SyscallN(symBuildIntToPtr, b.ref, val.ref, t.ref, cname)
2239  	runtime.KeepAlive(name)
2240  	return Value{r}
2241  }
2242  
2243  func (b Builder) CreateBitCast(val Value, t Type, name string) Value {
2244  	cname := cString(name)
2245  	r, _, _ := purego.SyscallN(symBuildBitCast, b.ref, val.ref, t.ref, cname)
2246  	runtime.KeepAlive(name)
2247  	return Value{r}
2248  }
2249  
2250  func (b Builder) CreatePointerCast(val Value, t Type, name string) Value {
2251  	cname := cString(name)
2252  	r, _, _ := purego.SyscallN(symBuildPointerCast, b.ref, val.ref, t.ref, cname)
2253  	runtime.KeepAlive(name)
2254  	return Value{r}
2255  }
2256  
2257  // Builder - comparisons
2258  
2259  func (b Builder) CreateICmp(pred IntPredicate, lhs, rhs Value, name string) Value {
2260  	cname := cString(name)
2261  	r, _, _ := purego.SyscallN(symBuildICmp, b.ref, uintptr(pred), lhs.ref, rhs.ref, cname)
2262  	runtime.KeepAlive(name)
2263  	return Value{r}
2264  }
2265  
2266  func (b Builder) CreateFCmp(pred FloatPredicate, lhs, rhs Value, name string) Value {
2267  	cname := cString(name)
2268  	r, _, _ := purego.SyscallN(symBuildFCmp, b.ref, uintptr(pred), lhs.ref, rhs.ref, cname)
2269  	runtime.KeepAlive(name)
2270  	return Value{r}
2271  }
2272  
2273  // Builder - misc
2274  
2275  func (b Builder) CreatePHI(t Type, name string) Value {
2276  	cname := cString(name)
2277  	r, _, _ := purego.SyscallN(symBuildPhi, b.ref, t.ref, cname)
2278  	runtime.KeepAlive(name)
2279  	return Value{r}
2280  }
2281  
2282  func (b Builder) CreateCall(fnType Type, fn Value, args []Value, name string) Value {
2283  	cname := cString(name)
2284  	r, _, _ := purego.SyscallN(symBuildCall2, b.ref, fnType.ref, fn.ref, valueRefPtr(args), uintptr(len(args)), cname)
2285  	runtime.KeepAlive(name)
2286  	return Value{r}
2287  }
2288  
2289  func (b Builder) CreateSelect(cond, thenVal, elseVal Value, name string) Value {
2290  	cname := cString(name)
2291  	r, _, _ := purego.SyscallN(symBuildSelect, b.ref, cond.ref, thenVal.ref, elseVal.ref, cname)
2292  	runtime.KeepAlive(name)
2293  	return Value{r}
2294  }
2295  
2296  func (b Builder) CreateExtractValue(agg Value, index int, name string) Value {
2297  	cname := cString(name)
2298  	r, _, _ := purego.SyscallN(symBuildExtractValue, b.ref, agg.ref, uintptr(index), cname)
2299  	runtime.KeepAlive(name)
2300  	return Value{r}
2301  }
2302  
2303  func (b Builder) CreateInsertValue(agg, val Value, index int, name string) Value {
2304  	cname := cString(name)
2305  	r, _, _ := purego.SyscallN(symBuildInsertValue, b.ref, agg.ref, val.ref, uintptr(index), cname)
2306  	runtime.KeepAlive(name)
2307  	return Value{r}
2308  }
2309  
2310  // ---- PHI ----
2311  
2312  func (v Value) AddIncoming(vals []Value, blocks []BasicBlock) {
2313  	if len(vals) == 0 {
2314  		return
2315  	}
2316  	purego.SyscallN(symAddIncoming, v.ref, valueRefPtr(vals), uintptr(unsafe.Pointer(&blocks[0])), uintptr(len(vals)))
2317  }
2318  
2319  // ---- Call site ----
2320  
2321  func (v Value) SetInstructionCallConv(cc CallConv) {
2322  	purego.SyscallN(symSetInstructionCallConv, v.ref, uintptr(cc))
2323  }
2324  
2325  func (v Value) InstructionCallConv() CallConv {
2326  	r, _, _ := purego.SyscallN(symGetInstructionCallConv, v.ref)
2327  	return CallConv(r)
2328  }
2329  
2330  func (v Value) AddCallSiteAttribute(index int, attr Attribute) {
2331  	purego.SyscallN(symAddCallSiteAttribute, v.ref, uintptr(index), attr.ref)
2332  }
2333  
2334  func (v Value) SetInstrParamAlignment(index, align int) {
2335  	purego.SyscallN(symSetInstrParamAlignment, v.ref, uintptr(index), uintptr(align))
2336  }
2337  
2338  // ---- Switch ----
2339  
2340  func (v Value) AddCase(onVal Value, dest BasicBlock) {
2341  	purego.SyscallN(symAddCase, v.ref, onVal.ref, dest.ref)
2342  }
2343  
2344  // ---- Landing pad ----
2345  
2346  func (b Builder) CreateLandingPad(t Type, numClauses int, name string) Value {
2347  	cname := cString(name)
2348  	r, _, _ := purego.SyscallN(symBuildLandingPad, b.ref, t.ref, 0, uintptr(numClauses), cname)
2349  	runtime.KeepAlive(name)
2350  	return Value{r}
2351  }
2352  
2353  func (v Value) SetCleanup(b bool) {
2354  	purego.SyscallN(symSetCleanup, v.ref, boolToInt(b))
2355  }
2356  
2357  func (v Value) AddClause(clauseVal Value) {
2358  	purego.SyscallN(symAddClause, v.ref, clauseVal.ref)
2359  }
2360  
2361  // ---- Invoke ----
2362  
2363  func (b Builder) CreateInvoke(fnType Type, fn Value, args []Value, thenBB, catchBB BasicBlock, name string) Value {
2364  	cname := cString(name)
2365  	r, _, _ := purego.SyscallN(symBuildInvoke2, b.ref, fnType.ref, fn.ref, valueRefPtr(args), uintptr(len(args)), thenBB.ref, catchBB.ref, cname)
2366  	runtime.KeepAlive(name)
2367  	return Value{r}
2368  }
2369  
2370  // ---- Resume ----
2371  
2372  func (b Builder) CreateResume(v Value) Value {
2373  	r, _, _ := purego.SyscallN(symBuildResume, b.ref, v.ref)
2374  	return Value{r}
2375  }
2376  
2377  // ---- Atomics ----
2378  
2379  func (b Builder) CreateFence(ordering AtomicOrdering, singleThread bool, name string) Value {
2380  	cname := cString(name)
2381  	r, _, _ := purego.SyscallN(symBuildFence, b.ref, uintptr(ordering), boolToInt(singleThread), cname)
2382  	runtime.KeepAlive(name)
2383  	return Value{r}
2384  }
2385  
2386  func (b Builder) CreateAtomicRMW(op AtomicRMWBinOp, ptr, val Value, ordering AtomicOrdering, singleThread bool) Value {
2387  	r, _, _ := purego.SyscallN(symBuildAtomicRMW, b.ref, uintptr(op), ptr.ref, val.ref, uintptr(ordering), boolToInt(singleThread))
2388  	return Value{r}
2389  }
2390  
2391  func (b Builder) CreateAtomicCmpXchg(ptr, cmp, new_ Value, successOrdering, failureOrdering AtomicOrdering, singleThread bool) Value {
2392  	r, _, _ := purego.SyscallN(symBuildAtomicCmpXchg, b.ref, ptr.ref, cmp.ref, new_.ref, uintptr(successOrdering), uintptr(failureOrdering), boolToInt(singleThread))
2393  	return Value{r}
2394  }
2395  
2396  func (v Value) SetOrdering(ordering AtomicOrdering) {
2397  	purego.SyscallN(symSetOrdering, v.ref, uintptr(ordering))
2398  }
2399  
2400  func (v Value) SetAtomicSingleThread(singleThread bool) {
2401  	purego.SyscallN(symSetAtomicSingleThread, v.ref, boolToInt(singleThread))
2402  }
2403  
2404  // ---- Metadata (glue functions) ----
2405  
2406  func (c Context) MDString(str string) Metadata {
2407  	if symMDString2 == 0 {
2408  		return Metadata{}
2409  	}
2410  	cstr := cString(str)
2411  	r, _, _ := purego.SyscallN(symMDString2, c.ref, cstr, uintptr(len(str)))
2412  	runtime.KeepAlive(str)
2413  	return Metadata{r}
2414  }
2415  
2416  func (c Context) MDNode(mds []Metadata) Metadata {
2417  	if symMDNode2 == 0 {
2418  		return Metadata{}
2419  	}
2420  	r, _, _ := purego.SyscallN(symMDNode2, c.ref, metadataRefPtr(mds), uintptr(len(mds)))
2421  	return Metadata{r}
2422  }
2423  
2424  func ConstantAsMetadata(v Value) Metadata {
2425  	if symConstantAsMetadata == 0 {
2426  		return Metadata{}
2427  	}
2428  	r, _, _ := purego.SyscallN(symConstantAsMetadata, v.ref)
2429  	return Metadata{r}
2430  }
2431  
2432  func (v Value) GlobalObjectAddMetadata(kind uint, md Metadata) {
2433  	if symGlobalObjectAddMetadata == 0 {
2434  		return
2435  	}
2436  	purego.SyscallN(symGlobalObjectAddMetadata, v.ref, uintptr(kind), md.ref)
2437  }
2438  
2439  // ---- Inline asm (glue) ----
2440  
2441  func InlineAsm(t Type, asmString, constraints string, hasSideEffects, isAlignStack bool, dialect InlineAsmDialect, canThrow bool) Value {
2442  	if symGoGetInlineAsm == 0 {
2443  		return Value{}
2444  	}
2445  	casm := cString(asmString)
2446  	ccon := cString(constraints)
2447  	r, _, _ := purego.SyscallN(symGoGetInlineAsm, t.ref,
2448  		casm, uintptr(len(asmString)),
2449  		ccon, uintptr(len(constraints)),
2450  		boolToInt(hasSideEffects), boolToInt(isAlignStack),
2451  		uintptr(dialect), boolToInt(canThrow))
2452  	runtime.KeepAlive(asmString)
2453  	runtime.KeepAlive(constraints)
2454  	return Value{r}
2455  }
2456  
2457  // ---- Debug location (glue) ----
2458  
2459  func (b Builder) SetCurrentDebugLocation(line, col uint, scope, inlinedAt Metadata) {
2460  	if symGoSetCurrentDebugLocation == 0 {
2461  		return
2462  	}
2463  	purego.SyscallN(symGoSetCurrentDebugLocation, b.ref, uintptr(line), uintptr(col), scope.ref, inlinedAt.ref)
2464  }
2465  
2466  func (b Builder) GetCurrentDebugLocation() DebugLoc {
2467  	if symGoGetCurrentDebugLocation == 0 {
2468  		return DebugLoc{}
2469  	}
2470  	var dl [4]uintptr
2471  	purego.SyscallN(symGoGetCurrentDebugLocation, b.ref,
2472  		uintptr(unsafe.Pointer(&dl[0])),
2473  		uintptr(unsafe.Pointer(&dl[1])),
2474  		uintptr(unsafe.Pointer(&dl[2])),
2475  		uintptr(unsafe.Pointer(&dl[3])))
2476  	return DebugLoc{Line: uint(dl[0]), Col: uint(dl[1]), Scope: Metadata{dl[2]}, InlinedAt: Metadata{dl[3]}}
2477  }
2478  
2479  // ---- Module verify ----
2480  
2481  func (m Module) VerifyModule() error {
2482  	var msg uintptr
2483  	r, _, _ := purego.SyscallN(symVerifyModule, m.ref, 2, uintptr(unsafe.Pointer(&msg)))
2484  	if r != 0 {
2485  		s := goString(msg)
2486  		purego.SyscallN(symDisposeMessage, msg)
2487  		return fmt.Errorf("%s", s)
2488  	}
2489  	return nil
2490  }
2491  
2492  func (v Value) VerifyFunction() error {
2493  	r, _, _ := purego.SyscallN(symVerifyFunction, v.ref, 2)
2494  	if r != 0 {
2495  		return fmt.Errorf("function verification failed")
2496  	}
2497  	return nil
2498  }
2499  
2500  // ---- Comdat ----
2501  
2502  func (m Module) Comdat(name string) Comdat {
2503  	cname := cString(name)
2504  	r, _, _ := purego.SyscallN(symGetOrInsertComdat, m.ref, cname)
2505  	runtime.KeepAlive(name)
2506  	return Comdat{r}
2507  }
2508  
2509  func (c Comdat) SetSelectionKind(kind ComdatSelectionKind) {
2510  	purego.SyscallN(symComdatSetSelectionKind, c.ref, uintptr(kind))
2511  }
2512  
2513  func (v Value) SetComdat(c Comdat) {
2514  	purego.SyscallN(symSetComdat, v.ref, c.ref)
2515  }
2516