Skip to content

Commit 8926d5e

Browse files
committed
Use ctypes in native function declarations
1 parent 37a2985 commit 8926d5e

17 files changed

+252
-223
lines changed

src/comp/back/link.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
import core::ctypes::{c_int, c_uint};
22
import driver::session;
33
import session::session;
44
import lib::llvm::llvm;
@@ -170,24 +170,25 @@ mod write {
170170
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
171171

172172
let FPMB = llvm::LLVMPassManagerBuilderCreate();
173-
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u);
173+
llvm::LLVMPassManagerBuilderSetOptLevel(FPMB, 2u32);
174174
llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(FPMB,
175175
fpm.llpm);
176176
llvm::LLVMPassManagerBuilderDispose(FPMB);
177177

178178
llvm::LLVMRunPassManager(fpm.llpm, llmod);
179-
let threshold: uint = 225u;
180-
if opts.optimize == 3u { threshold = 275u; }
179+
let threshold = 225u as c_uint;
180+
if opts.optimize == 3u { threshold = 275u as c_uint; }
181181

182182
let MPMB = llvm::LLVMPassManagerBuilderCreate();
183-
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB, opts.optimize);
183+
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB,
184+
opts.optimize as u32);
184185
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0);
185186
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
186187
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
187188
llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB,
188189
False);
189190

190-
if threshold != 0u {
191+
if threshold != 0u32 {
191192
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold
192193
(MPMB, threshold);
193194
}
@@ -198,12 +199,12 @@ mod write {
198199
}
199200
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
200201
if is_object_or_assembly_or_exe(opts.output_type) {
201-
let LLVMAssemblyFile: int = 0;
202-
let LLVMObjectFile: int = 1;
203-
let LLVMOptNone: int = 0; // -O0
204-
let LLVMOptLess: int = 1; // -O1
205-
let LLVMOptDefault: int = 2; // -O2, -Os
206-
let LLVMOptAggressive: int = 3; // -O3
202+
let LLVMAssemblyFile = 0 as c_int;
203+
let LLVMObjectFile = 1 as c_int;
204+
let LLVMOptNone = 0 as c_int; // -O0
205+
let LLVMOptLess = 1 as c_int; // -O1
206+
let LLVMOptDefault = 2 as c_int; // -O2, -Os
207+
let LLVMOptAggressive = 3 as c_int; // -O3
207208

208209
let CodeGenOptLevel;
209210
alt opts.optimize {

src/comp/lib/llvm.rs

Lines changed: 114 additions & 105 deletions
Large diffs are not rendered by default.

src/comp/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn get_metadata_section(sess: session::session,
221221
let name = unsafe { str::from_cstr(name_buf) };
222222
if str::eq(name, sess.targ_cfg.target_strs.meta_sect_name) {
223223
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
224-
let csz = llvm::LLVMGetSectionSize(si.llsi);
224+
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
225225
unsafe {
226226
let cvbuf: *u8 = unsafe::reinterpret_cast(cbuf);
227227
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));

src/comp/middle/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const DW_ATE_unsigned_char: int = 0x08;
4545

4646
fn llstr(s: str) -> ValueRef {
4747
str::as_buf(s, {|sbuf|
48-
llvm::LLVMMDString(sbuf, str::byte_len(s))
48+
llvm::LLVMMDString(sbuf, str::byte_len(s) as u32)
4949
})
5050
}
5151
fn lltag(lltag: int) -> ValueRef {
@@ -62,7 +62,7 @@ fn lli1(bval: bool) -> ValueRef {
6262
}
6363
fn llmdnode(elems: [ValueRef]) -> ValueRef unsafe {
6464
llvm::LLVMMDNode(vec::unsafe::to_ptr(elems),
65-
vec::len(elems))
65+
vec::len(elems) as u32)
6666
}
6767
fn llunused() -> ValueRef {
6868
lli32(0x0)

src/comp/middle/trans.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// but many TypeRefs correspond to one ty::t; for instance, tup(int, int,
1414
// int) and rec(x=int, y=int, z=int) will have the same TypeRef.
1515

16+
import core::ctypes::c_uint;
1617
import std::{map, time};
1718
import std::map::hashmap;
1819
import std::map::{new_int_hash, new_str_hash};
@@ -291,11 +292,12 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
291292
}
292293

293294

294-
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
295+
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) ->
296+
ValueRef {
295297
let llfn: ValueRef =
296298
str::as_buf(name, {|buf|
297299
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
298-
llvm::LLVMSetFunctionCallConv(llfn, cc);
300+
llvm::LLVMSetFunctionCallConv(llfn, cc as c_uint);
299301
ret llfn;
300302
}
301303

@@ -338,7 +340,8 @@ fn get_simple_extern_fn(cx: @block_ctxt,
338340
let inputs = vec::init_elt::<TypeRef>(ccx.int_type, n_args as uint);
339341
let output = ccx.int_type;
340342
let t = T_fn(inputs, output);
341-
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
343+
ret get_extern_fn(externs, llmod, name,
344+
lib::llvm::LLVMCCallConv, t);
342345
}
343346

344347
fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
@@ -389,12 +392,12 @@ fn align_to(cx: @block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef {
389392

390393
// Returns the real size of the given type for the current target.
391394
fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
392-
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t);
395+
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t) as uint;
393396
}
394397

395398
// Returns the real alignment of the given type for the current target.
396399
fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
397-
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t);
400+
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t) as uint;
398401
}
399402

400403
fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
@@ -1067,7 +1070,7 @@ fn set_no_inline(f: ValueRef) {
10671070
llvm::LLVMAddFunctionAttr(f,
10681071
lib::llvm::LLVMNoInlineAttribute as
10691072
lib::llvm::llvm::Attribute,
1070-
0u);
1073+
0u32);
10711074
}
10721075

