Skip to content

Commit cda4133

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 6109 b: refs/heads/master c: c0e9c42 h: refs/heads/master i: 6107: 4b625f1 v: v3
1 parent 0ff54ea commit cda4133

File tree

8 files changed

+150
-100
lines changed

8 files changed

+150
-100
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 2521cda1ec5e24cce81e25fcf64281584fcfdb5d
2+
refs/heads/master: c0e9c42bd2f81d9694ee4c77b3440a44d38737e6

trunk/src/comp/back/upcall.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import std::str;
3+
import driver::session;
34
import middle::trans;
45
import trans::decl_cdecl_fn;
56
import middle::trans_common::{T_f32, T_f64, T_fn, T_bool, T_i1, T_i8, T_i32,
@@ -32,7 +33,9 @@ type upcalls =
3233
call_c_stack_float: ValueRef,
3334
rust_personality: ValueRef};
3435

35-
fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
36+
fn declare_upcalls(targ_cfg: @session::config,
37+
_tn: type_names,
38+
tydesc_type: TypeRef,
3639
llmod: ModuleRef) -> @upcalls {
3740
fn decl(llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) ->
3841
ValueRef {
@@ -44,25 +47,35 @@ fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
4447
let d = bind decl(llmod, _, _, _);
4548
let dv = bind decl(llmod, _, _, T_void());
4649

47-
ret @{_fail: dv("fail", [T_ptr(T_i8()), T_ptr(T_i8()), T_size_t()]),
50+
let int_t = T_int(targ_cfg);
51+
let size_t = T_size_t(targ_cfg);
52+
let opaque_vec_t = T_opaque_vec(targ_cfg);
53+
54+
ret @{_fail: dv("fail", [T_ptr(T_i8()),
55+
T_ptr(T_i8()),
56+
size_t]),
4857
malloc:
49-
d("malloc", [T_size_t(), T_ptr(tydesc_type)], T_ptr(T_i8())),
50-
free: dv("free", [T_ptr(T_i8()), T_int()]),
58+
d("malloc", [size_t, T_ptr(tydesc_type)],
59+
T_ptr(T_i8())),
60+
free: dv("free", [T_ptr(T_i8()), int_t]),
5161
shared_malloc:
52-
d("shared_malloc", [T_size_t(), T_ptr(tydesc_type)],
62+
d("shared_malloc", [size_t, T_ptr(tydesc_type)],
5363
T_ptr(T_i8())),
5464
shared_free: dv("shared_free", [T_ptr(T_i8())]),
55-
mark: d("mark", [T_ptr(T_i8())], T_int()),
65+
mark: d("mark", [T_ptr(T_i8())], int_t),
5666
get_type_desc:
5767
d("get_type_desc",
58-
[T_ptr(T_nil()), T_size_t(), T_size_t(), T_size_t(),
59-
T_ptr(T_ptr(tydesc_type)), T_int()], T_ptr(tydesc_type)),
68+
[T_ptr(T_nil()), size_t,
69+
size_t, size_t,
70+
T_ptr(T_ptr(tydesc_type)), int_t],
71+
T_ptr(tydesc_type)),
6072
vec_grow:
61-
dv("vec_grow", [T_ptr(T_ptr(T_opaque_vec())), T_int()]),
73+
dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)),
74+
int_t]),
6275
vec_push:
6376
dv("vec_push",
64-
[T_ptr(T_ptr(T_opaque_vec())), T_ptr(tydesc_type),
65-
T_ptr(T_i8())]),
77+
[T_ptr(T_ptr(opaque_vec_t)), T_ptr(tydesc_type),
78+
T_ptr(T_i8())]),
6679
cmp_type:
6780
dv("cmp_type",
6881
[T_ptr(T_i1()), T_ptr(tydesc_type),
@@ -72,13 +85,13 @@ fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
7285
dv("log_type", [T_ptr(tydesc_type), T_ptr(T_i8()), T_i32()]),
7386
dynastack_mark: d("dynastack_mark", [], T_ptr(T_i8())),
7487
dynastack_alloc:
75-
d("dynastack_alloc_2", [T_size_t(), T_ptr(tydesc_type)],
88+
d("dynastack_alloc_2", [size_t, T_ptr(tydesc_type)],
7689
T_ptr(T_i8())),
7790
dynastack_free: dv("dynastack_free", [T_ptr(T_i8())]),
7891
alloc_c_stack: d("alloc_c_stack", [T_size_t()], T_ptr(T_i8())),
7992
call_c_stack: d("call_c_stack",
8093
[T_ptr(T_fn([], T_int())), T_ptr(T_i8())],
81-
T_int()),
94+
int_t),
8295
call_c_stack_i64: d("call_c_stack_i64",
8396
[T_ptr(T_fn([], T_int())), T_ptr(T_i8())],
8497
T_i64()),

trunk/src/comp/middle/gc.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str) -> ValueRef {
2929

3030
fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
3131
let bcx = cx;
32+
let ccx = bcx_ccx(cx);
3233
if !type_is_gc_relevant(bcx_tcx(cx), ty) ||
3334
ty::type_has_dynamic_size(bcx_tcx(cx), ty) {
3435
ret bcx;
@@ -61,10 +62,12 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
6162
gc_cx.next_tydesc_num += 1u;
6263

6364
let lldestindex =
64-
add_global(bcx_ccx(bcx), C_struct([C_int(0), C_uint(number)]),
65+
add_global(bcx_ccx(bcx), C_struct([C_int(ccx, 0),
66+
C_uint(ccx, number)]),
6567
"rust_gc_tydesc_dest_index");
6668
let llsrcindex =
67-
add_global(bcx_ccx(bcx), C_struct([C_int(1), C_uint(number)]),
69+
add_global(bcx_ccx(bcx), C_struct([C_int(ccx, 1),
70+
C_uint(ccx, number)]),
6871
"rust_gc_tydesc_src_index");
6972

7073
lldestindex = lll::LLVMConstPointerCast(lldestindex, T_ptr(T_i8()));
@@ -85,7 +88,7 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
8588
// Static type descriptor.
8689

8790
let llstaticgcmeta =
88-
add_global(bcx_ccx(bcx), C_struct([C_int(2), lltydesc]),
91+
add_global(bcx_ccx(bcx), C_struct([C_int(ccx, 2), lltydesc]),
8992
"rust_gc_tydesc_static_gc_meta");
9093
let llstaticgcmetaptr =
9194
lll::LLVMConstPointerCast(llstaticgcmeta, T_ptr(T_i8()));

trunk/src/comp/middle/trans.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
161161
ty::ty_vec(mt) {
162162
let mt_ty = mt.ty;
163163
if ty::type_has_dynamic_size(cx.tcx, mt_ty) {
164-
T_ptr(T_opaque_vec(cx))
164+
T_ptr(cx.opaque_vec_type)
165165
} else {
166166
// should be unnecessary
167167
check non_ty_var(cx, mt_ty);
@@ -359,7 +359,7 @@ fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
359359
get_simple_extern_fn(cx, externs, llmod, name, n);
360360
let call_args: [ValueRef] = [];
361361
for a: ValueRef in args {
362-
call_args += [ZExtOrBitCast(cx, a, T_int(bcx_ccx(cx)))];
362+
call_args += [ZExtOrBitCast(cx, a, bcx_ccx(cx).int_type)];
363363
}
364364
ret Call(cx, llnative, call_args);
365365
}
@@ -2616,7 +2616,7 @@ fn trans_for(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
26162616
let next_cx = new_sub_block_ctxt(cx, "next");
26172617
let seq_ty = ty::expr_ty(bcx_tcx(cx), seq);
26182618
let {bcx: bcx, val: seq} = trans_temp_expr(cx, seq);
2619-
let seq = PointerCast(bcx, seq, T_ptr(T_opaque_vec(ccx)));
2619+
let seq = PointerCast(bcx, seq, T_ptr(ccx.opaque_vec_type));
26202620
let fill = tvec::get_fill(bcx, seq);
26212621
if ty::type_is_str(bcx_tcx(bcx), seq_ty) {
26222622
fill = Sub(bcx, fill, C_int(ccx, 1));
@@ -6075,7 +6075,7 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
60756075
llvm::LLVMSetLinkage(map,
60766076
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
60776077
llvm::LLVMSetInitializer(map,
6078-
C_struct([p2i(create_module_map(ccx)),
6078+
C_struct([p2i(ccx, create_module_map(ccx)),
60796079
C_array(ccx.int_type, subcrates)]));
60806080
ret map;
60816081
>>>>>>> work on making the size of ints depend on the target arch
@@ -6129,15 +6129,16 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
61296129
let _: () =
61306130
str::as_buf(sess.get_targ_cfg().target_strs.target_triple,
61316131
{|buf| llvm::LLVMSetTarget(llmod, buf) });
6132+
let targ_cfg = sess.get_targ_cfg();
61326133
let td = mk_target_data(sess.get_targ_cfg().target_strs.data_layout);
61336134
let tn = mk_type_names();
61346135
let intrinsics = declare_intrinsics(llmod);
6135-
let int_type = T_int(sess.get_targ_cfg().arch);
6136-
let float_type = T_float(sess.get_targ_cfg().arch);
6137-
let task_type = T_task(sess.get_targ_cfg().arch);
6136+
let int_type = T_int(targ_cfg);
6137+
let float_type = T_float(targ_cfg);
6138+
let task_type = T_task(targ_cfg);
61386139
let taskptr_type = T_ptr(task_type);
61396140
tn.associate("taskptr", taskptr_type);
6140-
let tydesc_type = T_tydesc(taskptr_type);
6141+
let tydesc_type = T_tydesc(targ_cfg, taskptr_type);
61416142
tn.associate("tydesc", tydesc_type);
61426143
let hasher = ty::hash_ty;
61436144
let eqer = ty::eq_ty;
@@ -6184,12 +6185,14 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
61846185
mutable n_real_glues: 0u,
61856186
fn_times: @mutable []},
61866187
upcalls:
6187-
upcall::declare_upcalls(tn, tydesc_type, llmod),
6188+
upcall::declare_upcalls(targ_cfg, tn, tydesc_type,
6189+
llmod),
61886190
rust_object_type: T_rust_object(),
61896191
tydesc_type: tydesc_type,
61906192
int_type: int_type,
61916193
float_type: float_type,
61926194
task_type: task_type,
6195+
opaque_vec_type: T_opaque_vec(targ_cfg),
61936196
builder: BuilderRef_res(llvm::LLVMCreateBuilder()),
61946197
shape_cx: shape::mk_ctxt(llmod),
61956198
gc_cx: gc::mk_ctxt(),

trunk/src/comp/middle/trans_alt.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tag opt_result {
4444
range_result(result, result);
4545
}
4646
fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
47+
let ccx = bcx_ccx(bcx);
4748
alt o {
4849
lit(l) {
4950
alt l.node {
@@ -56,11 +57,11 @@ fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
5657
}
5758
_ {
5859
ret single_result(
59-
rslt(bcx, trans::trans_crate_lit(bcx_ccx(bcx), *l)));
60+
rslt(bcx, trans::trans_crate_lit(ccx, *l)));
6061
}
6162
}
6263
}
63-
var(id, _) { ret single_result(rslt(bcx, C_int(id as int))); }
64+
var(id, _) { ret single_result(rslt(bcx, C_int(ccx, id as int))); }
6465
range(l1, l2) {
6566
let cell1 = trans::empty_dest_cell();
6667
let cell2 = trans::empty_dest_cell();
@@ -257,8 +258,8 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
257258
vec::len(ty::tag_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
258259
if size > 0u && vec::len(variants) != 1u {
259260
let tagptr =
260-
PointerCast(bcx, val, trans_common::T_opaque_tag_ptr(ccx.tn));
261-
blobptr = GEP(bcx, tagptr, [C_int(0), C_int(1)]);
261+
PointerCast(bcx, val, trans_common::T_opaque_tag_ptr(ccx));
262+
blobptr = GEP(bcx, tagptr, [C_int(ccx, 0), C_int(ccx, 1)]);
262263
}
263264
let i = 0u;
264265
let vdefs_tg = vdefs.tg;
@@ -439,7 +440,8 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
439440
let box = Load(bcx, val);
440441
let unboxed =
441442
InBoundsGEP(bcx, box,
442-
[C_int(0), C_int(back::abi::box_rc_field_body)]);
443+
[C_int(ccx, 0),
444+
C_int(ccx, back::abi::box_rc_field_body)]);
443445
compile_submatch(bcx, enter_box(m, col, val), [unboxed] + vals_left,
444446
f, exits);
445447
ret;
@@ -465,8 +467,9 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
465467
} else {
466468
let tagptr =
467469
PointerCast(bcx, val,
468-
trans_common::T_opaque_tag_ptr(ccx.tn));
469-
let discrimptr = GEP(bcx, tagptr, [C_int(0), C_int(0)]);
470+
trans_common::T_opaque_tag_ptr(ccx));
471+
let discrimptr = GEP(bcx, tagptr, [C_int(ccx, 0),
472+
C_int(ccx, 0)]);
470473
test_val = Load(bcx, discrimptr);
471474
kind = switch;
472475
}
@@ -505,7 +508,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
505508
// holding a corrupted value (when the compiler is optimized).
506509
// This can be removed after our next LLVM upgrade.
507510
val_ty(sw);
508-
} else { sw = C_int(0); } // Placeholder for when not using a switch
511+
} else { sw = C_int(ccx, 0); } // Placeholder for when not using a switch
509512

510513
// Compile subtrees for each option
511514
for opt: opt in opts {
@@ -736,7 +739,8 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
736739
let box = Load(bcx, val);
737740
let unboxed =
738741
InBoundsGEP(bcx, box,
739-
[C_int(0), C_int(back::abi::box_rc_field_body)]);
742+
[C_int(ccx, 0),
743+
C_int(ccx, back::abi::box_rc_field_body)]);
740744
bcx = bind_irrefutable_pat(bcx, inner, unboxed, true);
741745
}
742746
ast::pat_uniq(inner) {

trunk/src/comp/middle/trans_common.rs

+29-22
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type crate_ctxt =
123123
int_type: TypeRef,
124124
float_type: TypeRef,
125125
task_type: TypeRef,
126+
opaque_vec_type: TypeRef,
126127
builder: BuilderRef_res,
127128
shape_cx: shape::ctxt,
128129
gc_cx: gc::ctxt,
@@ -490,26 +491,26 @@ fn T_f64() -> TypeRef { ret llvm::LLVMDoubleType(); }
490491

491492
fn T_bool() -> TypeRef { ret T_i1(); }
492493

493-
fn T_int(arch: session::arch) -> TypeRef {
494-
ret alt arch {
495-
arch_x86 { T_i32() }
496-
arch_x86_64 { T_i64() }
497-
arch_arm { T_i32() }
494+
fn T_int(targ_cfg: @session::config) -> TypeRef {
495+
ret alt targ_cfg.arch {
496+
session::arch_x86. { T_i32() }
497+
session::arch_x86_64. { T_i64() }
498+
session::arch_arm. { T_i32() }
498499
};
499500
}
500501

501-
fn T_float(arch: session::arch) -> TypeRef {
502-
ret alt arch {
503-
arch_x86 { T_f64() }
504-
arch_x86_64 { T_f64() }
505-
arch_arm { T_f64() }
502+
fn T_float(targ_cfg: @session::config) -> TypeRef {
503+
ret alt targ_cfg.arch {
504+
session::arch_x86. { T_f64() }
505+
session::arch_x86_64. { T_f64() }
506+
session::arch_arm. { T_f64() }
506507
};
507508
}
508509

509510
fn T_char() -> TypeRef { ret T_i32(); }
510511

511-
fn T_size_t(cx: @crate_ctxt) -> TypeRef {
512-
ret cx.int_type;
512+
fn T_size_t(targ_cfg: @session::config) -> TypeRef {
513+
ret T_int(targ_cfg);
513514
}
514515

515516
fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef {
@@ -553,7 +554,7 @@ fn T_rust_object() -> TypeRef {
553554
ret t;
554555
}
555556

556-
fn T_task(arch: session::arch) -> TypeRef {
557+
fn T_task(targ_cfg: @session::config) -> TypeRef {
557558
let t = T_named_struct("task");
558559

559560
// Refcount
@@ -567,7 +568,7 @@ fn T_task(arch: session::arch) -> TypeRef {
567568
// Domain pointer
568569
// Crate cache pointer
569570

570-
let t_int = T_int(arch);
571+
let t_int = T_int(targ_cfg);
571572
let elems =
572573
[t_int, t_int, t_int, t_int,
573574
t_int, t_int, t_int, t_int];
@@ -603,7 +604,7 @@ fn T_cmp_glue_fn(cx: @crate_ctxt) -> TypeRef {
603604
ret t;
604605
}
605606

606-
fn T_tydesc(cx: @crate_ctxt) -> TypeRef {
607+
fn T_tydesc(targ_cfg: @session::config) -> TypeRef {
607608
let tydesc = T_named_struct("tydesc");
608609
let tydescpp = T_ptr(T_ptr(tydesc));
609610
let pvoid = T_ptr(T_i8());
@@ -614,29 +615,35 @@ fn T_tydesc(cx: @crate_ctxt) -> TypeRef {
614615
T_ptr(T_fn([T_ptr(T_i1()), T_ptr(tydesc), tydescpp,
615616
pvoid, pvoid, T_i8()], T_void()));
616617

618+
let int_type = T_int(targ_cfg);
617619
let elems =
618-
[tydescpp, cx.int_type, cx.int_type,
620+
[tydescpp, int_type, int_type,
619621
glue_fn_ty, glue_fn_ty, glue_fn_ty,
620622
T_ptr(T_i8()), glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty,
621-
T_ptr(T_i8()), T_ptr(T_i8()), cx.int_type, cx.int_type];
623+
T_ptr(T_i8()), T_ptr(T_i8()), int_type, int_type];
622624
set_struct_body(tydesc, elems);
623625
ret tydesc;
624626
}
625627

626628
fn T_array(t: TypeRef, n: uint) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
627629

628-
629630
// Interior vector.
630631
//
631632
// TODO: Support user-defined vector sizes.
632-
fn T_vec(cx: @crate_ctxt, t: TypeRef) -> TypeRef {
633-
ret T_struct([cx.int_type, // fill
634-
cx.int_type, // alloc
633+
fn T_vec2(targ_cfg: @session::config, t: TypeRef) -> TypeRef {
634+
ret T_struct([T_int(targ_cfg), // fill
635+
T_int(targ_cfg), // alloc
635636
T_array(t, 0u)]); // elements
636637
}
637638

639+
fn T_vec(ccx: @crate_ctxt, t: TypeRef) -> TypeRef {
640+
ret T_vec2(ccx.sess.get_targ_cfg(), t);
641+
}
642+
638643
// Note that the size of this one is in bytes.
639-
fn T_opaque_vec(cx: @crate_ctxt) -> TypeRef { ret T_vec(cx, T_i8()); }
644+
fn T_opaque_vec(targ_cfg: @session::config) -> TypeRef {
645+
ret T_vec2(targ_cfg, T_i8());
646+
}
640647

641648
fn T_box(cx: @crate_ctxt, t: TypeRef) -> TypeRef {
642649
ret T_struct([cx.int_type, t]);

0 commit comments

Comments
 (0)