Skip to content

Commit 0ff54ea

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 6108 b: refs/heads/master c: 2521cda h: refs/heads/master v: v3
1 parent 4b625f1 commit 0ff54ea

File tree

4 files changed

+93
-61
lines changed

4 files changed

+93
-61
lines changed

[refs]

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

trunk/src/comp/middle/trans.rs

+63-35
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
134134
T_nil() /* ...I guess? */
135135
}
136136
ty::ty_bool. { T_bool() }
137-
ty::ty_int. { T_int(cx) }
138-
ty::ty_float. { T_float(cx) }
139-
ty::ty_uint. { T_int(cx) }
137+
ty::ty_int. { cx.int_type }
138+
ty::ty_float. { cx.float_type }
139+
ty::ty_uint. { cx.int_type }
140140
ty::ty_machine(tm) {
141141
alt tm {
142142
ast::ty_i8. | ast::ty_u8. { T_i8() }
@@ -345,8 +345,8 @@ fn get_simple_extern_fn(cx: @block_ctxt,
345345
llmod: ModuleRef,
346346
name: str, n_args: int) -> ValueRef {
347347
let ccx = cx.fcx.lcx.ccx;
348-
let inputs = std::vec::init_elt::<TypeRef>(T_int(ccx), n_args as uint);
349-
let output = T_int(ccx);
348+
let inputs = std::vec::init_elt::<TypeRef>(ccx.int_type, n_args as uint);
349+
let output = ccx.int_type;
350350
let t = T_fn(inputs, output);
351351
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
352352
}
@@ -405,12 +405,12 @@ fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
405405
}
406406

407407
fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
408-
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t), T_int(cx),
408+
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t), cx.int_type,
409409
False);
410410
}
411411

412412
fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
413-
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMAlignOf(t), T_int(cx),
413+
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMAlignOf(t), cx.int_type,
414414
False);
415415
}
416416

@@ -597,7 +597,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
597597
let ccx = bcx_ccx(bcx);
598598
// Compute max(variant sizes).
599599

600-
let max_size: ValueRef = alloca(bcx, T_int(ccx));
600+
let max_size: ValueRef = alloca(bcx, ccx.int_type);
601601
Store(bcx, C_int(ccx, 0), max_size);
602602
let variants = ty::tag_variants(bcx_tcx(bcx), tid);
603603
for variant: ty::variant_info in variants {
@@ -618,7 +618,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
618618
let max_size_val = Load(bcx, max_size);
619619
let total_size =
620620
if std::vec::len(variants) != 1u {
621-
Add(bcx, max_size_val, llsize_of(ccx, T_int(ccx)))
621+
Add(bcx, max_size_val, llsize_of(ccx, ccx.int_type))
622622
} else { max_size_val };
623623
ret rslt(bcx, total_size);
624624
}
@@ -2161,7 +2161,7 @@ fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
21612161
// if target int width is larger than host, at the moment;
21622162
// re-do the mach-int types using 'big' when that works.
21632163

