Imported Upstream version 5.18.0.161
Former-commit-id: 4db48158d3a35497b8f118ab21b5f08ac3d86d98
This commit is contained in:
parent
37fbf886a3
commit
e19d552987
@ -759,6 +759,9 @@
|
||||
/* Define to 1 if you have the `pthread_getattr_np' function. */
|
||||
#undef HAVE_PTHREAD_GETATTR_NP
|
||||
|
||||
/* Define to 1 if you have the `pthread_getname_np' function. */
|
||||
#undef HAVE_PTHREAD_GETNAME_NP
|
||||
|
||||
/* Define to 1 if you have the `pthread_get_stackaddr_np' function. */
|
||||
#undef HAVE_PTHREAD_GET_STACKADDR_NP
|
||||
|
||||
|
@ -1 +1 @@
|
||||
5113df261771724626d259406c2e4e814422a777
|
||||
03a3547c0c2a71c20a95455dfec5fde65e7ca0ce
|
@ -1 +1 @@
|
||||
9e1aa8c37142558ac64bb9f2641b629d74063e18
|
||||
6c39289f7d738d4a13dd3892766fe535d1a7dd5c
|
@ -22,7 +22,9 @@ namespace System.Text
|
||||
//
|
||||
// So if you change the wrappers in this class, you must change the wrappers in the other classes
|
||||
// as well because they should have the same behavior.
|
||||
|
||||
#if MONO
|
||||
[Serializable]
|
||||
#endif
|
||||
internal abstract class EncodingNLS : Encoding
|
||||
{
|
||||
protected EncodingNLS(int codePage) : base(codePage)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System.Text
|
||||
{
|
||||
@ -11,7 +12,12 @@ namespace System.Text
|
||||
// Latin1Encoding is a simple override to optimize the GetString version of Latin1Encoding.
|
||||
// because of the best fit cases we can't do this when encoding the string, only when decoding
|
||||
//
|
||||
#if MONO
|
||||
[Serializable]
|
||||
internal class Latin1Encoding : EncodingNLS, ISerializable
|
||||
#else
|
||||
internal class Latin1Encoding : EncodingNLS
|
||||
#endif
|
||||
{
|
||||
// Used by Encoding.Latin1 for lazy initialization
|
||||
// The initialization code will not be run until a static member of the class is referenced
|
||||
@ -22,6 +28,23 @@ namespace System.Text
|
||||
{
|
||||
}
|
||||
|
||||
#if MONO
|
||||
// ISerializable implementation, serialize it as a CodePageEncoding
|
||||
[System.Security.SecurityCritical] // auto-generated_required
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
// Make sure to get teh base stuff too This throws if info is null
|
||||
SerializeEncoding(info, context);
|
||||
|
||||
// In Everett this is a CodePageEncoding, so it needs maxCharSize
|
||||
info.AddValue("CodePageEncoding+maxCharSize", 1);
|
||||
|
||||
// And extras for Everett's wierdness
|
||||
info.AddValue("CodePageEncoding+m_codePage", this.CodePage);
|
||||
info.AddValue("CodePageEncoding+dataItem", null);
|
||||
}
|
||||
#endif
|
||||
|
||||
// GetByteCount
|
||||
// Note: We start by assuming that the output will be the same as count. Having
|
||||
// an encoder or fallback may change that assumption
|
||||
|
@ -31,7 +31,11 @@ namespace System.Collections.Generic.Tests
|
||||
Assert.False(comparer.Equals(EqualityComparer<Task<T>>.Default));
|
||||
}
|
||||
|
||||
#if MOBILE
|
||||
[Fact(Skip="Mono issue #10807")]
|
||||
#else
|
||||
[Fact]
|
||||
#endif
|
||||
public void EqualityComparer_EqualsShouldBeOverriddenAndWorkForDifferentInstances_cloned()
|
||||
{
|
||||
var comparer = EqualityComparer<T>.Default;
|
||||
|
3
external/llvm/.arcconfig
vendored
Normal file
3
external/llvm/.arcconfig
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"conduit_uri" : "https://reviews.llvm.org/"
|
||||
}
|
2
external/llvm/.clang-format
vendored
Normal file
2
external/llvm/.clang-format
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
BasedOnStyle: LLVM
|
||||
|
17
external/llvm/.clang-tidy
vendored
Normal file
17
external/llvm/.clang-tidy
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming'
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.ClassCase
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.EnumCase
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: camelBack
|
||||
- key: readability-identifier-naming.MemberCase
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.ParameterCase
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.UnionCase
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: CamelCase
|
||||
|
12
external/llvm/.gitattributes
vendored
Normal file
12
external/llvm/.gitattributes
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# binary files
|
||||
test/Object/Inputs/*.a-* binary
|
||||
test/tools/dsymutil/Inputs/* binary
|
||||
test/tools/llvm-ar/Inputs/*.lib binary
|
||||
test/tools/llvm-objdump/Inputs/*.a binary
|
||||
test/tools/llvm-rc/Inputs/* binary
|
||||
test/tools/llvm-strings/Inputs/numbers binary
|
||||
test/MC/AsmParser/incbin_abcd binary
|
||||
test/YAMLParser/spec-09-02.test binary
|
||||
|
||||
# Windows line ending test
|
||||
test/MC/AsmParser/preserve-comments-crlf.s text eol=crlf
|
76
external/llvm/.gitignore
vendored
Normal file
76
external/llvm/.gitignore
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
#==============================================================================#
|
||||
# This file specifies intentionally untracked files that git should ignore.
|
||||
# See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
|
||||
#
|
||||
# This file is intentionally different from the output of `git svn show-ignore`,
|
||||
# as most of those are useless.
|
||||
#==============================================================================#
|
||||
|
||||
#==============================================================================#
|
||||
# File extensions to be ignored anywhere in the tree.
|
||||
#==============================================================================#
|
||||
# Temp files created by most text editors.
|
||||
*~
|
||||
# Merge files created by git.
|
||||
*.orig
|
||||
# Byte compiled python modules.
|
||||
*.pyc
|
||||
# vim swap files
|
||||
.*.sw?
|
||||
.sw?
|
||||
#OS X specific files.
|
||||
.DS_store
|
||||
|
||||
# Nested build directory
|
||||
/build
|
||||
|
||||
#==============================================================================#
|
||||
# Explicit files to ignore (only matches one).
|
||||
#==============================================================================#
|
||||
# Various tag programs
|
||||
/tags
|
||||
/TAGS
|
||||
/GPATH
|
||||
/GRTAGS
|
||||
/GSYMS
|
||||
/GTAGS
|
||||
.gitusers
|
||||
autom4te.cache
|
||||
cscope.files
|
||||
cscope.out
|
||||
autoconf/aclocal.m4
|
||||
autoconf/autom4te.cache
|
||||
/compile_commands.json
|
||||
|
||||
#==============================================================================#
|
||||
# Directories to ignore (do not add trailing '/'s, they skip symlinks).
|
||||
#==============================================================================#
|
||||
# External projects that are tracked independently.
|
||||
projects/*
|
||||
!projects/*.*
|
||||
!projects/Makefile
|
||||
runtimes/*
|
||||
!runtimes/*.*
|
||||
# Clang, which is tracked independently.
|
||||
tools/clang
|
||||
# LLDB, which is tracked independently.
|
||||
tools/lldb
|
||||
# lld, which is tracked independently.
|
||||
tools/lld
|
||||
# llgo, which is tracked independently.
|
||||
tools/llgo
|
||||
# Polly, which is tracked independently.
|
||||
tools/polly
|
||||
# avrlit, which is tracked independently.
|
||||
tools/avrlit
|
||||
# Sphinx build tree, if building in-source dir.
|
||||
docs/_build
|
||||
# VS2017 and VSCode config files.
|
||||
.vscode
|
||||
.vs
|
||||
|
||||
#==============================================================================#
|
||||
# Files created in tree by the Go bindings.
|
||||
#==============================================================================#
|
||||
bindings/go/llvm/llvm_config.go
|
||||
bindings/go/llvm/workdir
|
1027
external/llvm/CMakeLists.txt
vendored
Normal file
1027
external/llvm/CMakeLists.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
215
external/llvm/CODE_OWNERS.TXT
vendored
Normal file
215
external/llvm/CODE_OWNERS.TXT
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
This file is a list of the people responsible for ensuring that patches for a
|
||||
particular part of LLVM are reviewed, either by themself or by someone else.
|
||||
They are also the gatekeepers for their part of LLVM, with the final word on
|
||||
what goes in or not.
|
||||
|
||||
The list is sorted by surname and formatted to allow easy grepping and
|
||||
beautification by scripts. The fields are: name (N), email (E), web-address
|
||||
(W), PGP key ID and fingerprint (P), description (D), snail-mail address
|
||||
(S) and (I) IRC handle. Each entry should contain at least the (N), (E) and
|
||||
(D) fields.
|
||||
|
||||
N: Justin Bogner
|
||||
E: mail@justinbogner.com
|
||||
D: InstrProfiling and related parts of ProfileData
|
||||
D: SelectionDAG (lib/CodeGen/SelectionDAG/*)
|
||||
|
||||
N: Alex Bradbury
|
||||
E: asb@lowrisc.org
|
||||
D: RISC-V backend (lib/Target/RISCV/*)
|
||||
|
||||
N: Matthias Braun
|
||||
E: matze@braunis.de
|
||||
I: MatzeB
|
||||
D: Instruction Scheduling
|
||||
|
||||
N: Chandler Carruth
|
||||
E: chandlerc@gmail.com
|
||||
E: chandlerc@google.com
|
||||
D: Config, ADT, Support, inlining & related passes, SROA/mem2reg & related passes, CMake, library layering
|
||||
|
||||
N: Evan Cheng
|
||||
E: evan.cheng@apple.com
|
||||
D: parts of code generator not covered by someone else
|
||||
|
||||
N: Eric Christopher
|
||||
E: echristo@gmail.com
|
||||
D: Debug Information, inline assembly
|
||||
|
||||
N: Andrey Churbanov
|
||||
E: andrey.churbanov@intel.com
|
||||
D: OpenMP runtime library
|
||||
|
||||
N: Greg Clayton
|
||||
E: clayborg@gmail.com
|
||||
D: LLDB
|
||||
|
||||
N: Pete Couperus
|
||||
E: petecoup@synopsys.com
|
||||
D: ARC backend (lib/Target/ARC/*)
|
||||
|
||||
N: Sanjoy Das
|
||||
E: sanjoy@playingwithpointers.com
|
||||
D: IndVar Simplify, Scalar Evolution
|
||||
|
||||
N: Marshall Clow
|
||||
E: mclow.lists@gmail.com
|
||||
D: libc++
|
||||
|
||||
N: Peter Collingbourne
|
||||
E: peter@pcc.me.uk
|
||||
D: llgo, libLTO (lib/LTO/* tools/lto/*), LLVM Bitcode (lib/Bitcode/* include/llvm/Bitcode/*)
|
||||
|
||||
N: Quentin Colombet
|
||||
E: qcolombet@apple.com
|
||||
D: Loop Strength Reduction, Register allocators
|
||||
|
||||
N: Simon Dardis
|
||||
E: simon.dardis@mips.com
|
||||
D: MIPS Backend (lib/Target/Mips/*)
|
||||
|
||||
N: Duncan P. N. Exon Smith
|
||||
E: dexonsmith@apple.com
|
||||
D: Branch weights and BlockFrequencyInfo
|
||||
|
||||
N: Hal Finkel
|
||||
E: hfinkel@anl.gov
|
||||
D: The loop reroller, alias analysis and the PowerPC target
|
||||
|
||||
N: Dan Gohman
|
||||
E: sunfish@mozilla.com
|
||||
D: WebAssembly Backend (lib/Target/WebAssembly/*)
|
||||
|
||||
N: Renato Golin
|
||||
E: renato.golin@linaro.org
|
||||
D: ARM Linux support
|
||||
|
||||
N: Venkatraman Govindaraju
|
||||
E: venkatra@cs.wisc.edu
|
||||
D: Sparc Backend (lib/Target/Sparc/*)
|
||||
|
||||
N: Tobias Grosser
|
||||
E: tobias@grosser.es
|
||||
D: Polly
|
||||
|
||||
N: James Grosbach
|
||||
E: grosbach@apple.com
|
||||
D: MC layer
|
||||
|
||||
N: Justin Holewinski
|
||||
E: jholewinski@nvidia.com
|
||||
D: NVPTX Target (lib/Target/NVPTX/*)
|
||||
|
||||
N: Lang Hames
|
||||
E: lhames@gmail.com
|
||||
D: MCJIT, RuntimeDyld and JIT event listeners, Orcish Warchief
|
||||
|
||||
N: Teresa Johnson
|
||||
E: tejohnson@google.com
|
||||
D: Gold plugin (tools/gold/*) and IR Linker
|
||||
|
||||
N: Galina Kistanova
|
||||
E: gkistanova@gmail.com
|
||||
D: LLVM Buildbot
|
||||
|
||||
N: Anton Korobeynikov
|
||||
E: anton@korobeynikov.info
|
||||
D: Exception handling, Windows codegen, ARM EABI
|
||||
|
||||
N: Benjamin Kramer
|
||||
E: benny.kra@gmail.com
|
||||
D: DWARF Parser
|
||||
|
||||
N: Michael Kuperstein
|
||||
E: mkuper@google.com
|
||||
D: Loop Vectorizer
|
||||
|
||||
N: Sergei Larin
|
||||
E: slarin@codeaurora.org
|
||||
D: VLIW Instruction Scheduling, Packetization
|
||||
|
||||
N: Chris Lattner
|
||||
E: sabre@nondot.org
|
||||
W: http://nondot.org/~sabre/
|
||||
D: Everything not covered by someone else
|
||||
|
||||
N: Robert Lytton
|
||||
E: robert@xmos.com
|
||||
D: XCore Backend
|
||||
|
||||
N: David Majnemer
|
||||
E: david.majnemer@gmail.com
|
||||
D: IR Constant Folder, InstCombine
|
||||
|
||||
N: Dylan McKay
|
||||
E: me@dylanmckay.io
|
||||
D: AVR Backend
|
||||
|
||||
N: Tim Northover
|
||||
E: t.p.northover@gmail.com
|
||||
D: AArch64 backend, misc ARM backend
|
||||
|
||||
N: Diego Novillo
|
||||
E: dnovillo@google.com
|
||||
D: SampleProfile and related parts of ProfileData
|
||||
|
||||
N: Jakob Olesen
|
||||
E: stoklund@2pi.dk
|
||||
D: TableGen
|
||||
|
||||
N: Krzysztof Parzyszek
|
||||
E: kparzysz@codeaurora.org
|
||||
D: Hexagon Backend
|
||||
|
||||
N: Jacques Pienaar
|
||||
E: jpienaar@google.com
|
||||
D: Lanai Backend
|
||||
|
||||
N: Paul Robinson
|
||||
E: paul_robinson@playstation.sony.com
|
||||
D: Sony PlayStation®4 support
|
||||
|
||||
N: Chad Rosier
|
||||
E: mcrosier@codeaurora.org
|
||||
D: Fast-Isel
|
||||
|
||||
N: Duncan Sands
|
||||
E: baldrick@free.fr
|
||||
D: DragonEgg
|
||||
|
||||
N: Kostya Serebryany
|
||||
E: kcc@google.com
|
||||
D: AddressSanitizer, ThreadSanitizer (LLVM parts)
|
||||
|
||||
N: Michael Spencer
|
||||
E: bigcheesegs@gmail.com
|
||||
D: Windows parts of Support, Object, ar, nm, objdump, ranlib, size
|
||||
|
||||
N: Alexei Starovoitov
|
||||
E: alexei.starovoitov@gmail.com
|
||||
D: BPF backend
|
||||
|
||||
N: Tom Stellard
|
||||
E: tstellar@redhat.com
|
||||
D: Stable release management (x.y.[1-9] releases), AMDGPU Backend, libclc
|
||||
|
||||
N: Evgeniy Stepanov
|
||||
E: eugenis@google.com
|
||||
D: MemorySanitizer (LLVM part)
|
||||
|
||||
N: Craig Topper
|
||||
E: craig.topper@gmail.com
|
||||
E: craig.topper@intel.com
|
||||
D: X86 Backend
|
||||
|
||||
N: Ulrich Weigand
|
||||
E: uweigand@de.ibm.com
|
||||
D: SystemZ Backend
|
||||
|
||||
N: Hans Wennborg
|
||||
E: hans@chromium.org
|
||||
D: Release management (x.y.0 releases)
|
||||
|
||||
N: whitequark
|
||||
E: whitequark@whitequark.org
|
||||
D: OCaml bindings
|
482
external/llvm/CREDITS.TXT
vendored
Normal file
482
external/llvm/CREDITS.TXT
vendored
Normal file
@ -0,0 +1,482 @@
|
||||
This file is a partial list of people who have contributed to the LLVM
|
||||
project. If you have contributed a patch or made some other contribution to
|
||||
LLVM, please submit a patch to this file to add yourself, and it will be
|
||||
done!
|
||||
|
||||
The list is sorted by surname and formatted to allow easy grepping and
|
||||
beautification by scripts. The fields are: name (N), email (E), web-address
|
||||
(W), PGP key ID and fingerprint (P), description (D), snail-mail address
|
||||
(S), and (I) IRC handle.
|
||||
|
||||
N: Vikram Adve
|
||||
E: vadve@cs.uiuc.edu
|
||||
W: http://www.cs.uiuc.edu/~vadve/
|
||||
D: The Sparc64 backend, provider of much wisdom, and motivator for LLVM
|
||||
|
||||
N: Owen Anderson
|
||||
E: resistor@mac.com
|
||||
D: LCSSA pass and related LoopUnswitch work
|
||||
D: GVNPRE pass, DataLayout refactoring, random improvements
|
||||
|
||||
N: Henrik Bach
|
||||
D: MingW Win32 API portability layer
|
||||
|
||||
N: Aaron Ballman
|
||||
E: aaron@aaronballman.com
|
||||
D: __declspec attributes, Windows support, general bug fixing
|
||||
|
||||
N: Nate Begeman
|
||||
E: natebegeman@mac.com
|
||||
D: PowerPC backend developer
|
||||
D: Target-independent code generator and analysis improvements
|
||||
|
||||
N: Daniel Berlin
|
||||
E: dberlin@dberlin.org
|
||||
D: ET-Forest implementation.
|
||||
D: Sparse bitmap
|
||||
|
||||
N: David Blaikie
|
||||
E: dblaikie@gmail.com
|
||||
D: General bug fixing/fit & finish, mostly in Clang
|
||||
|
||||
N: Neil Booth
|
||||
E: neil@daikokuya.co.uk
|
||||
D: APFloat implementation.
|
||||
|
||||
N: Alex Bradbury
|
||||
E: asb@lowrisc.org
|
||||
D: RISC-V backend
|
||||
|
||||
N: Misha Brukman
|
||||
E: brukman+llvm@uiuc.edu
|
||||
W: http://misha.brukman.net
|
||||
D: Portions of X86 and Sparc JIT compilers, PowerPC backend
|
||||
D: Incremental bitcode loader
|
||||
|
||||
N: Cameron Buschardt
|
||||
E: buschard@uiuc.edu
|
||||
D: The `mem2reg' pass - promotes values stored in memory to registers
|
||||
|
||||
N: Brendon Cahoon
|
||||
E: bcahoon@codeaurora.org
|
||||
D: Loop unrolling with run-time trip counts.
|
||||
|
||||
N: Chandler Carruth
|
||||
E: chandlerc@gmail.com
|
||||
E: chandlerc@google.com
|
||||
D: Hashing algorithms and interfaces
|
||||
D: Inline cost analysis
|
||||
D: Machine block placement pass
|
||||
D: SROA
|
||||
|
||||
N: Casey Carter
|
||||
E: ccarter@uiuc.edu
|
||||
D: Fixes to the Reassociation pass, various improvement patches
|
||||
|
||||
N: Evan Cheng
|
||||
E: evan.cheng@apple.com
|
||||
D: ARM and X86 backends
|
||||
D: Instruction scheduler improvements
|
||||
D: Register allocator improvements
|
||||
D: Loop optimizer improvements
|
||||
D: Target-independent code generator improvements
|
||||
|
||||
N: Dan Villiom Podlaski Christiansen
|
||||
E: danchr@gmail.com
|
||||
E: danchr@cs.au.dk
|
||||
W: http://villiom.dk
|
||||
D: LLVM Makefile improvements
|
||||
D: Clang diagnostic & driver tweaks
|
||||
S: Aarhus, Denmark
|
||||
|
||||
N: Jeff Cohen
|
||||
E: jeffc@jolt-lang.org
|
||||
W: http://jolt-lang.org
|
||||
D: Native Win32 API portability layer
|
||||
|
||||
N: John T. Criswell
|
||||
E: criswell@uiuc.edu
|
||||
D: Original Autoconf support, documentation improvements, bug fixes
|
||||
|
||||
N: Anshuman Dasgupta
|
||||
E: adasgupt@codeaurora.org
|
||||
D: Deterministic finite automaton based infrastructure for VLIW packetization
|
||||
|
||||
N: Stefanus Du Toit
|
||||
E: stefanus.du.toit@intel.com
|
||||
D: Bug fixes and minor improvements
|
||||
|
||||
N: Rafael Avila de Espindola
|
||||
E: rafael.espindola@gmail.com
|
||||
D: The ARM backend
|
||||
|
||||
N: Dave Estes
|
||||
E: cestes@codeaurora.org
|
||||
D: AArch64 machine description for Cortex-A53
|
||||
|
||||
N: Alkis Evlogimenos
|
||||
E: alkis@evlogimenos.com
|
||||
D: Linear scan register allocator, many codegen improvements, Java frontend
|
||||
|
||||
N: Hal Finkel
|
||||
E: hfinkel@anl.gov
|
||||
D: Basic-block autovectorization, PowerPC backend improvements
|
||||
|
||||
N: Eric Fiselier
|
||||
E: eric@efcs.ca
|
||||
D: LIT patches and documentation.
|
||||
|
||||
N: Ryan Flynn
|
||||
E: pizza@parseerror.com
|
||||
D: Miscellaneous bug fixes
|
||||
|
||||
N: Brian Gaeke
|
||||
E: gaeke@uiuc.edu
|
||||
W: http://www.students.uiuc.edu/~gaeke/
|
||||
D: Portions of X86 static and JIT compilers; initial SparcV8 backend
|
||||
D: Dynamic trace optimizer
|
||||
D: FreeBSD/X86 compatibility fixes, the llvm-nm tool
|
||||
|
||||
N: Nicolas Geoffray
|
||||
E: nicolas.geoffray@lip6.fr
|
||||
W: http://www-src.lip6.fr/homepages/Nicolas.Geoffray/
|
||||
D: PPC backend fixes for Linux
|
||||
|
||||
N: Louis Gerbarg
|
||||
E: lgg@apple.com
|
||||
D: Portions of the PowerPC backend
|
||||
|
||||
N: Saem Ghani
|
||||
E: saemghani@gmail.com
|
||||
D: Callgraph class cleanups
|
||||
|
||||
N: Mikhail Glushenkov
|
||||
E: foldr@codedgers.com
|
||||
D: Author of llvmc2
|
||||
|
||||
N: Dan Gohman
|
||||
E: sunfish@mozilla.com
|
||||
D: Miscellaneous bug fixes
|
||||
D: WebAssembly Backend
|
||||
|
||||
N: David Goodwin
|
||||
E: david@goodwinz.net
|
||||
D: Thumb-2 code generator
|
||||
|
||||
N: David Greene
|
||||
E: greened@obbligato.org
|
||||
D: Miscellaneous bug fixes
|
||||
D: Register allocation refactoring
|
||||
|
||||
N: Gabor Greif
|
||||
E: ggreif@gmail.com
|
||||
D: Improvements for space efficiency
|
||||
|
||||
N: James Grosbach
|
||||
E: grosbach@apple.com
|
||||
I: grosbach
|
||||
D: SjLj exception handling support
|
||||
D: General fixes and improvements for the ARM back-end
|
||||
D: MCJIT
|
||||
D: ARM integrated assembler and assembly parser
|
||||
D: Led effort for the backend formerly known as ARM64
|
||||
|
||||
N: Lang Hames
|
||||
E: lhames@gmail.com
|
||||
D: PBQP-based register allocator
|
||||
|
||||
N: Gordon Henriksen
|
||||
E: gordonhenriksen@mac.com
|
||||
D: Pluggable GC support
|
||||
D: C interface
|
||||
D: Ocaml bindings
|
||||
|
||||
N: Raul Fernandes Herbster
|
||||
E: raul@dsc.ufcg.edu.br
|
||||
D: JIT support for ARM
|
||||
|
||||
N: Paolo Invernizzi
|
||||
E: arathorn@fastwebnet.it
|
||||
D: Visual C++ compatibility fixes
|
||||
|
||||
N: Patrick Jenkins
|
||||
E: patjenk@wam.umd.edu
|
||||
D: Nightly Tester
|
||||
|
||||
N: Dale Johannesen
|
||||
E: dalej@apple.com
|
||||
D: ARM constant islands improvements
|
||||
D: Tail merging improvements
|
||||
D: Rewrite X87 back end
|
||||
D: Use APFloat for floating point constants widely throughout compiler
|
||||
D: Implement X87 long double
|
||||
|
||||
N: Brad Jones
|
||||
E: kungfoomaster@nondot.org
|
||||
D: Support for packed types
|
||||
|
||||
N: Rod Kay
|
||||
E: rkay@auroraux.org
|
||||
D: Author of LLVM Ada bindings
|
||||
|
||||
N: Eric Kidd
|
||||
W: http://randomhacks.net/
|
||||
D: llvm-config script
|
||||
|
||||
N: Anton Korobeynikov
|
||||
E: anton at korobeynikov dot info
|
||||
D: Mingw32 fixes, cross-compiling support, stdcall/fastcall calling conv.
|
||||
D: x86/linux PIC codegen, aliases, regparm/visibility attributes
|
||||
D: Switch lowering refactoring
|
||||
|
||||
N: Sumant Kowshik
|
||||
E: kowshik@uiuc.edu
|
||||
D: Author of the original C backend
|
||||
|
||||
N: Benjamin Kramer
|
||||
E: benny.kra@gmail.com
|
||||
D: Miscellaneous bug fixes
|
||||
|
||||
N: Sundeep Kushwaha
|
||||
E: sundeepk@codeaurora.org
|
||||
D: Implemented DFA-based target independent VLIW packetizer
|
||||
|
||||
N: Christopher Lamb
|
||||
E: christopher.lamb@gmail.com
|
||||
D: aligned load/store support, parts of noalias and restrict support
|
||||
D: vreg subreg infrastructure, X86 codegen improvements based on subregs
|
||||
D: address spaces
|
||||
|
||||
N: Jim Laskey
|
||||
E: jlaskey@apple.com
|
||||
D: Improvements to the PPC backend, instruction scheduling
|
||||
D: Debug and Dwarf implementation
|
||||
D: Auto upgrade mangler
|
||||
D: llvm-gcc4 svn wrangler
|
||||
|
||||
N: Chris Lattner
|
||||
E: sabre@nondot.org
|
||||
W: http://nondot.org/~sabre/
|
||||
D: Primary architect of LLVM
|
||||
|
||||
N: Tanya Lattner (Tanya Brethour)
|
||||
E: tonic@nondot.org
|
||||
W: http://nondot.org/~tonic/
|
||||
D: The initial llvm-ar tool, converted regression testsuite to dejagnu
|
||||
D: Modulo scheduling in the SparcV9 backend
|
||||
D: Release manager (1.7+)
|
||||
|
||||
N: Sylvestre Ledru
|
||||
E: sylvestre@debian.org
|
||||
W: http://sylvestre.ledru.info/
|
||||
W: http://apt.llvm.org/
|
||||
D: Debian and Ubuntu packaging
|
||||
D: Continuous integration with jenkins
|
||||
|
||||
N: Andrew Lenharth
|
||||
E: alenhar2@cs.uiuc.edu
|
||||
W: http://www.lenharth.org/~andrewl/
|
||||
D: Alpha backend
|
||||
D: Sampling based profiling
|
||||
|
||||
N: Nick Lewycky
|
||||
E: nicholas@mxc.ca
|
||||
D: PredicateSimplifier pass
|
||||
|
||||
N: Tony Linthicum, et. al.
|
||||
E: tlinth@codeaurora.org
|
||||
D: Backend for Qualcomm's Hexagon VLIW processor.
|
||||
|
||||
N: Bruno Cardoso Lopes
|
||||
E: bruno.cardoso@gmail.com
|
||||
I: bruno
|
||||
W: http://brunocardoso.cc
|
||||
D: Mips backend
|
||||
D: Random ARM integrated assembler and assembly parser improvements
|
||||
D: General X86 AVX1 support
|
||||
|
||||
N: Duraid Madina
|
||||
E: duraid@octopus.com.au
|
||||
W: http://kinoko.c.u-tokyo.ac.jp/~duraid/
|
||||
D: IA64 backend, BigBlock register allocator
|
||||
|
||||
N: John McCall
|
||||
E: rjmccall@apple.com
|
||||
D: Clang semantic analysis and IR generation
|
||||
|
||||
N: Michael McCracken
|
||||
E: michael.mccracken@gmail.com
|
||||
D: Line number support for llvmgcc
|
||||
|
||||
N: Vladimir Merzliakov
|
||||
E: wanderer@rsu.ru
|
||||
D: Test suite fixes for FreeBSD
|
||||
|
||||
N: Scott Michel
|
||||
E: scottm@aero.org
|
||||
D: Added STI Cell SPU backend.
|
||||
|
||||
N: Kai Nacke
|
||||
E: kai@redstar.de
|
||||
D: Support for implicit TLS model used with MS VC runtime
|
||||
D: Dumping of Win64 EH structures
|
||||
|
||||
N: Takumi Nakamura
|
||||
I: chapuni
|
||||
E: geek4civic@gmail.com
|
||||
E: chapuni@hf.rim.or.jp
|
||||
D: Maintaining the Git monorepo
|
||||
W: https://github.com/llvm-project/
|
||||
S: Ebina, Japan
|
||||
|
||||
N: Edward O'Callaghan
|
||||
E: eocallaghan@auroraux.org
|
||||
W: http://www.auroraux.org
|
||||
D: Add Clang support with various other improvements to utils/NewNightlyTest.pl
|
||||
D: Fix and maintain Solaris & AuroraUX support for llvm, various build warnings
|
||||
D: and error clean ups.
|
||||
|
||||
N: Morten Ofstad
|
||||
E: morten@hue.no
|
||||
D: Visual C++ compatibility fixes
|
||||
|
||||
N: Jakob Stoklund Olesen
|
||||
E: stoklund@2pi.dk
|
||||
D: Machine code verifier
|
||||
D: Blackfin backend
|
||||
D: Fast register allocator
|
||||
D: Greedy register allocator
|
||||
|
||||
N: Richard Osborne
|
||||
E: richard@xmos.com
|
||||
D: XCore backend
|
||||
|
||||
N: Piotr Padlewski
|
||||
E: piotr.padlewski@gmail.com
|
||||
D: !invariant.group metadata and other intrinsics for devirtualization in clang
|
||||
|
||||
N: Devang Patel
|
||||
E: dpatel@apple.com
|
||||
D: LTO tool, PassManager rewrite, Loop Pass Manager, Loop Rotate
|
||||
D: GCC PCH Integration (llvm-gcc), llvm-gcc improvements
|
||||
D: Optimizer improvements, Loop Index Split
|
||||
|
||||
N: Ana Pazos
|
||||
E: apazos@codeaurora.org
|
||||
D: Fixes and improvements to the AArch64 backend
|
||||
|
||||
N: Wesley Peck
|
||||
E: peckw@wesleypeck.com
|
||||
W: http://wesleypeck.com/
|
||||
D: MicroBlaze backend
|
||||
|
||||
N: Francois Pichet
|
||||
E: pichet2000@gmail.com
|
||||
D: MSVC support
|
||||
|
||||
N: Adrian Prantl
|
||||
E: aprantl@apple.com
|
||||
D: Debug Information
|
||||
|
||||
N: Vladimir Prus
|
||||
W: http://vladimir_prus.blogspot.com
|
||||
E: ghost@cs.msu.su
|
||||
D: Made inst_iterator behave like a proper iterator, LowerConstantExprs pass
|
||||
|
||||
N: Kalle Raiskila
|
||||
E: kalle.rasikila@nokia.com
|
||||
D: Some bugfixes to CellSPU
|
||||
|
||||
N: Xerxes Ranby
|
||||
E: xerxes@zafena.se
|
||||
D: Cmake dependency chain and various bug fixes
|
||||
|
||||
N: Alex Rosenberg
|
||||
E: alexr@leftfield.org
|
||||
I: arosenberg
|
||||
D: ARM calling conventions rewrite, hard float support
|
||||
|
||||
N: Chad Rosier
|
||||
E: mcrosier@codeaurora.org
|
||||
I: mcrosier
|
||||
D: AArch64 fast instruction selection pass
|
||||
D: Fixes and improvements to the ARM fast-isel pass
|
||||
D: Fixes and improvements to the AArch64 backend
|
||||
|
||||
N: Nadav Rotem
|
||||
E: nadav.rotem@me.com
|
||||
D: X86 code generation improvements, Loop Vectorizer, SLP Vectorizer
|
||||
|
||||
N: Roman Samoilov
|
||||
E: roman@codedgers.com
|
||||
D: MSIL backend
|
||||
|
||||
N: Duncan Sands
|
||||
E: baldrick@free.fr
|
||||
I: baldrick
|
||||
D: Ada support in llvm-gcc
|
||||
D: Dragonegg plugin
|
||||
D: Exception handling improvements
|
||||
D: Type legalizer rewrite
|
||||
|
||||
N: Ruchira Sasanka
|
||||
E: sasanka@uiuc.edu
|
||||
D: Graph coloring register allocator for the Sparc64 backend
|
||||
|
||||
N: Arnold Schwaighofer
|
||||
E: arnold.schwaighofer@gmail.com
|
||||
D: Tail call optimization for the x86 backend
|
||||
|
||||
N: Shantonu Sen
|
||||
E: ssen@apple.com
|
||||
D: Miscellaneous bug fixes
|
||||
|
||||
N: Anand Shukla
|
||||
E: ashukla@cs.uiuc.edu
|
||||
D: The `paths' pass
|
||||
|
||||
N: Michael J. Spencer
|
||||
E: bigcheesegs@gmail.com
|
||||
D: Shepherding Windows COFF support into MC.
|
||||
D: Lots of Windows stuff.
|
||||
|
||||
N: Reid Spencer
|
||||
E: rspencer@reidspencer.com
|
||||
W: http://reidspencer.com/
|
||||
D: Lots of stuff, see: http://wiki.llvm.org/index.php/User:Reid
|
||||
|
||||
N: Alp Toker
|
||||
E: alp@nuanti.com
|
||||
W: http://atoker.com/
|
||||
D: C++ frontend next generation standards implementation
|
||||
|
||||
N: Craig Topper
|
||||
E: craig.topper@gmail.com
|
||||
D: X86 codegen and disassembler improvements. AVX2 support.
|
||||
|
||||
N: Edwin Torok
|
||||
E: edwintorok@gmail.com
|
||||
D: Miscellaneous bug fixes
|
||||
|
||||
N: Adam Treat
|
||||
E: manyoso@yahoo.com
|
||||
D: C++ bugs filed, and C++ front-end bug fixes.
|
||||
|
||||
N: Andrew Trick
|
||||
E: atrick@apple.com
|
||||
D: Instruction Scheduling, ...
|
||||
|
||||
N: Lauro Ramos Venancio
|
||||
E: lauro.venancio@indt.org.br
|
||||
D: ARM backend improvements
|
||||
D: Thread Local Storage implementation
|
||||
|
||||
N: Bill Wendling
|
||||
I: wendling
|
||||
E: isanbard@gmail.com
|
||||
D: Release manager, IR Linker, LTO
|
||||
D: Bunches of stuff
|
||||
|
||||
N: Bob Wilson
|
||||
E: bob.wilson@acm.org
|
||||
D: Advanced SIMD (NEON) support in the ARM backend.
|
68
external/llvm/LICENSE.TXT
vendored
Normal file
68
external/llvm/LICENSE.TXT
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
==============================================================================
|
||||
LLVM Release License
|
||||
==============================================================================
|
||||
University of Illinois/NCSA
|
||||
Open Source License
|
||||
|
||||
Copyright (c) 2003-2017 University of Illinois at Urbana-Champaign.
|
||||
All rights reserved.
|
||||
|
||||
Developed by:
|
||||
|
||||
LLVM Team
|
||||
|
||||
University of Illinois at Urbana-Champaign
|
||||
|
||||
http://llvm.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal with
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimers.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimers in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the LLVM Team, University of Illinois at
|
||||
Urbana-Champaign, nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this Software without specific
|
||||
prior written permission.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
||||
SOFTWARE.
|
||||
|
||||
==============================================================================
|
||||
Copyrights and Licenses for Third Party Software Distributed with LLVM:
|
||||
==============================================================================
|
||||
The LLVM software contains code written by third parties. Such software will
|
||||
have its own individual LICENSE.TXT file in the directory in which it appears.
|
||||
This file will describe the copyrights, license, and restrictions which apply
|
||||
to that code.
|
||||
|
||||
The disclaimer of warranty in the University of Illinois Open Source License
|
||||
applies to all code in the LLVM Distribution, and nothing in any of the
|
||||
other licenses gives permission to use the names of the LLVM Team or the
|
||||
University of Illinois to endorse or promote products derived from this
|
||||
Software.
|
||||
|
||||
The following pieces of software have additional or alternate copyrights,
|
||||
licenses, and/or restrictions:
|
||||
|
||||
Program Directory
|
||||
------- ---------
|
||||
Google Test llvm/utils/unittest/googletest
|
||||
OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex}
|
||||
pyyaml tests llvm/test/YAMLParser/{*.data, LICENSE.TXT}
|
||||
ARM contributions llvm/lib/Target/ARM/LICENSE.TXT
|
||||
md5 contributions llvm/lib/Support/MD5.cpp llvm/include/llvm/Support/MD5.h
|
24
external/llvm/LLVMBuild.txt
vendored
Normal file
24
external/llvm/LLVMBuild.txt
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
;===- ./LLVMBuild.txt ------------------------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[common]
|
||||
subdirectories = bindings docs examples lib projects tools utils
|
||||
|
||||
[component_0]
|
||||
type = Group
|
||||
name = Miscellaneous
|
||||
parent = $ROOT
|
19
external/llvm/README.txt
vendored
Normal file
19
external/llvm/README.txt
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Low Level Virtual Machine (LLVM)
|
||||
================================
|
||||
|
||||
This directory and its subdirectories contain source code for LLVM,
|
||||
a toolkit for the construction of highly optimized compilers,
|
||||
optimizers, and runtime environments.
|
||||
|
||||
LLVM is open source software. You may freely distribute it under the terms of
|
||||
the license agreement found in LICENSE.txt.
|
||||
|
||||
Please see the documentation provided in docs/ for further
|
||||
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
|
||||
started with LLVM and docs/README.txt for an overview of LLVM's
|
||||
documentation setup.
|
||||
|
||||
If you are writing a package for LLVM, see docs/Packaging.rst for our
|
||||
suggestions.
|
||||
|
||||
|
52
external/llvm/RELEASE_TESTERS.TXT
vendored
Normal file
52
external/llvm/RELEASE_TESTERS.TXT
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
This file is a list of the people responsible for ensuring that targets and
|
||||
environments get tested and validated during the release process.
|
||||
|
||||
They will also, in conjunction with the release manager and the code owners,
|
||||
accept patches into stable release branches, tag critical bugs and release
|
||||
stoppers as well as make sure that no regressions were observed on their
|
||||
targets since the last release.
|
||||
|
||||
N: Ben Pope
|
||||
E: benpope81@gmail.com
|
||||
T: x86
|
||||
O: Ubuntu
|
||||
|
||||
N: Sylvestre Ledru
|
||||
E: sylvestre@debian.org
|
||||
T: x86
|
||||
O: Debian
|
||||
|
||||
N: Nikola Smiljanic
|
||||
E: popizdeh@gmail.com
|
||||
T: x86
|
||||
O: OpenSUSE, Fedora
|
||||
|
||||
N: Brian Cain
|
||||
E: brian.cain@gmail.com
|
||||
T: x86
|
||||
O: SuSE Enterprise, CentOS
|
||||
|
||||
N: Bernhard Rosenkränzer
|
||||
E: bero@linaro.org
|
||||
T: x86
|
||||
O: OpenMandriva
|
||||
|
||||
N: Dimitry Andric
|
||||
E: dimitry@andric.com
|
||||
T: x86
|
||||
O: FreeBSD
|
||||
|
||||
N: Hans Wennborg
|
||||
E: hans@chromium.org
|
||||
T: x86
|
||||
O: Windows
|
||||
|
||||
N: Diana Picus
|
||||
E: diana.picus@linaro.org
|
||||
T: ARM, AArch64
|
||||
O: Linux
|
||||
|
||||
N: Simon Dardis
|
||||
E: simon.dardis@mips.com
|
||||
T: MIPS
|
||||
O: Linux
|
21
external/llvm/bindings/LLVMBuild.txt
vendored
Normal file
21
external/llvm/bindings/LLVMBuild.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
;===- ./bindings/LLVMBuild.txt ---------------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Group
|
||||
name = Bindings
|
||||
parent = $ROOT
|
3
external/llvm/bindings/README.txt
vendored
Normal file
3
external/llvm/bindings/README.txt
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
This directory contains bindings for the LLVM compiler infrastructure to allow
|
||||
programs written in languages other than C or C++ to take advantage of the LLVM
|
||||
infrastructure--for instance, a self-hosted compiler front-end.
|
61
external/llvm/bindings/go/README.txt
vendored
Normal file
61
external/llvm/bindings/go/README.txt
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
This directory contains LLVM bindings for the Go programming language
|
||||
(http://golang.org).
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
* Go 1.2+.
|
||||
* CMake (to build LLVM).
|
||||
|
||||
Using the bindings
|
||||
------------------
|
||||
|
||||
The package path "llvm.org/llvm/bindings/go/llvm" can be used to
|
||||
import the latest development version of LLVM from SVN. Paths such as
|
||||
"llvm.org/llvm.v36/bindings/go/llvm" refer to released versions of LLVM.
|
||||
|
||||
It is recommended to use the "-d" flag with "go get" to download the
|
||||
package or a dependency, as an additional step is required to build LLVM
|
||||
(see "Building LLVM" below).
|
||||
|
||||
Building LLVM
|
||||
-------------
|
||||
|
||||
The script "build.sh" in this directory can be used to build LLVM and prepare
|
||||
it to be used by the bindings. If you receive an error message from "go build"
|
||||
like this:
|
||||
|
||||
./analysis.go:4:84: fatal error: llvm-c/Analysis.h: No such file or directory
|
||||
#include <llvm-c/Analysis.h> // If you are getting an error here read bindings/go/README.txt
|
||||
|
||||
or like this:
|
||||
|
||||
./llvm_dep.go:5: undefined: run_build_sh
|
||||
|
||||
it means that LLVM needs to be built or updated by running the script.
|
||||
|
||||
$ $GOPATH/src/llvm.org/llvm/bindings/go/build.sh
|
||||
|
||||
Any command line arguments supplied to the script are passed to LLVM's CMake
|
||||
build system. A good set of arguments to use during development are:
|
||||
|
||||
$ $GOPATH/src/llvm.org/llvm/bindings/go/build.sh -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD=host -DBUILD_SHARED_LIBS=ON
|
||||
|
||||
Note that CMake keeps a cache of build settings so once you have built
|
||||
LLVM there is no need to pass these arguments again after updating.
|
||||
|
||||
Alternatively, you can build LLVM yourself, but you must then set the
|
||||
CGO_CPPFLAGS, CGO_CXXFLAGS and CGO_LDFLAGS environment variables:
|
||||
|
||||
$ export CGO_CPPFLAGS="`/path/to/llvm-build/bin/llvm-config --cppflags`"
|
||||
$ export CGO_CXXFLAGS=-std=c++11
|
||||
$ export CGO_LDFLAGS="`/path/to/llvm-build/bin/llvm-config --ldflags --libs --system-libs all`"
|
||||
$ go build -tags byollvm
|
||||
|
||||
If you see a compilation error while compiling your code with Go 1.9.4 or later as follows,
|
||||
|
||||
go build llvm.org/llvm/bindings/go/llvm: invalid flag in #cgo LDFLAGS: -Wl,-headerpad_max_install_names
|
||||
|
||||
you need to setup $CGO_LDFLAGS_ALLOW to allow a compiler to specify some linker options:
|
||||
|
||||
$ export CGO_LDFLAGS_ALLOW='-Wl,(-search_paths_first|-headerpad_max_install_names)'
|
28
external/llvm/bindings/go/build.sh
vendored
Executable file
28
external/llvm/bindings/go/build.sh
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh -xe
|
||||
|
||||
gollvmdir=$(dirname "$0")/llvm
|
||||
|
||||
workdir=$gollvmdir/workdir
|
||||
llvmdir=$gollvmdir/../../..
|
||||
llvm_builddir=$workdir/llvm_build
|
||||
|
||||
mkdir -p $llvm_builddir
|
||||
|
||||
cmake_flags="../../../../.. $@"
|
||||
llvm_config="$llvm_builddir/bin/llvm-config"
|
||||
llvm_go="$llvm_builddir/bin/llvm-go"
|
||||
|
||||
if test -n "`which ninja`" ; then
|
||||
# If Ninja is available, we can speed up the build by building only the
|
||||
# required subset of LLVM.
|
||||
(cd $llvm_builddir && cmake -G Ninja $cmake_flags)
|
||||
ninja -C $llvm_builddir llvm-config llvm-go
|
||||
llvm_components="$($llvm_go print-components)"
|
||||
llvm_buildtargets="$($llvm_config --libs $llvm_components | sed -e 's/-l//g')"
|
||||
ninja -C $llvm_builddir $llvm_buildtargets FileCheck
|
||||
else
|
||||
(cd $llvm_builddir && cmake $cmake_flags)
|
||||
make -C $llvm_builddir -j4
|
||||
fi
|
||||
|
||||
$llvm_go print-config > $gollvmdir/llvm_config.go
|
16
external/llvm/bindings/go/conftest.go
vendored
Normal file
16
external/llvm/bindings/go/conftest.go
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"go/build"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Tests that the Go compiler is at least version 1.2.
|
||||
func main() {
|
||||
for _, tag := range build.Default.ReleaseTags {
|
||||
if tag == "go1.2" {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
234
external/llvm/bindings/go/llvm/DIBuilderBindings.cpp
vendored
Normal file
234
external/llvm/bindings/go/llvm/DIBuilderBindings.cpp
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
//===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines C bindings for the DIBuilder class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "DIBuilderBindings.h"
|
||||
#include "IRBindings.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef mref) {
|
||||
Module *m = unwrap(mref);
|
||||
return wrap(new DIBuilder(*m));
|
||||
}
|
||||
|
||||
void LLVMDIBuilderDestroy(LLVMDIBuilderRef dref) {
|
||||
DIBuilder *d = unwrap(dref);
|
||||
delete d;
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef File,
|
||||
unsigned Line,
|
||||
unsigned Column) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
auto *LB = D->createLexicalBlock(unwrap<DILocalScope>(Scope),
|
||||
unwrap<DIFile>(File), Line, Column);
|
||||
return wrap(LB);
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef File,
|
||||
unsigned Discriminator) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createLexicalBlockFile(unwrap<DILocalScope>(Scope),
|
||||
unwrap<DIFile>(File), Discriminator));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateFunction(
|
||||
LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
|
||||
const char *LinkageName, LLVMMetadataRef File, unsigned Line,
|
||||
LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
|
||||
unsigned ScopeLine, unsigned Flags, int IsOptimized) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createFunction(
|
||||
unwrap<DIScope>(Scope), Name, LinkageName,
|
||||
File ? unwrap<DIFile>(File) : nullptr, Line,
|
||||
unwrap<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
|
||||
ScopeLine, static_cast<DINode::DIFlags>(Flags), IsOptimized));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
|
||||
LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve,
|
||||
unsigned Flags, uint32_t AlignInBits) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(
|
||||
D->createAutoVariable(unwrap<DIScope>(Scope), Name, unwrap<DIFile>(File),
|
||||
Line, unwrap<DIType>(Ty), AlwaysPreserve,
|
||||
static_cast<DINode::DIFlags>(Flags), AlignInBits));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
|
||||
LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
|
||||
unsigned ArgNo, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
|
||||
int AlwaysPreserve, unsigned Flags) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createParameterVariable(
|
||||
unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File), Line,
|
||||
unwrap<DIType>(Ty), AlwaysPreserve, static_cast<DINode::DIFlags>(Flags)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
|
||||
const char *Name,
|
||||
uint64_t SizeInBits,
|
||||
unsigned Encoding) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createBasicType(Name, SizeInBits, Encoding));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef PointeeType,
|
||||
uint64_t SizeInBits,
|
||||
uint32_t AlignInBits,
|
||||
const char *Name) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits,
|
||||
AlignInBits, /* DWARFAddressSpace */ None,
|
||||
Name));
|
||||
}
|
||||
|
||||
LLVMMetadataRef
|
||||
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
|
||||
LLVMMetadataRef ParameterTypes) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(
|
||||
D->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateStructType(
|
||||
LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
|
||||
uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
|
||||
LLVMMetadataRef ElementTypes) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createStructType(
|
||||
unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line,
|
||||
SizeInBits, AlignInBits, static_cast<DINode::DIFlags>(Flags),
|
||||
DerivedFrom ? unwrap<DIType>(DerivedFrom) : nullptr,
|
||||
ElementTypes ? DINodeArray(unwrap<MDTuple>(ElementTypes)) : nullptr));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
|
||||
LLVMDIBuilderRef Dref, unsigned Tag, const char *Name,
|
||||
LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
|
||||
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
||||
unsigned Flags) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createReplaceableCompositeType(
|
||||
Tag, Name, unwrap<DIScope>(Scope), File ? unwrap<DIFile>(File) : nullptr,
|
||||
Line, RuntimeLang, SizeInBits, AlignInBits,
|
||||
static_cast<DINode::DIFlags>(Flags)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef
|
||||
LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
|
||||
const char *Name, LLVMMetadataRef File,
|
||||
unsigned Line, uint64_t SizeInBits,
|
||||
uint32_t AlignInBits, uint64_t OffsetInBits,
|
||||
unsigned Flags, LLVMMetadataRef Ty) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createMemberType(
|
||||
unwrap<DIScope>(Scope), Name, File ? unwrap<DIFile>(File) : nullptr, Line,
|
||||
SizeInBits, AlignInBits, OffsetInBits,
|
||||
static_cast<DINode::DIFlags>(Flags), unwrap<DIType>(Ty)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
|
||||
uint64_t SizeInBits,
|
||||
uint32_t AlignInBits,
|
||||
LLVMMetadataRef ElementType,
|
||||
LLVMMetadataRef Subscripts) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createArrayType(SizeInBits, AlignInBits,
|
||||
unwrap<DIType>(ElementType),
|
||||
DINodeArray(unwrap<MDTuple>(Subscripts))));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef Ty, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line,
|
||||
LLVMMetadataRef Context) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createTypedef(unwrap<DIType>(Ty), Name,
|
||||
File ? unwrap<DIFile>(File) : nullptr, Line,
|
||||
Context ? unwrap<DIScope>(Context) : nullptr));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
|
||||
int64_t Lo, int64_t Count) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->getOrCreateSubrange(Lo, Count));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef *Data,
|
||||
size_t Length) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
Metadata **DataValue = unwrap(Data);
|
||||
ArrayRef<Metadata *> Elements(DataValue, Length);
|
||||
DINodeArray A = D->getOrCreateArray(Elements);
|
||||
return wrap(A.get());
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
|
||||
LLVMMetadataRef *Data,
|
||||
size_t Length) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
Metadata **DataValue = unwrap(Data);
|
||||
ArrayRef<Metadata *> Elements(DataValue, Length);
|
||||
DITypeRefArray A = D->getOrCreateTypeArray(Elements);
|
||||
return wrap(A.get());
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
|
||||
int64_t *Addr, size_t Length) {
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
return wrap(D->createExpression(ArrayRef<int64_t>(Addr, Length)));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
|
||||
LLVMValueRef Storage,
|
||||
LLVMMetadataRef VarInfo,
|
||||
LLVMMetadataRef Expr,
|
||||
LLVMBasicBlockRef Block) {
|
||||
// Fail immediately here until the llgo folks update their bindings. The
|
||||
// called function is going to assert out anyway.
|
||||
llvm_unreachable("DIBuilder API change requires a DebugLoc");
|
||||
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
Instruction *Instr = D->insertDeclare(
|
||||
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
|
||||
unwrap<DIExpression>(Expr), /* DebugLoc */ nullptr, unwrap(Block));
|
||||
return wrap(Instr);
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
|
||||
LLVMValueRef Val,
|
||||
LLVMMetadataRef VarInfo,
|
||||
LLVMMetadataRef Expr,
|
||||
LLVMBasicBlockRef Block) {
|
||||
// Fail immediately here until the llgo folks update their bindings. The
|
||||
// called function is going to assert out anyway.
|
||||
llvm_unreachable("DIBuilder API change requires a DebugLoc");
|
||||
|
||||
DIBuilder *D = unwrap(Dref);
|
||||
Instruction *Instr = D->insertDbgValueIntrinsic(
|
||||
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
|
||||
/* DebugLoc */ nullptr, unwrap(Block));
|
||||
return wrap(Instr);
|
||||
}
|
134
external/llvm/bindings/go/llvm/DIBuilderBindings.h
vendored
Normal file
134
external/llvm/bindings/go/llvm/DIBuilderBindings.h
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
//===- DIBuilderBindings.h - Bindings for DIBuilder -------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines C bindings for the DIBuilder class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H
|
||||
#define LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H
|
||||
|
||||
#include "IRBindings.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/DebugInfo.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FIXME: These bindings shouldn't be Go-specific and should eventually move to
|
||||
// a (somewhat) less stable collection of C APIs for use in creating bindings of
|
||||
// LLVM in other languages.
|
||||
|
||||
typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
|
||||
|
||||
LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m);
|
||||
|
||||
void LLVMDIBuilderDestroy(LLVMDIBuilderRef d);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef File,
|
||||
unsigned Line, unsigned Column);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef File,
|
||||
unsigned Discriminator);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateFunction(
|
||||
LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
|
||||
const char *LinkageName, LLVMMetadataRef File, unsigned Line,
|
||||
LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
|
||||
unsigned ScopeLine, unsigned Flags, int IsOptimized);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
|
||||
LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve,
|
||||
unsigned Flags, uint32_t AlignInBits);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
|
||||
LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, unsigned ArgNo,
|
||||
LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve,
|
||||
unsigned Flags);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef D,
|
||||
const char *Name,
|
||||
uint64_t SizeInBits,
|
||||
unsigned Encoding);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef PointeeType,
|
||||
uint64_t SizeInBits,
|
||||
uint32_t AlignInBits,
|
||||
const char *Name);
|
||||
|
||||
LLVMMetadataRef
|
||||
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef D, LLVMMetadataRef File,
|
||||
LLVMMetadataRef ParameterTypes);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateStructType(
|
||||
LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line, uint64_t SizeInBits,
|
||||
uint32_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
|
||||
LLVMMetadataRef ElementTypes);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
|
||||
LLVMDIBuilderRef D, unsigned Tag, const char *Name, LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang,
|
||||
uint64_t SizeInBits, uint32_t AlignInBits, unsigned Flags);
|
||||
|
||||
LLVMMetadataRef
|
||||
LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef D, LLVMMetadataRef Scope,
|
||||
const char *Name, LLVMMetadataRef File,
|
||||
unsigned Line, uint64_t SizeInBits,
|
||||
uint32_t AlignInBits, uint64_t OffsetInBits,
|
||||
unsigned Flags, LLVMMetadataRef Ty);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef D,
|
||||
uint64_t SizeInBits,
|
||||
uint32_t AlignInBits,
|
||||
LLVMMetadataRef ElementType,
|
||||
LLVMMetadataRef Subscripts);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef Ty, const char *Name,
|
||||
LLVMMetadataRef File, unsigned Line,
|
||||
LLVMMetadataRef Context);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef D, int64_t Lo,
|
||||
int64_t Count);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef *Data,
|
||||
size_t Length);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef D,
|
||||
LLVMMetadataRef *Data,
|
||||
size_t Length);
|
||||
|
||||
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
|
||||
int64_t *Addr, size_t Length);
|
||||
|
||||
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef D,
|
||||
LLVMValueRef Storage,
|
||||
LLVMMetadataRef VarInfo,
|
||||
LLVMMetadataRef Expr,
|
||||
LLVMBasicBlockRef Block);
|
||||
|
||||
LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val,
|
||||
LLVMMetadataRef VarInfo,
|
||||
LLVMMetadataRef Expr,
|
||||
LLVMBasicBlockRef Block);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
89
external/llvm/bindings/go/llvm/IRBindings.cpp
vendored
Normal file
89
external/llvm/bindings/go/llvm/IRBindings.cpp
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
//===- IRBindings.cpp - Additional bindings for ir ------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines additional C bindings for the ir component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "IRBindings.h"
|
||||
#include "llvm/IR/Attributes.h"
|
||||
#include "llvm/IR/DebugLoc.h"
|
||||
#include "llvm/IR/DebugInfoMetadata.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef C) {
|
||||
return wrap(ConstantAsMetadata::get(unwrap<Constant>(C)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) {
|
||||
return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
|
||||
unsigned Count) {
|
||||
return wrap(
|
||||
MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
|
||||
}
|
||||
|
||||
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
|
||||
unsigned Count) {
|
||||
return wrap(MDTuple::getTemporary(*unwrap(C),
|
||||
ArrayRef<Metadata *>(unwrap(MDs), Count))
|
||||
.release());
|
||||
}
|
||||
|
||||
void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
|
||||
LLVMMetadataRef Val) {
|
||||
NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
|
||||
if (!N)
|
||||
return;
|
||||
if (!Val)
|
||||
return;
|
||||
N->addOperand(unwrap<MDNode>(Val));
|
||||
}
|
||||
|
||||
void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
|
||||
MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
|
||||
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
|
||||
}
|
||||
|
||||
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
|
||||
auto *Node = unwrap<MDNode>(MD);
|
||||
Node->replaceAllUsesWith(unwrap<Metadata>(New));
|
||||
MDNode::deleteTemporary(Node);
|
||||
}
|
||||
|
||||
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
|
||||
unsigned Col, LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef InlinedAt) {
|
||||
unwrap(Bref)->SetCurrentDebugLocation(
|
||||
DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
|
||||
InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));
|
||||
}
|
||||
|
||||
LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref) {
|
||||
const auto& Loc = unwrap(Bref)->getCurrentDebugLocation();
|
||||
const auto* InlinedAt = Loc.getInlinedAt();
|
||||
const LLVMDebugLocMetadata md{
|
||||
Loc.getLine(),
|
||||
Loc.getCol(),
|
||||
wrap(Loc.getScope()),
|
||||
InlinedAt == nullptr ? nullptr : wrap(InlinedAt->getRawInlinedAt()),
|
||||
};
|
||||
return md;
|
||||
}
|
||||
|
||||
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
|
||||
unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
|
||||
}
|
63
external/llvm/bindings/go/llvm/IRBindings.h
vendored
Normal file
63
external/llvm/bindings/go/llvm/IRBindings.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
//===- IRBindings.h - Additional bindings for IR ----------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines additional C bindings for the IR component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_BINDINGS_GO_LLVM_IRBINDINGS_H
|
||||
#define LLVM_BINDINGS_GO_LLVM_IRBINDINGS_H
|
||||
|
||||
#include "llvm-c/Core.h"
|
||||
#ifdef __cplusplus
|
||||
#include "llvm/IR/Metadata.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct LLVMDebugLocMetadata{
|
||||
unsigned Line;
|
||||
unsigned Col;
|
||||
LLVMMetadataRef Scope;
|
||||
LLVMMetadataRef InlinedAt;
|
||||
};
|
||||
|
||||
LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef Val);
|
||||
|
||||
LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen);
|
||||
LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
|
||||
unsigned Count);
|
||||
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
|
||||
unsigned Count);
|
||||
|
||||
void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
|
||||
LLVMMetadataRef Val);
|
||||
void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD);
|
||||
|
||||
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New);
|
||||
|
||||
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
|
||||
unsigned Col, LLVMMetadataRef Scope,
|
||||
LLVMMetadataRef InlinedAt);
|
||||
|
||||
struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref);
|
||||
|
||||
void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
46
external/llvm/bindings/go/llvm/InstrumentationBindings.cpp
vendored
Normal file
46
external/llvm/bindings/go/llvm/InstrumentationBindings.cpp
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//===- InstrumentationBindings.cpp - instrumentation bindings -------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines C bindings for the instrumentation component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InstrumentationBindings.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void LLVMAddAddressSanitizerFunctionPass(LLVMPassManagerRef PM) {
|
||||
unwrap(PM)->add(createAddressSanitizerFunctionPass());
|
||||
}
|
||||
|
||||
void LLVMAddAddressSanitizerModulePass(LLVMPassManagerRef PM) {
|
||||
unwrap(PM)->add(createAddressSanitizerModulePass());
|
||||
}
|
||||
|
||||
void LLVMAddThreadSanitizerPass(LLVMPassManagerRef PM) {
|
||||
unwrap(PM)->add(createThreadSanitizerPass());
|
||||
}
|
||||
|
||||
void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM) {
|
||||
unwrap(PM)->add(createMemorySanitizerPass());
|
||||
}
|
||||
|
||||
void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM,
|
||||
int ABIListFilesNum,
|
||||
const char **ABIListFiles) {
|
||||
std::vector<std::string> ABIListFilesVec;
|
||||
for (int i = 0; i != ABIListFilesNum; ++i) {
|
||||
ABIListFilesVec.push_back(ABIListFiles[i]);
|
||||
}
|
||||
unwrap(PM)->add(createDataFlowSanitizerPass(ABIListFilesVec));
|
||||
}
|
38
external/llvm/bindings/go/llvm/InstrumentationBindings.h
vendored
Normal file
38
external/llvm/bindings/go/llvm/InstrumentationBindings.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
//===- InstrumentationBindings.h - instrumentation bindings -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines C bindings for the Transforms/Instrumentation component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_BINDINGS_GO_LLVM_INSTRUMENTATIONBINDINGS_H
|
||||
#define LLVM_BINDINGS_GO_LLVM_INSTRUMENTATIONBINDINGS_H
|
||||
|
||||
#include "llvm-c/Core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// FIXME: These bindings shouldn't be Go-specific and should eventually move to
|
||||
// a (somewhat) less stable collection of C APIs for use in creating bindings of
|
||||
// LLVM in other languages.
|
||||
|
||||
void LLVMAddAddressSanitizerFunctionPass(LLVMPassManagerRef PM);
|
||||
void LLVMAddAddressSanitizerModulePass(LLVMPassManagerRef PM);
|
||||
void LLVMAddThreadSanitizerPass(LLVMPassManagerRef PM);
|
||||
void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM);
|
||||
void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, int ABIListFilesNum,
|
||||
const char **ABIListFiles);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
26
external/llvm/bindings/go/llvm/SupportBindings.cpp
vendored
Normal file
26
external/llvm/bindings/go/llvm/SupportBindings.cpp
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
//===- SupportBindings.cpp - Additional bindings for support --------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines additional C bindings for the support component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "SupportBindings.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void LLVMLoadLibraryPermanently2(const char *Filename, char **ErrMsg) {
|
||||
std::string ErrMsgStr;
|
||||
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Filename, &ErrMsgStr)) {
|
||||
*ErrMsg = static_cast<char *>(malloc(ErrMsgStr.size() + 1));
|
||||
memcpy(static_cast<void *>(*ErrMsg),
|
||||
static_cast<const void *>(ErrMsgStr.c_str()), ErrMsgStr.size() + 1);
|
||||
}
|
||||
}
|
30
external/llvm/bindings/go/llvm/SupportBindings.h
vendored
Normal file
30
external/llvm/bindings/go/llvm/SupportBindings.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
//===- SupportBindings.h - Additional bindings for Support ------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines additional C bindings for the Support component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_BINDINGS_GO_LLVM_SUPPORTBINDINGS_H
|
||||
#define LLVM_BINDINGS_GO_LLVM_SUPPORTBINDINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This function duplicates the LLVMLoadLibraryPermanently function in the
|
||||
// stable C API and adds an extra ErrMsg parameter to retrieve the error
|
||||
// message.
|
||||
void LLVMLoadLibraryPermanently2(const char *Filename, char **ErrMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
69
external/llvm/bindings/go/llvm/analysis.go
vendored
Normal file
69
external/llvm/bindings/go/llvm/analysis.go
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
//===- analysis.go - Bindings for analysis --------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the analysis component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Analysis.h" // If you are getting an error here read bindings/go/README.txt
|
||||
#include "llvm-c/Core.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "errors"
|
||||
|
||||
type VerifierFailureAction C.LLVMVerifierFailureAction
|
||||
|
||||
const (
|
||||
// verifier will print to stderr and abort()
|
||||
AbortProcessAction VerifierFailureAction = C.LLVMAbortProcessAction
|
||||
// verifier will print to stderr and return 1
|
||||
PrintMessageAction VerifierFailureAction = C.LLVMPrintMessageAction
|
||||
// verifier will just return 1
|
||||
ReturnStatusAction VerifierFailureAction = C.LLVMReturnStatusAction
|
||||
)
|
||||
|
||||
// Verifies that a module is valid, taking the specified action if not.
|
||||
// Optionally returns a human-readable description of any invalid constructs.
|
||||
func VerifyModule(m Module, a VerifierFailureAction) error {
|
||||
var cmsg *C.char
|
||||
broken := C.LLVMVerifyModule(m.C, C.LLVMVerifierFailureAction(a), &cmsg)
|
||||
|
||||
// C++'s verifyModule means isModuleBroken, so it returns false if
|
||||
// there are no errors
|
||||
if broken != 0 {
|
||||
err := errors.New(C.GoString(cmsg))
|
||||
C.LLVMDisposeMessage(cmsg)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var verifyFunctionError = errors.New("Function is broken")
|
||||
|
||||
// Verifies that a single function is valid, taking the specified action.
|
||||
// Useful for debugging.
|
||||
func VerifyFunction(f Value, a VerifierFailureAction) error {
|
||||
broken := C.LLVMVerifyFunction(f.C, C.LLVMVerifierFailureAction(a))
|
||||
|
||||
// C++'s verifyFunction means isFunctionBroken, so it returns false if
|
||||
// there are no errors
|
||||
if broken != 0 {
|
||||
return verifyFunctionError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Open up a ghostview window that displays the CFG of the current function.
|
||||
// Useful for debugging.
|
||||
func ViewFunctionCFG(f Value) { C.LLVMViewFunctionCFG(f.C) }
|
||||
func ViewFunctionCFGOnly(f Value) { C.LLVMViewFunctionCFGOnly(f.C) }
|
51
external/llvm/bindings/go/llvm/bitreader.go
vendored
Normal file
51
external/llvm/bindings/go/llvm/bitreader.go
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
//===- bitreader.go - Bindings for bitreader ------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the bitreader component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// ParseBitcodeFile parses the LLVM IR (bitcode) in the file with the
|
||||
// specified name, and returns a new LLVM module.
|
||||
func ParseBitcodeFile(name string) (Module, error) {
|
||||
var buf C.LLVMMemoryBufferRef
|
||||
var errmsg *C.char
|
||||
var cfilename *C.char = C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cfilename))
|
||||
result := C.LLVMCreateMemoryBufferWithContentsOfFile(cfilename, &buf, &errmsg)
|
||||
if result != 0 {
|
||||
err := errors.New(C.GoString(errmsg))
|
||||
C.free(unsafe.Pointer(errmsg))
|
||||
return Module{}, err
|
||||
}
|
||||
defer C.LLVMDisposeMemoryBuffer(buf)
|
||||
|
||||
var m Module
|
||||
if C.LLVMParseBitcode2(buf, &m.C) == 0 {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
err := errors.New(C.GoString(errmsg))
|
||||
C.free(unsafe.Pointer(errmsg))
|
||||
return Module{}, err
|
||||
}
|
39
external/llvm/bindings/go/llvm/bitwriter.go
vendored
Normal file
39
external/llvm/bindings/go/llvm/bitwriter.go
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
//===- bitwriter.go - Bindings for bitwriter ------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the bitwriter component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/BitWriter.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "os"
|
||||
import "errors"
|
||||
|
||||
var writeBitcodeToFileErr = errors.New("Failed to write bitcode to file")
|
||||
|
||||
func WriteBitcodeToFile(m Module, file *os.File) error {
|
||||
fail := C.LLVMWriteBitcodeToFD(m.C, C.int(file.Fd()), C.int(0), C.int(0))
|
||||
if fail != 0 {
|
||||
return writeBitcodeToFileErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteBitcodeToMemoryBuffer(m Module) MemoryBuffer {
|
||||
mb := C.LLVMWriteBitcodeToMemoryBuffer(m.C)
|
||||
return MemoryBuffer{mb}
|
||||
}
|
||||
|
||||
// TODO(nsf): Figure out way how to make it work with io.Writer
|
553
external/llvm/bindings/go/llvm/dibuilder.go
vendored
Normal file
553
external/llvm/bindings/go/llvm/dibuilder.go
vendored
Normal file
@ -0,0 +1,553 @@
|
||||
//===- dibuilder.go - Bindings for DIBuilder ------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the DIBuilder class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "DIBuilderBindings.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"debug/dwarf"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type DwarfTag uint32
|
||||
|
||||
const (
|
||||
DW_TAG_lexical_block DwarfTag = 0x0b
|
||||
DW_TAG_compile_unit DwarfTag = 0x11
|
||||
DW_TAG_variable DwarfTag = 0x34
|
||||
DW_TAG_base_type DwarfTag = 0x24
|
||||
DW_TAG_pointer_type DwarfTag = 0x0F
|
||||
DW_TAG_structure_type DwarfTag = 0x13
|
||||
DW_TAG_subroutine_type DwarfTag = 0x15
|
||||
DW_TAG_file_type DwarfTag = 0x29
|
||||
DW_TAG_subprogram DwarfTag = 0x2E
|
||||
DW_TAG_auto_variable DwarfTag = 0x100
|
||||
DW_TAG_arg_variable DwarfTag = 0x101
|
||||
)
|
||||
|
||||
const (
|
||||
FlagPrivate = 1 << iota
|
||||
FlagProtected
|
||||
FlagFwdDecl
|
||||
FlagAppleBlock
|
||||
FlagBlockByrefStruct
|
||||
FlagVirtual
|
||||
FlagArtificial
|
||||
FlagExplicit
|
||||
FlagPrototyped
|
||||
FlagObjcClassComplete
|
||||
FlagObjectPointer
|
||||
FlagVector
|
||||
FlagStaticMember
|
||||
FlagIndirectVariable
|
||||
)
|
||||
|
||||
type DwarfLang uint32
|
||||
|
||||
const (
|
||||
// http://dwarfstd.org/ShowIssue.php?issue=101014.1&type=open
|
||||
DW_LANG_Go DwarfLang = 0x0016
|
||||
)
|
||||
|
||||
type DwarfTypeEncoding uint32
|
||||
|
||||
const (
|
||||
DW_ATE_address DwarfTypeEncoding = 0x01
|
||||
DW_ATE_boolean DwarfTypeEncoding = 0x02
|
||||
DW_ATE_complex_float DwarfTypeEncoding = 0x03
|
||||
DW_ATE_float DwarfTypeEncoding = 0x04
|
||||
DW_ATE_signed DwarfTypeEncoding = 0x05
|
||||
DW_ATE_signed_char DwarfTypeEncoding = 0x06
|
||||
DW_ATE_unsigned DwarfTypeEncoding = 0x07
|
||||
DW_ATE_unsigned_char DwarfTypeEncoding = 0x08
|
||||
DW_ATE_imaginary_float DwarfTypeEncoding = 0x09
|
||||
DW_ATE_packed_decimal DwarfTypeEncoding = 0x0a
|
||||
DW_ATE_numeric_string DwarfTypeEncoding = 0x0b
|
||||
DW_ATE_edited DwarfTypeEncoding = 0x0c
|
||||
DW_ATE_signed_fixed DwarfTypeEncoding = 0x0d
|
||||
DW_ATE_unsigned_fixed DwarfTypeEncoding = 0x0e
|
||||
DW_ATE_decimal_float DwarfTypeEncoding = 0x0f
|
||||
DW_ATE_UTF DwarfTypeEncoding = 0x10
|
||||
DW_ATE_lo_user DwarfTypeEncoding = 0x80
|
||||
DW_ATE_hi_user DwarfTypeEncoding = 0xff
|
||||
)
|
||||
|
||||
// DIBuilder is a wrapper for the LLVM DIBuilder class.
|
||||
type DIBuilder struct {
|
||||
ref C.LLVMDIBuilderRef
|
||||
m Module
|
||||
}
|
||||
|
||||
// NewDIBuilder creates a new DIBuilder, associated with the given module.
|
||||
func NewDIBuilder(m Module) *DIBuilder {
|
||||
d := C.LLVMNewDIBuilder(m.C)
|
||||
return &DIBuilder{ref: d, m: m}
|
||||
}
|
||||
|
||||
// Destroy destroys the DIBuilder.
|
||||
func (d *DIBuilder) Destroy() {
|
||||
C.LLVMDIBuilderDestroy(d.ref)
|
||||
}
|
||||
|
||||
// FInalize finalizes the debug information generated by the DIBuilder.
|
||||
func (d *DIBuilder) Finalize() {
|
||||
C.LLVMDIBuilderFinalize(d.ref)
|
||||
}
|
||||
|
||||
// DICompileUnit holds the values for creating compile unit debug metadata.
|
||||
type DICompileUnit struct {
|
||||
Language DwarfLang
|
||||
File string
|
||||
Dir string
|
||||
Producer string
|
||||
Optimized bool
|
||||
Flags string
|
||||
RuntimeVersion int
|
||||
}
|
||||
|
||||
// CreateCompileUnit creates compile unit debug metadata.
|
||||
func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
|
||||
file := C.CString(cu.File)
|
||||
defer C.free(unsafe.Pointer(file))
|
||||
dir := C.CString(cu.Dir)
|
||||
defer C.free(unsafe.Pointer(dir))
|
||||
producer := C.CString(cu.Producer)
|
||||
defer C.free(unsafe.Pointer(producer))
|
||||
flags := C.CString(cu.Flags)
|
||||
defer C.free(unsafe.Pointer(flags))
|
||||
result := C.LLVMDIBuilderCreateCompileUnit(
|
||||
d.ref,
|
||||
C.LLVMDWARFSourceLanguage(cu.Language),
|
||||
C.LLVMDIBuilderCreateFile(d.ref, file, C.size_t(len(cu.File)), dir, C.size_t(len(cu.Dir))),
|
||||
producer, C.size_t(len(cu.Producer)),
|
||||
C.LLVMBool(boolToCInt(cu.Optimized)),
|
||||
flags, C.size_t(len(cu.Flags)),
|
||||
C.unsigned(cu.RuntimeVersion),
|
||||
/*SplitName=*/ nil, 0,
|
||||
C.LLVMDWARFEmissionFull,
|
||||
/*DWOId=*/ 0,
|
||||
/*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
|
||||
/*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// CreateCompileUnit creates file debug metadata.
|
||||
func (d *DIBuilder) CreateFile(filename, dir string) Metadata {
|
||||
cfilename := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cfilename))
|
||||
cdir := C.CString(dir)
|
||||
defer C.free(unsafe.Pointer(cdir))
|
||||
result := C.LLVMDIBuilderCreateFile(d.ref,
|
||||
cfilename, C.size_t(len(filename)),
|
||||
cdir, C.size_t(len(dir)))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DILexicalBlock holds the values for creating lexical block debug metadata.
|
||||
type DILexicalBlock struct {
|
||||
File Metadata
|
||||
Line int
|
||||
Column int
|
||||
}
|
||||
|
||||
// CreateCompileUnit creates lexical block debug metadata.
|
||||
func (d *DIBuilder) CreateLexicalBlock(diScope Metadata, b DILexicalBlock) Metadata {
|
||||
result := C.LLVMDIBuilderCreateLexicalBlock(
|
||||
d.ref,
|
||||
diScope.C,
|
||||
b.File.C,
|
||||
C.unsigned(b.Line),
|
||||
C.unsigned(b.Column),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
func (d *DIBuilder) CreateLexicalBlockFile(diScope Metadata, diFile Metadata, discriminator int) Metadata {
|
||||
result := C.LLVMDIBuilderCreateLexicalBlockFile(d.ref, diScope.C, diFile.C,
|
||||
C.unsigned(discriminator))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIFunction holds the values for creating function debug metadata.
|
||||
type DIFunction struct {
|
||||
Name string
|
||||
LinkageName string
|
||||
File Metadata
|
||||
Line int
|
||||
Type Metadata
|
||||
LocalToUnit bool
|
||||
IsDefinition bool
|
||||
ScopeLine int
|
||||
Flags int
|
||||
Optimized bool
|
||||
}
|
||||
|
||||
// CreateCompileUnit creates function debug metadata.
|
||||
func (d *DIBuilder) CreateFunction(diScope Metadata, f DIFunction) Metadata {
|
||||
name := C.CString(f.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
linkageName := C.CString(f.LinkageName)
|
||||
defer C.free(unsafe.Pointer(linkageName))
|
||||
result := C.LLVMDIBuilderCreateFunction(
|
||||
d.ref,
|
||||
diScope.C,
|
||||
name,
|
||||
linkageName,
|
||||
f.File.C,
|
||||
C.unsigned(f.Line),
|
||||
f.Type.C,
|
||||
boolToCInt(f.LocalToUnit),
|
||||
boolToCInt(f.IsDefinition),
|
||||
C.unsigned(f.ScopeLine),
|
||||
C.unsigned(f.Flags),
|
||||
boolToCInt(f.Optimized),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIAutoVariable holds the values for creating auto variable debug metadata.
|
||||
type DIAutoVariable struct {
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
Type Metadata
|
||||
AlwaysPreserve bool
|
||||
Flags int
|
||||
AlignInBits uint32
|
||||
}
|
||||
|
||||
// CreateAutoVariable creates local variable debug metadata.
|
||||
func (d *DIBuilder) CreateAutoVariable(scope Metadata, v DIAutoVariable) Metadata {
|
||||
name := C.CString(v.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateAutoVariable(
|
||||
d.ref,
|
||||
scope.C,
|
||||
name,
|
||||
v.File.C,
|
||||
C.unsigned(v.Line),
|
||||
v.Type.C,
|
||||
boolToCInt(v.AlwaysPreserve),
|
||||
C.unsigned(v.Flags),
|
||||
C.uint32_t(v.AlignInBits),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIParameterVariable holds the values for creating parameter variable debug metadata.
|
||||
type DIParameterVariable struct {
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
Type Metadata
|
||||
AlwaysPreserve bool
|
||||
Flags int
|
||||
|
||||
// ArgNo is the 1-based index of the argument in the function's
|
||||
// parameter list.
|
||||
ArgNo int
|
||||
}
|
||||
|
||||
// CreateParameterVariable creates parameter variable debug metadata.
|
||||
func (d *DIBuilder) CreateParameterVariable(scope Metadata, v DIParameterVariable) Metadata {
|
||||
name := C.CString(v.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateParameterVariable(
|
||||
d.ref,
|
||||
scope.C,
|
||||
name,
|
||||
C.unsigned(v.ArgNo),
|
||||
v.File.C,
|
||||
C.unsigned(v.Line),
|
||||
v.Type.C,
|
||||
boolToCInt(v.AlwaysPreserve),
|
||||
C.unsigned(v.Flags),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIBasicType holds the values for creating basic type debug metadata.
|
||||
type DIBasicType struct {
|
||||
Name string
|
||||
SizeInBits uint64
|
||||
Encoding DwarfTypeEncoding
|
||||
}
|
||||
|
||||
// CreateBasicType creates basic type debug metadata.
|
||||
func (d *DIBuilder) CreateBasicType(t DIBasicType) Metadata {
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateBasicType(
|
||||
d.ref,
|
||||
name,
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.unsigned(t.Encoding),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIPointerType holds the values for creating pointer type debug metadata.
|
||||
type DIPointerType struct {
|
||||
Pointee Metadata
|
||||
SizeInBits uint64
|
||||
AlignInBits uint32 // optional
|
||||
Name string // optional
|
||||
}
|
||||
|
||||
// CreateBasicType creates basic type debug metadata.
|
||||
func (d *DIBuilder) CreatePointerType(t DIPointerType) Metadata {
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreatePointerType(
|
||||
d.ref,
|
||||
t.Pointee.C,
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.uint32_t(t.AlignInBits),
|
||||
name,
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DISubroutineType holds the values for creating subroutine type debug metadata.
|
||||
type DISubroutineType struct {
|
||||
// File is the file in which the subroutine type is defined.
|
||||
File Metadata
|
||||
|
||||
// Parameters contains the subroutine parameter types,
|
||||
// including the return type at the 0th index.
|
||||
Parameters []Metadata
|
||||
}
|
||||
|
||||
// CreateSubroutineType creates subroutine type debug metadata.
|
||||
func (d *DIBuilder) CreateSubroutineType(t DISubroutineType) Metadata {
|
||||
params := d.getOrCreateTypeArray(t.Parameters)
|
||||
result := C.LLVMDIBuilderCreateSubroutineType(d.ref, t.File.C, params.C)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIStructType holds the values for creating struct type debug metadata.
|
||||
type DIStructType struct {
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
SizeInBits uint64
|
||||
AlignInBits uint32
|
||||
Flags int
|
||||
DerivedFrom Metadata
|
||||
Elements []Metadata
|
||||
}
|
||||
|
||||
// CreateStructType creates struct type debug metadata.
|
||||
func (d *DIBuilder) CreateStructType(scope Metadata, t DIStructType) Metadata {
|
||||
elements := d.getOrCreateArray(t.Elements)
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateStructType(
|
||||
d.ref,
|
||||
scope.C,
|
||||
name,
|
||||
t.File.C,
|
||||
C.unsigned(t.Line),
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.uint32_t(t.AlignInBits),
|
||||
C.unsigned(t.Flags),
|
||||
t.DerivedFrom.C,
|
||||
elements.C,
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIReplaceableCompositeType holds the values for creating replaceable
|
||||
// composite type debug metadata.
|
||||
type DIReplaceableCompositeType struct {
|
||||
Tag dwarf.Tag
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
RuntimeLang int
|
||||
SizeInBits uint64
|
||||
AlignInBits uint32
|
||||
Flags int
|
||||
}
|
||||
|
||||
// CreateReplaceableCompositeType creates replaceable composite type debug metadata.
|
||||
func (d *DIBuilder) CreateReplaceableCompositeType(scope Metadata, t DIReplaceableCompositeType) Metadata {
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateReplaceableCompositeType(
|
||||
d.ref,
|
||||
C.unsigned(t.Tag),
|
||||
name,
|
||||
scope.C,
|
||||
t.File.C,
|
||||
C.unsigned(t.Line),
|
||||
C.unsigned(t.RuntimeLang),
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.uint32_t(t.AlignInBits),
|
||||
C.unsigned(t.Flags),
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DIMemberType holds the values for creating member type debug metadata.
|
||||
type DIMemberType struct {
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
SizeInBits uint64
|
||||
AlignInBits uint32
|
||||
OffsetInBits uint64
|
||||
Flags int
|
||||
Type Metadata
|
||||
}
|
||||
|
||||
// CreateMemberType creates struct type debug metadata.
|
||||
func (d *DIBuilder) CreateMemberType(scope Metadata, t DIMemberType) Metadata {
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateMemberType(
|
||||
d.ref,
|
||||
scope.C,
|
||||
name,
|
||||
t.File.C,
|
||||
C.unsigned(t.Line),
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.uint32_t(t.AlignInBits),
|
||||
C.uint64_t(t.OffsetInBits),
|
||||
C.unsigned(t.Flags),
|
||||
t.Type.C,
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DISubrange describes an integer value range.
|
||||
type DISubrange struct {
|
||||
Lo int64
|
||||
Count int64
|
||||
}
|
||||
|
||||
// DIArrayType holds the values for creating array type debug metadata.
|
||||
type DIArrayType struct {
|
||||
SizeInBits uint64
|
||||
AlignInBits uint32
|
||||
ElementType Metadata
|
||||
Subscripts []DISubrange
|
||||
}
|
||||
|
||||
// CreateArrayType creates struct type debug metadata.
|
||||
func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata {
|
||||
subscriptsSlice := make([]Metadata, len(t.Subscripts))
|
||||
for i, s := range t.Subscripts {
|
||||
subscriptsSlice[i] = d.getOrCreateSubrange(s.Lo, s.Count)
|
||||
}
|
||||
subscripts := d.getOrCreateArray(subscriptsSlice)
|
||||
result := C.LLVMDIBuilderCreateArrayType(
|
||||
d.ref,
|
||||
C.uint64_t(t.SizeInBits),
|
||||
C.uint32_t(t.AlignInBits),
|
||||
t.ElementType.C,
|
||||
subscripts.C,
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// DITypedef holds the values for creating typedef type debug metadata.
|
||||
type DITypedef struct {
|
||||
Type Metadata
|
||||
Name string
|
||||
File Metadata
|
||||
Line int
|
||||
Context Metadata
|
||||
}
|
||||
|
||||
// CreateTypedef creates typedef type debug metadata.
|
||||
func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata {
|
||||
name := C.CString(t.Name)
|
||||
defer C.free(unsafe.Pointer(name))
|
||||
result := C.LLVMDIBuilderCreateTypedef(
|
||||
d.ref,
|
||||
t.Type.C,
|
||||
name,
|
||||
t.File.C,
|
||||
C.unsigned(t.Line),
|
||||
t.Context.C,
|
||||
)
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// getOrCreateSubrange gets a metadata node for the specified subrange,
|
||||
// creating if required.
|
||||
func (d *DIBuilder) getOrCreateSubrange(lo, count int64) Metadata {
|
||||
result := C.LLVMDIBuilderGetOrCreateSubrange(d.ref, C.int64_t(lo), C.int64_t(count))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// getOrCreateArray gets a metadata node containing the specified values,
|
||||
// creating if required.
|
||||
func (d *DIBuilder) getOrCreateArray(values []Metadata) Metadata {
|
||||
if len(values) == 0 {
|
||||
return Metadata{}
|
||||
}
|
||||
data, length := llvmMetadataRefs(values)
|
||||
result := C.LLVMDIBuilderGetOrCreateArray(d.ref, data, C.size_t(length))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// getOrCreateTypeArray gets a metadata node for a type array containing the
|
||||
// specified values, creating if required.
|
||||
func (d *DIBuilder) getOrCreateTypeArray(values []Metadata) Metadata {
|
||||
if len(values) == 0 {
|
||||
return Metadata{}
|
||||
}
|
||||
data, length := llvmMetadataRefs(values)
|
||||
result := C.LLVMDIBuilderGetOrCreateTypeArray(d.ref, data, C.size_t(length))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// CreateExpression creates a new descriptor for the specified
|
||||
// variable which has a complex address expression for its address.
|
||||
func (d *DIBuilder) CreateExpression(addr []int64) Metadata {
|
||||
var data *C.int64_t
|
||||
if len(addr) > 0 {
|
||||
data = (*C.int64_t)(unsafe.Pointer(&addr[0]))
|
||||
}
|
||||
result := C.LLVMDIBuilderCreateExpression(d.ref, data, C.size_t(len(addr)))
|
||||
return Metadata{C: result}
|
||||
}
|
||||
|
||||
// InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the
|
||||
// specified basic block for the given value and associated debug metadata.
|
||||
func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value {
|
||||
result := C.LLVMDIBuilderInsertDeclareAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C)
|
||||
return Value{C: result}
|
||||
}
|
||||
|
||||
// InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the
|
||||
// specified basic block for the given value and associated debug metadata.
|
||||
func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value {
|
||||
result := C.LLVMDIBuilderInsertValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C)
|
||||
return Value{C: result}
|
||||
}
|
||||
|
||||
func boolToCInt(v bool) C.int {
|
||||
if v {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
178
external/llvm/bindings/go/llvm/executionengine.go
vendored
Normal file
178
external/llvm/bindings/go/llvm/executionengine.go
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
//===- executionengine.go - Bindings for executionengine ------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the executionengine component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
import "errors"
|
||||
|
||||
func LinkInMCJIT() { C.LLVMLinkInMCJIT() }
|
||||
func LinkInInterpreter() { C.LLVMLinkInInterpreter() }
|
||||
|
||||
type GenericValue struct {
|
||||
C C.LLVMGenericValueRef
|
||||
}
|
||||
type ExecutionEngine struct {
|
||||
C C.LLVMExecutionEngineRef
|
||||
}
|
||||
|
||||
type MCJITCompilerOptions struct {
|
||||
C C.struct_LLVMMCJITCompilerOptions
|
||||
}
|
||||
|
||||
func (options *MCJITCompilerOptions) SetMCJITOptimizationLevel(level uint) {
|
||||
options.C.OptLevel = C.uint(level)
|
||||
}
|
||||
|
||||
func (options *MCJITCompilerOptions) SetMCJITNoFramePointerElim(nfp bool) {
|
||||
options.C.NoFramePointerElim = boolToLLVMBool(nfp)
|
||||
}
|
||||
|
||||
func (options *MCJITCompilerOptions) SetMCJITEnableFastISel(fastisel bool) {
|
||||
options.C.EnableFastISel = boolToLLVMBool(fastisel)
|
||||
}
|
||||
|
||||
func (options *MCJITCompilerOptions) SetMCJITCodeModel(CodeModel CodeModel) {
|
||||
options.C.CodeModel = C.LLVMCodeModel(CodeModel)
|
||||
}
|
||||
|
||||
// helpers
|
||||
func llvmGenericValueRefPtr(t *GenericValue) *C.LLVMGenericValueRef {
|
||||
return (*C.LLVMGenericValueRef)(unsafe.Pointer(t))
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// llvm.GenericValue
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
func NewGenericValueFromInt(t Type, n uint64, signed bool) (g GenericValue) {
|
||||
g.C = C.LLVMCreateGenericValueOfInt(t.C, C.ulonglong(n), boolToLLVMBool(signed))
|
||||
return
|
||||
}
|
||||
func NewGenericValueFromPointer(p unsafe.Pointer) (g GenericValue) {
|
||||
g.C = C.LLVMCreateGenericValueOfPointer(p)
|
||||
return
|
||||
}
|
||||
func NewGenericValueFromFloat(t Type, n float64) (g GenericValue) {
|
||||
g.C = C.LLVMCreateGenericValueOfFloat(t.C, C.double(n))
|
||||
return
|
||||
}
|
||||
func (g GenericValue) IntWidth() int { return int(C.LLVMGenericValueIntWidth(g.C)) }
|
||||
func (g GenericValue) Int(signed bool) uint64 {
|
||||
return uint64(C.LLVMGenericValueToInt(g.C, boolToLLVMBool(signed)))
|
||||
}
|
||||
func (g GenericValue) Float(t Type) float64 {
|
||||
return float64(C.LLVMGenericValueToFloat(t.C, g.C))
|
||||
}
|
||||
func (g GenericValue) Pointer() unsafe.Pointer {
|
||||
return C.LLVMGenericValueToPointer(g.C)
|
||||
}
|
||||
func (g GenericValue) Dispose() { C.LLVMDisposeGenericValue(g.C) }
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// llvm.ExecutionEngine
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
func NewExecutionEngine(m Module) (ee ExecutionEngine, err error) {
|
||||
var cmsg *C.char
|
||||
fail := C.LLVMCreateExecutionEngineForModule(&ee.C, m.C, &cmsg)
|
||||
if fail != 0 {
|
||||
ee.C = nil
|
||||
err = errors.New(C.GoString(cmsg))
|
||||
C.LLVMDisposeMessage(cmsg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewInterpreter(m Module) (ee ExecutionEngine, err error) {
|
||||
var cmsg *C.char
|
||||
fail := C.LLVMCreateInterpreterForModule(&ee.C, m.C, &cmsg)
|
||||
if fail != 0 {
|
||||
ee.C = nil
|
||||
err = errors.New(C.GoString(cmsg))
|
||||
C.LLVMDisposeMessage(cmsg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewMCJITCompilerOptions() MCJITCompilerOptions {
|
||||
var options C.struct_LLVMMCJITCompilerOptions
|
||||
C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})))
|
||||
return MCJITCompilerOptions{options}
|
||||
}
|
||||
|
||||
func NewMCJITCompiler(m Module, options MCJITCompilerOptions) (ee ExecutionEngine, err error) {
|
||||
var cmsg *C.char
|
||||
fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &options.C, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})), &cmsg)
|
||||
if fail != 0 {
|
||||
ee.C = nil
|
||||
err = errors.New(C.GoString(cmsg))
|
||||
C.LLVMDisposeMessage(cmsg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) Dispose() { C.LLVMDisposeExecutionEngine(ee.C) }
|
||||
func (ee ExecutionEngine) RunStaticConstructors() { C.LLVMRunStaticConstructors(ee.C) }
|
||||
func (ee ExecutionEngine) RunStaticDestructors() { C.LLVMRunStaticDestructors(ee.C) }
|
||||
|
||||
func (ee ExecutionEngine) RunFunction(f Value, args []GenericValue) (g GenericValue) {
|
||||
nargs := len(args)
|
||||
var argptr *GenericValue
|
||||
if nargs > 0 {
|
||||
argptr = &args[0]
|
||||
}
|
||||
g.C = C.LLVMRunFunction(ee.C, f.C,
|
||||
C.unsigned(nargs), llvmGenericValueRefPtr(argptr))
|
||||
return
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) FreeMachineCodeForFunction(f Value) {
|
||||
C.LLVMFreeMachineCodeForFunction(ee.C, f.C)
|
||||
}
|
||||
func (ee ExecutionEngine) AddModule(m Module) { C.LLVMAddModule(ee.C, m.C) }
|
||||
|
||||
func (ee ExecutionEngine) RemoveModule(m Module) {
|
||||
var modtmp C.LLVMModuleRef
|
||||
C.LLVMRemoveModule(ee.C, m.C, &modtmp, nil)
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) FindFunction(name string) (f Value) {
|
||||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
C.LLVMFindFunction(ee.C, cname, &f.C)
|
||||
return
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) RecompileAndRelinkFunction(f Value) unsafe.Pointer {
|
||||
return C.LLVMRecompileAndRelinkFunction(ee.C, f.C)
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) TargetData() (td TargetData) {
|
||||
td.C = C.LLVMGetExecutionEngineTargetData(ee.C)
|
||||
return
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) AddGlobalMapping(global Value, addr unsafe.Pointer) {
|
||||
C.LLVMAddGlobalMapping(ee.C, global.C, addr)
|
||||
}
|
||||
|
||||
func (ee ExecutionEngine) PointerToGlobal(global Value) unsafe.Pointer {
|
||||
return C.LLVMGetPointerToGlobal(ee.C, global.C)
|
||||
}
|
97
external/llvm/bindings/go/llvm/executionengine_test.go
vendored
Normal file
97
external/llvm/bindings/go/llvm/executionengine_test.go
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
//===- executionengine_test.go - Tests for executionengine ----------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file tests bindings for the executionengine component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFactorial(t *testing.T) {
|
||||
LinkInMCJIT()
|
||||
InitializeNativeTarget()
|
||||
InitializeNativeAsmPrinter()
|
||||
|
||||
mod := NewModule("fac_module")
|
||||
|
||||
fac_args := []Type{Int32Type()}
|
||||
fac_type := FunctionType(Int32Type(), fac_args, false)
|
||||
fac := AddFunction(mod, "fac", fac_type)
|
||||
fac.SetFunctionCallConv(CCallConv)
|
||||
n := fac.Param(0)
|
||||
|
||||
entry := AddBasicBlock(fac, "entry")
|
||||
iftrue := AddBasicBlock(fac, "iftrue")
|
||||
iffalse := AddBasicBlock(fac, "iffalse")
|
||||
end := AddBasicBlock(fac, "end")
|
||||
|
||||
builder := NewBuilder()
|
||||
defer builder.Dispose()
|
||||
|
||||
builder.SetInsertPointAtEnd(entry)
|
||||
If := builder.CreateICmp(IntEQ, n, ConstInt(Int32Type(), 0, false), "cmptmp")
|
||||
builder.CreateCondBr(If, iftrue, iffalse)
|
||||
|
||||
builder.SetInsertPointAtEnd(iftrue)
|
||||
res_iftrue := ConstInt(Int32Type(), 1, false)
|
||||
builder.CreateBr(end)
|
||||
|
||||
builder.SetInsertPointAtEnd(iffalse)
|
||||
n_minus := builder.CreateSub(n, ConstInt(Int32Type(), 1, false), "subtmp")
|
||||
call_fac_args := []Value{n_minus}
|
||||
call_fac := builder.CreateCall(fac, call_fac_args, "calltmp")
|
||||
res_iffalse := builder.CreateMul(n, call_fac, "multmp")
|
||||
builder.CreateBr(end)
|
||||
|
||||
builder.SetInsertPointAtEnd(end)
|
||||
res := builder.CreatePHI(Int32Type(), "result")
|
||||
phi_vals := []Value{res_iftrue, res_iffalse}
|
||||
phi_blocks := []BasicBlock{iftrue, iffalse}
|
||||
res.AddIncoming(phi_vals, phi_blocks)
|
||||
builder.CreateRet(res)
|
||||
|
||||
err := VerifyModule(mod, ReturnStatusAction)
|
||||
if err != nil {
|
||||
t.Errorf("Error verifying module: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
options := NewMCJITCompilerOptions()
|
||||
options.SetMCJITOptimizationLevel(2)
|
||||
options.SetMCJITEnableFastISel(true)
|
||||
options.SetMCJITNoFramePointerElim(true)
|
||||
options.SetMCJITCodeModel(CodeModelJITDefault)
|
||||
engine, err := NewMCJITCompiler(mod, options)
|
||||
if err != nil {
|
||||
t.Errorf("Error creating JIT: %s", err)
|
||||
return
|
||||
}
|
||||
defer engine.Dispose()
|
||||
|
||||
pass := NewPassManager()
|
||||
defer pass.Dispose()
|
||||
|
||||
pass.AddConstantPropagationPass()
|
||||
pass.AddInstructionCombiningPass()
|
||||
pass.AddPromoteMemoryToRegisterPass()
|
||||
pass.AddGVNPass()
|
||||
pass.AddCFGSimplificationPass()
|
||||
pass.Run(mod)
|
||||
|
||||
exec_args := []GenericValue{NewGenericValueFromInt(Int32Type(), 10, false)}
|
||||
exec_res := engine.RunFunction(fac, exec_args)
|
||||
var fac10 uint64 = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1
|
||||
if exec_res.Int(false) != fac10 {
|
||||
t.Errorf("Expected %d, got %d", fac10, exec_res.Int(false))
|
||||
}
|
||||
}
|
1891
external/llvm/bindings/go/llvm/ir.go
vendored
Normal file
1891
external/llvm/bindings/go/llvm/ir.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
162
external/llvm/bindings/go/llvm/ir_test.go
vendored
Normal file
162
external/llvm/bindings/go/llvm/ir_test.go
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
//===- ir_test.go - Tests for ir ------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file tests bindings for the ir component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testAttribute(t *testing.T, name string) {
|
||||
mod := NewModule("")
|
||||
defer mod.Dispose()
|
||||
|
||||
ftyp := FunctionType(VoidType(), nil, false)
|
||||
fn := AddFunction(mod, "foo", ftyp)
|
||||
|
||||
kind := AttributeKindID(name)
|
||||
attr := mod.Context().CreateEnumAttribute(kind, 0)
|
||||
|
||||
fn.AddFunctionAttr(attr)
|
||||
newattr := fn.GetEnumFunctionAttribute(kind)
|
||||
if attr != newattr {
|
||||
t.Errorf("got attribute mask %d, want %d", newattr, attr)
|
||||
}
|
||||
|
||||
text := mod.String()
|
||||
if !strings.Contains(text, " "+name+" ") {
|
||||
t.Errorf("expected attribute '%s', got:\n%s", name, text)
|
||||
}
|
||||
|
||||
fn.RemoveEnumFunctionAttribute(kind)
|
||||
newattr = fn.GetEnumFunctionAttribute(kind)
|
||||
if !newattr.IsNil() {
|
||||
t.Errorf("got attribute mask %d, want 0", newattr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributes(t *testing.T) {
|
||||
// Tests that our attribute constants haven't drifted from LLVM's.
|
||||
attrTests := []string{
|
||||
"sanitize_address",
|
||||
"alwaysinline",
|
||||
"builtin",
|
||||
"byval",
|
||||
"convergent",
|
||||
"inalloca",
|
||||
"inlinehint",
|
||||
"inreg",
|
||||
"jumptable",
|
||||
"minsize",
|
||||
"naked",
|
||||
"nest",
|
||||
"noalias",
|
||||
"nobuiltin",
|
||||
"nocapture",
|
||||
"noduplicate",
|
||||
"noimplicitfloat",
|
||||
"noinline",
|
||||
"nonlazybind",
|
||||
"nonnull",
|
||||
"noredzone",
|
||||
"noreturn",
|
||||
"nounwind",
|
||||
"optnone",
|
||||
"optsize",
|
||||
"readnone",
|
||||
"readonly",
|
||||
"returned",
|
||||
"returns_twice",
|
||||
"signext",
|
||||
"safestack",
|
||||
"ssp",
|
||||
"sspreq",
|
||||
"sspstrong",
|
||||
"sret",
|
||||
"sanitize_thread",
|
||||
"sanitize_memory",
|
||||
"uwtable",
|
||||
"zeroext",
|
||||
"cold",
|
||||
}
|
||||
|
||||
for _, name := range attrTests {
|
||||
testAttribute(t, name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebugLoc(t *testing.T) {
|
||||
mod := NewModule("")
|
||||
defer mod.Dispose()
|
||||
|
||||
ctx := mod.Context()
|
||||
|
||||
b := ctx.NewBuilder()
|
||||
defer b.Dispose()
|
||||
|
||||
d := NewDIBuilder(mod)
|
||||
defer func() {
|
||||
d.Destroy()
|
||||
}()
|
||||
file := d.CreateFile("dummy_file", "dummy_dir")
|
||||
voidInfo := d.CreateBasicType(DIBasicType{Name: "void"})
|
||||
typeInfo := d.CreateSubroutineType(DISubroutineType{file, []Metadata{voidInfo}})
|
||||
scope := d.CreateFunction(file, DIFunction{
|
||||
Name: "foo",
|
||||
LinkageName: "foo",
|
||||
Line: 10,
|
||||
ScopeLine: 10,
|
||||
Type: typeInfo,
|
||||
File: file,
|
||||
IsDefinition: true,
|
||||
})
|
||||
|
||||
b.SetCurrentDebugLocation(10, 20, scope, Metadata{})
|
||||
loc := b.GetCurrentDebugLocation()
|
||||
if loc.Line != 10 {
|
||||
t.Errorf("Got line %d, though wanted 10", loc.Line)
|
||||
}
|
||||
if loc.Col != 20 {
|
||||
t.Errorf("Got column %d, though wanted 20", loc.Col)
|
||||
}
|
||||
if loc.Scope.C != scope.C {
|
||||
t.Errorf("Got metadata %v as scope, though wanted %v", loc.Scope.C, scope.C)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubtypes(t *testing.T) {
|
||||
cont := NewContext()
|
||||
defer cont.Dispose()
|
||||
|
||||
int_pointer := PointerType(cont.Int32Type(), 0)
|
||||
int_inner := int_pointer.Subtypes()
|
||||
if len(int_inner) != 1 {
|
||||
t.Errorf("Got size %d, though wanted 1", len(int_inner))
|
||||
}
|
||||
if int_inner[0] != cont.Int32Type() {
|
||||
t.Errorf("Expected int32 type")
|
||||
}
|
||||
|
||||
st_pointer := cont.StructType([]Type{cont.Int32Type(), cont.Int8Type()}, false)
|
||||
st_inner := st_pointer.Subtypes()
|
||||
if len(st_inner) != 2 {
|
||||
t.Errorf("Got size %d, though wanted 2", len(int_inner))
|
||||
}
|
||||
if st_inner[0] != cont.Int32Type() {
|
||||
t.Errorf("Expected first struct field to be int32")
|
||||
}
|
||||
if st_inner[1] != cont.Int8Type() {
|
||||
t.Errorf("Expected second struct field to be int8")
|
||||
}
|
||||
}
|
31
external/llvm/bindings/go/llvm/linker.go
vendored
Normal file
31
external/llvm/bindings/go/llvm/linker.go
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//===- linker.go - Bindings for linker ------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the linker component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Linker.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "errors"
|
||||
|
||||
func LinkModules(Dest, Src Module) error {
|
||||
failed := C.LLVMLinkModules2(Dest.C, Src.C)
|
||||
if failed != 0 {
|
||||
err := errors.New("Linking failed")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
12
external/llvm/bindings/go/llvm/llvm_config.go.in
vendored
Normal file
12
external/llvm/bindings/go/llvm/llvm_config.go.in
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// +build !byollvm
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#cgo CXXFLAGS: -std=c++11
|
||||
#cgo CPPFLAGS: @LLVM_CFLAGS@
|
||||
#cgo LDFLAGS: @LLVM_LDFLAGS@
|
||||
*/
|
||||
import "C"
|
||||
|
||||
type (run_build_sh int)
|
19
external/llvm/bindings/go/llvm/llvm_dep.go
vendored
Normal file
19
external/llvm/bindings/go/llvm/llvm_dep.go
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
//===- llvm_dep.go - creates LLVM dependency ------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file ensures that the LLVM libraries are built before using the
|
||||
// bindings.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// +build !byollvm
|
||||
|
||||
package llvm
|
||||
|
||||
var _ run_build_sh
|
105
external/llvm/bindings/go/llvm/string.go
vendored
Normal file
105
external/llvm/bindings/go/llvm/string.go
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
//===- string.go - Stringer implementation for Type -----------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the Stringer interface for the Type type.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (t TypeKind) String() string {
|
||||
switch t {
|
||||
case VoidTypeKind:
|
||||
return "VoidTypeKind"
|
||||
case FloatTypeKind:
|
||||
return "FloatTypeKind"
|
||||
case DoubleTypeKind:
|
||||
return "DoubleTypeKind"
|
||||
case X86_FP80TypeKind:
|
||||
return "X86_FP80TypeKind"
|
||||
case FP128TypeKind:
|
||||
return "FP128TypeKind"
|
||||
case PPC_FP128TypeKind:
|
||||
return "PPC_FP128TypeKind"
|
||||
case LabelTypeKind:
|
||||
return "LabelTypeKind"
|
||||
case IntegerTypeKind:
|
||||
return "IntegerTypeKind"
|
||||
case FunctionTypeKind:
|
||||
return "FunctionTypeKind"
|
||||
case StructTypeKind:
|
||||
return "StructTypeKind"
|
||||
case ArrayTypeKind:
|
||||
return "ArrayTypeKind"
|
||||
case PointerTypeKind:
|
||||
return "PointerTypeKind"
|
||||
case VectorTypeKind:
|
||||
return "VectorTypeKind"
|
||||
case MetadataTypeKind:
|
||||
return "MetadataTypeKind"
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (t Type) String() string {
|
||||
ts := typeStringer{s: make(map[Type]string)}
|
||||
return ts.typeString(t)
|
||||
}
|
||||
|
||||
type typeStringer struct {
|
||||
s map[Type]string
|
||||
}
|
||||
|
||||
func (ts *typeStringer) typeString(t Type) string {
|
||||
if s, ok := ts.s[t]; ok {
|
||||
return s
|
||||
}
|
||||
|
||||
k := t.TypeKind()
|
||||
s := k.String()
|
||||
s = s[:len(s)-len("Kind")]
|
||||
|
||||
switch k {
|
||||
case ArrayTypeKind:
|
||||
s += fmt.Sprintf("(%v[%v])", ts.typeString(t.ElementType()), t.ArrayLength())
|
||||
case PointerTypeKind:
|
||||
s += fmt.Sprintf("(%v)", ts.typeString(t.ElementType()))
|
||||
case FunctionTypeKind:
|
||||
params := t.ParamTypes()
|
||||
s += "("
|
||||
if len(params) > 0 {
|
||||
s += fmt.Sprintf("%v", ts.typeString(params[0]))
|
||||
for i := 1; i < len(params); i++ {
|
||||
s += fmt.Sprintf(", %v", ts.typeString(params[i]))
|
||||
}
|
||||
}
|
||||
s += fmt.Sprintf("):%v", ts.typeString(t.ReturnType()))
|
||||
case StructTypeKind:
|
||||
if name := t.StructName(); name != "" {
|
||||
ts.s[t] = "%" + name
|
||||
s = fmt.Sprintf("%%%s: %s", name, s)
|
||||
}
|
||||
etypes := t.StructElementTypes()
|
||||
s += "("
|
||||
if n := len(etypes); n > 0 {
|
||||
s += ts.typeString(etypes[0])
|
||||
for i := 1; i < n; i++ {
|
||||
s += fmt.Sprintf(", %v", ts.typeString(etypes[i]))
|
||||
}
|
||||
}
|
||||
s += ")"
|
||||
case IntegerTypeKind:
|
||||
s += fmt.Sprintf("(%d bits)", t.IntTypeWidth())
|
||||
}
|
||||
|
||||
ts.s[t] = s
|
||||
return s
|
||||
}
|
28
external/llvm/bindings/go/llvm/string_test.go
vendored
Normal file
28
external/llvm/bindings/go/llvm/string_test.go
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
//===- string_test.go - test Stringer implementation for Type -------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file tests the Stringer interface for the Type type.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStringRecursiveType(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
defer ctx.Dispose()
|
||||
s := ctx.StructCreateNamed("recursive")
|
||||
s.StructSetBody([]Type{s, s}, false)
|
||||
if str := s.String(); str != "%recursive: StructType(%recursive, %recursive)" {
|
||||
t.Errorf("incorrect string result %q", str)
|
||||
}
|
||||
}
|
54
external/llvm/bindings/go/llvm/support.go
vendored
Normal file
54
external/llvm/bindings/go/llvm/support.go
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
//===- support.go - Bindings for support ----------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the support component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Support.h"
|
||||
#include "SupportBindings.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Loads a dynamic library such that it may be used as an LLVM plugin.
|
||||
// See llvm::sys::DynamicLibrary::LoadLibraryPermanently.
|
||||
func LoadLibraryPermanently(lib string) error {
|
||||
var errstr *C.char
|
||||
libstr := C.CString(lib)
|
||||
defer C.free(unsafe.Pointer(libstr))
|
||||
C.LLVMLoadLibraryPermanently2(libstr, &errstr)
|
||||
if errstr != nil {
|
||||
err := errors.New(C.GoString(errstr))
|
||||
C.free(unsafe.Pointer(errstr))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parse the given arguments using the LLVM command line parser.
|
||||
// See llvm::cl::ParseCommandLineOptions.
|
||||
func ParseCommandLineOptions(args []string, overview string) {
|
||||
argstrs := make([]*C.char, len(args))
|
||||
for i, arg := range args {
|
||||
argstrs[i] = C.CString(arg)
|
||||
defer C.free(unsafe.Pointer(argstrs[i]))
|
||||
}
|
||||
overviewstr := C.CString(overview)
|
||||
defer C.free(unsafe.Pointer(overviewstr))
|
||||
C.LLVMParseCommandLineOptions(C.int(len(args)), &argstrs[0], overviewstr)
|
||||
}
|
296
external/llvm/bindings/go/llvm/target.go
vendored
Normal file
296
external/llvm/bindings/go/llvm/target.go
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
//===- target.go - Bindings for target ------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the target component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Target.h"
|
||||
#include "llvm-c/TargetMachine.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
import "errors"
|
||||
|
||||
type (
|
||||
TargetData struct {
|
||||
C C.LLVMTargetDataRef
|
||||
}
|
||||
Target struct {
|
||||
C C.LLVMTargetRef
|
||||
}
|
||||
TargetMachine struct {
|
||||
C C.LLVMTargetMachineRef
|
||||
}
|
||||
ByteOrdering C.enum_LLVMByteOrdering
|
||||
RelocMode C.LLVMRelocMode
|
||||
CodeGenOptLevel C.LLVMCodeGenOptLevel
|
||||
CodeGenFileType C.LLVMCodeGenFileType
|
||||
CodeModel C.LLVMCodeModel
|
||||
)
|
||||
|
||||
const (
|
||||
BigEndian ByteOrdering = C.LLVMBigEndian
|
||||
LittleEndian ByteOrdering = C.LLVMLittleEndian
|
||||
)
|
||||
|
||||
const (
|
||||
RelocDefault RelocMode = C.LLVMRelocDefault
|
||||
RelocStatic RelocMode = C.LLVMRelocStatic
|
||||
RelocPIC RelocMode = C.LLVMRelocPIC
|
||||
RelocDynamicNoPic RelocMode = C.LLVMRelocDynamicNoPic
|
||||
)
|
||||
|
||||
const (
|
||||
CodeGenLevelNone CodeGenOptLevel = C.LLVMCodeGenLevelNone
|
||||
CodeGenLevelLess CodeGenOptLevel = C.LLVMCodeGenLevelLess
|
||||
CodeGenLevelDefault CodeGenOptLevel = C.LLVMCodeGenLevelDefault
|
||||
CodeGenLevelAggressive CodeGenOptLevel = C.LLVMCodeGenLevelAggressive
|
||||
)
|
||||
|
||||
const (
|
||||
CodeModelDefault CodeModel = C.LLVMCodeModelDefault
|
||||
CodeModelJITDefault CodeModel = C.LLVMCodeModelJITDefault
|
||||
CodeModelSmall CodeModel = C.LLVMCodeModelSmall
|
||||
CodeModelKernel CodeModel = C.LLVMCodeModelKernel
|
||||
CodeModelMedium CodeModel = C.LLVMCodeModelMedium
|
||||
CodeModelLarge CodeModel = C.LLVMCodeModelLarge
|
||||
)
|
||||
|
||||
const (
|
||||
AssemblyFile CodeGenFileType = C.LLVMAssemblyFile
|
||||
ObjectFile CodeGenFileType = C.LLVMObjectFile
|
||||
)
|
||||
|
||||
// InitializeAllTargetInfos - The main program should call this function if it
|
||||
// wants access to all available targets that LLVM is configured to support.
|
||||
func InitializeAllTargetInfos() { C.LLVMInitializeAllTargetInfos() }
|
||||
|
||||
// InitializeAllTargets - The main program should call this function if it wants
|
||||
// to link in all available targets that LLVM is configured to support.
|
||||
func InitializeAllTargets() { C.LLVMInitializeAllTargets() }
|
||||
|
||||
func InitializeAllTargetMCs() { C.LLVMInitializeAllTargetMCs() }
|
||||
|
||||
func InitializeAllAsmParsers() { C.LLVMInitializeAllAsmParsers() }
|
||||
|
||||
func InitializeAllAsmPrinters() { C.LLVMInitializeAllAsmPrinters() }
|
||||
|
||||
var initializeNativeTargetError = errors.New("Failed to initialize native target")
|
||||
|
||||
// InitializeNativeTarget - The main program should call this function to
|
||||
// initialize the native target corresponding to the host. This is useful
|
||||
// for JIT applications to ensure that the target gets linked in correctly.
|
||||
func InitializeNativeTarget() error {
|
||||
fail := C.LLVMInitializeNativeTarget()
|
||||
if fail != 0 {
|
||||
return initializeNativeTargetError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitializeNativeAsmPrinter() error {
|
||||
fail := C.LLVMInitializeNativeAsmPrinter()
|
||||
if fail != 0 {
|
||||
return initializeNativeTargetError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// llvm.TargetData
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// Creates target data from a target layout string.
|
||||
// See the constructor llvm::TargetData::TargetData.
|
||||
func NewTargetData(rep string) (td TargetData) {
|
||||
crep := C.CString(rep)
|
||||
defer C.free(unsafe.Pointer(crep))
|
||||
td.C = C.LLVMCreateTargetData(crep)
|
||||
return
|
||||
}
|
||||
|
||||
// Converts target data to a target layout string. The string must be disposed
|
||||
// with LLVMDisposeMessage.
|
||||
// See the constructor llvm::TargetData::TargetData.
|
||||
func (td TargetData) String() (s string) {
|
||||
cmsg := C.LLVMCopyStringRepOfTargetData(td.C)
|
||||
s = C.GoString(cmsg)
|
||||
C.LLVMDisposeMessage(cmsg)
|
||||
return
|
||||
}
|
||||
|
||||
// Returns the byte order of a target, either BigEndian or LittleEndian.
|
||||
// See the method llvm::TargetData::isLittleEndian.
|
||||
func (td TargetData) ByteOrder() ByteOrdering { return ByteOrdering(C.LLVMByteOrder(td.C)) }
|
||||
|
||||
// Returns the pointer size in bytes for a target.
|
||||
// See the method llvm::TargetData::getPointerSize.
|
||||
func (td TargetData) PointerSize() int { return int(C.LLVMPointerSize(td.C)) }
|
||||
|
||||
// Returns the integer type that is the same size as a pointer on a target.
|
||||
// See the method llvm::TargetData::getIntPtrType.
|
||||
func (td TargetData) IntPtrType() (t Type) { t.C = C.LLVMIntPtrType(td.C); return }
|
||||
|
||||
// Computes the size of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getTypeSizeInBits.
|
||||
func (td TargetData) TypeSizeInBits(t Type) uint64 {
|
||||
return uint64(C.LLVMSizeOfTypeInBits(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the storage size of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getTypeStoreSize.
|
||||
func (td TargetData) TypeStoreSize(t Type) uint64 {
|
||||
return uint64(C.LLVMStoreSizeOfType(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the ABI size of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getTypeAllocSize.
|
||||
func (td TargetData) TypeAllocSize(t Type) uint64 {
|
||||
return uint64(C.LLVMABISizeOfType(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the ABI alignment of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getABITypeAlignment.
|
||||
func (td TargetData) ABITypeAlignment(t Type) int {
|
||||
return int(C.LLVMABIAlignmentOfType(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the call frame alignment of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getCallFrameTypeAlignment.
|
||||
func (td TargetData) CallFrameTypeAlignment(t Type) int {
|
||||
return int(C.LLVMCallFrameAlignmentOfType(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the preferred alignment of a type in bytes for a target.
|
||||
// See the method llvm::TargetData::getPrefTypeAlignment.
|
||||
func (td TargetData) PrefTypeAlignment(t Type) int {
|
||||
return int(C.LLVMPreferredAlignmentOfType(td.C, t.C))
|
||||
}
|
||||
|
||||
// Computes the preferred alignment of a global variable in bytes for a target.
|
||||
// See the method llvm::TargetData::getPreferredAlignment.
|
||||
func (td TargetData) PreferredAlignment(g Value) int {
|
||||
return int(C.LLVMPreferredAlignmentOfGlobal(td.C, g.C))
|
||||
}
|
||||
|
||||
// Computes the structure element that contains the byte offset for a target.
|
||||
// See the method llvm::StructLayout::getElementContainingOffset.
|
||||
func (td TargetData) ElementContainingOffset(t Type, offset uint64) int {
|
||||
return int(C.LLVMElementAtOffset(td.C, t.C, C.ulonglong(offset)))
|
||||
}
|
||||
|
||||
// Computes the byte offset of the indexed struct element for a target.
|
||||
// See the method llvm::StructLayout::getElementOffset.
|
||||
func (td TargetData) ElementOffset(t Type, element int) uint64 {
|
||||
return uint64(C.LLVMOffsetOfElement(td.C, t.C, C.unsigned(element)))
|
||||
}
|
||||
|
||||
// Deallocates a TargetData.
|
||||
// See the destructor llvm::TargetData::~TargetData.
|
||||
func (td TargetData) Dispose() { C.LLVMDisposeTargetData(td.C) }
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// llvm.Target
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
func FirstTarget() Target {
|
||||
return Target{C.LLVMGetFirstTarget()}
|
||||
}
|
||||
|
||||
func (t Target) NextTarget() Target {
|
||||
return Target{C.LLVMGetNextTarget(t.C)}
|
||||
}
|
||||
|
||||
func GetTargetFromTriple(triple string) (t Target, err error) {
|
||||
var errstr *C.char
|
||||
ctriple := C.CString(triple)
|
||||
defer C.free(unsafe.Pointer(ctriple))
|
||||
fail := C.LLVMGetTargetFromTriple(ctriple, &t.C, &errstr)
|
||||
if fail != 0 {
|
||||
err = errors.New(C.GoString(errstr))
|
||||
C.free(unsafe.Pointer(errstr))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (t Target) Name() string {
|
||||
return C.GoString(C.LLVMGetTargetName(t.C))
|
||||
}
|
||||
|
||||
func (t Target) Description() string {
|
||||
return C.GoString(C.LLVMGetTargetDescription(t.C))
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// llvm.TargetMachine
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// CreateTargetMachine creates a new TargetMachine.
|
||||
func (t Target) CreateTargetMachine(Triple string, CPU string, Features string,
|
||||
Level CodeGenOptLevel, Reloc RelocMode,
|
||||
CodeModel CodeModel) (tm TargetMachine) {
|
||||
cTriple := C.CString(Triple)
|
||||
defer C.free(unsafe.Pointer(cTriple))
|
||||
cCPU := C.CString(CPU)
|
||||
defer C.free(unsafe.Pointer(cCPU))
|
||||
cFeatures := C.CString(Features)
|
||||
defer C.free(unsafe.Pointer(cFeatures))
|
||||
tm.C = C.LLVMCreateTargetMachine(t.C, cTriple, cCPU, cFeatures,
|
||||
C.LLVMCodeGenOptLevel(Level),
|
||||
C.LLVMRelocMode(Reloc),
|
||||
C.LLVMCodeModel(CodeModel))
|
||||
return
|
||||
}
|
||||
|
||||
// CreateTargetData returns a new TargetData describing the TargetMachine's
|
||||
// data layout. The returned TargetData is owned by the caller, who is
|
||||
// responsible for disposing of it by calling the TargetData.Dispose method.
|
||||
func (tm TargetMachine) CreateTargetData() TargetData {
|
||||
return TargetData{C.LLVMCreateTargetDataLayout(tm.C)}
|
||||
}
|
||||
|
||||
// Triple returns the triple describing the machine (arch-vendor-os).
|
||||
func (tm TargetMachine) Triple() string {
|
||||
cstr := C.LLVMGetTargetMachineTriple(tm.C)
|
||||
return C.GoString(cstr)
|
||||
}
|
||||
|
||||
func (tm TargetMachine) EmitToMemoryBuffer(m Module, ft CodeGenFileType) (MemoryBuffer, error) {
|
||||
var errstr *C.char
|
||||
var mb MemoryBuffer
|
||||
fail := C.LLVMTargetMachineEmitToMemoryBuffer(tm.C, m.C, C.LLVMCodeGenFileType(ft), &errstr, &mb.C)
|
||||
if fail != 0 {
|
||||
err := errors.New(C.GoString(errstr))
|
||||
C.free(unsafe.Pointer(errstr))
|
||||
return MemoryBuffer{}, err
|
||||
}
|
||||
return mb, nil
|
||||
}
|
||||
|
||||
func (tm TargetMachine) AddAnalysisPasses(pm PassManager) {
|
||||
C.LLVMAddAnalysisPasses(tm.C, pm.C)
|
||||
}
|
||||
|
||||
// Dispose releases resources related to the TargetMachine.
|
||||
func (tm TargetMachine) Dispose() {
|
||||
C.LLVMDisposeTargetMachine(tm.C)
|
||||
}
|
||||
|
||||
func DefaultTargetTriple() (triple string) {
|
||||
cTriple := C.LLVMGetDefaultTargetTriple()
|
||||
defer C.free(unsafe.Pointer(cTriple))
|
||||
triple = C.GoString(cTriple)
|
||||
return
|
||||
}
|
46
external/llvm/bindings/go/llvm/transforms_instrumentation.go
vendored
Normal file
46
external/llvm/bindings/go/llvm/transforms_instrumentation.go
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
//===- transforms_instrumentation.go - Bindings for instrumentation -------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the instrumentation component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "InstrumentationBindings.h"
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func (pm PassManager) AddAddressSanitizerFunctionPass() {
|
||||
C.LLVMAddAddressSanitizerFunctionPass(pm.C)
|
||||
}
|
||||
|
||||
func (pm PassManager) AddAddressSanitizerModulePass() {
|
||||
C.LLVMAddAddressSanitizerModulePass(pm.C)
|
||||
}
|
||||
|
||||
func (pm PassManager) AddThreadSanitizerPass() {
|
||||
C.LLVMAddThreadSanitizerPass(pm.C)
|
||||
}
|
||||
|
||||
func (pm PassManager) AddMemorySanitizerPass() {
|
||||
C.LLVMAddMemorySanitizerPass(pm.C)
|
||||
}
|
||||
|
||||
func (pm PassManager) AddDataFlowSanitizerPass(abilist []string) {
|
||||
abiliststrs := make([]*C.char, len(abilist))
|
||||
for i, arg := range abilist {
|
||||
abiliststrs[i] = C.CString(arg)
|
||||
defer C.free(unsafe.Pointer(abiliststrs[i]))
|
||||
}
|
||||
C.LLVMAddDataFlowSanitizerPass(pm.C, C.int(len(abilist)), &abiliststrs[0])
|
||||
}
|
42
external/llvm/bindings/go/llvm/transforms_ipo.go
vendored
Normal file
42
external/llvm/bindings/go/llvm/transforms_ipo.go
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//===- transforms_ipo.go - Bindings for ipo -------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the ipo component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Transforms/IPO.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// helpers
|
||||
func boolToUnsigned(b bool) C.unsigned {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (pm PassManager) AddArgumentPromotionPass() { C.LLVMAddArgumentPromotionPass(pm.C) }
|
||||
func (pm PassManager) AddConstantMergePass() { C.LLVMAddConstantMergePass(pm.C) }
|
||||
func (pm PassManager) AddDeadArgEliminationPass() { C.LLVMAddDeadArgEliminationPass(pm.C) }
|
||||
func (pm PassManager) AddFunctionAttrsPass() { C.LLVMAddFunctionAttrsPass(pm.C) }
|
||||
func (pm PassManager) AddFunctionInliningPass() { C.LLVMAddFunctionInliningPass(pm.C) }
|
||||
func (pm PassManager) AddGlobalDCEPass() { C.LLVMAddGlobalDCEPass(pm.C) }
|
||||
func (pm PassManager) AddGlobalOptimizerPass() { C.LLVMAddGlobalOptimizerPass(pm.C) }
|
||||
func (pm PassManager) AddIPConstantPropagationPass() { C.LLVMAddIPConstantPropagationPass(pm.C) }
|
||||
func (pm PassManager) AddPruneEHPass() { C.LLVMAddPruneEHPass(pm.C) }
|
||||
func (pm PassManager) AddIPSCCPPass() { C.LLVMAddIPSCCPPass(pm.C) }
|
||||
func (pm PassManager) AddInternalizePass(allButMain bool) {
|
||||
C.LLVMAddInternalizePass(pm.C, boolToUnsigned(allButMain))
|
||||
}
|
||||
func (pm PassManager) AddStripDeadPrototypesPass() { C.LLVMAddStripDeadPrototypesPass(pm.C) }
|
68
external/llvm/bindings/go/llvm/transforms_pmbuilder.go
vendored
Normal file
68
external/llvm/bindings/go/llvm/transforms_pmbuilder.go
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
//===- transforms_pmbuilder.go - Bindings for PassManagerBuilder ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the PassManagerBuilder class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Transforms/PassManagerBuilder.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
type PassManagerBuilder struct {
|
||||
C C.LLVMPassManagerBuilderRef
|
||||
}
|
||||
|
||||
func NewPassManagerBuilder() (pmb PassManagerBuilder) {
|
||||
pmb.C = C.LLVMPassManagerBuilderCreate()
|
||||
return
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) SetOptLevel(level int) {
|
||||
C.LLVMPassManagerBuilderSetOptLevel(pmb.C, C.uint(level))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) SetSizeLevel(level int) {
|
||||
C.LLVMPassManagerBuilderSetSizeLevel(pmb.C, C.uint(level))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) Populate(pm PassManager) {
|
||||
C.LLVMPassManagerBuilderPopulateModulePassManager(pmb.C, pm.C)
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) PopulateFunc(pm PassManager) {
|
||||
C.LLVMPassManagerBuilderPopulateFunctionPassManager(pmb.C, pm.C)
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) PopulateLTOPassManager(pm PassManager, internalize bool, runInliner bool) {
|
||||
C.LLVMPassManagerBuilderPopulateLTOPassManager(pmb.C, pm.C, boolToLLVMBool(internalize), boolToLLVMBool(runInliner))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) Dispose() {
|
||||
C.LLVMPassManagerBuilderDispose(pmb.C)
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) SetDisableUnitAtATime(val bool) {
|
||||
C.LLVMPassManagerBuilderSetDisableUnitAtATime(pmb.C, boolToLLVMBool(val))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) SetDisableUnrollLoops(val bool) {
|
||||
C.LLVMPassManagerBuilderSetDisableUnrollLoops(pmb.C, boolToLLVMBool(val))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) SetDisableSimplifyLibCalls(val bool) {
|
||||
C.LLVMPassManagerBuilderSetDisableSimplifyLibCalls(pmb.C, boolToLLVMBool(val))
|
||||
}
|
||||
|
||||
func (pmb PassManagerBuilder) UseInlinerWithThreshold(threshold uint) {
|
||||
C.LLVMPassManagerBuilderUseInlinerWithThreshold(pmb.C, C.uint(threshold))
|
||||
}
|
45
external/llvm/bindings/go/llvm/transforms_scalar.go
vendored
Normal file
45
external/llvm/bindings/go/llvm/transforms_scalar.go
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
//===- transforms_scalar.go - Bindings for scalaropts ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines bindings for the scalaropts component.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm-c/Transforms/Scalar.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func (pm PassManager) AddAggressiveDCEPass() { C.LLVMAddAggressiveDCEPass(pm.C) }
|
||||
func (pm PassManager) AddCFGSimplificationPass() { C.LLVMAddCFGSimplificationPass(pm.C) }
|
||||
func (pm PassManager) AddDeadStoreEliminationPass() { C.LLVMAddDeadStoreEliminationPass(pm.C) }
|
||||
func (pm PassManager) AddGVNPass() { C.LLVMAddGVNPass(pm.C) }
|
||||
func (pm PassManager) AddIndVarSimplifyPass() { C.LLVMAddIndVarSimplifyPass(pm.C) }
|
||||
func (pm PassManager) AddInstructionCombiningPass() { C.LLVMAddInstructionCombiningPass(pm.C) }
|
||||
func (pm PassManager) AddJumpThreadingPass() { C.LLVMAddJumpThreadingPass(pm.C) }
|
||||
func (pm PassManager) AddLICMPass() { C.LLVMAddLICMPass(pm.C) }
|
||||
func (pm PassManager) AddLoopDeletionPass() { C.LLVMAddLoopDeletionPass(pm.C) }
|
||||
func (pm PassManager) AddLoopRotatePass() { C.LLVMAddLoopRotatePass(pm.C) }
|
||||
func (pm PassManager) AddLoopUnrollPass() { C.LLVMAddLoopUnrollPass(pm.C) }
|
||||
func (pm PassManager) AddLoopUnswitchPass() { C.LLVMAddLoopUnswitchPass(pm.C) }
|
||||
func (pm PassManager) AddMemCpyOptPass() { C.LLVMAddMemCpyOptPass(pm.C) }
|
||||
func (pm PassManager) AddPromoteMemoryToRegisterPass() { C.LLVMAddPromoteMemoryToRegisterPass(pm.C) }
|
||||
func (pm PassManager) AddReassociatePass() { C.LLVMAddReassociatePass(pm.C) }
|
||||
func (pm PassManager) AddSCCPPass() { C.LLVMAddSCCPPass(pm.C) }
|
||||
func (pm PassManager) AddScalarReplAggregatesPass() { C.LLVMAddScalarReplAggregatesPass(pm.C) }
|
||||
func (pm PassManager) AddScalarReplAggregatesPassWithThreshold(threshold int) {
|
||||
C.LLVMAddScalarReplAggregatesPassWithThreshold(pm.C, C.int(threshold))
|
||||
}
|
||||
func (pm PassManager) AddSimplifyLibCallsPass() { C.LLVMAddSimplifyLibCallsPass(pm.C) }
|
||||
func (pm PassManager) AddTailCallEliminationPass() { C.LLVMAddTailCallEliminationPass(pm.C) }
|
||||
func (pm PassManager) AddConstantPropagationPass() { C.LLVMAddConstantPropagationPass(pm.C) }
|
||||
func (pm PassManager) AddDemoteMemoryToRegisterPass() { C.LLVMAddDemoteMemoryToRegisterPass(pm.C) }
|
||||
func (pm PassManager) AddVerifierPass() { C.LLVMAddVerifierPass(pm.C) }
|
21
external/llvm/bindings/go/llvm/version.go
vendored
Normal file
21
external/llvm/bindings/go/llvm/version.go
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
//===- version.go - LLVM version info -------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines LLVM version information.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
package llvm
|
||||
|
||||
/*
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const Version = C.LLVM_VERSION_STRING
|
11
external/llvm/bindings/ocaml/CMakeLists.txt
vendored
Normal file
11
external/llvm/bindings/ocaml/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
add_subdirectory(llvm)
|
||||
add_subdirectory(all_backends)
|
||||
add_subdirectory(analysis)
|
||||
add_subdirectory(backends)
|
||||
add_subdirectory(bitreader)
|
||||
add_subdirectory(bitwriter)
|
||||
add_subdirectory(irreader)
|
||||
add_subdirectory(linker)
|
||||
add_subdirectory(target)
|
||||
add_subdirectory(transforms)
|
||||
add_subdirectory(executionengine)
|
29
external/llvm/bindings/ocaml/README.txt
vendored
Normal file
29
external/llvm/bindings/ocaml/README.txt
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
This directory contains LLVM bindings for the OCaml programming language
|
||||
(http://ocaml.org).
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
* OCaml 4.00.0+.
|
||||
* ctypes 0.4+.
|
||||
* oUnit 2+ (only required for tests).
|
||||
* CMake (to build LLVM).
|
||||
|
||||
Building the bindings
|
||||
---------------------
|
||||
|
||||
If all dependencies are present, the bindings will be built and installed
|
||||
as a part of the default CMake configuration, with no further action.
|
||||
They will only work with the specific OCaml compiler detected during the build.
|
||||
|
||||
The bindings can also be built out-of-tree, i.e. targeting a preinstalled
|
||||
LLVM. To do this, configure the LLVM build tree as follows:
|
||||
|
||||
$ cmake -DLLVM_OCAML_OUT_OF_TREE=TRUE \
|
||||
-DCMAKE_INSTALL_PREFIX=[OCaml install prefix] \
|
||||
[... any other options]
|
||||
|
||||
then build and install it as:
|
||||
|
||||
$ make ocaml_all
|
||||
$ cmake -P bindings/ocaml/cmake_install.cmake
|
5
external/llvm/bindings/ocaml/all_backends/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/all_backends/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_all_backends
|
||||
OCAML llvm_all_backends
|
||||
OCAMLDEP llvm
|
||||
C all_backends_ocaml
|
||||
LLVM ${LLVM_TARGETS_TO_BUILD})
|
32
external/llvm/bindings/ocaml/all_backends/all_backends_ocaml.c
vendored
Normal file
32
external/llvm/bindings/ocaml/all_backends/all_backends_ocaml.c
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*===-- all_backends_ocaml.c - LLVM OCaml Glue ------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Target.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/custom.h"
|
||||
|
||||
/* unit -> unit */
|
||||
CAMLprim value llvm_initialize_all(value Unit) {
|
||||
LLVMInitializeAllTargetInfos();
|
||||
LLVMInitializeAllTargets();
|
||||
LLVMInitializeAllTargetMCs();
|
||||
LLVMInitializeAllAsmPrinters();
|
||||
LLVMInitializeAllAsmParsers();
|
||||
return Val_unit;
|
||||
}
|
10
external/llvm/bindings/ocaml/all_backends/llvm_all_backends.ml
vendored
Normal file
10
external/llvm/bindings/ocaml/all_backends/llvm_all_backends.ml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
(*===-- llvm_all_backends.ml - LLVM OCaml Interface -----------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
external initialize : unit -> unit = "llvm_initialize_all"
|
11
external/llvm/bindings/ocaml/all_backends/llvm_all_backends.mli
vendored
Normal file
11
external/llvm/bindings/ocaml/all_backends/llvm_all_backends.mli
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
(*===-- llvm_all_backends.mli - LLVM OCaml Interface ----------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Initialize all the backends targets *)
|
||||
val initialize : unit -> unit
|
5
external/llvm/bindings/ocaml/analysis/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/analysis/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_analysis
|
||||
OCAML llvm_analysis
|
||||
OCAMLDEP llvm
|
||||
C analysis_ocaml
|
||||
LLVM analysis)
|
72
external/llvm/bindings/ocaml/analysis/analysis_ocaml.c
vendored
Normal file
72
external/llvm/bindings/ocaml/analysis/analysis_ocaml.c
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/*===-- analysis_ocaml.c - LLVM OCaml Glue ----------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Analysis.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/mlvalues.h"
|
||||
#include "caml/memory.h"
|
||||
|
||||
/* Llvm.llmodule -> string option */
|
||||
CAMLprim value llvm_verify_module(LLVMModuleRef M) {
|
||||
CAMLparam0();
|
||||
CAMLlocal2(String, Option);
|
||||
|
||||
char *Message;
|
||||
int Result = LLVMVerifyModule(M, LLVMReturnStatusAction, &Message);
|
||||
|
||||
if (0 == Result) {
|
||||
Option = Val_int(0);
|
||||
} else {
|
||||
Option = alloc(1, 0);
|
||||
String = copy_string(Message);
|
||||
Store_field(Option, 0, String);
|
||||
}
|
||||
|
||||
LLVMDisposeMessage(Message);
|
||||
|
||||
CAMLreturn(Option);
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> bool */
|
||||
CAMLprim value llvm_verify_function(LLVMValueRef Fn) {
|
||||
return Val_bool(LLVMVerifyFunction(Fn, LLVMReturnStatusAction) == 0);
|
||||
}
|
||||
|
||||
/* Llvm.llmodule -> unit */
|
||||
CAMLprim value llvm_assert_valid_module(LLVMModuleRef M) {
|
||||
LLVMVerifyModule(M, LLVMAbortProcessAction, 0);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> unit */
|
||||
CAMLprim value llvm_assert_valid_function(LLVMValueRef Fn) {
|
||||
LLVMVerifyFunction(Fn, LLVMAbortProcessAction);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> unit */
|
||||
CAMLprim value llvm_view_function_cfg(LLVMValueRef Fn) {
|
||||
LLVMViewFunctionCFG(Fn);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> unit */
|
||||
CAMLprim value llvm_view_function_cfg_only(LLVMValueRef Fn) {
|
||||
LLVMViewFunctionCFGOnly(Fn);
|
||||
return Val_unit;
|
||||
}
|
22
external/llvm/bindings/ocaml/analysis/llvm_analysis.ml
vendored
Normal file
22
external/llvm/bindings/ocaml/analysis/llvm_analysis.ml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
(*===-- llvm_analysis.ml - LLVM OCaml Interface ---------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
|
||||
external verify_module : Llvm.llmodule -> string option = "llvm_verify_module"
|
||||
|
||||
external verify_function : Llvm.llvalue -> bool = "llvm_verify_function"
|
||||
|
||||
external assert_valid_module : Llvm.llmodule -> unit
|
||||
= "llvm_assert_valid_module"
|
||||
|
||||
external assert_valid_function : Llvm.llvalue -> unit
|
||||
= "llvm_assert_valid_function"
|
||||
external view_function_cfg : Llvm.llvalue -> unit = "llvm_view_function_cfg"
|
||||
external view_function_cfg_only : Llvm.llvalue -> unit
|
||||
= "llvm_view_function_cfg_only"
|
46
external/llvm/bindings/ocaml/analysis/llvm_analysis.mli
vendored
Normal file
46
external/llvm/bindings/ocaml/analysis/llvm_analysis.mli
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
(*===-- llvm_analysis.mli - LLVM OCaml Interface --------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Intermediate representation analysis.
|
||||
|
||||
This interface provides an OCaml API for LLVM IR analyses, the classes in
|
||||
the Analysis library. *)
|
||||
|
||||
(** [verify_module m] returns [None] if the module [m] is valid, and
|
||||
[Some reason] if it is invalid. [reason] is a string containing a
|
||||
human-readable validation report. See [llvm::verifyModule]. *)
|
||||
external verify_module : Llvm.llmodule -> string option = "llvm_verify_module"
|
||||
|
||||
(** [verify_function f] returns [None] if the function [f] is valid, and
|
||||
[Some reason] if it is invalid. [reason] is a string containing a
|
||||
human-readable validation report. See [llvm::verifyFunction]. *)
|
||||
external verify_function : Llvm.llvalue -> bool = "llvm_verify_function"
|
||||
|
||||
(** [verify_module m] returns if the module [m] is valid, but prints a
|
||||
validation report to [stderr] and aborts the program if it is invalid. See
|
||||
[llvm::verifyModule]. *)
|
||||
external assert_valid_module : Llvm.llmodule -> unit
|
||||
= "llvm_assert_valid_module"
|
||||
|
||||
(** [verify_function f] returns if the function [f] is valid, but prints a
|
||||
validation report to [stderr] and aborts the program if it is invalid. See
|
||||
[llvm::verifyFunction]. *)
|
||||
external assert_valid_function : Llvm.llvalue -> unit
|
||||
= "llvm_assert_valid_function"
|
||||
|
||||
(** [view_function_cfg f] opens up a ghostscript window displaying the CFG of
|
||||
the current function with the code for each basic block inside.
|
||||
See [llvm::Function::viewCFG]. *)
|
||||
external view_function_cfg : Llvm.llvalue -> unit = "llvm_view_function_cfg"
|
||||
|
||||
(** [view_function_cfg_only f] works just like [view_function_cfg], but does not
|
||||
include the contents of basic blocks into the nodes.
|
||||
See [llvm::Function::viewCFGOnly]. *)
|
||||
external view_function_cfg_only : Llvm.llvalue -> unit
|
||||
= "llvm_view_function_cfg_only"
|
27
external/llvm/bindings/ocaml/backends/CMakeLists.txt
vendored
Normal file
27
external/llvm/bindings/ocaml/backends/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
foreach(TARGET ${LLVM_TARGETS_TO_BUILD})
|
||||
set(OCAML_LLVM_TARGET ${TARGET})
|
||||
|
||||
foreach( ext ml mli )
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/llvm_backend.${ext}.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/llvm_${TARGET}.${ext}")
|
||||
endforeach()
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/backend_ocaml.c"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_ocaml.c")
|
||||
|
||||
add_ocaml_library(llvm_${TARGET}
|
||||
OCAML llvm_${TARGET}
|
||||
C ${TARGET}_ocaml
|
||||
CFLAGS -DTARGET=${TARGET}
|
||||
LLVM ${TARGET}
|
||||
NOCOPY)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/META.llvm_backend.in"
|
||||
"${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}")
|
||||
|
||||
install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}"
|
||||
DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
|
||||
endforeach()
|
7
external/llvm/bindings/ocaml/backends/META.llvm_backend.in
vendored
Normal file
7
external/llvm/bindings/ocaml/backends/META.llvm_backend.in
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
name = "llvm_@TARGET@"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "@TARGET@ Backend for LLVM"
|
||||
requires = "llvm"
|
||||
archive(byte) = "llvm_@TARGET@.cma"
|
||||
archive(native) = "llvm_@TARGET@.cmxa"
|
||||
directory = "llvm"
|
38
external/llvm/bindings/ocaml/backends/backend_ocaml.c
vendored
Normal file
38
external/llvm/bindings/ocaml/backends/backend_ocaml.c
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/*===-- backend_ocaml.c - LLVM OCaml Glue -----------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Target.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/memory.h"
|
||||
|
||||
/* TODO: Figure out how to call these only for targets which support them.
|
||||
* LLVMInitialize ## target ## AsmPrinter();
|
||||
* LLVMInitialize ## target ## AsmParser();
|
||||
* LLVMInitialize ## target ## Disassembler();
|
||||
*/
|
||||
|
||||
#define INITIALIZER1(target) \
|
||||
CAMLprim value llvm_initialize_ ## target(value Unit) { \
|
||||
LLVMInitialize ## target ## TargetInfo(); \
|
||||
LLVMInitialize ## target ## Target(); \
|
||||
LLVMInitialize ## target ## TargetMC(); \
|
||||
return Val_unit; \
|
||||
}
|
||||
|
||||
#define INITIALIZER(target) INITIALIZER1(target)
|
||||
|
||||
INITIALIZER(TARGET)
|
10
external/llvm/bindings/ocaml/backends/llvm_backend.ml.in
vendored
Normal file
10
external/llvm/bindings/ocaml/backends/llvm_backend.ml.in
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
(*===-- llvm_backend.ml.in - LLVM OCaml Interface -------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
external initialize : unit -> unit = "llvm_initialize_@TARGET@"
|
19
external/llvm/bindings/ocaml/backends/llvm_backend.mli.in
vendored
Normal file
19
external/llvm/bindings/ocaml/backends/llvm_backend.mli.in
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
(*===-- llvm_backend.mli.in - LLVM OCaml Interface ------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** @TARGET@ Initialization.
|
||||
|
||||
This interface provides an OCaml API for initialization of
|
||||
the @TARGET@ LLVM target. By referencing this module, you will cause
|
||||
OCaml to load or link in the LLVM libraries corresponding to the target.
|
||||
By calling [initialize], you will register components of this target
|
||||
in the target registry, which is necessary in order to emit assembly,
|
||||
object files, and so on. *)
|
||||
|
||||
external initialize : unit -> unit = "llvm_initialize_@TARGET@"
|
5
external/llvm/bindings/ocaml/bitreader/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/bitreader/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_bitreader
|
||||
OCAML llvm_bitreader
|
||||
OCAMLDEP llvm
|
||||
C bitreader_ocaml
|
||||
LLVM bitreader)
|
42
external/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c
vendored
Normal file
42
external/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
|
||||
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
||||
CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
||||
LLVMModuleRef M;
|
||||
|
||||
if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
|
||||
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
||||
CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
|
||||
LLVMModuleRef M;
|
||||
|
||||
if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
|
||||
llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
|
||||
|
||||
return M;
|
||||
}
|
19
external/llvm/bindings/ocaml/bitreader/llvm_bitreader.ml
vendored
Normal file
19
external/llvm/bindings/ocaml/bitreader/llvm_bitreader.ml
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
(*===-- llvm_bitreader.ml - LLVM OCaml Interface --------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
exception Error of string
|
||||
|
||||
let () = Callback.register_exception "Llvm_bitreader.Error" (Error "")
|
||||
|
||||
external get_module
|
||||
: Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
||||
= "llvm_get_module"
|
||||
external parse_bitcode
|
||||
: Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
||||
= "llvm_parse_bitcode"
|
27
external/llvm/bindings/ocaml/bitreader/llvm_bitreader.mli
vendored
Normal file
27
external/llvm/bindings/ocaml/bitreader/llvm_bitreader.mli
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
(*===-- llvm_bitreader.mli - LLVM OCaml Interface -------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Bitcode reader.
|
||||
|
||||
This interface provides an OCaml API for the LLVM bitcode reader, the
|
||||
classes in the Bitreader library. *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** [get_module context mb] reads the bitcode for a new module [m] from the
|
||||
memory buffer [mb] in the context [context]. Returns [m] if successful, or
|
||||
raises [Error msg] otherwise, where [msg] is a description of the error
|
||||
encountered. See the function [llvm::getBitcodeModule]. *)
|
||||
val get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
||||
|
||||
(** [parse_bitcode context mb] parses the bitcode for a new module [m] from the
|
||||
memory buffer [mb] in the context [context]. Returns [m] if successful, or
|
||||
raises [Error msg] otherwise, where [msg] is a description of the error
|
||||
encountered. See the function [llvm::ParseBitcodeFile]. *)
|
||||
val parse_bitcode : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
5
external/llvm/bindings/ocaml/bitwriter/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/bitwriter/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_bitwriter
|
||||
OCAML llvm_bitwriter
|
||||
OCAMLDEP llvm
|
||||
C bitwriter_ocaml
|
||||
LLVM bitwriter)
|
48
external/llvm/bindings/ocaml/bitwriter/bitwriter_ocaml.c
vendored
Normal file
48
external/llvm/bindings/ocaml/bitwriter/bitwriter_ocaml.c
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/BitWriter.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/mlvalues.h"
|
||||
#include "caml/memory.h"
|
||||
|
||||
/* Llvm.llmodule -> string -> bool */
|
||||
CAMLprim value llvm_write_bitcode_file(LLVMModuleRef M, value Path) {
|
||||
int Result = LLVMWriteBitcodeToFile(M, String_val(Path));
|
||||
return Val_bool(Result == 0);
|
||||
}
|
||||
|
||||
/* ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool */
|
||||
CAMLprim value llvm_write_bitcode_to_fd(value U, LLVMModuleRef M, value FD) {
|
||||
int Unbuffered;
|
||||
int Result;
|
||||
|
||||
if (U == Val_int(0)) {
|
||||
Unbuffered = 0;
|
||||
} else {
|
||||
Unbuffered = Bool_val(Field(U, 0));
|
||||
}
|
||||
|
||||
Result = LLVMWriteBitcodeToFD(M, Int_val(FD), 0, Unbuffered);
|
||||
return Val_bool(Result == 0);
|
||||
}
|
||||
|
||||
/* Llvm.llmodule -> Llvm.llmemorybuffer */
|
||||
CAMLprim LLVMMemoryBufferRef llvm_write_bitcode_to_memory_buffer(LLVMModuleRef M) {
|
||||
return LLVMWriteBitcodeToMemoryBuffer(M);
|
||||
}
|
28
external/llvm/bindings/ocaml/bitwriter/llvm_bitwriter.ml
vendored
Normal file
28
external/llvm/bindings/ocaml/bitwriter/llvm_bitwriter.ml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
(*===-- llvm_bitwriter.ml - LLVM OCaml Interface --------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===
|
||||
*
|
||||
* This interface provides an OCaml API for the LLVM intermediate
|
||||
* representation, the classes in the VMCore library.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
external write_bitcode_file
|
||||
: Llvm.llmodule -> string -> bool
|
||||
= "llvm_write_bitcode_file"
|
||||
|
||||
external write_bitcode_to_fd
|
||||
: ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool
|
||||
= "llvm_write_bitcode_to_fd"
|
||||
|
||||
external write_bitcode_to_memory_buffer
|
||||
: Llvm.llmodule -> Llvm.llmemorybuffer
|
||||
= "llvm_write_bitcode_to_memory_buffer"
|
||||
|
||||
let output_bitcode ?unbuffered channel m =
|
||||
write_bitcode_to_fd ?unbuffered m (Unix.descr_of_out_channel channel)
|
37
external/llvm/bindings/ocaml/bitwriter/llvm_bitwriter.mli
vendored
Normal file
37
external/llvm/bindings/ocaml/bitwriter/llvm_bitwriter.mli
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
(*===-- llvm_bitwriter.mli - LLVM OCaml Interface -------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Bitcode writer.
|
||||
|
||||
This interface provides an OCaml API for the LLVM bitcode writer, the
|
||||
classes in the Bitwriter library. *)
|
||||
|
||||
(** [write_bitcode_file m path] writes the bitcode for module [m] to the file at
|
||||
[path]. Returns [true] if successful, [false] otherwise. *)
|
||||
external write_bitcode_file
|
||||
: Llvm.llmodule -> string -> bool
|
||||
= "llvm_write_bitcode_file"
|
||||
|
||||
(** [write_bitcode_to_fd ~unbuffered fd m] writes the bitcode for module
|
||||
[m] to the channel [c]. If [unbuffered] is [true], after every write the fd
|
||||
will be flushed. Returns [true] if successful, [false] otherwise. *)
|
||||
external write_bitcode_to_fd
|
||||
: ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool
|
||||
= "llvm_write_bitcode_to_fd"
|
||||
|
||||
(** [write_bitcode_to_memory_buffer m] returns a memory buffer containing
|
||||
the bitcode for module [m]. *)
|
||||
external write_bitcode_to_memory_buffer
|
||||
: Llvm.llmodule -> Llvm.llmemorybuffer
|
||||
= "llvm_write_bitcode_to_memory_buffer"
|
||||
|
||||
(** [output_bitcode ~unbuffered c m] writes the bitcode for module [m]
|
||||
to the channel [c]. If [unbuffered] is [true], after every write the fd
|
||||
will be flushed. Returns [true] if successful, [false] otherwise. *)
|
||||
val output_bitcode : ?unbuffered:bool -> out_channel -> Llvm.llmodule -> bool
|
6
external/llvm/bindings/ocaml/executionengine/CMakeLists.txt
vendored
Normal file
6
external/llvm/bindings/ocaml/executionengine/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
add_ocaml_library(llvm_executionengine
|
||||
OCAML llvm_executionengine
|
||||
OCAMLDEP llvm llvm_target
|
||||
C executionengine_ocaml
|
||||
LLVM executionengine mcjit native
|
||||
PKG ctypes)
|
127
external/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
vendored
Normal file
127
external/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
/*===-- executionengine_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Target.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/custom.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
|
||||
/* unit -> bool */
|
||||
CAMLprim value llvm_ee_initialize(value Unit) {
|
||||
LLVMLinkInMCJIT();
|
||||
|
||||
return Val_bool(!LLVMInitializeNativeTarget() &&
|
||||
!LLVMInitializeNativeAsmParser() &&
|
||||
!LLVMInitializeNativeAsmPrinter());
|
||||
}
|
||||
|
||||
/* llmodule -> llcompileroption -> ExecutionEngine.t */
|
||||
CAMLprim LLVMExecutionEngineRef llvm_ee_create(value OptRecordOpt, LLVMModuleRef M) {
|
||||
value OptRecord;
|
||||
LLVMExecutionEngineRef MCJIT;
|
||||
char *Error;
|
||||
struct LLVMMCJITCompilerOptions Options;
|
||||
|
||||
LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options));
|
||||
if (OptRecordOpt != Val_int(0)) {
|
||||
OptRecord = Field(OptRecordOpt, 0);
|
||||
Options.OptLevel = Int_val(Field(OptRecord, 0));
|
||||
Options.CodeModel = Int_val(Field(OptRecord, 1));
|
||||
Options.NoFramePointerElim = Int_val(Field(OptRecord, 2));
|
||||
Options.EnableFastISel = Int_val(Field(OptRecord, 3));
|
||||
Options.MCJMM = NULL;
|
||||
}
|
||||
|
||||
if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options,
|
||||
sizeof(Options), &Error))
|
||||
llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
|
||||
return MCJIT;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) {
|
||||
LLVMDisposeExecutionEngine(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* llmodule -> ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_add_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) {
|
||||
LLVMAddModule(EE, M);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* llmodule -> ExecutionEngine.t -> llmodule */
|
||||
CAMLprim value llvm_ee_remove_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) {
|
||||
LLVMModuleRef RemovedModule;
|
||||
char *Error;
|
||||
if (LLVMRemoveModule(EE, M, &RemovedModule, &Error))
|
||||
llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_run_static_ctors(LLVMExecutionEngineRef EE) {
|
||||
LLVMRunStaticConstructors(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* ExecutionEngine.t -> unit */
|
||||
CAMLprim value llvm_ee_run_static_dtors(LLVMExecutionEngineRef EE) {
|
||||
LLVMRunStaticDestructors(EE);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);
|
||||
|
||||
/* ExecutionEngine.t -> Llvm_target.DataLayout.t */
|
||||
CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
|
||||
value DataLayout;
|
||||
LLVMTargetDataRef OrigDataLayout;
|
||||
char* TargetDataCStr;
|
||||
|
||||
OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
|
||||
TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
|
||||
DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
|
||||
LLVMDisposeMessage(TargetDataCStr);
|
||||
|
||||
return DataLayout;
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> int64 -> llexecutionengine -> unit */
|
||||
CAMLprim value llvm_ee_add_global_mapping(LLVMValueRef Global, value Ptr,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
LLVMAddGlobalMapping(EE, Global, (void*) (Int64_val(Ptr)));
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
CAMLprim value llvm_ee_get_global_value_address(value Name,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
return caml_copy_int64((int64_t) LLVMGetGlobalValueAddress(EE, String_val(Name)));
|
||||
}
|
||||
|
||||
CAMLprim value llvm_ee_get_function_address(value Name,
|
||||
LLVMExecutionEngineRef EE) {
|
||||
return caml_copy_int64((int64_t) LLVMGetFunctionAddress(EE, String_val(Name)));
|
||||
}
|
72
external/llvm/bindings/ocaml/executionengine/llvm_executionengine.ml
vendored
Normal file
72
external/llvm/bindings/ocaml/executionengine/llvm_executionengine.ml
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
(*===-- llvm_executionengine.ml - LLVM OCaml Interface --------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
exception Error of string
|
||||
|
||||
let () = Callback.register_exception "Llvm_executionengine.Error" (Error "")
|
||||
|
||||
external initialize : unit -> bool
|
||||
= "llvm_ee_initialize"
|
||||
|
||||
type llexecutionengine
|
||||
|
||||
type llcompileroptions = {
|
||||
opt_level: int;
|
||||
code_model: Llvm_target.CodeModel.t;
|
||||
no_framepointer_elim: bool;
|
||||
enable_fast_isel: bool;
|
||||
}
|
||||
|
||||
let default_compiler_options = {
|
||||
opt_level = 0;
|
||||
code_model = Llvm_target.CodeModel.JITDefault;
|
||||
no_framepointer_elim = false;
|
||||
enable_fast_isel = false }
|
||||
|
||||
external create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine
|
||||
= "llvm_ee_create"
|
||||
external dispose : llexecutionengine -> unit
|
||||
= "llvm_ee_dispose"
|
||||
external add_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
= "llvm_ee_add_module"
|
||||
external remove_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
= "llvm_ee_remove_module"
|
||||
external run_static_ctors : llexecutionengine -> unit
|
||||
= "llvm_ee_run_static_ctors"
|
||||
external run_static_dtors : llexecutionengine -> unit
|
||||
= "llvm_ee_run_static_dtors"
|
||||
external data_layout : llexecutionengine -> Llvm_target.DataLayout.t
|
||||
= "llvm_ee_get_data_layout"
|
||||
external add_global_mapping_ : Llvm.llvalue -> nativeint -> llexecutionengine -> unit
|
||||
= "llvm_ee_add_global_mapping"
|
||||
external get_global_value_address_ : string -> llexecutionengine -> nativeint
|
||||
= "llvm_ee_get_global_value_address"
|
||||
external get_function_address_ : string -> llexecutionengine -> nativeint
|
||||
= "llvm_ee_get_function_address"
|
||||
|
||||
let add_global_mapping llval ptr ee =
|
||||
add_global_mapping_ llval (Ctypes.raw_address_of_ptr (Ctypes.to_voidp ptr)) ee
|
||||
|
||||
let get_global_value_address name typ ee =
|
||||
let vptr = get_global_value_address_ name ee in
|
||||
if Nativeint.to_int vptr <> 0 then
|
||||
let open Ctypes in !@ (coerce (ptr void) (ptr typ) (ptr_of_raw_address vptr))
|
||||
else
|
||||
raise (Error ("Value " ^ name ^ " not found"))
|
||||
|
||||
let get_function_address name typ ee =
|
||||
let fptr = get_function_address_ name ee in
|
||||
if Nativeint.to_int fptr <> 0 then
|
||||
let open Ctypes in coerce (ptr void) typ (ptr_of_raw_address fptr)
|
||||
else
|
||||
raise (Error ("Function " ^ name ^ " not found"))
|
||||
|
||||
(* The following are not bound. Patches are welcome.
|
||||
target_machine : llexecutionengine -> Llvm_target.TargetMachine.t
|
||||
*)
|
93
external/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli
vendored
Normal file
93
external/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
(*===-- llvm_executionengine.mli - LLVM OCaml Interface -------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** JIT Interpreter.
|
||||
|
||||
This interface provides an OCaml API for LLVM execution engine (JIT/
|
||||
interpreter), the classes in the [ExecutionEngine] library. *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** [initialize ()] initializes the backend corresponding to the host.
|
||||
Returns [true] if initialization is successful; [false] indicates
|
||||
that there is no such backend or it is unable to emit object code
|
||||
via MCJIT. *)
|
||||
val initialize : unit -> bool
|
||||
|
||||
(** An execution engine is either a JIT compiler or an interpreter, capable of
|
||||
directly loading an LLVM module and executing its functions without first
|
||||
invoking a static compiler and generating a native executable. *)
|
||||
type llexecutionengine
|
||||
|
||||
(** MCJIT compiler options. See [llvm::TargetOptions]. *)
|
||||
type llcompileroptions = {
|
||||
opt_level: int;
|
||||
code_model: Llvm_target.CodeModel.t;
|
||||
no_framepointer_elim: bool;
|
||||
enable_fast_isel: bool;
|
||||
}
|
||||
|
||||
(** Default MCJIT compiler options:
|
||||
[{ opt_level = 0; code_model = CodeModel.JIT_default;
|
||||
no_framepointer_elim = false; enable_fast_isel = false }] *)
|
||||
val default_compiler_options : llcompileroptions
|
||||
|
||||
(** [create m optlevel] creates a new MCJIT just-in-time compiler, taking
|
||||
ownership of the module [m] if successful with the desired optimization
|
||||
level [optlevel]. Raises [Error msg] if an error occurrs. The execution
|
||||
engine is not garbage collected and must be destroyed with [dispose ee].
|
||||
|
||||
Run {!initialize} before using this function.
|
||||
|
||||
See the function [llvm::EngineBuilder::create]. *)
|
||||
val create : ?options:llcompileroptions -> Llvm.llmodule -> llexecutionengine
|
||||
|
||||
(** [dispose ee] releases the memory used by the execution engine and must be
|
||||
invoked to avoid memory leaks. *)
|
||||
val dispose : llexecutionengine -> unit
|
||||
|
||||
(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)
|
||||
val add_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
|
||||
(** [remove_module m ee] removes the module [m] from the execution engine
|
||||
[ee]. Raises [Error msg] if an error occurs. *)
|
||||
val remove_module : Llvm.llmodule -> llexecutionengine -> unit
|
||||
|
||||
(** [run_static_ctors ee] executes the static constructors of each module in
|
||||
the execution engine [ee]. *)
|
||||
val run_static_ctors : llexecutionengine -> unit
|
||||
|
||||
(** [run_static_dtors ee] executes the static destructors of each module in
|
||||
the execution engine [ee]. *)
|
||||
val run_static_dtors : llexecutionengine -> unit
|
||||
|
||||
(** [data_layout ee] is the data layout of the execution engine [ee]. *)
|
||||
val data_layout : llexecutionengine -> Llvm_target.DataLayout.t
|
||||
|
||||
(** [add_global_mapping gv ptr ee] tells the execution engine [ee] that
|
||||
the global [gv] is at the specified location [ptr], which must outlive
|
||||
[gv] and [ee].
|
||||
All uses of [gv] in the compiled code will refer to [ptr]. *)
|
||||
val add_global_mapping : Llvm.llvalue -> 'a Ctypes.ptr -> llexecutionengine -> unit
|
||||
|
||||
(** [get_global_value_address id typ ee] returns a pointer to the
|
||||
identifier [id] as type [typ], which will be a pointer type for a
|
||||
value, and which will be live as long as [id] and [ee]
|
||||
are. Caution: this function finalizes, i.e. forces code
|
||||
generation, all loaded modules. Further modifications to the
|
||||
modules will not have any effect. *)
|
||||
val get_global_value_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
|
||||
|
||||
(** [get_function_address fn typ ee] returns a pointer to the function
|
||||
[fn] as type [typ], which will be a pointer type for a function
|
||||
(e.g. [(int -> int) typ]), and which will be live as long as [fn]
|
||||
and [ee] are. Caution: this function finalizes, i.e. forces code
|
||||
generation, all loaded modules. Further modifications to the
|
||||
modules will not have any effect. *)
|
||||
val get_function_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
|
5
external/llvm/bindings/ocaml/irreader/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/irreader/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_irreader
|
||||
OCAML llvm_irreader
|
||||
OCAMLDEP llvm
|
||||
C irreader_ocaml
|
||||
LLVM irreader)
|
35
external/llvm/bindings/ocaml/irreader/irreader_ocaml.c
vendored
Normal file
35
external/llvm/bindings/ocaml/irreader/irreader_ocaml.c
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*===-- irreader_ocaml.c - LLVM OCaml Glue ----------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/IRReader.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
|
||||
/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
|
||||
CAMLprim value llvm_parse_ir(LLVMContextRef C,
|
||||
LLVMMemoryBufferRef MemBuf) {
|
||||
CAMLparam0();
|
||||
CAMLlocal2(Variant, MessageVal);
|
||||
LLVMModuleRef M;
|
||||
char *Message;
|
||||
|
||||
if (LLVMParseIRInContext(C, MemBuf, &M, &Message))
|
||||
llvm_raise(*caml_named_value("Llvm_irreader.Error"), Message);
|
||||
|
||||
CAMLreturn((value) M);
|
||||
}
|
16
external/llvm/bindings/ocaml/irreader/llvm_irreader.ml
vendored
Normal file
16
external/llvm/bindings/ocaml/irreader/llvm_irreader.ml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
(*===-- llvm_irreader.ml - LLVM OCaml Interface ---------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
|
||||
exception Error of string
|
||||
|
||||
let _ = Callback.register_exception "Llvm_irreader.Error" (Error "")
|
||||
|
||||
external parse_ir : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
||||
= "llvm_parse_ir"
|
21
external/llvm/bindings/ocaml/irreader/llvm_irreader.mli
vendored
Normal file
21
external/llvm/bindings/ocaml/irreader/llvm_irreader.mli
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
(*===-- llvm_irreader.mli - LLVM OCaml Interface --------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** IR reader.
|
||||
|
||||
This interface provides an OCaml API for the LLVM assembly reader, the
|
||||
classes in the IRReader library. *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** [parse_ir context mb] parses the IR for a new module [m] from the
|
||||
memory buffer [mb] in the context [context]. Returns [m] if successful, or
|
||||
raises [Error msg] otherwise, where [msg] is a description of the error
|
||||
encountered. See the function [llvm::ParseIR]. *)
|
||||
val parse_ir : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
|
5
external/llvm/bindings/ocaml/linker/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/linker/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_linker
|
||||
OCAML llvm_linker
|
||||
OCAMLDEP llvm
|
||||
C linker_ocaml
|
||||
LLVM linker)
|
33
external/llvm/bindings/ocaml/linker/linker_ocaml.c
vendored
Normal file
33
external/llvm/bindings/ocaml/linker/linker_ocaml.c
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/*===-- linker_ocaml.c - LLVM OCaml Glue ------------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Linker.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
|
||||
/* llmodule -> llmodule -> unit */
|
||||
CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src) {
|
||||
if (LLVMLinkModules2(Dst, Src))
|
||||
llvm_raise(*caml_named_value("Llvm_linker.Error"), LLVMCreateMessage("Linking failed"));
|
||||
|
||||
return Val_unit;
|
||||
}
|
15
external/llvm/bindings/ocaml/linker/llvm_linker.ml
vendored
Normal file
15
external/llvm/bindings/ocaml/linker/llvm_linker.ml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
(*===-- llvm_linker.ml - LLVM OCaml Interface ------------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
exception Error of string
|
||||
|
||||
let () = Callback.register_exception "Llvm_linker.Error" (Error "")
|
||||
|
||||
external link_modules' : Llvm.llmodule -> Llvm.llmodule -> unit
|
||||
= "llvm_link_modules"
|
19
external/llvm/bindings/ocaml/linker/llvm_linker.mli
vendored
Normal file
19
external/llvm/bindings/ocaml/linker/llvm_linker.mli
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
(*===-- llvm_linker.mli - LLVM OCaml Interface -----------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Linker.
|
||||
|
||||
This interface provides an OCaml API for LLVM bitcode linker,
|
||||
the classes in the Linker library. *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** [link_modules' dst src] links [src] into [dst], raising [Error]
|
||||
if the linking fails. The src module is destroyed. *)
|
||||
val link_modules' : Llvm.llmodule -> Llvm.llmodule -> unit
|
11
external/llvm/bindings/ocaml/llvm/CMakeLists.txt
vendored
Normal file
11
external/llvm/bindings/ocaml/llvm/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
add_ocaml_library(llvm
|
||||
OCAML llvm
|
||||
C llvm_ocaml
|
||||
LLVM core support)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/META.llvm.in"
|
||||
"${LLVM_LIBRARY_DIR}/ocaml/META.llvm")
|
||||
|
||||
install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm"
|
||||
DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
|
110
external/llvm/bindings/ocaml/llvm/META.llvm.in
vendored
Normal file
110
external/llvm/bindings/ocaml/llvm/META.llvm.in
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
name = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "LLVM OCaml bindings"
|
||||
archive(byte) = "llvm.cma"
|
||||
archive(native) = "llvm.cmxa"
|
||||
directory = "llvm"
|
||||
|
||||
package "analysis" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Intermediate representation analysis for LLVM"
|
||||
archive(byte) = "llvm_analysis.cma"
|
||||
archive(native) = "llvm_analysis.cmxa"
|
||||
)
|
||||
|
||||
package "bitreader" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Bitcode reader for LLVM"
|
||||
archive(byte) = "llvm_bitreader.cma"
|
||||
archive(native) = "llvm_bitreader.cmxa"
|
||||
)
|
||||
|
||||
package "bitwriter" (
|
||||
requires = "llvm,unix"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Bitcode writer for LLVM"
|
||||
archive(byte) = "llvm_bitwriter.cma"
|
||||
archive(native) = "llvm_bitwriter.cmxa"
|
||||
)
|
||||
|
||||
package "executionengine" (
|
||||
requires = "llvm,llvm.target,ctypes.foreign"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "JIT and Interpreter for LLVM"
|
||||
archive(byte) = "llvm_executionengine.cma"
|
||||
archive(native) = "llvm_executionengine.cmxa"
|
||||
)
|
||||
|
||||
package "ipo" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "IPO Transforms for LLVM"
|
||||
archive(byte) = "llvm_ipo.cma"
|
||||
archive(native) = "llvm_ipo.cmxa"
|
||||
)
|
||||
|
||||
package "irreader" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "IR assembly reader for LLVM"
|
||||
archive(byte) = "llvm_irreader.cma"
|
||||
archive(native) = "llvm_irreader.cmxa"
|
||||
)
|
||||
|
||||
package "scalar_opts" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Scalar Transforms for LLVM"
|
||||
archive(byte) = "llvm_scalar_opts.cma"
|
||||
archive(native) = "llvm_scalar_opts.cmxa"
|
||||
)
|
||||
|
||||
package "transform_utils" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Transform utilities for LLVM"
|
||||
archive(byte) = "llvm_transform_utils.cma"
|
||||
archive(native) = "llvm_transform_utils.cmxa"
|
||||
)
|
||||
|
||||
package "vectorize" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Vector Transforms for LLVM"
|
||||
archive(byte) = "llvm_vectorize.cma"
|
||||
archive(native) = "llvm_vectorize.cmxa"
|
||||
)
|
||||
|
||||
package "passmgr_builder" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Pass Manager Builder for LLVM"
|
||||
archive(byte) = "llvm_passmgr_builder.cma"
|
||||
archive(native) = "llvm_passmgr_builder.cmxa"
|
||||
)
|
||||
|
||||
package "target" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Target Information for LLVM"
|
||||
archive(byte) = "llvm_target.cma"
|
||||
archive(native) = "llvm_target.cmxa"
|
||||
)
|
||||
|
||||
package "linker" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "Intermediate Representation Linker for LLVM"
|
||||
archive(byte) = "llvm_linker.cma"
|
||||
archive(native) = "llvm_linker.cmxa"
|
||||
)
|
||||
|
||||
package "all_backends" (
|
||||
requires = "llvm"
|
||||
version = "@PACKAGE_VERSION@"
|
||||
description = "All backends for LLVM"
|
||||
archive(byte) = "llvm_all_backends.cma"
|
||||
archive(native) = "llvm_all_backends.cmxa"
|
||||
)
|
1372
external/llvm/bindings/ocaml/llvm/llvm.ml
vendored
Normal file
1372
external/llvm/bindings/ocaml/llvm/llvm.ml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
external/llvm/bindings/ocaml/llvm/llvm.mli.REMOVED.git-id
vendored
Normal file
1
external/llvm/bindings/ocaml/llvm/llvm.mli.REMOVED.git-id
vendored
Normal file
@ -0,0 +1 @@
|
||||
3387c1ec52fe96bd60bd9457fbe1446b21e32dbc
|
2516
external/llvm/bindings/ocaml/llvm/llvm_ocaml.c
vendored
Normal file
2516
external/llvm/bindings/ocaml/llvm/llvm_ocaml.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
external/llvm/bindings/ocaml/target/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/target/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_target
|
||||
OCAML llvm_target
|
||||
OCAMLDEP llvm
|
||||
C target_ocaml
|
||||
LLVM target)
|
136
external/llvm/bindings/ocaml/target/llvm_target.ml
vendored
Normal file
136
external/llvm/bindings/ocaml/target/llvm_target.ml
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
(*===-- llvm_target.ml - LLVM OCaml Interface ------------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
module Endian = struct
|
||||
type t =
|
||||
| Big
|
||||
| Little
|
||||
end
|
||||
|
||||
module CodeGenOptLevel = struct
|
||||
type t =
|
||||
| None
|
||||
| Less
|
||||
| Default
|
||||
| Aggressive
|
||||
end
|
||||
|
||||
module RelocMode = struct
|
||||
type t =
|
||||
| Default
|
||||
| Static
|
||||
| PIC
|
||||
| DynamicNoPIC
|
||||
end
|
||||
|
||||
module CodeModel = struct
|
||||
type t =
|
||||
| Default
|
||||
| JITDefault
|
||||
| Small
|
||||
| Kernel
|
||||
| Medium
|
||||
| Large
|
||||
end
|
||||
|
||||
module CodeGenFileType = struct
|
||||
type t =
|
||||
| AssemblyFile
|
||||
| ObjectFile
|
||||
end
|
||||
|
||||
exception Error of string
|
||||
|
||||
let () = Callback.register_exception "Llvm_target.Error" (Error "")
|
||||
|
||||
module DataLayout = struct
|
||||
type t
|
||||
|
||||
external of_string : string -> t = "llvm_datalayout_of_string"
|
||||
external as_string : t -> string = "llvm_datalayout_as_string"
|
||||
external byte_order : t -> Endian.t = "llvm_datalayout_byte_order"
|
||||
external pointer_size : t -> int = "llvm_datalayout_pointer_size"
|
||||
external intptr_type : Llvm.llcontext -> t -> Llvm.lltype
|
||||
= "llvm_datalayout_intptr_type"
|
||||
external qualified_pointer_size : int -> t -> int
|
||||
= "llvm_datalayout_qualified_pointer_size"
|
||||
external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
|
||||
= "llvm_datalayout_qualified_intptr_type"
|
||||
external size_in_bits : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_size_in_bits"
|
||||
external store_size : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_store_size"
|
||||
external abi_size : Llvm.lltype -> t -> Int64.t
|
||||
= "llvm_datalayout_abi_size"
|
||||
external abi_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_abi_align"
|
||||
external stack_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_stack_align"
|
||||
external preferred_align : Llvm.lltype -> t -> int
|
||||
= "llvm_datalayout_preferred_align"
|
||||
external preferred_align_of_global : Llvm.llvalue -> t -> int
|
||||
= "llvm_datalayout_preferred_align_of_global"
|
||||
external element_at_offset : Llvm.lltype -> Int64.t -> t -> int
|
||||
= "llvm_datalayout_element_at_offset"
|
||||
external offset_of_element : Llvm.lltype -> int -> t -> Int64.t
|
||||
= "llvm_datalayout_offset_of_element"
|
||||
end
|
||||
|
||||
module Target = struct
|
||||
type t
|
||||
|
||||
external default_triple : unit -> string = "llvm_target_default_triple"
|
||||
external first : unit -> t option = "llvm_target_first"
|
||||
external succ : t -> t option = "llvm_target_succ"
|
||||
external by_name : string -> t option = "llvm_target_by_name"
|
||||
external by_triple : string -> t = "llvm_target_by_triple"
|
||||
external name : t -> string = "llvm_target_name"
|
||||
external description : t -> string = "llvm_target_description"
|
||||
external has_jit : t -> bool = "llvm_target_has_jit"
|
||||
external has_target_machine : t -> bool = "llvm_target_has_target_machine"
|
||||
external has_asm_backend : t -> bool = "llvm_target_has_asm_backend"
|
||||
|
||||
let all () =
|
||||
let rec step elem lst =
|
||||
match elem with
|
||||
| Some target -> step (succ target) (target :: lst)
|
||||
| None -> lst
|
||||
in
|
||||
step (first ()) []
|
||||
end
|
||||
|
||||
module TargetMachine = struct
|
||||
type t
|
||||
|
||||
external create : triple:string -> ?cpu:string -> ?features:string ->
|
||||
?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t ->
|
||||
?code_model:CodeModel.t -> Target.t -> t
|
||||
= "llvm_create_targetmachine_bytecode"
|
||||
"llvm_create_targetmachine_native"
|
||||
external target : t -> Target.t
|
||||
= "llvm_targetmachine_target"
|
||||
external triple : t -> string
|
||||
= "llvm_targetmachine_triple"
|
||||
external cpu : t -> string
|
||||
= "llvm_targetmachine_cpu"
|
||||
external features : t -> string
|
||||
= "llvm_targetmachine_features"
|
||||
external data_layout : t -> DataLayout.t
|
||||
= "llvm_targetmachine_data_layout"
|
||||
external add_analysis_passes : [< Llvm.PassManager.any ] Llvm.PassManager.t -> t -> unit
|
||||
= "llvm_targetmachine_add_analysis_passes"
|
||||
external set_verbose_asm : bool -> t -> unit
|
||||
= "llvm_targetmachine_set_verbose_asm"
|
||||
external emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string ->
|
||||
t -> unit
|
||||
= "llvm_targetmachine_emit_to_file"
|
||||
external emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t ->
|
||||
t -> Llvm.llmemorybuffer
|
||||
= "llvm_targetmachine_emit_to_memory_buffer"
|
||||
end
|
220
external/llvm/bindings/ocaml/target/llvm_target.mli
vendored
Normal file
220
external/llvm/bindings/ocaml/target/llvm_target.mli
vendored
Normal file
@ -0,0 +1,220 @@
|
||||
(*===-- llvm_target.mli - LLVM OCaml Interface -----------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** Target Information.
|
||||
|
||||
This interface provides an OCaml API for LLVM target information,
|
||||
the classes in the Target library. *)
|
||||
|
||||
module Endian : sig
|
||||
type t =
|
||||
| Big
|
||||
| Little
|
||||
end
|
||||
|
||||
module CodeGenOptLevel : sig
|
||||
type t =
|
||||
| None
|
||||
| Less
|
||||
| Default
|
||||
| Aggressive
|
||||
end
|
||||
|
||||
module RelocMode : sig
|
||||
type t =
|
||||
| Default
|
||||
| Static
|
||||
| PIC
|
||||
| DynamicNoPIC
|
||||
end
|
||||
|
||||
module CodeModel : sig
|
||||
type t =
|
||||
| Default
|
||||
| JITDefault
|
||||
| Small
|
||||
| Kernel
|
||||
| Medium
|
||||
| Large
|
||||
end
|
||||
|
||||
module CodeGenFileType : sig
|
||||
type t =
|
||||
| AssemblyFile
|
||||
| ObjectFile
|
||||
end
|
||||
|
||||
(** {6 Exceptions} *)
|
||||
|
||||
exception Error of string
|
||||
|
||||
(** {6 Data Layout} *)
|
||||
|
||||
module DataLayout : sig
|
||||
type t
|
||||
|
||||
(** [of_string rep] parses the data layout string representation [rep].
|
||||
See the constructor [llvm::DataLayout::DataLayout]. *)
|
||||
val of_string : string -> t
|
||||
|
||||
(** [as_string dl] is the string representation of the data layout [dl].
|
||||
See the method [llvm::DataLayout::getStringRepresentation]. *)
|
||||
val as_string : t -> string
|
||||
|
||||
(** Returns the byte order of a target, either [Endian.Big] or
|
||||
[Endian.Little].
|
||||
See the method [llvm::DataLayout::isLittleEndian]. *)
|
||||
val byte_order : t -> Endian.t
|
||||
|
||||
(** Returns the pointer size in bytes for a target.
|
||||
See the method [llvm::DataLayout::getPointerSize]. *)
|
||||
val pointer_size : t -> int
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target.
|
||||
See the method [llvm::DataLayout::getIntPtrType]. *)
|
||||
val intptr_type : Llvm.llcontext -> t -> Llvm.lltype
|
||||
|
||||
(** Returns the pointer size in bytes for a target in a given address space.
|
||||
See the method [llvm::DataLayout::getPointerSize]. *)
|
||||
val qualified_pointer_size : int -> t -> int
|
||||
|
||||
(** Returns the integer type that is the same size as a pointer on a target
|
||||
in a given address space.
|
||||
See the method [llvm::DataLayout::getIntPtrType]. *)
|
||||
val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
|
||||
|
||||
(** Computes the size of a type in bits for a target.
|
||||
See the method [llvm::DataLayout::getTypeSizeInBits]. *)
|
||||
val size_in_bits : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the storage size of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeStoreSize]. *)
|
||||
val store_size : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the ABI size of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeAllocSize]. *)
|
||||
val abi_size : Llvm.lltype -> t -> Int64.t
|
||||
|
||||
(** Computes the ABI alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val abi_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the call frame alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val stack_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the preferred alignment of a type in bytes for a target.
|
||||
See the method [llvm::DataLayout::getTypeABISize]. *)
|
||||
val preferred_align : Llvm.lltype -> t -> int
|
||||
|
||||
(** Computes the preferred alignment of a global variable in bytes for
|
||||
a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)
|
||||
val preferred_align_of_global : Llvm.llvalue -> t -> int
|
||||
|
||||
(** Computes the structure element that contains the byte offset for a target.
|
||||
See the method [llvm::StructLayout::getElementContainingOffset]. *)
|
||||
val element_at_offset : Llvm.lltype -> Int64.t -> t -> int
|
||||
|
||||
(** Computes the byte offset of the indexed struct element for a target.
|
||||
See the method [llvm::StructLayout::getElementContainingOffset]. *)
|
||||
val offset_of_element : Llvm.lltype -> int -> t -> Int64.t
|
||||
end
|
||||
|
||||
(** {6 Target} *)
|
||||
|
||||
module Target : sig
|
||||
type t
|
||||
|
||||
(** [default_triple ()] returns the default target triple for current
|
||||
platform. *)
|
||||
val default_triple : unit -> string
|
||||
|
||||
(** [first ()] returns the first target in the registered targets
|
||||
list, or [None]. *)
|
||||
val first : unit -> t option
|
||||
|
||||
(** [succ t] returns the next target after [t], or [None]
|
||||
if [t] was the last target. *)
|
||||
val succ : t -> t option
|
||||
|
||||
(** [all ()] returns a list of known targets. *)
|
||||
val all : unit -> t list
|
||||
|
||||
(** [by_name name] returns [Some t] if a target [t] named [name] is
|
||||
registered, or [None] otherwise. *)
|
||||
val by_name : string -> t option
|
||||
|
||||
(** [by_triple triple] returns a target for a triple [triple], or raises
|
||||
[Error] if [triple] does not correspond to a registered target. *)
|
||||
val by_triple : string -> t
|
||||
|
||||
(** Returns the name of a target. See [llvm::Target::getName]. *)
|
||||
val name : t -> string
|
||||
|
||||
(** Returns the description of a target.
|
||||
See [llvm::Target::getDescription]. *)
|
||||
val description : t -> string
|
||||
|
||||
(** Returns [true] if the target has a JIT. *)
|
||||
val has_jit : t -> bool
|
||||
|
||||
(** Returns [true] if the target has a target machine associated. *)
|
||||
val has_target_machine : t -> bool
|
||||
|
||||
(** Returns [true] if the target has an ASM backend (required for
|
||||
emitting output). *)
|
||||
val has_asm_backend : t -> bool
|
||||
end
|
||||
|
||||
(** {6 Target Machine} *)
|
||||
|
||||
module TargetMachine : sig
|
||||
type t
|
||||
|
||||
(** Creates a new target machine.
|
||||
See [llvm::Target::createTargetMachine]. *)
|
||||
val create : triple:string -> ?cpu:string -> ?features:string ->
|
||||
?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t ->
|
||||
?code_model:CodeModel.t -> Target.t -> t
|
||||
|
||||
(** Returns the Target used in a TargetMachine *)
|
||||
val target : t -> Target.t
|
||||
|
||||
(** Returns the triple used while creating this target machine. See
|
||||
[llvm::TargetMachine::getTriple]. *)
|
||||
val triple : t -> string
|
||||
|
||||
(** Returns the CPU used while creating this target machine. See
|
||||
[llvm::TargetMachine::getCPU]. *)
|
||||
val cpu : t -> string
|
||||
|
||||
(** Returns the data layout of this target machine. *)
|
||||
val data_layout : t -> DataLayout.t
|
||||
|
||||
(** Returns the feature string used while creating this target machine. See
|
||||
[llvm::TargetMachine::getFeatureString]. *)
|
||||
val features : t -> string
|
||||
|
||||
(** Adds the target-specific analysis passes to the pass manager.
|
||||
See [llvm::TargetMachine::addAnalysisPasses]. *)
|
||||
val add_analysis_passes : [< Llvm.PassManager.any ] Llvm.PassManager.t -> t -> unit
|
||||
|
||||
(** Sets the assembly verbosity of this target machine.
|
||||
See [llvm::TargetMachine::setAsmVerbosity]. *)
|
||||
val set_verbose_asm : bool -> t -> unit
|
||||
|
||||
(** Emits assembly or object data for the given module to the given
|
||||
file or raise [Error]. *)
|
||||
val emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string -> t -> unit
|
||||
|
||||
(** Emits assembly or object data for the given module to a fresh memory
|
||||
buffer or raise [Error]. *)
|
||||
val emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t -> t ->
|
||||
Llvm.llmemorybuffer
|
||||
end
|
347
external/llvm/bindings/ocaml/target/target_ocaml.c
vendored
Normal file
347
external/llvm/bindings/ocaml/target/target_ocaml.c
vendored
Normal file
@ -0,0 +1,347 @@
|
||||
/*===-- target_ocaml.c - LLVM OCaml Glue ------------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Target.h"
|
||||
#include "llvm-c/TargetMachine.h"
|
||||
#include "caml/alloc.h"
|
||||
#include "caml/fail.h"
|
||||
#include "caml/memory.h"
|
||||
#include "caml/custom.h"
|
||||
#include "caml/callback.h"
|
||||
|
||||
void llvm_raise(value Prototype, char *Message);
|
||||
value llvm_string_of_message(char* Message);
|
||||
|
||||
/*===---- Data Layout -----------------------------------------------------===*/
|
||||
|
||||
#define DataLayout_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
|
||||
|
||||
static void llvm_finalize_data_layout(value DataLayout) {
|
||||
LLVMDisposeTargetData(DataLayout_val(DataLayout));
|
||||
}
|
||||
|
||||
static struct custom_operations llvm_data_layout_ops = {
|
||||
(char *) "Llvm_target.DataLayout.t",
|
||||
llvm_finalize_data_layout,
|
||||
custom_compare_default,
|
||||
custom_hash_default,
|
||||
custom_serialize_default,
|
||||
custom_deserialize_default,
|
||||
custom_compare_ext_default
|
||||
};
|
||||
|
||||
value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) {
|
||||
value V = alloc_custom(&llvm_data_layout_ops, sizeof(LLVMTargetDataRef),
|
||||
0, 1);
|
||||
DataLayout_val(V) = DataLayout;
|
||||
return V;
|
||||
}
|
||||
|
||||
/* string -> DataLayout.t */
|
||||
CAMLprim value llvm_datalayout_of_string(value StringRep) {
|
||||
return llvm_alloc_data_layout(LLVMCreateTargetData(String_val(StringRep)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> string */
|
||||
CAMLprim value llvm_datalayout_as_string(value TD) {
|
||||
char *StringRep = LLVMCopyStringRepOfTargetData(DataLayout_val(TD));
|
||||
value Copy = copy_string(StringRep);
|
||||
LLVMDisposeMessage(StringRep);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
/* DataLayout.t -> Endian.t */
|
||||
CAMLprim value llvm_datalayout_byte_order(value DL) {
|
||||
return Val_int(LLVMByteOrder(DataLayout_val(DL)));
|
||||
}
|
||||
|
||||
/* DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_pointer_size(value DL) {
|
||||
return Val_int(LLVMPointerSize(DataLayout_val(DL)));
|
||||
}
|
||||
|
||||
/* Llvm.llcontext -> DataLayout.t -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_datalayout_intptr_type(LLVMContextRef C, value DL) {
|
||||
return LLVMIntPtrTypeInContext(C, DataLayout_val(DL));
|
||||
}
|
||||
|
||||
/* int -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_qualified_pointer_size(value AS, value DL) {
|
||||
return Val_int(LLVMPointerSizeForAS(DataLayout_val(DL), Int_val(AS)));
|
||||
}
|
||||
|
||||
/* Llvm.llcontext -> int -> DataLayout.t -> Llvm.lltype */
|
||||
CAMLprim LLVMTypeRef llvm_datalayout_qualified_intptr_type(LLVMContextRef C,
|
||||
value AS,
|
||||
value DL) {
|
||||
return LLVMIntPtrTypeForASInContext(C, DataLayout_val(DL), Int_val(AS));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_size_in_bits(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMSizeOfTypeInBits(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_store_size(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMStoreSizeOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_abi_size(LLVMTypeRef Ty, value DL) {
|
||||
return caml_copy_int64(LLVMABISizeOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_abi_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMABIAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_stack_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMCallFrameAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_preferred_align(LLVMTypeRef Ty, value DL) {
|
||||
return Val_int(LLVMPreferredAlignmentOfType(DataLayout_val(DL), Ty));
|
||||
}
|
||||
|
||||
/* Llvm.llvalue -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_preferred_align_of_global(LLVMValueRef GlobalVar,
|
||||
value DL) {
|
||||
return Val_int(LLVMPreferredAlignmentOfGlobal(DataLayout_val(DL), GlobalVar));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> Int64.t -> DataLayout.t -> int */
|
||||
CAMLprim value llvm_datalayout_element_at_offset(LLVMTypeRef Ty, value Offset,
|
||||
value DL) {
|
||||
return Val_int(LLVMElementAtOffset(DataLayout_val(DL), Ty,
|
||||
Int64_val(Offset)));
|
||||
}
|
||||
|
||||
/* Llvm.lltype -> int -> DataLayout.t -> Int64.t */
|
||||
CAMLprim value llvm_datalayout_offset_of_element(LLVMTypeRef Ty, value Index,
|
||||
value DL) {
|
||||
return caml_copy_int64(LLVMOffsetOfElement(DataLayout_val(DL), Ty,
|
||||
Int_val(Index)));
|
||||
}
|
||||
|
||||
/*===---- Target ----------------------------------------------------------===*/
|
||||
|
||||
static value llvm_target_option(LLVMTargetRef Target) {
|
||||
if(Target != NULL) {
|
||||
value Result = caml_alloc_small(1, 0);
|
||||
Store_field(Result, 0, (value) Target);
|
||||
return Result;
|
||||
}
|
||||
|
||||
return Val_int(0);
|
||||
}
|
||||
|
||||
/* unit -> string */
|
||||
CAMLprim value llvm_target_default_triple(value Unit) {
|
||||
char *TripleCStr = LLVMGetDefaultTargetTriple();
|
||||
value TripleStr = caml_copy_string(TripleCStr);
|
||||
LLVMDisposeMessage(TripleCStr);
|
||||
|
||||
return TripleStr;
|
||||
}
|
||||
|
||||
/* unit -> Target.t option */
|
||||
CAMLprim value llvm_target_first(value Unit) {
|
||||
return llvm_target_option(LLVMGetFirstTarget());
|
||||
}
|
||||
|
||||
/* Target.t -> Target.t option */
|
||||
CAMLprim value llvm_target_succ(LLVMTargetRef Target) {
|
||||
return llvm_target_option(LLVMGetNextTarget(Target));
|
||||
}
|
||||
|
||||
/* string -> Target.t option */
|
||||
CAMLprim value llvm_target_by_name(value Name) {
|
||||
return llvm_target_option(LLVMGetTargetFromName(String_val(Name)));
|
||||
}
|
||||
|
||||
/* string -> Target.t */
|
||||
CAMLprim LLVMTargetRef llvm_target_by_triple(value Triple) {
|
||||
LLVMTargetRef T;
|
||||
char *Error;
|
||||
|
||||
if(LLVMGetTargetFromTriple(String_val(Triple), &T, &Error))
|
||||
llvm_raise(*caml_named_value("Llvm_target.Error"), Error);
|
||||
|
||||
return T;
|
||||
}
|
||||
|
||||
/* Target.t -> string */
|
||||
CAMLprim value llvm_target_name(LLVMTargetRef Target) {
|
||||
return caml_copy_string(LLVMGetTargetName(Target));
|
||||
}
|
||||
|
||||
/* Target.t -> string */
|
||||
CAMLprim value llvm_target_description(LLVMTargetRef Target) {
|
||||
return caml_copy_string(LLVMGetTargetDescription(Target));
|
||||
}
|
||||
|
||||
/* Target.t -> bool */
|
||||
CAMLprim value llvm_target_has_jit(LLVMTargetRef Target) {
|
||||
return Val_bool(LLVMTargetHasJIT(Target));
|
||||
}
|
||||
|
||||
/* Target.t -> bool */
|
||||
CAMLprim value llvm_target_has_target_machine(LLVMTargetRef Target) {
|
||||
return Val_bool(LLVMTargetHasTargetMachine(Target));
|
||||
}
|
||||
|
||||
/* Target.t -> bool */
|
||||
CAMLprim value llvm_target_has_asm_backend(LLVMTargetRef Target) {
|
||||
return Val_bool(LLVMTargetHasAsmBackend(Target));
|
||||
}
|
||||
|
||||
/*===---- Target Machine --------------------------------------------------===*/
|
||||
|
||||
#define TargetMachine_val(v) (*(LLVMTargetMachineRef *)(Data_custom_val(v)))
|
||||
|
||||
static void llvm_finalize_target_machine(value Machine) {
|
||||
LLVMDisposeTargetMachine(TargetMachine_val(Machine));
|
||||
}
|
||||
|
||||
static struct custom_operations llvm_target_machine_ops = {
|
||||
(char *) "Llvm_target.TargetMachine.t",
|
||||
llvm_finalize_target_machine,
|
||||
custom_compare_default,
|
||||
custom_hash_default,
|
||||
custom_serialize_default,
|
||||
custom_deserialize_default,
|
||||
custom_compare_ext_default
|
||||
};
|
||||
|
||||
static value llvm_alloc_targetmachine(LLVMTargetMachineRef Machine) {
|
||||
value V = alloc_custom(&llvm_target_machine_ops, sizeof(LLVMTargetMachineRef),
|
||||
0, 1);
|
||||
TargetMachine_val(V) = Machine;
|
||||
return V;
|
||||
}
|
||||
|
||||
/* triple:string -> ?cpu:string -> ?features:string
|
||||
?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t
|
||||
?code_model:CodeModel.t -> Target.t -> TargetMachine.t */
|
||||
CAMLprim value llvm_create_targetmachine_native(value Triple, value CPU,
|
||||
value Features, value OptLevel, value RelocMode,
|
||||
value CodeModel, LLVMTargetRef Target) {
|
||||
LLVMTargetMachineRef Machine;
|
||||
const char *CPUStr = "", *FeaturesStr = "";
|
||||
LLVMCodeGenOptLevel OptLevelEnum = LLVMCodeGenLevelDefault;
|
||||
LLVMRelocMode RelocModeEnum = LLVMRelocDefault;
|
||||
LLVMCodeModel CodeModelEnum = LLVMCodeModelDefault;
|
||||
|
||||
if(CPU != Val_int(0))
|
||||
CPUStr = String_val(Field(CPU, 0));
|
||||
if(Features != Val_int(0))
|
||||
FeaturesStr = String_val(Field(Features, 0));
|
||||
if(OptLevel != Val_int(0))
|
||||
OptLevelEnum = Int_val(Field(OptLevel, 0));
|
||||
if(RelocMode != Val_int(0))
|
||||
RelocModeEnum = Int_val(Field(RelocMode, 0));
|
||||
if(CodeModel != Val_int(0))
|
||||
CodeModelEnum = Int_val(Field(CodeModel, 0));
|
||||
|
||||
Machine = LLVMCreateTargetMachine(Target, String_val(Triple), CPUStr,
|
||||
FeaturesStr, OptLevelEnum, RelocModeEnum, CodeModelEnum);
|
||||
|
||||
return llvm_alloc_targetmachine(Machine);
|
||||
}
|
||||
|
||||
CAMLprim value llvm_create_targetmachine_bytecode(value *argv, int argn) {
|
||||
return llvm_create_targetmachine_native(argv[0], argv[1], argv[2], argv[3],
|
||||
argv[4], argv[5], (LLVMTargetRef) argv[6]);
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> Target.t */
|
||||
CAMLprim LLVMTargetRef llvm_targetmachine_target(value Machine) {
|
||||
return LLVMGetTargetMachineTarget(TargetMachine_val(Machine));
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> string */
|
||||
CAMLprim value llvm_targetmachine_triple(value Machine) {
|
||||
return llvm_string_of_message(LLVMGetTargetMachineTriple(
|
||||
TargetMachine_val(Machine)));
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> string */
|
||||
CAMLprim value llvm_targetmachine_cpu(value Machine) {
|
||||
return llvm_string_of_message(LLVMGetTargetMachineCPU(
|
||||
TargetMachine_val(Machine)));
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> string */
|
||||
CAMLprim value llvm_targetmachine_features(value Machine) {
|
||||
return llvm_string_of_message(LLVMGetTargetMachineFeatureString(
|
||||
TargetMachine_val(Machine)));
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> DataLayout.t */
|
||||
CAMLprim value llvm_targetmachine_data_layout(value Machine) {
|
||||
return llvm_alloc_data_layout(LLVMCreateTargetDataLayout(
|
||||
TargetMachine_val(Machine)));
|
||||
}
|
||||
|
||||
/* bool -> TargetMachine.t -> unit */
|
||||
CAMLprim value llvm_targetmachine_set_verbose_asm(value Verb, value Machine) {
|
||||
LLVMSetTargetMachineAsmVerbosity(TargetMachine_val(Machine), Bool_val(Verb));
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* Llvm.llmodule -> CodeGenFileType.t -> string -> TargetMachine.t -> unit */
|
||||
CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module,
|
||||
value FileType, value FileName, value Machine) {
|
||||
char *ErrorMessage;
|
||||
|
||||
if(LLVMTargetMachineEmitToFile(TargetMachine_val(Machine), Module,
|
||||
String_val(FileName), Int_val(FileType),
|
||||
&ErrorMessage)) {
|
||||
llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage);
|
||||
}
|
||||
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* Llvm.llmodule -> CodeGenFileType.t -> TargetMachine.t ->
|
||||
Llvm.llmemorybuffer */
|
||||
CAMLprim LLVMMemoryBufferRef llvm_targetmachine_emit_to_memory_buffer(
|
||||
LLVMModuleRef Module, value FileType,
|
||||
value Machine) {
|
||||
char *ErrorMessage;
|
||||
LLVMMemoryBufferRef Buffer;
|
||||
|
||||
if(LLVMTargetMachineEmitToMemoryBuffer(TargetMachine_val(Machine), Module,
|
||||
Int_val(FileType), &ErrorMessage,
|
||||
&Buffer)) {
|
||||
llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage);
|
||||
}
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
/* TargetMachine.t -> Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_targetmachine_add_analysis_passes(LLVMPassManagerRef PM,
|
||||
value Machine) {
|
||||
LLVMAddAnalysisPasses(TargetMachine_val(Machine), PM);
|
||||
return Val_unit;
|
||||
}
|
5
external/llvm/bindings/ocaml/transforms/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/transforms/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_subdirectory(ipo)
|
||||
add_subdirectory(passmgr_builder)
|
||||
add_subdirectory(scalar_opts)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(vectorize)
|
5
external/llvm/bindings/ocaml/transforms/ipo/CMakeLists.txt
vendored
Normal file
5
external/llvm/bindings/ocaml/transforms/ipo/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
add_ocaml_library(llvm_ipo
|
||||
OCAML llvm_ipo
|
||||
OCAMLDEP llvm
|
||||
C ipo_ocaml
|
||||
LLVM ipo)
|
104
external/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c
vendored
Normal file
104
external/llvm/bindings/ocaml/transforms/ipo/ipo_ocaml.c
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
/*===-- ipo_ocaml.c - LLVM OCaml Glue ---------------------------*- C++ -*-===*\
|
||||
|* *|
|
||||
|* The LLVM Compiler Infrastructure *|
|
||||
|* *|
|
||||
|* This file is distributed under the University of Illinois Open Source *|
|
||||
|* License. See LICENSE.TXT for details. *|
|
||||
|* *|
|
||||
|*===----------------------------------------------------------------------===*|
|
||||
|* *|
|
||||
|* This file glues LLVM's OCaml interface to its C interface. These functions *|
|
||||
|* are by and large transparent wrappers to the corresponding C functions. *|
|
||||
|* *|
|
||||
|* Note that these functions intentionally take liberties with the CAMLparamX *|
|
||||
|* macros, since most of the parameters are not GC heap objects. *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#include "llvm-c/Transforms/IPO.h"
|
||||
#include "caml/mlvalues.h"
|
||||
#include "caml/misc.h"
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_argument_promotion(LLVMPassManagerRef PM) {
|
||||
LLVMAddArgumentPromotionPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_constant_merge(LLVMPassManagerRef PM) {
|
||||
LLVMAddConstantMergePass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_dead_arg_elimination(LLVMPassManagerRef PM) {
|
||||
LLVMAddDeadArgEliminationPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_function_attrs(LLVMPassManagerRef PM) {
|
||||
LLVMAddFunctionAttrsPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_function_inlining(LLVMPassManagerRef PM) {
|
||||
LLVMAddFunctionInliningPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_always_inliner(LLVMPassManagerRef PM) {
|
||||
LLVMAddAlwaysInlinerPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_global_dce(LLVMPassManagerRef PM) {
|
||||
LLVMAddGlobalDCEPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_global_optimizer(LLVMPassManagerRef PM) {
|
||||
LLVMAddGlobalOptimizerPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_ip_constant_propagation(LLVMPassManagerRef PM) {
|
||||
LLVMAddIPConstantPropagationPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_prune_eh(LLVMPassManagerRef PM) {
|
||||
LLVMAddPruneEHPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_ipsccp(LLVMPassManagerRef PM) {
|
||||
LLVMAddIPSCCPPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> all_but_main:bool -> unit */
|
||||
CAMLprim value llvm_add_internalize(LLVMPassManagerRef PM, value AllButMain) {
|
||||
LLVMAddInternalizePass(PM, Bool_val(AllButMain));
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_strip_dead_prototypes(LLVMPassManagerRef PM) {
|
||||
LLVMAddStripDeadPrototypesPass(PM);
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
/* [`Module] Llvm.PassManager.t -> unit */
|
||||
CAMLprim value llvm_add_strip_symbols(LLVMPassManagerRef PM) {
|
||||
LLVMAddStripSymbolsPass(PM);
|
||||
return Val_unit;
|
||||
}
|
51
external/llvm/bindings/ocaml/transforms/ipo/llvm_ipo.ml
vendored
Normal file
51
external/llvm/bindings/ocaml/transforms/ipo/llvm_ipo.ml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
(*===-- llvm_ipo.ml - LLVM OCaml Interface --------------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
external add_argument_promotion
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_argument_promotion"
|
||||
external add_constant_merge
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_constant_merge"
|
||||
external add_dead_arg_elimination
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_dead_arg_elimination"
|
||||
external add_function_attrs
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_function_attrs"
|
||||
external add_function_inlining
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_function_inlining"
|
||||
external add_always_inliner
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_always_inliner"
|
||||
external add_global_dce
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_global_dce"
|
||||
external add_global_optimizer
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_global_optimizer"
|
||||
external add_ipc_propagation
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_ip_constant_propagation"
|
||||
external add_prune_eh
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_prune_eh"
|
||||
external add_ipsccp
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_ipsccp"
|
||||
external add_internalize
|
||||
: [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit
|
||||
= "llvm_add_internalize"
|
||||
external add_strip_dead_prototypes
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_strip_dead_prototypes"
|
||||
external add_strip_symbols
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_strip_symbols"
|
83
external/llvm/bindings/ocaml/transforms/ipo/llvm_ipo.mli
vendored
Normal file
83
external/llvm/bindings/ocaml/transforms/ipo/llvm_ipo.mli
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
(*===-- llvm_ipo.mli - LLVM OCaml Interface -------------------*- OCaml -*-===*
|
||||
*
|
||||
* The LLVM Compiler Infrastructure
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*===----------------------------------------------------------------------===*)
|
||||
|
||||
(** IPO Transforms.
|
||||
|
||||
This interface provides an OCaml API for LLVM interprocedural optimizations, the
|
||||
classes in the [LLVMIPO] library. *)
|
||||
|
||||
(** See the [llvm::createAddArgumentPromotionPass] function. *)
|
||||
external add_argument_promotion
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_argument_promotion"
|
||||
|
||||
(** See the [llvm::createConstantMergePass] function. *)
|
||||
external add_constant_merge
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_constant_merge"
|
||||
|
||||
(** See the [llvm::createDeadArgEliminationPass] function. *)
|
||||
external add_dead_arg_elimination
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_dead_arg_elimination"
|
||||
|
||||
(** See the [llvm::createFunctionAttrsPass] function. *)
|
||||
external add_function_attrs
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_function_attrs"
|
||||
|
||||
(** See the [llvm::createFunctionInliningPass] function. *)
|
||||
external add_function_inlining
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_function_inlining"
|
||||
|
||||
(** See the [llvm::createAlwaysInlinerPass] function. *)
|
||||
external add_always_inliner
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_always_inliner"
|
||||
|
||||
(** See the [llvm::createGlobalDCEPass] function. *)
|
||||
external add_global_dce
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_global_dce"
|
||||
|
||||
(** See the [llvm::createGlobalOptimizerPass] function. *)
|
||||
external add_global_optimizer
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_global_optimizer"
|
||||
|
||||
(** See the [llvm::createIPConstantPropagationPass] function. *)
|
||||
external add_ipc_propagation
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_ip_constant_propagation"
|
||||
|
||||
(** See the [llvm::createPruneEHPass] function. *)
|
||||
external add_prune_eh
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_prune_eh"
|
||||
|
||||
(** See the [llvm::createIPSCCPPass] function. *)
|
||||
external add_ipsccp
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_ipsccp"
|
||||
|
||||
(** See the [llvm::createInternalizePass] function. *)
|
||||
external add_internalize
|
||||
: [ `Module ] Llvm.PassManager.t -> all_but_main:bool -> unit
|
||||
= "llvm_add_internalize"
|
||||
|
||||
(** See the [llvm::createStripDeadPrototypesPass] function. *)
|
||||
external add_strip_dead_prototypes
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_strip_dead_prototypes"
|
||||
|
||||
(** See the [llvm::createStripSymbolsPass] function. *)
|
||||
external add_strip_symbols
|
||||
: [ `Module ] Llvm.PassManager.t -> unit
|
||||
= "llvm_add_strip_symbols"
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user