Skip to content

Commit b999973

Browse files
committed
Add a morestack_addr (temporary) intrinsic
1 parent a02ab41 commit b999973

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/rustc/middle/trans/foreign.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,16 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
993993
lv_temporary),
994994
arg_vals(~[frameaddress_val]), ignore);
995995
}
996+
~"morestack_addr" => {
997+
// XXX This is a hack to grab the address of this particular
998+
// native function. There should be a general in-language
999+
// way to do this
1000+
let llfty = type_of_fn(bcx.ccx(), ~[], ty::mk_nil(bcx.tcx()));
1001+
let morestack_addr = decl_cdecl_fn(
1002+
bcx.ccx().llmod, ~"__morestack", llfty);
1003+
let morestack_addr = PointerCast(bcx, morestack_addr, T_ptr(T_nil()));
1004+
Store(bcx, morestack_addr, fcx.llretptr);
1005+
}
9961006
_ => {
9971007
// Could we make this an enum rather than a string? does it get
9981008
// checked earlier?

src/rustc/middle/typeck/check.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
25902590
});
25912591
(0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx))
25922592
}
2593+
~"morestack_addr" => {
2594+
(0u, ~[], ty::mk_nil_ptr(tcx))
2595+
}
25932596
other => {
25942597
tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" +
25952598
other + ~"`");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[nolink]
2+
#[abi = "rust-intrinsic"]
3+
extern mod rusti {
4+
fn morestack_addr() -> *();
5+
}
6+
7+
fn main() {
8+
let addr = rusti::morestack_addr();
9+
assert addr.is_not_null();
10+
error!("%?", addr);
11+
}

0 commit comments

Comments
 (0)