@@ -134,9 +134,9 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
134
134
T_nil ( ) /* ...I guess? */
135
135
}
136
136
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 }
140
140
ty:: ty_machine ( tm) {
141
141
alt tm {
142
142
ast : : ty_i8. | ast:: ty_u8 . { T_i8( ) }
@@ -345,8 +345,8 @@ fn get_simple_extern_fn(cx: @block_ctxt,
345
345
llmod : ModuleRef ,
346
346
name : str , n_args : int ) -> ValueRef {
347
347
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 ;
350
350
let t = T_fn ( inputs, output) ;
351
351
ret get_extern_fn ( externs, llmod, name, lib:: llvm:: LLVMCCallConv , t) ;
352
352
}
@@ -405,12 +405,12 @@ fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
405
405
}
406
406
407
407
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 ,
409
409
False ) ;
410
410
}
411
411
412
412
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 ,
414
414
False ) ;
415
415
}
416
416
@@ -597,7 +597,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
597
597
let ccx = bcx_ccx ( bcx) ;
598
598
// Compute max(variant sizes).
599
599
600
- let max_size: ValueRef = alloca ( bcx, T_int ( ccx) ) ;
600
+ let max_size: ValueRef = alloca ( bcx, ccx. int_type ) ;
601
601
Store ( bcx, C_int ( ccx, 0 ) , max_size) ;
602
602
let variants = ty:: tag_variants ( bcx_tcx ( bcx) , tid) ;
603
603
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 {
618
618
let max_size_val = Load ( bcx, max_size) ;
619
619
let total_size =
620
620
if std:: vec:: len ( variants) != 1 u {
621
- Add ( bcx, max_size_val, llsize_of ( ccx, T_int ( ccx) ) )
621
+ Add ( bcx, max_size_val, llsize_of ( ccx, ccx. int_type ) )
622
622
} else { max_size_val } ;
623
623
ret rslt( bcx, total_size) ;
624
624
}
@@ -2161,7 +2161,7 @@ fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
2161
2161
// if target int width is larger than host, at the moment;
2162
2162
// re-do the mach-int types using 'big' when that works.
2163
2163
2164
- let t = T_int ( cx ) ;
2164
+ let t = cx . int_type ;
2165
2165
let s = True ;
2166
2166
alt tm {
2167
2167
ast : : ty_u8. { t = T_i8 ( ) ; s = False ; }
@@ -2177,7 +2177,7 @@ fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
2177
2177
}
2178
2178
ast:: lit_float ( fs) { ret C_float ( cx, fs) ; }
2179
2179
ast:: lit_mach_float ( tm, s) {
2180
- let t = T_float ( cx ) ;
2180
+ let t = cx . float_type ;
2181
2181
alt tm { ast : : ty_f32. { t = T_f32 ( ) ; } ast:: ty_f64. { t = T_f64 ( ) ; } }
2182
2182
ret C_floating ( s, t) ;
2183
2183
}
@@ -2961,7 +2961,7 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
2961
2961
let gvar =
2962
2962
str:: as_buf ( sym,
2963
2963
{ |buf|
2964
- llvm:: LLVMAddGlobal ( ccx. llmod , T_int ( ccx) , buf)
2964
+ llvm:: LLVMAddGlobal ( ccx. llmod , ccx. int_type , buf)
2965
2965
} ) ;
2966
2966
llvm:: LLVMSetLinkage ( gvar,
2967
2967
lib:: llvm:: LLVMExternalLinkage as llvm:: Linkage ) ;
@@ -3120,11 +3120,11 @@ fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr,
3120
3120
// Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
3121
3121
let ix_val;
3122
3122
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 ) ;
3124
3124
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 ) ;
3126
3126
} 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 ) ;
3128
3128
} else { ix_val = ix. val ; }
3129
3129
3130
3130
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 {
4420
4420
let s = link:: mangle_internal_name_by_path_and_seq (
4421
4421
lcx. ccx , lcx. module_path , "loglevel" ) ;
4422
4422
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)
4424
4424
} ) ;
4425
4425
llvm:: LLVMSetGlobalConstant ( global, False ) ;
4426
- llvm:: LLVMSetInitializer ( global, C_null ( T_int ( ccx) ) ) ;
4426
+ llvm:: LLVMSetInitializer ( global, C_null ( ccx. int_type ) ) ;
4427
4427
llvm:: LLVMSetLinkage ( global,
4428
4428
lib:: llvm:: LLVMInternalLinkage as llvm:: Linkage ) ;
4429
4429
lcx. ccx . module_data . insert ( modname, global) ;
@@ -5651,14 +5651,14 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5651
5651
cast_to_i32 = true ;
5652
5652
}
5653
5653
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 ) ) ;
5655
5655
ccx. item_ids . insert ( id, llfn) ;
5656
5656
ccx. item_symbols . insert ( id, name) ;
5657
5657
ret;
5658
5658
}
5659
5659
ast:: native_abi_c_stack_stdcall. {
5660
5660
let llfn = decl_fn ( ccx. llmod , name, lib:: llvm:: LLVMX86StdcallCallConv ,
5661
- T_fn ( [ ] , T_int ( ) ) ) ;
5661
+ T_fn ( [ ] , ccx . int_type ) ) ;
5662
5662
ccx. item_ids . insert ( id, llfn) ;
5663
5663
ccx. item_symbols . insert ( id, name) ;
5664
5664
ret;
@@ -5706,21 +5706,23 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5706
5706
fn convert_arg_to_i32 ( cx : @block_ctxt , v : ValueRef , t : ty:: t ,
5707
5707
mode : ty:: mode ) -> ValueRef {
5708
5708
if mode == ast:: by_ref || mode == ast:: by_val {
5709
+ let ccx = bcx_ccx ( cx) ;
5709
5710
if ty:: type_is_integral ( bcx_tcx ( cx) , t) {
5710
5711
// FIXME: would be nice to have a postcondition that says
5711
5712
// 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 ;
5714
5714
let sp = cx. sp ;
5715
5715
check ( type_has_static_size ( ccx, t) ) ;
5716
5716
let llsrctype = type_of ( ccx, sp, t) ;
5717
5717
if llvm:: LLVMGetIntTypeWidth ( lldsttype) >
5718
5718
llvm:: LLVMGetIntTypeWidth ( llsrctype) {
5719
- ret ZExtOrBitCast ( cx, v, T_int ( ) ) ;
5719
+ ret ZExtOrBitCast ( cx, v, ccx . int_type ) ;
5720
5720
}
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 ) ;
5722
5725
}
5723
- if ty:: type_is_fp ( bcx_tcx ( cx) , t) { ret FPToSI ( cx, v, T_int ( ) ) ; }
5724
5726
}
5725
5727
ret vp2i( cx, v) ;
5726
5728
}
@@ -5927,11 +5929,10 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
5927
5929
let p = new_pt + [ it. ident , variant. node . name , "discrim" ] ;
5928
5930
let s = mangle_exported_name ( ccx, p, ty:: mk_int ( ccx. tcx ) ) ;
5929
5931
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 ) ) ;
5935
5936
llvm:: LLVMSetGlobalConstant ( discrim_gvar, True ) ;
5936
5937
ccx. discrims . insert (
5937
5938
ast_util:: local_def ( variant. node . id ) , discrim_gvar) ;
@@ -5951,10 +5952,13 @@ fn trans_constants(ccx: @crate_ctxt, crate: @ast::crate) {
5951
5952
}
5952
5953
5953
5954
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 ) ;
5955
5957
}
5956
5958
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
+ }
5958
5962
5959
5963
fn declare_intrinsics ( llmod : ModuleRef ) -> hashmap < str , ValueRef > {
5960
5964
let T_memmove32_args : [ TypeRef ] =
@@ -6005,7 +6009,7 @@ fn trap(bcx: @block_ctxt) {
6005
6009
}
6006
6010
6007
6011
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 ] ) ;
6009
6013
let maptype = T_array ( elttype, ccx. module_data . size ( ) + 1 u) ;
6010
6014
let map =
6011
6015
str:: as_buf ( "_rust_mod_map" ,
@@ -6057,6 +6061,24 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
6057
6061
subcrates += [ C_int ( 0 ) ] ;
6058
6062
llvm:: LLVMSetInitializer ( map, C_struct ( [ p2i ( create_module_map ( ccx) ) ,
6059
6063
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
6060
6082
}
6061
6083
6062
6084
fn write_metadata ( cx : @crate_ctxt , crate : @ast:: crate ) {
@@ -6090,7 +6112,7 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
6090
6112
6091
6113
// Writes the current ABI version into the crate.
6092
6114
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) ,
6094
6116
false ) ;
6095
6117
}
6096
6118
@@ -6110,8 +6132,12 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
6110
6132
let td = mk_target_data ( sess. get_targ_cfg ( ) . target_strs . data_layout ) ;
6111
6133
let tn = mk_type_names ( ) ;
6112
6134
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) ;
6115
6141
tn. associate ( "tydesc" , tydesc_type) ;
6116
6142
let hasher = ty:: hash_ty;
6117
6143
let eqer = ty:: eq_ty;
@@ -6161,6 +6187,8 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
6161
6187
upcall:: declare_upcalls ( tn, tydesc_type, llmod) ,
6162
6188
rust_object_type: T_rust_object ( ) ,
6163
6189
tydesc_type: tydesc_type,
6190
+ int_type: int_type,
6191
+ float_type: float_type,
6164
6192
task_type: task_type,
6165
6193
builder: BuilderRef_res ( llvm:: LLVMCreateBuilder ( ) ) ,
6166
6194
shape_cx: shape:: mk_ctxt ( llmod) ,
0 commit comments