Skip to content

Commit dde4186

Browse files
committed
Use ctypes in native function declarations
1 parent f03eb96 commit dde4186

17 files changed

+252
-223
lines changed

src/comp/back/link.rs

+13-12
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

+114-105
Large diffs are not rendered by default.

src/comp/metadata/creader.rs

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const DW_ATE_unsigned_char: int = 0x08;
4646

4747
fn llstr(s: str) -> ValueRef {
4848
str::as_buf(s, {|sbuf|
49-
llvm::LLVMMDString(sbuf, str::byte_len(s))
49+
llvm::LLVMMDString(sbuf, str::byte_len(s) as u32)
5050
})
5151
}
5252
fn lltag(lltag: int) -> ValueRef {
@@ -63,7 +63,7 @@ fn lli1(bval: bool) -> ValueRef {
6363
}
6464
fn llmdnode(elems: [ValueRef]) -> ValueRef unsafe {
6565
llvm::LLVMMDNode(vec::unsafe::to_ptr(elems),
66-
vec::len(elems))
66+
vec::len(elems) as u32)
6767
}
6868
fn llunused() -> ValueRef {
6969
lli32(0x0)

src/comp/middle/trans.rs

+33-28
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};
@@ -292,11 +293,12 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
292293
}
293294

294295

295-
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
296+
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) ->
297+
ValueRef {
296298
let llfn: ValueRef =
297299
str::as_buf(name, {|buf|
298300
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
299-
llvm::LLVMSetFunctionCallConv(llfn, cc);
301+
llvm::LLVMSetFunctionCallConv(llfn, cc as c_uint);
300302
ret llfn;
301303
}
302304

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

345348
fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
@@ -390,12 +393,12 @@ fn align_to(cx: @block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef {
390393

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

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

401404
fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
@@ -1070,7 +1073,7 @@ fn set_no_inline(f: ValueRef) {
10701073
llvm::LLVMAddFunctionAttr(f,
10711074
lib::llvm::LLVMNoInlineAttribute as
10721075
lib::llvm::llvm::Attribute,
1073-
0u);
1076+
0u32);
10741077
}
10751078

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

10851088
fn set_always_inline(f: ValueRef) {
10861089
llvm::LLVMAddFunctionAttr(f,
10871090
lib::llvm::LLVMAlwaysInlineAttribute as
10881091
lib::llvm::llvm::Attribute,
1089-
0u);
1092+
0u32);
10901093
}
10911094

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

10971100
fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
@@ -1178,7 +1181,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11781181
} else { T_ptr(T_i8()) };
11791182

11801183
let ty_param_count = vec::len::<uint>(ty_params);
1181-
let lltyparams = llvm::LLVMGetParam(llfn, 2u);
1184+
let lltyparams = llvm::LLVMGetParam(llfn, 2u32);
11821185
let load_env_bcx = new_raw_block_ctxt(fcx, fcx.llloadenv);
11831186
let lltydescs = [mutable];
11841187
let p = 0u;
@@ -1193,7 +1196,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t,
11931196

11941197
let bcx = new_top_block_ctxt(fcx);
11951198
let lltop = bcx.llbb;
1196-
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u);
1199+
let llrawptr0 = llvm::LLVMGetParam(llfn, 3u32);
11971200
let llval0 = BitCast(bcx, llrawptr0, llty);
11981201
helper(bcx, llval0, t);
11991202
finish_fn(fcx, lltop);
@@ -4300,8 +4303,8 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
43004303
-> @fn_ctxt {
43014304
let llbbs = mk_standard_basic_blocks(llfndecl);
43024305
ret @{llfn: llfndecl,
4303-
llenv: llvm::LLVMGetParam(llfndecl, 1u),
4304-
llretptr: llvm::LLVMGetParam(llfndecl, 0u),
4306+
llenv: llvm::LLVMGetParam(llfndecl, 1u32),
4307+
llretptr: llvm::LLVMGetParam(llfndecl, 0u32),
43054308
mutable llstaticallocas: llbbs.sa,
43064309
mutable llloadenv: llbbs.ca,
43074310
mutable llderivedtydescs_first: llbbs.dt,
@@ -4344,7 +4347,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43444347
// Skip the implicit arguments 0, and 1. TODO: Pull out 2u and define
43454348
// it as a constant, since we're using it in several places in trans this
43464349
// way.
4347-
let arg_n = 2u;
4350+
let arg_n = 2u32;
43484351
alt ty_self {
43494352
impl_self(tt) {
43504353
cx.llself = some({v: cx.llenv, t: tt});
@@ -4353,12 +4356,12 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43534356
}
43544357
for tp in ty_params {
43554358
let lltydesc = llvm::LLVMGetParam(cx.llfn, arg_n), dicts = none;
4356-
arg_n += 1u;
4359+
arg_n += 1u32;
43574360
for bound in *fcx_tcx(cx).ty_param_bounds.get(tp.id) {
43584361
alt bound {
43594362
ty::bound_iface(_) {
43604363
let dict = llvm::LLVMGetParam(cx.llfn, arg_n);
4361-
arg_n += 1u;
4364+
arg_n += 1u32;
43624365
dicts = some(alt dicts {
43634366
none. { [dict] }
43644367
some(ds) { ds + [dict] }
@@ -4379,7 +4382,7 @@ fn create_llargs_for_fn_args(cx: @fn_ctxt, ty_self: self_arg,
43794382
// copy_args_to_allocas will overwrite the table entry with local_imm
43804383
// before it's actually used.
43814384
cx.llargs.insert(arg.id, local_mem(llarg));
4382-
arg_n += 1u;
4385+
arg_n += 1u32;
43834386
}
43844387
}
43854388

@@ -4798,7 +4801,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
47984801
let fcx = new_fn_ctxt(lcx, span, llshimfn);
47994802
let bcx = new_top_block_ctxt(fcx);
48004803
let lltop = bcx.llbb;
4801-
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u);
4804+
let llargbundle = llvm::LLVMGetParam(llshimfn, 0u32);
48024805
let i = 0u, n = vec::len(tys.arg_tys);
48034806
let llargvals = [];
48044807
while i < n {
@@ -4808,7 +4811,8 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48084811
}
48094812

48104813
// Create the call itself and store the return value:
4811-
let llretval = CallWithConv(bcx, llbasefn, llargvals, cc); // r
4814+
let llretval = CallWithConv(bcx, llbasefn,
4815+
llargvals, cc as c_uint); // r
48124816
if tys.ret_def {
48134817
// R** llretptr = &args->r;
48144818
let llretptr = GEPi(bcx, llargbundle, [0, n as int]);
@@ -4842,11 +4846,12 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48424846
let i = 0u, n = vec::len(tys.arg_tys);
48434847
let implicit_args = 2u + num_tps; // ret + env
48444848
while i < n {
4845-
let llargval = llvm::LLVMGetParam(llwrapfn, i + implicit_args);
4849+
let llargval = llvm::LLVMGetParam(llwrapfn,
4850+
(i + implicit_args) as c_uint);
48464851
store_inbounds(bcx, llargval, llargbundle, [0, i as int]);
48474852
i += 1u;
48484853
}
4849-
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u);
4854+
let llretptr = llvm::LLVMGetParam(llwrapfn, 0u32);
48504855
store_inbounds(bcx, llretptr, llargbundle, [0, n as int]);
48514856

48524857
// Create call itself.
@@ -4859,7 +4864,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
48594864
}
48604865

48614866
let ccx = lcx_ccx(lcx);
4862-
let cc: uint = lib::llvm::LLVMCCallConv;
4867+
let cc = lib::llvm::LLVMCCallConv;
48634868
alt abi {
48644869
ast::native_abi_rust_intrinsic. { ret; }
48654870
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
@@ -5031,10 +5036,10 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50315036
let bcx = new_top_block_ctxt(fcx);
50325037
let lltop = bcx.llbb;
50335038

5034-
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
5035-
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u);
5039+
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u32);
5040+
let llenvarg = llvm::LLVMGetParam(llfdecl, 1u32);
50365041
let args = [lloutputarg, llenvarg];
5037-
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u)]; }
5042+
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 2u32)]; }
50385043
Call(bcx, main_llfn, args);
50395044
build_return(bcx);
50405045

@@ -5065,11 +5070,11 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
50655070
let start = str::as_buf("rust_start", {|buf|
50665071
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
50675072
});
5068-
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u),
5069-
llvm::LLVMGetParam(llfn, 1u), crate_map];
5073+
let args = [rust_main, llvm::LLVMGetParam(llfn, 0u32),
5074+
llvm::LLVMGetParam(llfn, 1u32), crate_map];
50705075
let result = unsafe {
50715076
llvm::LLVMBuildCall(bld, start, vec::to_ptr(args),
5072-
vec::len(args), noname())
5077+
vec::len(args) as c_uint, noname())
50735078
};
50745079
llvm::LLVMBuildRet(bld, result);
50755080
}

0 commit comments

Comments
 (0)