10731076
// Tell LLVM to emit the information necessary to unwind the stack for the
@@ -1076,19 +1079,19 @@ fn set_uwtable(f: ValueRef) {
10761079
llvm::LLVMAddFunctionAttr(f,
10771080
lib::llvm::LLVMUWTableAttribute as
10781081
lib::llvm::llvm::Attribute,
1079-
0u);
1082+
0u32);
10801083
}
10811084

10821085
fn set_always_inline(f: ValueRef) {
10831086
llvm::LLVMAddFunctionAttr(f,
10841087
lib::llvm::LLVMAlwaysInlineAttribute as
10851088
lib::llvm::llvm::Attribute,
1086-
0u);
1089+
0u32);
10871090
}
10881091

10891092
fn set_custom_stack_growth_fn(f: ValueRef) {
10901093
// TODO: Remove this hack to work around the lack of u64 in the FFI.
1091-
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, 1u);
1094+
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, 1u32);
10921095
}
10931096

10941097
fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
@@ -1175,7 +1178,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11751178
} else { T_ptr(T_i8()) };
11761179

11771180
let ty_param_count = vec::len::<uint>(ty_params);
1178-
let lltyparams = llvm::LLVMGetParam(llfn, 2u);
1181+
let lltyparams = llvm::LLVMGetParam(llfn, 2u32);
11791182
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
11801183
let lltydescs = [mutable];
11811184
let p = 0u;
@@ -1190,7 +1193,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11901193

