Skip to content

Commit 8f1ae68

Browse files
committed
---
yaml --- r: 4798 b: refs/heads/master c: 0a8bffc h: refs/heads/master v: v3
1 parent c4dbd98 commit 8f1ae68

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c2d8a4df35a0a22d64d7d15ccd5fe25a495a2bc1
2+
refs/heads/master: 0a8bffceb3ba25b12926bbd42ed3d282f573c9a0

trunk/src/comp/middle/trans.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6378,6 +6378,8 @@ fn decl_fn_and_pair_full(ccx: &@crate_ctxt, sp: &span, path: &[str],
63786378
}
63796379
}
63806380

6381+
// Create a _rust_main(args: [str]) function which will be called from the
6382+
// runtime rust_start function
63816383
fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
63826384
main_llfn: ValueRef, main_node_type: ty::t) {
63836385

@@ -6392,14 +6394,13 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
63926394
};
63936395

63946396
let llfn = create_main(ccx, sp, main_llfn, main_takes_ivec);
6395-
create_main_type_indicator(ccx, main_takes_ivec);
63966397
ccx.main_fn = some(llfn);
63976398

63986399
fn create_main(ccx: &@crate_ctxt,
63996400
sp: &span,
64006401
main_llfn: ValueRef,
64016402
takes_ivec: bool) -> ValueRef {
6402-
let ivecarg = {
6403+
let ivecarg_ty: ty::arg = {
64036404
mode: ty::mo_val,
64046405
ty: ty::mk_ivec(ccx.tcx, {
64056406
ty: ty::mk_str(ccx.tcx),
@@ -6408,13 +6409,15 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
64086409
};
64096410
let llfty = type_of_fn(ccx, sp,
64106411
ast::proto_fn,
6411-
~[ivecarg],
6412+
~[ivecarg_ty],
64126413
ty::mk_nil(ccx.tcx),
64136414
0u);
64146415
let llfdecl = decl_fastcall_fn(ccx.llmod, "_rust_main", llfty);
64156416

64166417
let fcx = new_fn_ctxt(new_local_ctxt(ccx), sp, llfdecl);
6418+
64176419
let bcx = new_top_block_ctxt(fcx);
6420+
let lltop = bcx.llbb;
64186421

64196422
if takes_ivec {
64206423
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
@@ -6430,28 +6433,26 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
64306433
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
64316434
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
64326435
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
6436+
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
6437+
6438+
// If the crate's main function doesn't take the args vector then
6439+
// we're responsible for freeing it
6440+
let llivecptr = alloca(bcx, val_ty(llargvarg));
6441+
bcx.build.Store(llargvarg, llivecptr);
6442+
bcx = maybe_free_ivec_heap_part(bcx, llivecptr,
6443+
ty::mk_str(ccx.tcx)).bcx;
6444+
64336445
let args = ~[lloutputarg,
64346446
lltaskarg,
64356447
llenvarg];
64366448
bcx.build.FastCall(main_llfn, args);
64376449
}
64386450
build_return(bcx);
64396451

6440-
let lltop = bcx.llbb;
64416452
finish_fn(fcx, lltop);
64426453

64436454
ret llfdecl;
64446455
}
6445-
6446-
// FIXME: Remove after main takes only ivec
6447-
// Sets a global value hinting to the runtime whether main takes
6448-
// a vec or an ivec
6449-
fn create_main_type_indicator(ccx: &@crate_ctxt, takes_ivec: bool) {
6450-
let i = llvm::LLVMAddGlobal(ccx.llmod, T_int(),
6451-
str::buf("_rust_main_is_ivec"));
6452-
llvm::LLVMSetInitializer(i, C_int(takes_ivec as int));
6453-
llvm::LLVMSetGlobalConstant(i, True);
6454-
}
64556456
}
64566457

64576458

trunk/src/rt/main.ll.in

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
@_rust_crate_map_toplevel = external global %0
1616

17-
; FIXME: Remove after main takes only ivec
18-
@_rust_main_is_ivec = external global i32
19-
20-
declare i32 @rust_start(i32, i32, i32, i32, i32)
17+
declare i32 @rust_start(i32, i32, i32, i32)
2118

2219
declare external fastcc void @_rust_main(i1* nocapture, %task*, %2* nocapture, %ivec)
2320

@@ -29,8 +26,6 @@ define void @_rust_main_wrap(i1* nocapture, %task *, %2* nocapture, %ivec *)
2926
}
3027

3128
define i32 @"MAIN"(i32, i32) {
32-
%is_ivec = load i32 *@_rust_main_is_ivec
33-
34-
%3 = tail call i32 @rust_start(i32 ptrtoint (void (i1*, %task*, %2*, %ivec*)* @_rust_main_wrap to i32), i32 %0, i32 %1, i32 ptrtoint (%0* @_rust_crate_map_toplevel to i32), i32 %is_ivec)
29+
%3 = tail call i32 @rust_start(i32 ptrtoint (void (i1*, %task*, %2*, %ivec*)* @_rust_main_wrap to i32), i32 %0, i32 %1, i32 ptrtoint (%0* @_rust_crate_map_toplevel to i32))
3530
ret i32 %3
3631
}

trunk/src/rt/rust.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ command_line_args : public kernel_owned<command_line_args>
1414

1515
command_line_args(rust_task *task,
1616
int sys_argc,
17-
char **sys_argv,
18-
bool main_is_ivec)
17+
char **sys_argv)
1918
: kernel(task->kernel),
2019
task(task),
2120
argc(sys_argc),
@@ -67,15 +66,13 @@ command_line_args : public kernel_owned<command_line_args>
6766
args_ivec->fill = 0;
6867
size_t ivec_exterior_sz = sizeof(rust_str *) * argc;
6968
args_ivec->alloc = ivec_exterior_sz;
70-
if (main_is_ivec) {
71-
// NB: This is freed by some ivec machinery, probably the drop
72-
// glue in main, so we don't free it ourselves
73-
args_ivec->payload.ptr = (rust_ivec_heap *)
74-
kernel->malloc(ivec_exterior_sz + sizeof(size_t),
75-
"command line arg exterior");
76-
args_ivec->payload.ptr->fill = ivec_exterior_sz;
77-
memcpy(&args_ivec->payload.ptr->data, strs, ivec_exterior_sz);
78-
}
69+
// NB: This is freed by some ivec machinery, probably the drop
70+
// glue in main, so we don't free it ourselves
71+
args_ivec->payload.ptr = (rust_ivec_heap *)
72+
kernel->malloc(ivec_exterior_sz + sizeof(size_t),
73+
"command line arg exterior");
74+
args_ivec->payload.ptr->fill = ivec_exterior_sz;
75+
memcpy(&args_ivec->payload.ptr->data, strs, ivec_exterior_sz);
7976
}
8077

8178
~command_line_args() {
@@ -107,7 +104,7 @@ int check_claims = 0;
107104

108105
extern "C" CDECL int
109106
rust_start(uintptr_t main_fn, int argc, char **argv,
110-
void* crate_map, int main_takes_ivec) {
107+
void* crate_map) {
111108

112109
rust_env *env = load_env();
113110

@@ -122,7 +119,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv,
122119
rust_scheduler *sched = root_task->sched;
123120
command_line_args *args
124121
= new (kernel, "main command line args")
125-
command_line_args(root_task, argc, argv, main_takes_ivec);
122+
command_line_args(root_task, argc, argv);
126123

127124
DLOG(sched, dom, "startup: %d args in 0x%" PRIxPTR,
128125
args->argc, (uintptr_t)args->args);
@@ -154,7 +151,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv,
154151
extern "C" CDECL int
155152
rust_start_ivec(uintptr_t main_fn, int argc, char **argv,
156153
void* crate_map, int main_takes_ivec) {
157-
return rust_start(main_fn, argc, argv, crate_map, main_takes_ivec);
154+
return rust_start(main_fn, argc, argv, crate_map);
158155
}
159156

160157

0 commit comments

Comments
 (0)