Skip to content

Commit

Permalink
Fix simple generic type parameters in LLVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
jyasskin authored and graydon committed Jul 22, 2010
1 parent 09885b5 commit 2c24f70
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,6 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
generic-recursive-tag.rs \
generic-tag-alt.rs \
generic-tag.rs \
generic-type-synonym.rs \
generic-type.rs \
import.rs \
inner-module.rs \
large-records.rs \
Expand Down
24 changes: 24 additions & 0 deletions src/boot/llvm/llabi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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 *)
Expand Down Expand Up @@ -53,6 +55,27 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
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. *)
Expand All @@ -64,6 +87,7 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
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
}
;;
Expand Down
7 changes: 4 additions & 3 deletions src/boot/llvm/lltrans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ let trans_crate
| Ast.TY_native _ ->
word_ty

| Ast.TY_param _ ->
abi.Llabi.tydesc_ty

| Ast.TY_tag _ | Ast.TY_iso _ | Ast.TY_idx _
| Ast.TY_obj _ | Ast.TY_type ->
| Ast.TY_obj _ | Ast.TY_type | Ast.TY_named _ ->
Common.unimpl None "LLVM type translation for: %a" Ast.sprintf_ty ty

| Ast.TY_param _ | Ast.TY_named _ ->
bug () "unresolved type in lltrans"

and trans_ty t =
htab_search_or_add lltys t (fun _ -> trans_ty_full t)
Expand Down

0 comments on commit 2c24f70

Please sign in to comment.