11911194
let bcx = new_top_block_ctxt(fcx);
11921195
let lltop = bcx.llbb;
1193-
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u);
1196+
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u32);
11941197
let llval0 = BitCast(bcx, llrawptr0, llty);
11951198
helper(bcx, llval0, t);
11961199
finish_fn(fcx, lltop);
@@ -4302,8 +4305,8 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
43024305
-> @fn_ctxt {
43034306
let llbbs = mk_standard_basic_blocks(llfndecl);
43044307
ret @{llfn: llfndecl,
4305-
llenv: llvm::LLVMGetParam(llfndecl, 1u),
4306-
llretptr: llvm::LLVMGetParam(llfndecl, 0u),
4308+
llenv: llvm::LLVMGetParam(llfndecl, 1u32),
4309+
llretptr: llvm::LLVMGetParam(llfndecl, 0u32),
43074310
mutable llstaticallocas: llbbs.sa,
43084311
mutable llloadenv: llbbs.ca,
43094312
mutable llderivedtydescs_first: llbbs.dt,
@@ -4346,7 +4349,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43464349
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
43474350
// it as a constant, since we're using it in several places in trans this
43484351
// way.
4349-
let arg_n = 2u;
4352+
let arg_n = 2u32;
43504353
alt ty_self {
43514354
impl_self(tt) {
43524355
cx.llself = some({v: cx.llenv, t: tt});
@@ -4355,12 +4358,12 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43554358
}
43564359
for tp in ty_params {
43574360
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n), dicts = none;
4358-
arg_n += 1u;
4361+
arg_n += 1u32;
43594362
for bound in *fcx_tcx(cx).ty_param_bounds.get(tp.id) {
43604363
alt bound {
43614364
ty::bound_iface(_) {
43624365
let dict = llvm::LLVMGetParam(cx.llfn, arg_n);
4363-
arg_n += 1u;
4366+
arg_n += 1u32;
43644367
dicts = some(alt dicts {
43654368
none. { [dict] }
43664369
some(ds) { ds + [dict] }
@@ -4381,7 +4384,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43814384
// copy_args_to_allocas will overwrite the table entry with local_imm
43824385
// before it's actually used.
43834386
cx.llargs.insert(arg.id, local_mem(llarg));
4384-
arg_n += 1u;
4387+
arg_n += 1u32;
43854388
}
43864389
}
43874390

@@ -4804,7 +4807,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48044807
let fcx = new_fn_ctxt(lcx, span, llshimfn);
48054808
let bcx = new_top_block_ctxt(fcx);
48064809
let lltop = bcx.llbb;
4807-
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u);
4810+
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u32);
48084811
let i = 0u, n = vec::len(tys.arg_tys);
48094812
let llargvals = [];
48104813
while i < n {
@@ -4814,7 +4817,8 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48144817
}
48154818

48164819
// Create the call itself and store the return value:
4817-
let llretval = CallWithConv(bcx, llbasefn, llargvals, cc); // r
4820+
let llretval = CallWithConv(bcx, llbasefn,
4821+
llargvals, cc as c_uint); // r
48184822
if tys.ret_def {
48194823
// R** llretptr = &args->r;
48204824
let llretptr = GEPi(bcx, llargbundle, [0, n as int]);
@@ -4848,11 +4852,12 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48484852
let i = 0u, n = vec::len(tys.arg_tys);
48494853
let implicit_args = 2u + num_tps; // ret + env
48504854
while i < n {
4851-
let llargval = llvm::LLVMGetParam(llwrapfn, i + implicit_args);
4855+
let llargval = llvm::LLVMGetParam(llwrapfn,
4856+
(i + implicit_args) as c_uint);
48524857
store_inbounds(bcx, llargval, llargbundle, [0, i as int]);
48534858
i += 1u;
48544859
}
4855-
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u);
4860+
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u32);
48564861
store_inbounds(bcx, llretptr, llargbundle, [0, n as int]);
48574862

48584863
// Create call itself.
@@ -4865,7 +4870,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48654870
}
48664871

48674872
let ccx = lcx_ccx(lcx);
4868-
let cc: uint = lib::llvm::LLVMCCallConv;
4873+
let cc = lib::llvm::LLVMCCallConv;
48694874
alt abi {
48704875
ast::native_abi_rust_intrinsic. { ret; }
48714876
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
@@ -5037,10 +5042,10 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50375042
let bcx = new_top_block_ctxt(fcx);
50385043
let lltop = bcx.llbb;
50395044

5040-
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
5041-
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u);
5045+
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u32);
5046+
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u32);
50425047
let args = [lloutputarg, llenvarg];
5043-
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u)]; }
5048+
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u32)]; }
50445049
Call(bcx, main_llfn, args);
50455050
build_return(bcx);
50465051

@@ -5071,11 +5076,11 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50715076
let start = str::as_buf("rust_start", {|buf|
50725077
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
50735078
});
5074-
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u),
5075-
llvm::LLVMGetParam(llfn, 1u), crate_map];
5079+
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u32),
5080+
llvm::LLVMGetParam(llfn, 1u32), crate_map];
50765081
let result = unsafe {
50775082
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
5078-
vec::len(args), noname())
5083+
vec::len(args) as c_uint, noname())
50795084
};
50805085
llvm::LLVMBuildRet(bld, result);
50815086
}

0 commit comments

Comments
 (0)