Skip to content

Commit 6965fe4

Browse files
nikomatsakisbrson
authored andcommitted
Add AbiSet and integrate it into the AST.
I believe this patch incorporates all expected syntax changes from extern function reform (#3678). You can now write things like: extern "<abi>" fn foo(s: S) -> T { ... } extern "<abi>" mod { ... } extern "<abi>" fn(S) -> T The ABI for foreign functions is taken from this syntax (rather than from an annotation). We support the full ABI specification I described on the mailing list. The correct ABI is chosen based on the target architecture. Calls by pointer to C functions are not yet supported, and the Rust type of crust fns is still *u8.
1 parent f864934 commit 6965fe4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+879
-352
lines changed

src/libcore/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
pub mod rusti {
1414
#[abi = "rust-intrinsic"]
1515
#[link_name = "rusti"]
16-
pub extern {
16+
pub extern "rust-intrinsic" {
1717
fn forget<T>(+x: T);
1818
fn reinterpret_cast<T, U>(&&e: T) -> U;
1919
}

src/libcore/libc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ pub mod funcs {
16171617
use libc::types::os::arch::extra::{HANDLE};
16181618

16191619
#[abi = "stdcall"]
1620-
pub extern {
1620+
pub extern "stdcall" {
16211621
unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
16221622
v: LPWSTR,
16231623
nsize: DWORD)

src/libcore/os.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ pub fn errno() -> uint {
942942
943943
#[link_name = "kernel32"]
944944
#[abi = "stdcall"]
945-
extern {
945+
extern "stdcall" {
946946
unsafe fn GetLastError() -> DWORD;
947947
}
948948
@@ -1004,7 +1004,7 @@ pub fn last_os_error() -> ~str {
10041004
10051005
#[link_name = "kernel32"]
10061006
#[abi = "stdcall"]
1007-
extern {
1007+
extern "stdcall" {
10081008
unsafe fn FormatMessageA(flags: DWORD, lpSrc: LPVOID,
10091009
msgId: DWORD, langId: DWORD,
10101010
buf: LPSTR, nsize: DWORD,
@@ -1118,15 +1118,15 @@ type LPCWSTR = *u16;
11181118
#[cfg(windows)]
11191119
#[link_name="kernel32"]
11201120
#[abi="stdcall"]
1121-
extern {
1121+
extern "stdcall" {
11221122
fn GetCommandLineW() -> LPCWSTR;
11231123
fn LocalFree(ptr: *c_void);
11241124
}
11251125
11261126
#[cfg(windows)]
11271127
#[link_name="shell32"]
11281128
#[abi="stdcall"]
1129-
extern {
1129+
extern "stdcall" {
11301130
fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16;
11311131
}
11321132

src/libcore/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub mod libc_ {
4343

4444
pub mod rusti {
4545
#[abi = "rust-intrinsic"]
46-
pub extern {
46+
pub extern "rust-intrinsic" {
4747
fn addr_of<T>(&&val: T) -> *T;
4848
}
4949
}

src/libcore/rt/thread_local_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub unsafe fn get(key: Key) -> *mut c_void {
7373

7474
#[cfg(windows)]
7575
#[abi = "stdcall"]
76-
extern {
76+
extern "stdcall" {
7777
fn TlsAlloc() -> DWORD;
7878
fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
7979
fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;

src/libcore/stackwalk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub mod rustrt {
9494

9595
pub mod rusti {
9696
#[abi = "rust-intrinsic"]
97-
pub extern {
97+
pub extern "rust-intrinsic" {
9898
pub fn frame_address(f: &once fn(x: *u8));
9999
}
100100
}

src/libcore/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Closure {
3939

4040
pub mod rusti {
4141
#[abi = "rust-intrinsic"]
42-
pub extern {
42+
pub extern "rust-intrinsic" {
4343
fn get_tydesc<T>() -> *();
4444
fn size_of<T>() -> uint;
4545
fn pref_align_of<T>() -> uint;

src/libcore/unstable/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The intrinsics are defined in librustc/middle/trans/foreign.rs.
1515
*/
1616

1717
#[abi = "rust-intrinsic"]
18-
pub extern {
18+
pub extern "rust-intrinsic" {
1919
pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
2020
pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
2121
pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;

src/librustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub mod jit {
9797
pub mod rusti {
9898
#[nolink]
9999
#[abi = "rust-intrinsic"]
100-
pub extern {
100+
pub extern "rust-intrinsic" {
101101
pub fn morestack_addr() -> *();
102102
}
103103
}

src/librustc/driver/driver.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::getopts::groups::{optopt, optmulti, optflag, optflagopt, getopts};
3333
use std::getopts::{opt_present};
3434
use std::getopts;
3535
use syntax::ast;
36+
use syntax::abi;
3637
use syntax::attr;
3738
use syntax::codemap;
3839
use syntax::diagnostic;
@@ -85,10 +86,10 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
8586
// ARM is bi-endian, however using NDK seems to default
8687
// to little-endian unless a flag is provided.
8788
let (end,arch,wordsz) = match sess.targ_cfg.arch {
88-
session::arch_x86 => (~"little",~"x86",~"32"),
89-
session::arch_x86_64 => (~"little",~"x86_64",~"64"),
90-
session::arch_arm => (~"little",~"arm",~"32"),
91-
session::arch_mips => (~"little",~"arm",~"32")
89+
abi::X86 => (~"little",~"x86",~"32"),
90+
abi::X86_64 => (~"little",~"x86_64",~"64"),
91+
abi::Arm => (~"little",~"arm",~"32"),
92+
abi::Mips => (~"little",~"arm",~"32")
9293
};
9394

9495
return ~[ // Target bindings.
@@ -308,7 +309,7 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
308309
};
309310

310311
// NOTE: Android hack
311-
if sess.targ_cfg.arch == session::arch_arm &&
312+
if sess.targ_cfg.arch == abi::Arm &&
312313
(sess.opts.output_type == link::output_type_object ||
313314
sess.opts.output_type == link::output_type_exe) {
314315
let output_type = link::output_type_assembly;
@@ -453,20 +454,20 @@ pub fn get_os(triple: &str) -> Option<session::os> {
453454
} else { None }
454455
}
455456

456-
pub fn get_arch(triple: &str) -> Option<session::arch> {
457+
pub fn get_arch(triple: &str) -> Option<abi::Architecture> {
457458
if str::contains(triple, ~"i386") ||
458459
str::contains(triple, ~"i486") ||
459460
str::contains(triple, ~"i586") ||
460461
str::contains(triple, ~"i686") ||
461462
str::contains(triple, ~"i786") {
462-
Some(session::arch_x86)
463+
Some(abi::X86)
463464
} else if str::contains(triple, ~"x86_64") {
464-
Some(session::arch_x86_64)
465+
Some(abi::X86_64)
465466
} else if str::contains(triple, ~"arm") ||
466467
str::contains(triple, ~"xscale") {
467-
Some(session::arch_arm)
468+
Some(abi::Arm)
468469
} else if str::contains(triple, ~"mips") {
469-
Some(session::arch_mips)
470+
Some(abi::Mips)
470471
} else { None }
471472
}
472473

@@ -483,16 +484,16 @@ pub fn build_target_config(sopts: @session::options,
483484
~"unknown architecture: " + sopts.target_triple)
484485
};
485486
let (int_type, uint_type, float_type) = match arch {
486-
session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
487-
session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
488-
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
489-
session::arch_mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
487+
abi::X86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
488+
abi::X86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
489+
abi::Arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
490+
abi::Mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
490491
};
491492
let target_strs = match arch {
492-
session::arch_x86 => x86::get_target_strs(os),
493-
session::arch_x86_64 => x86_64::get_target_strs(os),
494-
session::arch_arm => arm::get_target_strs(os),
495-
session::arch_mips => mips::get_target_strs(os)
493+
abi::X86 => x86::get_target_strs(os),
494+
abi::X86_64 => x86_64::get_target_strs(os),
495+
abi::Arm => arm::get_target_strs(os),
496+
abi::Mips => mips::get_target_strs(os)
496497
};
497498
let target_cfg = @session::config {
498499
os: os,

0 commit comments

Comments
 (0)