Skip to content

Commit fbd8eae

Browse files
committed
auto merge of #5631 : brson/rust/abiset, r=brson,brson
Continuing #5421
2 parents f864934 + 6965fe4 commit fbd8eae

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

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

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

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

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

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

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

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

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

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

+19-18
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,

src/librustc/driver/session.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@ use syntax::codemap::span;
2525
use syntax::diagnostic;
2626
use syntax::parse::ParseSess;
2727
use syntax::{ast, codemap};
28+
use syntax::abi;
2829
use syntax;
2930

3031
#[deriving(Eq)]
3132
pub enum os { os_win32, os_macos, os_linux, os_android, os_freebsd, }
3233

33-
#[deriving(Eq)]
34-
pub enum arch { arch_x86, arch_x86_64, arch_arm, arch_mips, }
35-
3634
pub enum crate_type { bin_crate, lib_crate, unknown_crate, }
3735

3836
pub struct config {
3937
os: os,
40-
arch: arch,
38+
arch: abi::Architecture,
4139
target_strs: target_strs::t,
4240
int_type: int_ty,
4341
uint_type: uint_ty,

src/librustc/front/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn fold_foreign_mod(
9292
nm.view_items.filter_mapped(|a| filter_view_item(cx, *a));
9393
ast::foreign_mod {
9494
sort: nm.sort,
95-
abi: nm.abi,
95+
abis: nm.abis,
9696
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
9797
items: filtered_items
9898
}

src/librustc/front/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub mod intrinsic {
126126
use super::{TyDesc, TyVisitor};
127127

128128
#[abi = "rust-intrinsic"]
129-
pub extern {
129+
pub extern "rust-intrinsic" {
130130
pub fn get_tydesc<T>() -> *();
131131
pub fn visit_tydesc(++td: *TyDesc, &&tv: @TyVisitor);
132132
}

src/librustc/front/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: @fold::ast_fold)
146146

147147
if is_test_fn(i) || is_bench_fn(i) {
148148
match i.node {
149-
ast::item_fn(_, purity, _, _) if purity == ast::unsafe_fn => {
149+
ast::item_fn(_, purity, _, _, _) if purity == ast::unsafe_fn => {
150150
let sess = cx.sess;
151151
sess.span_fatal(
152152
i.span,
@@ -178,7 +178,7 @@ fn is_test_fn(i: @ast::item) -> bool {
178178

179179
fn has_test_signature(i: @ast::item) -> bool {
180180
match &i.node {
181-
&ast::item_fn(ref decl, _, ref generics, _) => {
181+
&ast::item_fn(ref decl, _, _, ref generics, _) => {
182182
let no_output = match decl.output.node {
183183
ast::ty_nil => true,
184184
_ => false
@@ -200,7 +200,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
200200

201201
fn has_test_signature(i: @ast::item) -> bool {
202202
match i.node {
203-
ast::item_fn(ref decl, _, ref generics, _) => {
203+
ast::item_fn(ref decl, _, _, ref generics, _) => {
204204
let input_cnt = vec::len(decl.inputs);
205205
let no_output = match decl.output.node {
206206
ast::ty_nil => true,

src/librustc/metadata/creader.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,8 @@ fn visit_view_item(e: @mut Env, i: @ast::view_item) {
156156
fn visit_item(e: @mut Env, i: @ast::item) {
157157
match i.node {
158158
ast::item_foreign_mod(ref fm) => {
159-
match attr::foreign_abi(i.attrs) {
160-
either::Right(abi) => {
161-
if abi != ast::foreign_abi_cdecl &&
162-
abi != ast::foreign_abi_stdcall { return; }
163-
}
164-
either::Left(ref msg) => e.diag.span_fatal(i.span, (*msg))
159+
if fm.abis.is_rust() || fm.abis.is_intrinsic() {
160+
return;
165161
}
166162

167163
let cstore = e.cstore;

src/librustc/metadata/encoder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use core::uint;
3535
use core::vec;
3636
use std::serialize::Encodable;
3737
use std;
38+
use syntax::abi::AbiSet;
3839
use syntax::ast::*;
3940
use syntax::ast;
4041
use syntax::ast_map;
@@ -653,7 +654,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
653654
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
654655
ebml_w.end_tag();
655656
}
656-
item_fn(_, purity, ref generics, _) => {
657+
item_fn(_, purity, _, ref generics, _) => {
657658
add_to_index();
658659
ebml_w.start_tag(tag_items_data_item);
659660
encode_def_id(ebml_w, local_def(item.id));
@@ -979,7 +980,7 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext,
979980
nitem: @foreign_item,
980981
index: @mut ~[entry<int>],
981982
+path: ast_map::path,
982-
abi: foreign_abi) {
983+
abi: AbiSet) {
983984
if !reachable(ecx, nitem.id) { return; }
984985
index.push(entry { val: nitem.id, pos: ebml_w.writer.tell() });
985986
@@ -990,7 +991,7 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext,
990991
encode_family(ebml_w, purity_fn_family(purity));
991992
encode_type_param_bounds(ebml_w, ecx, &generics.ty_params);
992993
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
993-
if abi == foreign_abi_rust_intrinsic {
994+
if abi.is_intrinsic() {
994995
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_foreign(nitem));
995996
} else {
996997
encode_symbol(ecx, ebml_w, nitem.id);

src/librustc/metadata/tydecode.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use middle::ty;
2121
use core::str;
2222
use core::uint;
2323
use core::vec;
24+
use syntax::abi::AbiSet;
25+
use syntax::abi;
2426
use syntax::ast;
2527
use syntax::ast::*;
2628
use syntax::codemap::dummy_sp;
@@ -76,17 +78,28 @@ fn next_byte(st: @mut PState) -> u8 {
7678
return b;
7779
}
7880

81+
fn scan<R>(st: &mut PState, is_last: &fn(char) -> bool,
82+
op: &fn(&[u8]) -> R) -> R
83+
{
84+
let start_pos = st.pos;
85+
debug!("scan: '%c' (start)", st.data[st.pos] as char);
86+
while !is_last(st.data[st.pos] as char) {
87+
st.pos += 1;
88+
debug!("scan: '%c'", st.data[st.pos] as char);
89+
}
90+
let end_pos = st.pos;
91+
st.pos += 1;
92+
return op(st.data.slice(start_pos, end_pos));
93+
}
94+
7995
pub fn parse_ident(st: @mut PState, last: char) -> ast::ident {
8096
fn is_last(b: char, c: char) -> bool { return c == b; }
8197
return parse_ident_(st, |a| is_last(last, a) );
8298
}
8399

84100
fn parse_ident_(st: @mut PState, is_last: @fn(char) -> bool) ->
85101
ast::ident {
86-
let mut rslt = ~"";
87-
while !is_last(peek(st)) {
88-
rslt += str::from_byte(next_byte(st));
89-
}
102+
let rslt = scan(st, is_last, str::from_bytes);
90103
return st.tcx.sess.ident_of(rslt);
91104
}
92105

@@ -417,11 +430,17 @@ fn parse_purity(c: char) -> purity {
417430
}
418431
}
419432
420-
fn parse_abi(c: char) -> Abi {
421-
match c {
422-
'r' => ast::RustAbi,
423-
_ => fail!(fmt!("parse_abi: bad ABI '%c'", c))
433+
fn parse_abi_set(st: @mut PState) -> AbiSet {
434+
assert!(next(st) == '[');
435+
let mut abis = AbiSet::empty();
436+
while peek(st) != ']' {
437+
// FIXME(#5422) str API should not force this copy
438+
let abi_str = scan(st, |c| c == ',', str::from_bytes);
439+
let abi = abi::lookup(abi_str).expect(abi_str);
440+
abis.add(abi);
424441
}
442+
assert!(next(st) == ']');
443+
return abis;
425444
}
426445
427446
fn parse_onceness(c: char) -> ast::Onceness {
@@ -462,11 +481,11 @@ fn parse_closure_ty(st: @mut PState, conv: conv_did) -> ty::ClosureTy {
462481
463482
fn parse_bare_fn_ty(st: @mut PState, conv: conv_did) -> ty::BareFnTy {
464483
let purity = parse_purity(next(st));
465-
let abi = parse_abi(next(st));
484+
let abi = parse_abi_set(st);
466485
let sig = parse_sig(st, conv);
467486
ty::BareFnTy {
468487
purity: purity,
469-
abi: abi,
488+
abis: abi,
470489
sig: sig
471490
}
472491
}

0 commit comments

Comments
 (0)