Skip to content

Commit

Permalink
Add a morestack_addr (temporary) intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Aug 28, 2012
1 parent 9bb97d7 commit b74e625
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,16 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
lv_temporary),
arg_vals(~[frameaddress_val]), ignore);
}
~"morestack_addr" => {
// XXX This is a hack to grab the address of this particular
// native function. There should be a general in-language
// way to do this
let llfty = type_of_fn(bcx.ccx(), ~[], ty::mk_nil(bcx.tcx()));
let morestack_addr = decl_cdecl_fn(
bcx.ccx().llmod, ~"__morestack", llfty);
let morestack_addr = PointerCast(bcx, morestack_addr, T_ptr(T_nil()));
Store(bcx, morestack_addr, fcx.llretptr);
}
_ => {
// Could we make this an enum rather than a string? does it get
// checked earlier?
Expand Down
3 changes: 3 additions & 0 deletions src/rustc/middle/typeck/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
});
(0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx))
}
~"morestack_addr" => {
(0u, ~[], ty::mk_nil_ptr(tcx))
}
other => {
tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" +
other + ~"`");
Expand Down
11 changes: 11 additions & 0 deletions src/test/run-pass/morestack-address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[nolink]
#[abi = "rust-intrinsic"]
extern mod rusti {
fn morestack_addr() -> *();
}

fn main() {
let addr = rusti::morestack_addr();
assert addr.is_not_null();
error!("%?", addr);
}

0 comments on commit b74e625

Please sign in to comment.