2164-
let t = T_int(cx);
2164+
let t = cx.int_type;
21652165
let s = True;
21662166
alt tm {
21672167
ast::ty_u8. { t = T_i8(); s = False; }
@@ -2177,7 +2177,7 @@ fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
21772177
}
21782178
ast::lit_float(fs) { ret C_float(cx, fs); }
21792179
ast::lit_mach_float(tm, s) {
2180-
let t = T_float(cx);
2180+
let t = cx.float_type;
21812181
alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } }
21822182
ret C_floating(s, t);
21832183
}
@@ -2961,7 +2961,7 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
29612961
let gvar =
29622962
str::as_buf(sym,
29632963
{|buf|
2964-
llvm::LLVMAddGlobal(ccx.llmod, T_int(ccx), buf)
2964+
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
29652965
});
29662966
llvm::LLVMSetLinkage(gvar,
29672967
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
@@ -3120,11 +3120,11 @@ fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr,
31203120
// Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
31213121
let ix_val;
31223122
let ix_size = llsize_of_real(bcx_ccx(cx), val_ty(ix.val));
3123-
let int_size = llsize_of_real(bcx_ccx(cx), T_int(ccx));
3123+
let int_size = llsize_of_real(bcx_ccx(cx), ccx.int_type);
31243124
if ix_size < int_size {
3125-
ix_val = ZExt(bcx, ix.val, T_int(ccx));
3125+
ix_val = ZExt(bcx, ix.val, ccx.int_type);
31263126
} else if ix_size > int_size {
3127-
ix_val = Trunc(bcx, ix.val, T_int(ccx));
3127+
ix_val = Trunc(bcx, ix.val, ccx.int_type);
31283128
} else { ix_val = ix.val; }
31293129

31303130
let unit_ty = node_id_type(bcx_ccx(cx), id);
@@ -4420,10 +4420,10 @@ fn trans_log(lvl: int, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
44204420
let s = link::mangle_internal_name_by_path_and_seq(
44214421
lcx.ccx, lcx.module_path, "loglevel");
44224422
let global = str::as_buf(s, {|buf|
4423-
llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(ccx), buf)
4423+
llvm::LLVMAddGlobal(lcx.ccx.llmod, ccx.int_type, buf)
44244424
});
44254425
llvm::LLVMSetGlobalConstant(global, False);
4426-
llvm::LLVMSetInitializer(global, C_null(T_int(ccx)));
4426+
llvm::LLVMSetInitializer(global, C_null(ccx.int_type));
44274427
llvm::LLVMSetLinkage(global,
44284428
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
44294429
lcx.ccx.module_data.insert(modname, global);
@@ -5651,14 +5651,14 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
56515651
cast_to_i32 = true;
56525652
}
56535653
ast::native_abi_c_stack_cdecl. {
5654-
let llfn = decl_cdecl_fn(ccx.llmod, name, T_fn([], T_int()));
5654+
let llfn = decl_cdecl_fn(ccx.llmod, name, T_fn([], ccx.int_type));
56555655
ccx.item_ids.insert(id, llfn);
56565656
ccx.item_symbols.insert(id, name);
56575657
ret;
56585658
}
56595659
ast::native_abi_c_stack_stdcall. {
56605660
let llfn = decl_fn(ccx.llmod, name, lib::llvm::LLVMX86StdcallCallConv,
5661-
T_fn([], T_int()));
5661+
T_fn([], ccx.int_type));
56625662
ccx.item_ids.insert(id, llfn);
56635663
ccx.item_symbols.insert(id, name);
56645664
ret;
@@ -5706,21 +5706,23 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
57065706
fn convert_arg_to_i32(cx: @block_ctxt, v: ValueRef, t: ty::t,
57075707
mode: ty::mode) -> ValueRef {
57085708
if mode == ast::by_ref || mode == ast::by_val {
5709+
let ccx = bcx_ccx(cx);
57095710
if ty::type_is_integral(bcx_tcx(cx), t) {
57105711
// FIXME: would be nice to have a postcondition that says
57115712
// if a type is integral, then it has static size (#586)
5712-
let lldsttype = T_int();
5713-
let ccx = bcx_ccx(cx);
5713+
let lldsttype = ccx.int_type;
57145714
let sp = cx.sp;
57155715
check (type_has_static_size(ccx, t));
57165716
let llsrctype = type_of(ccx, sp, t);
57175717
if llvm::LLVMGetIntTypeWidth(lldsttype) >
57185718
llvm::LLVMGetIntTypeWidth(llsrctype) {
5719-
ret ZExtOrBitCast(cx, v, T_int());
5719+
ret ZExtOrBitCast(cx, v, ccx.int_type);
57205720
}
5721-
ret TruncOrBitCast(cx, v, T_int());
5721+
ret TruncOrBitCast(cx, v, ccx.int_type);
5722+
}
5723+
if ty::type_is_fp(bcx_tcx(cx), t) {
5724+
ret FPToSI(cx, v, ccx.int_type);
57225725
}
5723-
if ty::type_is_fp(bcx_tcx(cx), t) { ret FPToSI(cx, v, T_int()); }
57245726
}
57255727
ret vp2i(cx, v);
57265728
}
@@ -5927,11 +5929,10 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
59275929
let p = new_pt + [it.ident, variant.node.name, "discrim"];
59285930
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
59295931
let discrim_gvar =
5930-
str::as_buf(s,
5931-
{|buf|
5932-
llvm::LLVMAddGlobal(ccx.llmod, T_int(), buf)
5933-
});
5934-
llvm::LLVMSetInitializer(discrim_gvar, C_int(i as int));
5932+
str::as_buf(s, {|buf|
5933+
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
5934+
});
5935+
llvm::LLVMSetInitializer(discrim_gvar, C_int(ccx, i as int));
59355936
llvm::LLVMSetGlobalConstant(discrim_gvar, True);
59365937
ccx.discrims.insert(
59375938
ast_util::local_def(variant.node.id), discrim_gvar);
@@ -5951,10 +5952,13 @@ fn trans_constants(ccx: @crate_ctxt, crate: @ast::crate) {
59515952
}
59525953

59535954
fn vp2i(cx: @block_ctxt, v: ValueRef) -> ValueRef {
5954-
ret PtrToInt(cx, v, T_int());
5955+
let ccx = bcx_ccx(cx);
5956+
ret PtrToInt(cx, v, ccx.int_type);
59555957
}
59565958

5957-
fn p2i(v: ValueRef) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); }
5959+
fn p2i(ccx: @crate_ctxt, v: ValueRef) -> ValueRef {
5960+
ret llvm::LLVMConstPtrToInt(v, ccx.int_type);
5961+
}
59585962

59595963
fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
59605964
let T_memmove32_args: [TypeRef] =
@@ -6005,7 +6009,7 @@ fn trap(bcx: @block_ctxt) {
60056009
}
60066010

