[sledge] link in cxxabi

Summary:
* Adds compilation of cxxabi.bc
* Includes the cxxabi.bc into the sledge executable via opam-crunch
* Links cxxabi.bc in sledge frontend

Reviewed By: jberdine

Differential Revision: D15415190

fbshipit-source-id: cc42f09fb
master
Timotej Kapus 6 years ago committed by Facebook Github Bot
parent 04c3ccaac5
commit d47824fe37

1
sledge/.gitignore vendored

@ -2,6 +2,7 @@
/bin/
/llvm/
/model/cxxabi.bc
/model/dune
/src/dune
/src/import/dune
/src/llair/dune

@ -19,7 +19,7 @@ facebook/Makefile:
DBG_TARGETS = $(patsubst %,_build/dev/%.exe,$(EXES)) $(patsubst %,_build/dev/%.install,$(INSTALLS))
OPT_TARGETS = $(patsubst %,_build/release/%.exe,$(EXES)) $(patsubst %,_build/release/%.install,$(INSTALLS))
DUNEINS = $(shell find src facebook -name dune.in)
DUNEINS = $(shell find src facebook model -name dune.in)
DUNES = $(patsubst %.in,%,$(DUNEINS))
.PHONY: dunes

@ -9,9 +9,10 @@ CLANG_ARGS?=-g $(OPT_ARGS)
# select llvm and clang
SWITCH?=$(shell opam switch show)
LLVM?=../llvm/_install/$(SWITCH)
ROOT?=..
LLVM=$(ROOT)/llvm/_install/$(SWITCH)
LIBCXXABI=../llvm/projects/libcxxabi
LIBCXXABI=$(ROOT)/llvm/projects/libcxxabi
cxxabi.bc : cxxabi.cpp
$(LLVM)/bin/clang $(CLANG_ARGS) -I$(LLVM)/include/c++/v1 -I$(LIBCXXABI)/include -I$(LIBCXXABI)/src -c -emit-llvm cxxabi.cpp

@ -0,0 +1,32 @@
(* -*- tuareg -*- *)
(*
* Copyright (c) 2019-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
let deps = []
;;
Jbuild_plugin.V1.send
@@ Format.sprintf
{|
(rule
(targets cxxabi.bc)
(deps cxxabi.cpp Makefile llair_intrinsics.h)
(action (run make ROOT=../../.. cxxabi.bc)))
(rule
(targets model.ml)
(deps cxxabi.bc)
(action (run ocaml-crunch -m plain -e bc -o model.ml .)))
(library
(name model)
(public_name llair.model)
%s
(libraries %s))
|}
(flags `lib deps)
(libraries deps)

@ -14,6 +14,7 @@ depends: [
"base" {>= "v0.12.0"}
"cmdliner"
"core_kernel"
"crunch" {build}
"ctypes"
"ctypes-foreign"
"dune" {build}

@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*)
let deps = ["import"; "trace"]
let deps = ["model"; "import"; "trace"]
;;
Jbuild_plugin.V1.send
@ -16,7 +16,7 @@ Jbuild_plugin.V1.send
(name llair_)
(public_name llair)
%s
(libraries ctypes ctypes.foreign llvm llvm.irreader llvm.analysis llvm.scalar_opts llvm.target llvm.ipo %s))
(libraries ctypes ctypes.foreign llvm llvm.irreader llvm.analysis llvm.scalar_opts llvm.target llvm.ipo llvm.linker %s))
|}
(flags `lib deps)
(libraries deps)

@ -1350,11 +1350,19 @@ let translate : string -> Llair.t =
;
Llvm.install_fatal_error_handler invalid_llvm ;
let llcontext = Llvm.global_context () in
let model_module =
let model_memorybuffer =
Llvm.MemoryBuffer.of_string
(Option.value_exn (Model.read "/cxxabi.bc"))
in
Llvm_irreader.parse_ir llcontext model_memorybuffer
in
let llmodule =
let llmemorybuffer = Llvm.MemoryBuffer.of_file file in
try Llvm_irreader.parse_ir llcontext llmemorybuffer
with Llvm_irreader.Error msg -> invalid_llvm msg
in
Llvm_linker.link_modules' llmodule model_module ;
Llvm_analysis.verify_module llmodule |> Option.iter ~f:invalid_llvm ;
transform llmodule ;
scan_locs llmodule ;

Loading…
Cancel
Save