rustc: Use integer from ctypes consistently

This commit is contained in:
Haitao Li 2012-01-18 19:29:37 +08:00
parent dde41869ce
commit 04882d7c43
7 changed files with 60 additions and 49 deletions

View File

@ -170,27 +170,27 @@ fn run_passes(sess: session, llmod: ModuleRef, output: str) {
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
let FPMB = llvm::LLVMPassManagerBuilderCreate();
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u32);
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u as c_uint);
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(FPMB,
fpm.llpm);
llvm::LLVMPassManagerBuilderDispose(FPMB);
llvm::LLVMRunPassManager(fpm.llpm, llmod);
let threshold = 225u as c_uint;
if opts.optimize == 3u { threshold = 275u as c_uint; }
let threshold = 225u;
if opts.optimize == 3u { threshold = 275u; }
let MPMB = llvm::LLVMPassManagerBuilderCreate();
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB,
opts.optimize as u32);
opts.optimize as c_uint);
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0);
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB,
False);
if threshold != 0u32 {
if threshold != 0u {
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold
(MPMB, threshold);
(MPMB, threshold as c_uint);
}
llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB,
pm.llpm);

View File

@ -46,7 +46,7 @@
fn llstr(s: str) -> ValueRef {
str::as_buf(s, {|sbuf|
llvm::LLVMMDString(sbuf, str::byte_len(s) as u32)
llvm::LLVMMDString(sbuf, str::byte_len(s) as ctypes::c_uint)
})
}
fn lltag(lltag: int) -> ValueRef {
@ -63,7 +63,7 @@ fn lli1(bval: bool) -> ValueRef {
}
fn llmdnode(elems: [ValueRef]) -> ValueRef unsafe {
llvm::LLVMMDNode(vec::unsafe::to_ptr(elems),
vec::len(elems) as u32)
vec::len(elems) as ctypes::c_uint)
}
fn llunused() -> ValueRef {
lli32(0x0)

View File

@ -1073,7 +1073,7 @@ fn set_no_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMNoInlineAttribute as
lib::llvm::llvm::Attribute,
0u32);
0u as c_uint);
}
// Tell LLVM to emit the information necessary to unwind the stack for the
@ -1082,19 +1082,20 @@ fn set_uwtable(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMUWTableAttribute as
lib::llvm::llvm::Attribute,
0u32);
0u as c_uint);
}
fn set_always_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMAlwaysInlineAttribute as
lib::llvm::llvm::Attribute,
0u32);
0u as c_uint);
}
fn set_custom_stack_growth_fn(f: ValueRef) {
// TODO: Remove this hack to work around the lack of u64 in the FFI.
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, 1u32);
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute,
1u as c_uint);
}
fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
@ -1181,7 +1182,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
} else { T_ptr(T_i8()) };
let ty_param_count = vec::len::<uint>(ty_params);
let lltyparams = llvm::LLVMGetParam(llfn, 2u32);
let lltyparams = llvm::LLVMGetParam(llfn, 2u as c_uint);
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
let lltydescs = [mutable];
let p = 0u;
@ -1196,7 +1197,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u32);
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u as c_uint);
let llval0 = BitCast(bcx, llrawptr0, llty);
helper(bcx, llval0, t);
finish_fn(fcx, lltop);
@ -4303,8 +4304,8 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
-> @fn_ctxt {
let llbbs = mk_standard_basic_blocks(llfndecl);
ret @{llfn: llfndecl,
llenv: llvm::LLVMGetParam(llfndecl, 1u32),
llretptr: llvm::LLVMGetParam(llfndecl, 0u32),
llenv: llvm::LLVMGetParam(llfndecl, 1u as c_uint),
llretptr: llvm::LLVMGetParam(llfndecl, 0u as c_uint),
mutable llstaticallocas: llbbs.sa,
mutable llloadenv: llbbs.ca,
mutable llderivedtydescs_first: llbbs.dt,
@ -4347,7 +4348,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
// it as a constant, since we're using it in several places in trans this
// way.
let arg_n = 2u32;
let arg_n = 2u;
alt ty_self {
impl_self(tt) {
cx.llself = some({v: cx.llenv, t: tt});
@ -4355,13 +4356,14 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
no_self. {}
}
for tp in ty_params {
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n), dicts = none;
arg_n += 1u32;
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
let dicts = none;
arg_n += 1u;
for bound in *fcx_tcx(cx).ty_param_bounds.get(tp.id) {
alt bound {
ty::bound_iface(_) {
let dict = llvm::LLVMGetParam(cx.llfn, arg_n);
arg_n += 1u32;
let dict = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
arg_n += 1u;
dicts = some(alt dicts {
none. { [dict] }
some(ds) { ds + [dict] }
@ -4376,13 +4378,13 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
// Populate the llargs field of the function context with the ValueRefs
// that we get from llvm::LLVMGetParam for each argument.
for arg: ast::arg in args {
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
assert (llarg as int != 0);
// Note that this uses local_mem even for things passed by value.
// copy_args_to_allocas will overwrite the table entry with local_imm
// before it's actually used.
cx.llargs.insert(arg.id, local_mem(llarg));
arg_n += 1u32;
arg_n += 1u;
}
}
@ -4801,7 +4803,7 @@ fn build_shim_fn(lcx: @local_ctxt,
let fcx = new_fn_ctxt(lcx, span, llshimfn);
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u32);
let llargbundle = llvm::LLVMGetParam(llshimfn, 0 as c_uint);
let i = 0u, n = vec::len(tys.arg_tys);
let llargvals = [];
while i < n {
@ -4851,7 +4853,7 @@ fn build_wrap_fn(lcx: @local_ctxt,
store_inbounds(bcx, llargval, llargbundle, [0, i as int]);
i += 1u;
}
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u32);
let llretptr = llvm::LLVMGetParam(llwrapfn, 0 as c_uint);
store_inbounds(bcx, llretptr, llargbundle, [0, n as int]);
// Create call itself.
@ -5036,10 +5038,10 @@ fn create_main(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u32);
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u32);
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint);
let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint);
let args = [lloutputarg, llenvarg];
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u32)]; }
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2 as c_uint)]; }
Call(bcx, main_llfn, args);
build_return(bcx);
@ -5070,8 +5072,8 @@ fn create_entry_fn(ccx: @crate_ctxt, rust_main: ValueRef) {
let start = str::as_buf("rust_start", {|buf|
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
});
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u32),
llvm::LLVMGetParam(llfn, 1u32), crate_map];
let args = [rust_main, llvm::LLVMGetParam(llfn, 0 as c_uint),
llvm::LLVMGetParam(llfn, 1 as c_uint), crate_map];
let result = unsafe {
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
vec::len(args) as c_uint, noname())