60076011
fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
6008-
let elttype = T_struct([T_int(), T_int()]);
6012+
let elttype = T_struct([ccx.int_type, ccx.int_type]);
60096013
let maptype = T_array(elttype, ccx.module_data.size() + 1u);
60106014
let map =
60116015
str::as_buf("_rust_mod_map",
@@ -6057,6 +6061,24 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
60576061
subcrates += [C_int(0)];
60586062
llvm::LLVMSetInitializer(map, C_struct([p2i(create_module_map(ccx)),
60596063
C_array(T_int(), subcrates)]));
6064+
subcrates += [C_int(ccx, 0)];
6065+
let mapname;
6066+
if ccx.sess.get_opts().library {
6067+
mapname = ccx.link_meta.name;
6068+
} else { mapname = "toplevel"; }
6069+
let sym_name = "_rust_crate_map_" + mapname;
6070+
let arrtype = T_array(ccx.int_type, std::vec::len::<ValueRef>(subcrates));
6071+
let maptype = T_struct([ccx.int_type, arrtype]);
6072+
let map =
6073+
str::as_buf(sym_name,
6074+
{|buf| llvm::LLVMAddGlobal(ccx.llmod, maptype, buf) });
6075+
llvm::LLVMSetLinkage(map,
6076+
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
6077+
llvm::LLVMSetInitializer(map,
6078+
C_struct([p2i(create_module_map(ccx)),
6079+
C_array(ccx.int_type, subcrates)]));
6080+
ret map;
6081+
>>>>>>> work on making the size of ints depend on the target arch
60606082
}
60616083

60626084
fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
@@ -6090,7 +6112,7 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
60906112

60916113
// Writes the current ABI version into the crate.
60926114
fn write_abi_version(ccx: @crate_ctxt) {
6093-
shape::mk_global(ccx, "rust_abi_version", C_uint(abi::abi_version),
6115+
shape::mk_global(ccx, "rust_abi_version", C_uint(ccx, abi::abi_version),
60946116
false);
60956117
}
60966118

@@ -6110,8 +6132,12 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
61106132
let td = mk_target_data(sess.get_targ_cfg().target_strs.data_layout);
61116133
let tn = mk_type_names();
61126134
let intrinsics = declare_intrinsics(llmod);
6113-
let task_type = T_task();
6114-
let tydesc_type = T_tydesc();
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);
6138+
let taskptr_type = T_ptr(task_type);
6139+
tn.associate("taskptr", taskptr_type);
6140+
let tydesc_type = T_tydesc(taskptr_type);
61156141
tn.associate("tydesc", tydesc_type);
61166142
let hasher = ty::hash_ty;
61176143
let eqer = ty::eq_ty;
@@ -6161,6 +6187,8 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
61616187
upcall::declare_upcalls(tn, tydesc_type, llmod),
61626188
rust_object_type: T_rust_object(),
61636189
tydesc_type: tydesc_type,
6190+
int_type: int_type,
6191+
float_type: float_type,
61646192
task_type: task_type,
61656193
builder: BuilderRef_res(llvm::LLVMCreateBuilder()),
61666194
shape_cx: shape::mk_ctxt(llmod),

trunk/src/comp/middle/trans_build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn Load(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef {
306306
if cx.unreachable {
307307
let ty = val_ty(PointerVal);
308308
let eltty = if llvm::LLVMGetTypeKind(ty) == 11 {
309-
llvm::LLVMGetElementType(ty) } else { T_int(ccx) };
309+
llvm::LLVMGetElementType(ty) } else { ccx.int_type };
310310
ret llvm::LLVMGetUndef(eltty);
311311
}
312312
ret llvm::LLVMBuildLoad(B(cx), PointerVal, noname());
@@ -492,7 +492,7 @@ fn _UndefReturn(cx: @block_ctxt, Fn: ValueRef) -> ValueRef {
492492
let ccx = cx.fcx.lcx.ccx;
493493
let ty = val_ty(Fn);
494494
let retty = if llvm::LLVMGetTypeKind(ty) == 8 {
495-
llvm::LLVMGetReturnType(ty) } else { T_int(ccx) };
495+
llvm::LLVMGetReturnType(ty) } else { ccx.int_type };
496496
ret llvm::LLVMGetUndef(retty);
497497
}
498498

@@ -577,7 +577,7 @@ fn IsNotNull(cx: @block_ctxt, Val: ValueRef) -> ValueRef {
577577

578578
fn PtrDiff(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
579579
let ccx = cx.fcx.lcx.ccx;
580-
if cx.unreachable { ret llvm::LLVMGetUndef(T_int(ccx)); }
580+
if cx.unreachable { ret llvm::LLVMGetUndef(ccx.int_type); }
581581
ret llvm::LLVMBuildPtrDiff(B(cx), LHS, RHS, noname());
582582
}
583583

0 commit comments

Comments
 (0)