mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Remove LLVM rustboot backend.
This commit is contained in:
parent
a634b21563
commit
454bf428ef
162
src/Makefile
162
src/Makefile
@ -23,10 +23,6 @@ CFG_GCC_CFLAGS :=
|
||||
CFG_GCC_LINK_FLAGS :=
|
||||
CFG_VALGRIND :=
|
||||
|
||||
# Disable the ocaml backend on rustboot. It's too frustrating at this
|
||||
# point.
|
||||
NO_OCAML_LLVM := 1
|
||||
|
||||
CFG_LLVM_CONFIG ?= llvm-config
|
||||
CFG_BOOT_FLAGS := $(FLAGS)
|
||||
CFG_RUSTC_FLAGS := -nowarn
|
||||
@ -145,7 +141,6 @@ ifdef PROFILE
|
||||
$(info cfg: building with profiling info (forcing native output))
|
||||
CFG_NATIVE := 1
|
||||
CFG_OCAMLOPT_PROFILE_FLAGS := -p
|
||||
NO_LLVM := 1
|
||||
endif
|
||||
|
||||
ifdef DEBUG
|
||||
@ -182,52 +177,13 @@ ifneq ($(CFG_LLVM_CONFIG),)
|
||||
expected one of $(CFG_LLVM_ALLOWED_VERSIONS))
|
||||
endif
|
||||
endif
|
||||
ifneq ($(CFG_LLVM_CONFIG),)
|
||||
CFG_OCAML_LIBPATH := $(lastword \
|
||||
$(shell ocamlc$(OPT) -config | grep standard_library:))
|
||||
CFG_OCAML_LLVM := $(shell \
|
||||
for path in $(shell $(CFG_LLVM_CONFIG) --libdir)/ocaml \
|
||||
$(CFG_OCAML_LIBPATH) \
|
||||
$(CFG_OCAML_LIBPATH)/llvm \
|
||||
$(CFG_OCAML_LIBPATH)/llvm-$(CFG_LLVM_VERSION) ; do \
|
||||
if test -e $${path}/llvm.cma; then echo $${path}; break; fi \
|
||||
done)
|
||||
ifneq ($(CFG_OCAML_LLVM),)
|
||||
$(info cfg: found LLVM ocaml bindings in $(CFG_OCAML_LLVM))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef NO_OCAML_LLVM
|
||||
$(info cfg: disabling LLVM ocaml bindings)
|
||||
CFG_OCAML_LLVM :=
|
||||
endif
|
||||
VARIANT=x86
|
||||
|
||||
ifdef CFG_LLVM_CONFIG
|
||||
LLC := "$(shell $(CFG_LLVM_CONFIG) --bindir)/llc"
|
||||
CFG_LLC_CFLAGS := -march=x86
|
||||
LLVM-DIS := "$(shell $(CFG_LLVM_CONFIG) --bindir)/llvm-dis"
|
||||
ifneq ($(CFG_OCAML_LLVM),)
|
||||
VARIANT=llvm
|
||||
LLVM_LIBS := llvm.cma llvm_bitwriter.cma
|
||||
LLVM_NATIVE_LIBS := llvm.cmxa llvm_bitwriter.cmxa
|
||||
LLVM_CLIBS := $(shell for c in `$(CFG_LLVM_CONFIG) --ldflags --libs` \
|
||||
-lllvm -lllvm_bitwriter; do echo -cclib && echo $$c; done | xargs echo)
|
||||
LLVM_INCS := -I boot/llvm -I $(CFG_OCAML_LLVM)
|
||||
LLVM_MLS := $(addprefix boot/llvm/, llabi.ml llasm.ml llfinal.ml \
|
||||
lltrans.ml llemit.ml)
|
||||
else
|
||||
VARIANT=x86
|
||||
LLVM_CLIBS :=
|
||||
LLVM_INCS :=
|
||||
LLVM_MLS :=
|
||||
$(info cfg: disabling LLVM ocaml backend)
|
||||
endif
|
||||
else
|
||||
VARIANT=x86
|
||||
LLVM_CLIBS :=
|
||||
LLVM_INCS :=
|
||||
LLVM_MLS :=
|
||||
$(info cfg: disabling LLVM backend)
|
||||
endif
|
||||
|
||||
MKFILES := Makefile
|
||||
@ -241,7 +197,7 @@ CFG_BOOT_FLAGS += -L .
|
||||
######################################################################
|
||||
|
||||
ML_DEP_INCS := -I boot/fe -I boot/me -I boot/be -I boot/driver/$(VARIANT) \
|
||||
-I boot/driver -I boot/util -I boot/llvm
|
||||
-I boot/driver -I boot/util
|
||||
ML_INCS := $(ML_DEP_INCS) $(LLVM_INCS)
|
||||
ML_LIBS := unix.cma nums.cma bigarray.cma
|
||||
ML_NATIVE_LIBS := unix.cmxa nums.cmxa bigarray.cmxa
|
||||
@ -249,11 +205,6 @@ OCAMLC_FLAGS := -g $(ML_INCS) -w Ael -warn-error Ael
|
||||
OCAMLOPT_FLAGS := $(ML_INCS) -w Ael -warn-error Ael \
|
||||
$(CFG_OCAMLOPT_PROFILE_FLAGS)
|
||||
|
||||
ifdef CFG_LLVM_CONFIG
|
||||
ML_LIBS += $(LLVM_LIBS) -custom -cclib -lstdc++ $(LLVM_CLIBS)
|
||||
ML_NATIVE_LIBS += $(LLVM_NATIVE_LIBS) -cclib -lstdc++ $(LLVM_CLIBS)
|
||||
endif
|
||||
|
||||
# List them in link order.
|
||||
# Nobody calculates the link-order DAG automatically, sadly.
|
||||
|
||||
@ -270,7 +221,7 @@ FE_MLS := $(addprefix boot/fe/, ast.ml token.ml lexer.ml parser.ml \
|
||||
DRIVER_TOP_MLS := $(addprefix boot/driver/, lib.ml $(VARIANT)/glue.ml main.ml)
|
||||
|
||||
BOOT_MLS := $(UTIL_BOT_MLS) $(DRIVER_BOT_MLS) $(FE_MLS) $(IL_MLS) $(ME_MLS) \
|
||||
$(BE_MLS) $(LLVM_MLS) $(DRIVER_TOP_MLS)
|
||||
$(BE_MLS) $(DRIVER_TOP_MLS)
|
||||
BOOT_CMOS := $(BOOT_MLS:.ml=.cmo)
|
||||
BOOT_CMXS := $(BOOT_MLS:.ml=.cmx)
|
||||
BOOT_OBJS := $(BOOT_MLS:.ml=.o)
|
||||
@ -458,59 +409,6 @@ TEST_XFAILS_X86 := $(TASK_XFAILS) \
|
||||
test/compile-fail/infinite-vec-type-recursion.rs \
|
||||
test/compile-fail/writing-through-read-alias.rs
|
||||
|
||||
# Most tests fail on the boot-llvm backend, so we list the run-pass
|
||||
# xfails inside-out, by listing those that *don't* fail. A bit
|
||||
# double-negative-y but it's a bit unwieldy the other way just now.
|
||||
|
||||
TEST_XFAILS_LLVM := $(TASK_XFAILS) \
|
||||
$(NOMINAL_TAG_XFAILS) \
|
||||
$(CONST_TAG_XFAILS) \
|
||||
$(filter-out \
|
||||
$(addprefix test/run-pass/, \
|
||||
arith-0.rs \
|
||||
arith-2.rs \
|
||||
box.rs \
|
||||
char.rs \
|
||||
dead-code-one-arm-if.rs \
|
||||
div-mod.rs \
|
||||
drop-on-ret.rs \
|
||||
else-if.rs \
|
||||
fact.rs \
|
||||
generic-fn-twice.rs \
|
||||
generic-type.rs \
|
||||
generic-type-synonym.rs \
|
||||
hello.rs \
|
||||
inner-module.rs \
|
||||
int.rs \
|
||||
item-name-overload.rs \
|
||||
multiline-comment.rs \
|
||||
native.rs \
|
||||
native-mod.rs \
|
||||
native-opaque-type.rs \
|
||||
opeq.rs \
|
||||
return-nil.rs \
|
||||
syntax-extension-shell.rs \
|
||||
tup.rs), \
|
||||
$(wildcard test/run-pass/*.rs) ) \
|
||||
$(addprefix test/run-fail/, \
|
||||
explicit-fail.rs \
|
||||
fail.rs \
|
||||
linked-failure.rs \
|
||||
non-exhaustive-match.rs \
|
||||
pred.rs \
|
||||
str-overrun.rs \
|
||||
vec-overrun.rs \
|
||||
vec-underrun.rs \
|
||||
task-comm-14.rs \
|
||||
) \
|
||||
$(addprefix test/compile-fail/, \
|
||||
bad-recv.rs \
|
||||
bad-send.rs \
|
||||
infinite-vec-type-recursion.rs \
|
||||
rec-missing-fields.rs \
|
||||
writing-through-read-alias.rs \
|
||||
)
|
||||
|
||||
# Same strategy here for the time being: just list the ones that
|
||||
# work and assume the others don't. Invert this when we're closer
|
||||
# to actually bootstrapping.
|
||||
@ -578,12 +476,10 @@ TEST_XFAILS_SELF := $(filter-out \
|
||||
|
||||
ifdef MINGW_CROSS
|
||||
TEST_XFAILS_X86 += test/run-pass/native-mod.rc
|
||||
TEST_XFAILS_LLVM += test/run-pass/native-mod.rc
|
||||
TEST_XFAILS_SELF += test/run-pass/native-mod.rc
|
||||
endif
|
||||
ifdef CFG_WINDOWSY
|
||||
TEST_XFAILS_X86 += test/run-pass/native-mod.rc
|
||||
TEST_XFAILS_LLVM += test/run-pass/native-mod.rc
|
||||
TEST_XFAILS_SELF += test/run-pass/native-mod.rc
|
||||
endif
|
||||
|
||||
@ -596,105 +492,76 @@ CFAIL_RS := $(wildcard test/compile-fail/*.rs)
|
||||
|
||||
ifdef CHECK_XFAILS
|
||||
TEST_RPASS_CRATES_X86 := $(filter $(TEST_XFAILS_X86), $(RPASS_RC))
|
||||
TEST_RPASS_CRATES_LLVM := $(filter $(TEST_XFAILS_LLVM), $(RPASS_RC))
|
||||
TEST_RPASS_CRATES_SELF := $(filter $(TEST_XFAILS_SELF), $(RPASS_RC))
|
||||
TEST_RPASS_SOURCES_X86 := $(filter $(TEST_XFAILS_X86), $(RPASS_RS))
|
||||
TEST_RPASS_SOURCES_LLVM := $(filter $(TEST_XFAILS_LLVM), $(RPASS_RS))
|
||||
TEST_RPASS_SOURCES_SELF := $(filter $(TEST_XFAILS_SELF), $(RPASS_RS))
|
||||
else
|
||||
TEST_RPASS_CRATES_X86 := $(filter-out $(TEST_XFAILS_X86), $(RPASS_RC))
|
||||
TEST_RPASS_CRATES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(RPASS_RC))
|
||||
TEST_RPASS_CRATES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(RPASS_RC))
|
||||
TEST_RPASS_SOURCES_X86 := $(filter-out $(TEST_XFAILS_X86), $(RPASS_RS))
|
||||
TEST_RPASS_SOURCES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(RPASS_RS))
|
||||
TEST_RPASS_SOURCES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(RPASS_RS))
|
||||
endif
|
||||
|
||||
TEST_RPASS_EXES_X86 := \
|
||||
$(TEST_RPASS_CRATES_X86:.rc=-boot.x86$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RPASS_SOURCES_X86:.rs=-boot.x86$(CFG_EXE_SUFFIX))
|
||||
TEST_RPASS_EXES_LLVM := \
|
||||
$(TEST_RPASS_CRATES_LLVM:.rc=-boot.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RPASS_SOURCES_LLVM:.rs=-boot.llvm$(CFG_EXE_SUFFIX))
|
||||
TEST_RPASS_EXES_SELF := \
|
||||
$(TEST_RPASS_CRATES_SELF:.rc=.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RPASS_SOURCES_SELF:.rs=.llvm$(CFG_EXE_SUFFIX))
|
||||
|
||||
TEST_RPASS_OUTS_X86 := \
|
||||
$(TEST_RPASS_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86.out)
|
||||
TEST_RPASS_OUTS_LLVM := \
|
||||
$(TEST_RPASS_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
TEST_RPASS_OUTS_SELF := \
|
||||
$(TEST_RPASS_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
|
||||
TEST_RPASS_TMPS_X86 := \
|
||||
$(TEST_RPASS_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_RPASS_TMPS_LLVM := \
|
||||
$(TEST_RPASS_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_RPASS_TMPS_SELF := \
|
||||
$(TEST_RPASS_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
|
||||
|
||||
TEST_RFAIL_CRATES_X86 := $(filter-out $(TEST_XFAILS_X86), $(RFAIL_RC))
|
||||
TEST_RFAIL_CRATES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(RFAIL_RC))
|
||||
TEST_RFAIL_CRATES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(RFAIL_RC))
|
||||
TEST_RFAIL_SOURCES_X86 := $(filter-out $(TEST_XFAILS_X86), $(RFAIL_RS))
|
||||
TEST_RFAIL_SOURCES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(RFAIL_RS))
|
||||
TEST_RFAIL_SOURCES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(RFAIL_RS))
|
||||
|
||||
TEST_RFAIL_EXES_X86 := \
|
||||
$(TEST_RFAIL_CRATES_X86:.rc=-boot.x86$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RFAIL_SOURCES_X86:.rs=-boot.x86$(CFG_EXE_SUFFIX))
|
||||
TEST_RFAIL_EXES_LLVM := \
|
||||
$(TEST_RFAIL_CRATES_LLVM:.rc=-boot.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RFAIL_SOURCES_LLVM:.rs=-boot.llvm$(CFG_EXE_SUFFIX))
|
||||
TEST_RFAIL_EXES_SELF := \
|
||||
$(TEST_RFAIL_CRATES_SELF:.rc=-boot.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_RFAIL_SOURCES_SELF:.rs=-boot.llvm$(CFG_EXE_SUFFIX))
|
||||
|
||||
TEST_RFAIL_OUTS_X86 := \
|
||||
$(TEST_RFAIL_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86.out)
|
||||
TEST_RFAIL_OUTS_LLVM := \
|
||||
$(TEST_RFAIL_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
TEST_RFAIL_OUTS_SELF := \
|
||||
$(TEST_RFAIL_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
|
||||
TEST_RFAIL_TMPS_X86 := \
|
||||
$(TEST_RFAIL_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_RFAIL_TMPS_LLVM := \
|
||||
$(TEST_RFAIL_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_RFAIL_TMPS_SELF := \
|
||||
$(TEST_RFAIL_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
|
||||
|
||||
TEST_CFAIL_CRATES_X86 := $(filter-out $(TEST_XFAILS_X86), $(CFAIL_RC))
|
||||
TEST_CFAIL_CRATES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(CFAIL_RC))
|
||||
TEST_CFAIL_CRATES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(CFAIL_RC))
|
||||
TEST_CFAIL_SOURCES_X86 := $(filter-out $(TEST_XFAILS_X86), $(CFAIL_RS))
|
||||
TEST_CFAIL_SOURCES_LLVM := $(filter-out $(TEST_XFAILS_LLVM), $(CFAIL_RS))
|
||||
TEST_CFAIL_SOURCES_SELF := $(filter-out $(TEST_XFAILS_SELF), $(CFAIL_RS))
|
||||
|
||||
TEST_CFAIL_EXES_X86 := \
|
||||
$(TEST_CFAIL_CRATES_X86:.rc=-boot.x86$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_CFAIL_SOURCES_X86:.rs=-boot.x86$(CFG_EXE_SUFFIX))
|
||||
TEST_CFAIL_EXES_LLVM := \
|
||||
$(TEST_CFAIL_CRATES_LLVM:.rc=-boot.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_CFAIL_SOURCES_LLVM:.rs=-boot.llvm$(CFG_EXE_SUFFIX))
|
||||
TEST_CFAIL_EXES_SELF := \
|
||||
$(TEST_CFAIL_CRATES_SELF:.rc=.llvm$(CFG_EXE_SUFFIX)) \
|
||||
$(TEST_CFAIL_SOURCES_SELF:.rs=.llvm$(CFG_EXE_SUFFIX))
|
||||
|
||||
TEST_CFAIL_OUTS_X86 := \
|
||||
$(TEST_CFAIL_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86.out)
|
||||
TEST_CFAIL_OUTS_LLVM := \
|
||||
$(TEST_CFAIL_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
TEST_CFAIL_OUTS_SELF := \
|
||||
$(TEST_CFAIL_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm.out)
|
||||
|
||||
TEST_CFAIL_TMPS_X86 := \
|
||||
$(TEST_CFAIL_EXES_X86:.x86$(CFG_EXE_SUFFIX)=.x86$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_CFAIL_TMPS_LLVM := \
|
||||
$(TEST_CFAIL_EXES_LLVM:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
TEST_CFAIL_TMPS_SELF := \
|
||||
$(TEST_CFAIL_EXES_SELF:.llvm$(CFG_EXE_SUFFIX)=.llvm$(CFG_EXE_SUFFIX).tmp)
|
||||
|
||||
@ -723,28 +590,6 @@ compile-check: tidy \
|
||||
|
||||
ifdef CFG_LLVM_CONFIG
|
||||
|
||||
ifneq ($(CFG_OCAML_LLVM),)
|
||||
|
||||
ALL_TEST_CRATES += $(TEST_CFAIL_CRATES_LLVM) \
|
||||
$(TEST_RFAIL_CRATES_LLVM) \
|
||||
$(TEST_RPASS_CRATES_LLVM)
|
||||
|
||||
ALL_TEST_SOURCES += $(TEST_CFAIL_SOURCES_LLVM) \
|
||||
$(TEST_RFAIL_SOURCES_LLVM) \
|
||||
$(TEST_RPASS_SOURCES_LLVM)
|
||||
|
||||
check_nocompile: $(TEST_CFAIL_OUTS_LLVM)
|
||||
|
||||
check: tidy \
|
||||
$(TEST_RPASS_EXES_LLVM) $(TEST_RFAIL_EXES_LLVM) \
|
||||
$(TEST_RPASS_OUTS_LLVM) $(TEST_RFAIL_OUTS_LLVM) \
|
||||
$(TEST_CFAIL_OUTS_LLVM)
|
||||
|
||||
compile-check: tidy \
|
||||
$(TEST_RPASS_EXES_LLVM) $(TEST_RFAIL_EXES_LLVM)
|
||||
|
||||
endif
|
||||
|
||||
ALL_TEST_CRATES += $(TEST_CFAIL_CRATES_SELF) \
|
||||
$(TEST_RFAIL_CRATES_SELF) \
|
||||
$(TEST_RPASS_CRATES_SELF)
|
||||
@ -761,7 +606,6 @@ check: tidy \
|
||||
$(TEST_CFAIL_OUTS_SELF)
|
||||
|
||||
compile-check: tidy \
|
||||
$(TEST_RPASS_EXES_LLVM) $(TEST_RFAIL_EXES_LLVM) \
|
||||
$(TEST_RPASS_EXES_SELF) $(TEST_RFAIL_EXES_SELF)
|
||||
|
||||
endif
|
||||
|
@ -1,39 +0,0 @@
|
||||
(*
|
||||
* Glue for the LLVM backend.
|
||||
*)
|
||||
|
||||
let alt_argspecs sess = [
|
||||
("-llvm", Arg.Unit (fun _ -> sess.Session.sess_alt_backend <- true),
|
||||
"emit LLVM bitcode")
|
||||
];;
|
||||
|
||||
let alt_pipeline sess sem_cx crate =
|
||||
let process processor =
|
||||
processor sem_cx crate;
|
||||
if sess.Session.sess_failed then exit 1 else ()
|
||||
in
|
||||
Array.iter process
|
||||
[|
|
||||
Resolve.process_crate;
|
||||
Simplify.process_crate;
|
||||
Type.process_crate;
|
||||
Typestate.process_crate;
|
||||
Layer.process_crate;
|
||||
Effect.process_crate;
|
||||
Loop.process_crate;
|
||||
Alias.process_crate;
|
||||
Dead.process_crate;
|
||||
Layout.process_crate
|
||||
|];
|
||||
Llemit.trans_and_process_crate sess sem_cx crate
|
||||
;;
|
||||
|
||||
(*
|
||||
* Local Variables:
|
||||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -k -C ../../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
||||
|
@ -1,94 +0,0 @@
|
||||
(*
|
||||
* LLVM integration with the Rust runtime.
|
||||
*)
|
||||
|
||||
type abi = {
|
||||
crate_ty: Llvm.lltype;
|
||||
task_ty: Llvm.lltype;
|
||||
word_ty: Llvm.lltype;
|
||||
tydesc_ty: Llvm.lltype;
|
||||
rust_start: Llvm.llvalue;
|
||||
};;
|
||||
|
||||
let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
|
||||
let i32 = Llvm.i32_type llctx in
|
||||
(* FIXME: Use Llvm_target.intptr_type for more platform support. *)
|
||||
let word_ty = i32 in
|
||||
let p ty = Llvm.pointer_type ty in
|
||||
|
||||
let crate_ty =
|
||||
(* TODO: other architectures besides x86 *)
|
||||
let crate_opaque_ty = Llvm.opaque_type llctx in
|
||||
let crate_tyhandle = Llvm.handle_to_type (Llvm.struct_type llctx [|
|
||||
i32; (* ptrdiff_t image_base_off *)
|
||||
Llvm.pointer_type crate_opaque_ty;(* uintptr_t self_addr *)
|
||||
i32; (* ptrdiff_t debug_abbrev_off *)
|
||||
i32; (* size_t debug_abbrev_sz *)
|
||||
i32; (* ptrdiff_t debug_info_off *)
|
||||
i32; (* size_t debug_info_sz *)
|
||||
i32; (* size_t activate_glue_off *)
|
||||
i32; (* size_t yield_glue_off *)
|
||||
i32; (* size_t unwind_glue_off *)
|
||||
i32; (* size_t gc_glue_off *)
|
||||
i32; (* size_t main_exit_task_glue_off *)
|
||||
i32; (* int n_rust_syms *)
|
||||
i32; (* int n_c_syms *)
|
||||
i32 (* int n_libs *)
|
||||
|])
|
||||
in
|
||||
Llvm.refine_type crate_opaque_ty (Llvm.type_of_handle crate_tyhandle);
|
||||
Llvm.type_of_handle crate_tyhandle
|
||||
in
|
||||
ignore (Llvm.define_type_name "rust_crate" crate_ty llmod);
|
||||
|
||||
let task_ty =
|
||||
(* TODO: other architectures besides x86 *)
|
||||
Llvm.struct_type llctx [|
|
||||
i32; (* size_t refcnt *)
|
||||
Llvm.pointer_type i32; (* rust_task *_delegate *)
|
||||
Llvm.pointer_type i32; (* stk_seg *stk *)
|
||||
Llvm.pointer_type i32; (* uintptr_t runtime_sp *)
|
||||
Llvm.pointer_type i32; (* uintptr_t rust_sp *)
|
||||
Llvm.pointer_type i32; (* rust_rt *rt *)
|
||||
Llvm.pointer_type i32 (* rust_crate_cache *cache *)
|
||||
|]
|
||||
in
|
||||
ignore (Llvm.define_type_name "rust_task" task_ty llmod);
|
||||
|
||||
(* This is the type_desc struct in rust_internal.h *)
|
||||
let tydesc_ty =
|
||||
(* TODO: other architectures besides x86 *)
|
||||
let tydesc_opaque_ty = Llvm.opaque_type llctx in
|
||||
let tydesc_tyhandle = Llvm.handle_to_type (Llvm.struct_type llctx [|
|
||||
p (p tydesc_opaque_ty); (* const type_desc **first_param *)
|
||||
word_ty; (* size_t size *)
|
||||
word_ty; (* size_t align *)
|
||||
word_ty; (* uintptr_t copy_glue_off *)
|
||||
word_ty; (* uintptr_t drop_glue_off *)
|
||||
word_ty; (* uintptr_t free_glue_off *)
|
||||
word_ty; (* uintptr_t sever_glue_off *)
|
||||
word_ty; (* uintptr_t mark_glue_off *)
|
||||
word_ty; (* uintptr_t obj_drop_glue_off *)
|
||||
|])
|
||||
in
|
||||
Llvm.refine_type tydesc_opaque_ty (Llvm.type_of_handle tydesc_tyhandle);
|
||||
Llvm.type_of_handle tydesc_tyhandle
|
||||
in
|
||||
ignore (Llvm.define_type_name "type_desc" tydesc_ty llmod);
|
||||
|
||||
let rust_start_ty =
|
||||
(* Rust's main function can have several types, so we cast them
|
||||
all to uintptr_t. *)
|
||||
let main_ty = word_ty in
|
||||
let args_ty = [| main_ty; Llvm.pointer_type crate_ty; i32; i32 |] in
|
||||
Llvm.function_type i32 args_ty
|
||||
in
|
||||
{
|
||||
crate_ty = crate_ty;
|
||||
task_ty = task_ty;
|
||||
word_ty = word_ty;
|
||||
tydesc_ty = tydesc_ty;
|
||||
rust_start = Llvm.declare_function "rust_start" rust_start_ty llmod
|
||||
}
|
||||
;;
|
||||
|
@ -1,208 +0,0 @@
|
||||
(*
|
||||
* machine-specific assembler routines.
|
||||
*)
|
||||
|
||||
open Common;;
|
||||
|
||||
type asm_glue =
|
||||
{
|
||||
asm_activate_glue : Llvm.llvalue;
|
||||
asm_yield_glue : Llvm.llvalue;
|
||||
asm_upcall_glues : Llvm.llvalue array;
|
||||
}
|
||||
;;
|
||||
|
||||
let n_upcall_glues = 7
|
||||
;;
|
||||
|
||||
(* x86-specific asm. *)
|
||||
|
||||
let x86_glue
|
||||
(llctx:Llvm.llcontext)
|
||||
(llmod:Llvm.llmodule)
|
||||
(abi:Llabi.abi)
|
||||
(sess:Session.sess)
|
||||
: asm_glue =
|
||||
let (prefix,align) =
|
||||
match sess.Session.sess_targ with
|
||||
Linux_x86_elf -> ("", 4)
|
||||
| Win32_x86_pe -> ("_",4)
|
||||
| MacOS_x86_macho -> ("_", 16)
|
||||
in
|
||||
let save_callee_saves =
|
||||
["pushl %ebp";
|
||||
"pushl %edi";
|
||||
"pushl %esi";
|
||||
"pushl %ebx";]
|
||||
in
|
||||
let restore_callee_saves =
|
||||
["popl %ebx";
|
||||
"popl %esi";
|
||||
"popl %edi";
|
||||
"popl %ebp";]
|
||||
in
|
||||
let load_esp_from_rust_sp =
|
||||
[ Printf.sprintf "movl %d(%%edx), %%esp"
|
||||
(Abi.task_field_rust_sp * 4)]
|
||||
in
|
||||
let load_esp_from_runtime_sp =
|
||||
[ Printf.sprintf "movl %d(%%edx), %%esp"
|
||||
(Abi.task_field_runtime_sp * 4) ]
|
||||
in
|
||||
let store_esp_to_rust_sp =
|
||||
[ Printf.sprintf "movl %%esp, %d(%%edx)"
|
||||
(Abi.task_field_rust_sp * 4) ]
|
||||
in
|
||||
let store_esp_to_runtime_sp =
|
||||
[ Printf.sprintf "movl %%esp, %d(%%edx)"
|
||||
(Abi.task_field_runtime_sp * 4) ]
|
||||
in
|
||||
|
||||
let list_init i f = (Array.to_list (Array.init i f)) in
|
||||
let list_init_concat i f = List.concat (list_init i f) in
|
||||
|
||||
let glue =
|
||||
[
|
||||
("rust_activate_glue",
|
||||
String.concat "\n\t"
|
||||
(["movl 4(%esp), %edx # edx = rust_task"]
|
||||
@ save_callee_saves
|
||||
@ store_esp_to_runtime_sp
|
||||
@ load_esp_from_rust_sp
|
||||
(*
|
||||
* This 'add' instruction is a bit surprising.
|
||||
* See lengthy comment in boot/be/x86.ml activate_glue.
|
||||
*)
|
||||
@ [ Printf.sprintf
|
||||
"addl $20, %d(%%edx)"
|
||||
(Abi.task_field_rust_sp * 4) ]
|
||||
|
||||
@ restore_callee_saves
|
||||
@ ["ret"]));
|
||||
|
||||
("rust_yield_glue",
|
||||
String.concat "\n\t"
|
||||
|
||||
(["movl 0(%esp), %edx # edx = rust_task"]
|
||||
@ load_esp_from_rust_sp
|
||||
@ save_callee_saves
|
||||
@ store_esp_to_rust_sp
|
||||
@ load_esp_from_runtime_sp
|
||||
@ restore_callee_saves
|
||||
@ ["ret"]))
|
||||
]
|
||||
@ list_init n_upcall_glues
|
||||
begin
|
||||
fun i ->
|
||||
(*
|
||||
* 0, 4, 8, 12 are callee-saves
|
||||
* 16 is retpc
|
||||
* 20 is taskptr
|
||||
* 24 is callee
|
||||
* 28 .. (7+i) * 4 are args
|
||||
*)
|
||||
|
||||
((Printf.sprintf "rust_upcall_%d" i),
|
||||
String.concat "\n\t"
|
||||
(save_callee_saves
|
||||
@ ["movl %esp, %ebp # ebp = rust_sp";
|
||||
"movl 20(%esp), %edx # edx = rust_task"]
|
||||
@ store_esp_to_rust_sp
|
||||
@ load_esp_from_runtime_sp
|
||||
@ [Printf.sprintf
|
||||
"subl $%d, %%esp # esp -= args" ((i+1)*4);
|
||||
"andl $~0xf, %esp # align esp down";
|
||||
"movl %edx, (%esp) # arg[0] = rust_task "]
|
||||
|
||||
@ (list_init_concat i
|
||||
begin
|
||||
fun j ->
|
||||
[ Printf.sprintf "movl %d(%%ebp),%%edx" ((j+7)*4);
|
||||
Printf.sprintf "movl %%edx,%d(%%esp)" ((j+1)*4) ]
|
||||
end)
|
||||
|
||||
@ ["movl 24(%ebp), %edx # edx = callee";
|
||||
"call *%edx # call *%edx";
|
||||
"movl 20(%ebp), %edx # edx = rust_task"]
|
||||
@ load_esp_from_rust_sp
|
||||
@ restore_callee_saves
|
||||
@ ["ret"]))
|
||||
end
|
||||
in
|
||||
|
||||
let _ =
|
||||
Llvm.set_module_inline_asm llmod
|
||||
begin
|
||||
String.concat "\n"
|
||||
begin
|
||||
List.map
|
||||
begin
|
||||
fun (sym,asm) ->
|
||||
Printf.sprintf
|
||||
"\t.globl %s%s\n\t.balign %d\n%s%s:\n\t%s"
|
||||
prefix sym align prefix sym asm
|
||||
end
|
||||
glue
|
||||
end
|
||||
end
|
||||
in
|
||||
|
||||
let decl_cdecl_fn name out_ty arg_tys =
|
||||
let ty = Llvm.function_type out_ty arg_tys in
|
||||
let fn = Llvm.declare_function name ty llmod in
|
||||
Llvm.set_function_call_conv Llvm.CallConv.c fn;
|
||||
fn
|
||||
in
|
||||
|
||||
let decl_glue s =
|
||||
let task_ptr_ty = Llvm.pointer_type abi.Llabi.task_ty in
|
||||
let void_ty = Llvm.void_type llctx in
|
||||
decl_cdecl_fn s void_ty [| task_ptr_ty |]
|
||||
in
|
||||
|
||||
let decl_upcall n =
|
||||
let task_ptr_ty = Llvm.pointer_type abi.Llabi.task_ty in
|
||||
let word_ty = abi.Llabi.word_ty in
|
||||
let callee_ty = word_ty in
|
||||
let args_ty =
|
||||
Array.append
|
||||
[| task_ptr_ty; callee_ty |]
|
||||
(Array.init n (fun _ -> word_ty))
|
||||
in
|
||||
let name = Printf.sprintf "rust_upcall_%d" n in
|
||||
decl_cdecl_fn name word_ty args_ty
|
||||
in
|
||||
{
|
||||
asm_activate_glue = decl_glue "rust_activate_glue";
|
||||
asm_yield_glue = decl_glue "rust_yield_glue";
|
||||
asm_upcall_glues = Array.init n_upcall_glues decl_upcall;
|
||||
}
|
||||
;;
|
||||
|
||||
(* x64-specific asm. *)
|
||||
(* arm-specific asm. *)
|
||||
(* ... *)
|
||||
|
||||
|
||||
let get_glue
|
||||
(llctx:Llvm.llcontext)
|
||||
(llmod:Llvm.llmodule)
|
||||
(abi:Llabi.abi)
|
||||
(sess:Session.sess)
|
||||
: asm_glue =
|
||||
match sess.Session.sess_targ with
|
||||
Linux_x86_elf
|
||||
| Win32_x86_pe
|
||||
| MacOS_x86_macho ->
|
||||
x86_glue llctx llmod abi sess
|
||||
;;
|
||||
|
||||
|
||||
(*
|
||||
* Local Variables:
|
||||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
@ -1,36 +0,0 @@
|
||||
(*
|
||||
* LLVM emitter.
|
||||
*)
|
||||
|
||||
(* The top-level interface to the LLVM translation subsystem. *)
|
||||
let trans_and_process_crate
|
||||
(sess:Session.sess)
|
||||
(sem_cx:Semant.ctxt)
|
||||
(crate:Ast.crate)
|
||||
: unit =
|
||||
let llcontext = Llvm.create_context () in
|
||||
let emit_file (llmod:Llvm.llmodule) : unit =
|
||||
let filename = Session.filename_of sess.Session.sess_out in
|
||||
if not (Llvm_bitwriter.write_bitcode_file llmod filename)
|
||||
then raise (Failure ("failed to write the LLVM bitcode '" ^ filename
|
||||
^ "'"))
|
||||
in
|
||||
let llmod = Lltrans.trans_crate sem_cx llcontext sess crate in
|
||||
begin
|
||||
try
|
||||
emit_file llmod
|
||||
with e -> Llvm.dispose_module llmod; raise e
|
||||
end;
|
||||
Llvm.dispose_module llmod;
|
||||
Llvm.dispose_context llcontext
|
||||
;;
|
||||
|
||||
(*
|
||||
* Local Variables:
|
||||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
||||
|
@ -1,105 +0,0 @@
|
||||
(*
|
||||
* LLVM ABI-level stuff that needs to happen after modules have been
|
||||
* translated.
|
||||
*)
|
||||
|
||||
let finalize_module
|
||||
(sess:Session.sess)
|
||||
(llctx:Llvm.llcontext)
|
||||
(llmod:Llvm.llmodule)
|
||||
(abi:Llabi.abi)
|
||||
(asm_glue:Llasm.asm_glue)
|
||||
(exit_task_glue:Llvm.llvalue)
|
||||
(crate_ptr:Llvm.llvalue)
|
||||
: unit =
|
||||
let i32 = Llvm.i32_type llctx in
|
||||
|
||||
(*
|
||||
* Count the number of Rust functions and the number of C functions by
|
||||
* simply (and crudely) testing whether each function in the module begins
|
||||
* with "_rust_".
|
||||
*)
|
||||
|
||||
let (rust_fn_count, c_fn_count) =
|
||||
let count (rust_fn_count, c_fn_count) fn =
|
||||
let begins_with prefix str =
|
||||
let (str_len, prefix_len) =
|
||||
(String.length str, String.length prefix)
|
||||
in
|
||||
prefix_len <= str_len && (String.sub str 0 prefix_len) = prefix
|
||||
in
|
||||
if begins_with "_rust_" (Llvm.value_name fn) then
|
||||
(rust_fn_count + 1, c_fn_count)
|
||||
else
|
||||
(rust_fn_count, c_fn_count + 1)
|
||||
in
|
||||
Llvm.fold_left_functions count (0, 0) llmod
|
||||
in
|
||||
|
||||
let crate_val =
|
||||
let crate_addr = Llvm.const_ptrtoint crate_ptr i32 in
|
||||
let glue_off glue =
|
||||
let addr = Llvm.const_ptrtoint glue i32 in
|
||||
Llvm.const_sub addr crate_addr
|
||||
in
|
||||
let activate_glue_off = glue_off asm_glue.Llasm.asm_activate_glue in
|
||||
let yield_glue_off = glue_off asm_glue.Llasm.asm_yield_glue in
|
||||
let exit_task_glue_off = glue_off exit_task_glue in
|
||||
|
||||
Llvm.const_struct llctx [|
|
||||
Llvm.const_int i32 0; (* ptrdiff_t image_base_off *)
|
||||
crate_ptr; (* uintptr_t self_addr *)
|
||||
Llvm.const_int i32 0; (* ptrdiff_t debug_abbrev_off *)
|
||||
Llvm.const_int i32 0; (* size_t debug_abbrev_sz *)
|
||||
Llvm.const_int i32 0; (* ptrdiff_t debug_info_off *)
|
||||
Llvm.const_int i32 0; (* size_t debug_info_sz *)
|
||||
activate_glue_off; (* size_t activate_glue_off *)
|
||||
yield_glue_off; (* size_t yield_glue_off *)
|
||||
Llvm.const_int i32 0; (* size_t unwind_glue_off *)
|
||||
Llvm.const_int i32 0; (* size_t gc_glue_off *)
|
||||
exit_task_glue_off; (* size_t main_exit_task_glue_off *)
|
||||
Llvm.const_int i32 rust_fn_count; (* int n_rust_syms *)
|
||||
Llvm.const_int i32 c_fn_count; (* int n_c_syms *)
|
||||
Llvm.const_int i32 0 (* int n_libs *)
|
||||
|]
|
||||
in
|
||||
|
||||
Llvm.set_initializer crate_val crate_ptr;
|
||||
|
||||
(* Define the main function for crt0 to call. *)
|
||||
let main_fn =
|
||||
let main_ty = Llvm.function_type i32 [| i32; i32 |] in
|
||||
let main_name =
|
||||
match sess.Session.sess_targ with
|
||||
Common.Win32_x86_pe -> "WinMain@16"
|
||||
| Common.Linux_x86_elf
|
||||
| Common.MacOS_x86_macho -> "main"
|
||||
in
|
||||
Llvm.define_function main_name main_ty llmod
|
||||
in
|
||||
let argc = Llvm.param main_fn 0 in
|
||||
let argv = Llvm.param main_fn 1 in
|
||||
let main_builder = Llvm.builder_at_end llctx (Llvm.entry_block main_fn) in
|
||||
let rust_main_fn =
|
||||
match Llvm.lookup_function "_rust_main" llmod with
|
||||
None -> raise (Failure "no main function found")
|
||||
| Some fn -> fn
|
||||
in
|
||||
let rust_start = abi.Llabi.rust_start in
|
||||
let rust_start_args = [| Llvm.const_ptrtoint rust_main_fn abi.Llabi.word_ty;
|
||||
crate_ptr; argc; argv |] in
|
||||
ignore (Llvm.build_call
|
||||
rust_start rust_start_args "start_rust" main_builder);
|
||||
ignore (Llvm.build_ret (Llvm.const_int i32 0) main_builder)
|
||||
;;
|
||||
|
||||
|
||||
(*
|
||||
* Local Variables:
|
||||
* fill-column: 78;
|
||||
* indent-tabs-mode: nil
|
||||
* buffer-file-coding-system: utf-8-unix
|
||||
* compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
* End:
|
||||
*)
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user