View File

@ -1,5 +1,5 @@
import core::{vec, str};
import core::ctypes::c_uint;
import core::ctypes::{c_uint, c_int};
import str::sbuf;
import lib::llvm::llvm;
import syntax::codemap;
@ -311,7 +311,7 @@ fn Load(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef {
let ccx = cx.fcx.lcx.ccx;
if cx.unreachable {
let ty = val_ty(PointerVal);
let eltty = if llvm::LLVMGetTypeKind(ty) == 11i32 {
let eltty = if llvm::LLVMGetTypeKind(ty) == 11 as c_int {
llvm::LLVMGetElementType(ty) } else { ccx.int_type };
ret llvm::LLVMGetUndef(eltty);
}
@ -500,14 +500,14 @@ fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
unsafe {
let valptr = unsafe::reinterpret_cast(ptr::addr_of(val));
let bbptr = unsafe::reinterpret_cast(ptr::addr_of(bb));
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1u32);
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
}
}
fn _UndefReturn(cx: @block_ctxt, Fn: ValueRef) -> ValueRef {
let ccx = cx.fcx.lcx.ccx;
let ty = val_ty(Fn);
let retty = if llvm::LLVMGetTypeKind(ty) == 8i32 {
let retty = if llvm::LLVMGetTypeKind(ty) == 8 as c_int {
llvm::LLVMGetReturnType(ty) } else { ccx.int_type };
ret llvm::LLVMGetUndef(retty);
}

View File

@ -1,3 +1,4 @@
import core::ctypes::c_uint;
import syntax::ast;
import syntax::ast_util;
import lib::llvm::llvm;
@ -918,7 +919,7 @@ fn trans_bind_thunk(cx: @local_ctxt,
fcx.lltyparams += [{desc: dsc, dicts: dicts}];
}
let a: u32 = 2u32; // retptr, env come first
let a: uint = 2u; // retptr, env come first
let b: int = starting_idx;
let outgoing_arg_index: uint = 0u;
let llout_arg_tys: [TypeRef] =
@ -955,12 +956,12 @@ fn trans_bind_thunk(cx: @local_ctxt,
// Arg will be provided when the thunk is invoked.
none. {
let arg: ValueRef = llvm::LLVMGetParam(llthunk, a);
let arg: ValueRef = llvm::LLVMGetParam(llthunk, a as c_uint);
if ty::type_contains_params(cx.ccx.tcx, out_arg.ty) {
arg = PointerCast(bcx, arg, llout_arg_ty);
}
llargs += [arg];
a += 1u32;
a += 1u;
}
}
outgoing_arg_index += 1u;

View File

@ -1,3 +1,4 @@
import core::ctypes::c_uint;
import trans::*;
import trans_common::*;
import trans_build::*;
@ -191,9 +192,10 @@ fn trans_impl_wrapper(ccx: @crate_ctxt, pt: [ast::ident],
vec::slice(real_args, 2u + vec::len(extra_ptrs), vec::len(real_args));
let llfn_ty = T_fn(wrap_args, real_ret);
trans_wrapper(ccx, pt, llfn_ty, {|llfn, bcx|
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0u32), env_ty);
let dict = PointerCast(bcx, LLVMGetParam(llfn, 0 as c_uint), env_ty);
// retptr, self
let args = [LLVMGetParam(llfn, 1u32), LLVMGetParam(llfn, 2u32)];
let args = [LLVMGetParam(llfn, 1 as c_uint),
LLVMGetParam(llfn, 2 as c_uint)];
let i = 0u;
// saved tydescs/dicts
while i < n_extra_ptrs {
@ -201,10 +203,11 @@ fn trans_impl_wrapper(ccx: @crate_ctxt, pt: [ast::ident],
args += [load_inbounds(bcx, dict, [0, i as int])];
}
// the rest of the parameters
let i = 3u32, params_total = llvm::LLVMCountParamTypes(llfn_ty);
while i < params_total {
args += [LLVMGetParam(llfn, i)];
i += 1u32;
let j = 3u as c_uint;
let params_total = llvm::LLVMCountParamTypes(llfn_ty);
while j < params_total {
args += [LLVMGetParam(llfn, j)];
j += 1u as c_uint;
}
Call(bcx, real_fn, args);
bcx
@ -232,7 +235,8 @@ fn trans_iface_wrapper(ccx: @crate_ctxt, pt: [ast::ident], m: ty::method,
n: uint) -> ValueRef {
let {llty: llfty, _} = wrapper_fn_ty(ccx, T_ptr(T_i8()), m);
trans_wrapper(ccx, pt, llfty, {|llfn, bcx|
let self = Load(bcx, PointerCast(bcx, LLVMGetParam(llfn, 2u32),
let self = Load(bcx, PointerCast(bcx,
LLVMGetParam(llfn, 2u as c_uint),
T_ptr(T_opaque_iface_ptr(ccx))));
let boxed = GEPi(bcx, self, [0, abi::box_rc_field_body]);
let dict = Load(bcx, PointerCast(bcx, GEPi(bcx, boxed, [0, 1]),
@ -243,12 +247,12 @@ fn trans_iface_wrapper(ccx: @crate_ctxt, pt: [ast::ident], m: ty::method,
// FIXME[impl] This doesn't account for more-than-ptr-sized alignment
let inner_self = GEPi(bcx, boxed, [0, 2]);
let args = [PointerCast(bcx, dict, T_ptr(T_i8())),
LLVMGetParam(llfn, 1u32),
LLVMGetParam(llfn, 1u as c_uint),
PointerCast(bcx, inner_self, T_opaque_cbox_ptr(ccx))];
let i = 3u32, total = llvm::LLVMCountParamTypes(llfty);
let i = 3u as c_uint, total = llvm::LLVMCountParamTypes(llfty);
while i < total {
args += [LLVMGetParam(llfn, i)];
i += 1u32;
i += 1u as c_uint;
}
Call(bcx, mptr, args);
bcx

View File

@ -120,7 +120,9 @@ fn connect_many(paths: [path]) : vec::is_not_empty(paths) -> path {
Indicates whether a path represents a directory.
*/
fn path_is_dir(p: path) -> bool {
ret str::as_buf(p, {|buf| rustrt::rust_path_is_dir(buf) != 0i32 });
ret str::as_buf(p, {|buf|
rustrt::rust_path_is_dir(buf) != 0 as ctypes::c_int
});
}
/*
@ -129,7 +131,9 @@ fn path_is_dir(p: path) -> bool {
Indicates whether a path exists.
*/
fn path_exists(p: path) -> bool {
ret str::as_buf(p, {|buf| rustrt::rust_path_exists(buf) != 0i32 });
ret str::as_buf(p, {|buf|
rustrt::rust_path_exists(buf) != 0 as ctypes::c_int
});
}
/*