From dce4a407a24b04eebc6a376f8e62b41aaa7b071f Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Thu, 29 May 2014 02:49:00 -0700 Subject: Update LLVM for 3.5 rebase (r209712). Change-Id: I149556c940fb7dc92d075273c87ff584f400941f --- bindings/ocaml/Makefile | 2 +- bindings/ocaml/all_backends/Makefile | 21 +++++++++++++++ bindings/ocaml/all_backends/all_backends_ocaml.c | 32 +++++++++++++++++++++++ bindings/ocaml/all_backends/llvm_all_backends.ml | 10 +++++++ bindings/ocaml/all_backends/llvm_all_backends.mli | 11 ++++++++ bindings/ocaml/llvm/META.llvm.in | 8 ++++++ bindings/python/llvm/object.py | 25 ++++++++---------- bindings/python/llvm/tests/test_object.py | 2 +- 8 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 bindings/ocaml/all_backends/Makefile create mode 100644 bindings/ocaml/all_backends/all_backends_ocaml.c create mode 100644 bindings/ocaml/all_backends/llvm_all_backends.ml create mode 100644 bindings/ocaml/all_backends/llvm_all_backends.mli (limited to 'bindings') diff --git a/bindings/ocaml/Makefile b/bindings/ocaml/Makefile index 44562fe8..b0e1f09 100644 --- a/bindings/ocaml/Makefile +++ b/bindings/ocaml/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. DIRS = llvm bitreader bitwriter irreader analysis target executionengine \ - transforms linker backends + transforms linker backends all_backends ExtraMakefiles = $(PROJ_OBJ_DIR)/Makefile.ocaml ocamldoc: diff --git a/bindings/ocaml/all_backends/Makefile b/bindings/ocaml/all_backends/Makefile new file mode 100644 index 0000000..a5ff290 --- /dev/null +++ b/bindings/ocaml/all_backends/Makefile @@ -0,0 +1,21 @@ +##===- bindings/ocaml/all_backends/Makefile ----------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +# +# This is the makefile for the Objective Caml Llvm_backends interface. +# +##===----------------------------------------------------------------------===## + +LEVEL := ../../.. +include $(LEVEL)/Makefile.config + +LIBRARYNAME := llvm_all_backends +UsedComponents := $(TARGETS_TO_BUILD) +UsedOcamlInterfaces := + +include ../Makefile.ocaml diff --git a/bindings/ocaml/all_backends/all_backends_ocaml.c b/bindings/ocaml/all_backends/all_backends_ocaml.c new file mode 100644 index 0000000..8fe7d9b --- /dev/null +++ b/bindings/ocaml/all_backends/all_backends_ocaml.c @@ -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; +} diff --git a/bindings/ocaml/all_backends/llvm_all_backends.ml b/bindings/ocaml/all_backends/llvm_all_backends.ml new file mode 100644 index 0000000..f4f4725 --- /dev/null +++ b/bindings/ocaml/all_backends/llvm_all_backends.ml @@ -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" diff --git a/bindings/ocaml/all_backends/llvm_all_backends.mli b/bindings/ocaml/all_backends/llvm_all_backends.mli new file mode 100644 index 0000000..1808544 --- /dev/null +++ b/bindings/ocaml/all_backends/llvm_all_backends.mli @@ -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 diff --git a/bindings/ocaml/llvm/META.llvm.in b/bindings/ocaml/llvm/META.llvm.in index c241ea5..edb84e0 100644 --- a/bindings/ocaml/llvm/META.llvm.in +++ b/bindings/ocaml/llvm/META.llvm.in @@ -93,3 +93,11 @@ package "linker" ( 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" +) diff --git a/bindings/python/llvm/object.py b/bindings/python/llvm/object.py index 473aa3a..4e912ed 100644 --- a/bindings/python/llvm/object.py +++ b/bindings/python/llvm/object.py @@ -78,7 +78,10 @@ Here are some examples on how to perform iteration: """ from ctypes import c_char_p +from ctypes import c_char +from ctypes import POINTER from ctypes import c_uint64 +from ctypes import string_at from .common import CachedProperty from .common import LLVMObject @@ -211,7 +214,12 @@ class Section(LLVMObject): if self.expired: raise Exception('Section instance has expired.') - return lib.LLVMGetSectionContents(self) + siz = self.size + + r = lib.LLVMGetSectionContents(self) + if r: + return string_at(r, siz) + return None @CachedProperty def address(self): @@ -311,14 +319,6 @@ class Symbol(LLVMObject): return lib.LLVMGetSymbolAddress(self) @CachedProperty - def file_offset(self): - """The offset of this symbol in the file, in long bytes.""" - if self.expired: - raise Exception('Symbol instance has expired.') - - return lib.LLVMGetSymbolFileOffset(self) - - @CachedProperty def size(self): """The size of the symbol, in long bytes.""" if self.expired: @@ -345,7 +345,6 @@ class Symbol(LLVMObject): """Cache all cacheable properties.""" getattr(self, 'name') getattr(self, 'address') - getattr(self, 'file_offset') getattr(self, 'size') def expire(self): @@ -471,7 +470,8 @@ def register_library(library): library.LLVMGetSectionSize.restype = c_uint64 library.LLVMGetSectionContents.argtypes = [c_object_p] - library.LLVMGetSectionContents.restype = c_char_p + # Can't use c_char_p here as it isn't a NUL-terminated string. + library.LLVMGetSectionContents.restype = POINTER(c_char) library.LLVMGetSectionAddress.argtypes = [c_object_p] library.LLVMGetSectionAddress.restype = c_uint64 @@ -495,9 +495,6 @@ def register_library(library): library.LLVMGetSymbolAddress.argtypes = [Symbol] library.LLVMGetSymbolAddress.restype = c_uint64 - library.LLVMGetSymbolFileOffset.argtypes = [Symbol] - library.LLVMGetSymbolFileOffset.restype = c_uint64 - library.LLVMGetSymbolSize.argtypes = [Symbol] library.LLVMGetSymbolSize.restype = c_uint64 diff --git a/bindings/python/llvm/tests/test_object.py b/bindings/python/llvm/tests/test_object.py index 7ff981b..3f92d81 100644 --- a/bindings/python/llvm/tests/test_object.py +++ b/bindings/python/llvm/tests/test_object.py @@ -23,6 +23,7 @@ class TestObjectFile(TestBase): assert isinstance(section.size, long) assert isinstance(section.contents, str) assert isinstance(section.address, long) + assert len(section.contents) == section.size self.assertGreater(count, 0) @@ -39,7 +40,6 @@ class TestObjectFile(TestBase): assert isinstance(symbol.name, str) assert isinstance(symbol.address, long) assert isinstance(symbol.size, long) - assert isinstance(symbol.file_offset, long) self.assertGreater(count, 0) -- cgit v1.1