Skip to content

Commit 978069e

Browse files
committed
---
yaml --- r: 44292 b: refs/heads/snap-stage3 c: 5098cf5 h: refs/heads/master v: v3
1 parent 0f479f3 commit 978069e

File tree

7 files changed

+222
-23
lines changed

7 files changed

+222
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6439e286f90a34d96cec91d82f941f7572817939
4+
refs/heads/snap-stage3: 5098cf5bd2abbef4418e93c9ab7db1eac43bb1bb
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/AUTHORS.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Josh Matthews <[email protected]>
9393
Joshua Clark <[email protected]>
9494
Joshua Wise <[email protected]>
9595
Jyun-Yan You <[email protected]>
96-
Kang Seonghoon <[email protected]>
9796
Kelly Wilson <[email protected]>
9897
Kevin Atkinson <[email protected]>
9998
Kevin Cantu <[email protected]>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
12+
use lib::llvm::struct_tys;
13+
use lib::llvm::TypeRef;
14+
use lib::llvm::{Attribute, StructRetAttribute};
15+
use middle::trans::cabi::{ABIInfo, FnType, LLVMType};
16+
use middle::trans::common::{T_i8, T_i16, T_i32, T_i64};
17+
use middle::trans::common::{T_array, T_ptr, T_void};
18+
19+
use core::option::{Option, None, Some};
20+
use core::uint;
21+
use core::vec;
22+
23+
fn align_up_to(off: uint, a: uint) -> uint {
24+
return (off + a - 1u) / a * a;
25+
}
26+
27+
fn align(off: uint, ty: TypeRef) -> uint {
28+
let a = ty_align(ty);
29+
return align_up_to(off, a);
30+
}
31+
32+
fn ty_align(ty: TypeRef) -> uint {
33+
unsafe {
34+
return match llvm::LLVMGetTypeKind(ty) {
35+
Integer => {
36+
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8
37+
}
38+
Pointer => 4,
39+
Float => 4,
40+
Double => 8,
41+
Struct => {
42+
do vec::foldl(1, struct_tys(ty)) |a, t| {
43+
uint::max(a, ty_align(*t))
44+
}
45+
}
46+
Array => {
47+
let elt = llvm::LLVMGetElementType(ty);
48+
ty_align(elt)
49+
}
50+
_ => fail!(~"ty_align: unhandled type")
51+
};
52+
}
53+
}
54+
55+
fn ty_size(ty: TypeRef) -> uint {
56+
unsafe {
57+
return match llvm::LLVMGetTypeKind(ty) {
58+
Integer => {
59+
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8
60+
}
61+
Pointer => 4,
62+
Float => 4,
63+
Double => 8,
64+
Struct => {
65+
let size = do vec::foldl(0, struct_tys(ty)) |s, t| {
66+
align(s, *t) + ty_size(*t)
67+
};
68+
align(size, ty)
69+
}
70+
Array => {
71+
let len = llvm::LLVMGetArrayLength(ty) as uint;
72+
let elt = llvm::LLVMGetElementType(ty);
73+
let eltsz = ty_size(elt);
74+
len * eltsz
75+
}
76+
_ => fail!(~"ty_size: unhandled type")
77+
};
78+
}
79+
}
80+
81+
fn classify_ret_ty(ty: TypeRef) -> (LLVMType, Option<Attribute>) {
82+
if is_reg_ty(ty) {
83+
return (LLVMType { cast: false, ty: ty }, None);
84+
}
85+
let size = ty_size(ty);
86+
if size <= 4 {
87+
let llty = if size <= 1 {
88+
T_i8()
89+
} else if size <= 2 {
90+
T_i16()
91+
} else {
92+
T_i32()
93+
};
94+
return (LLVMType { cast: true, ty: llty }, None);
95+
}
96+
(LLVMType { cast: false, ty: T_ptr(ty) }, Some(StructRetAttribute))
97+
}
98+
99+
fn classify_arg_ty(ty: TypeRef) -> (LLVMType, Option<Attribute>) {
100+
if is_reg_ty(ty) {
101+
return (LLVMType { cast: false, ty: ty }, None);
102+
}
103+
let align = ty_align(ty);
104+
let size = ty_size(ty);
105+
let llty = if align <= 4 {
106+
T_array(T_i32(), (size + 3) / 4)
107+
} else {
108+
T_array(T_i64(), (size + 7) / 8)
109+
};
110+
(LLVMType { cast: true, ty: llty }, None)
111+
}
112+
113+
fn is_reg_ty(ty: TypeRef) -> bool {
114+
unsafe {
115+
return match llvm::LLVMGetTypeKind(ty) {
116+
Integer
117+
| Pointer
118+
| Float
119+
| Double => true,
120+
_ => false
121+
};
122+
}
123+
}
124+
125+
enum ARM_ABIInfo { ARM_ABIInfo }
126+
127+
impl ABIInfo for ARM_ABIInfo {
128+
fn compute_info(&self,
129+
atys: &[TypeRef],
130+
rty: TypeRef,
131+
ret_def: bool) -> FnType {
132+
let mut arg_tys = ~[];
133+
let mut attrs = ~[];
134+
for atys.each |&aty| {
135+
let (ty, attr) = classify_arg_ty(aty);
136+
arg_tys.push(ty);
137+
attrs.push(attr);
138+
}
139+
140+
let mut (ret_ty, ret_attr) = if ret_def {
141+
classify_ret_ty(rty)
142+
} else {
143+
(LLVMType { cast: false, ty: T_void() }, None)
144+
};
145+
146+
let sret = ret_attr.is_some();
147+
if sret {
148+
arg_tys.unshift(ret_ty);
149+
attrs.unshift(ret_attr);
150+
ret_ty = LLVMType { cast: false, ty: T_void() };
151+
}
152+
153+
return FnType {
154+
arg_tys: arg_tys,
155+
ret_ty: ret_ty,
156+
attrs: attrs,
157+
sret: sret
158+
};
159+
}
160+
}
161+
162+
pub fn abi_info() -> ABIInfo {
163+
return ARM_ABIInfo as ABIInfo;
164+
}

branches/snap-stage3/src/librustc/middle/trans/foreign.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use lib;
2121
use middle::trans::base::*;
2222
use middle::trans::cabi;
2323
use middle::trans::cabi_x86_64::*;
24+
use middle::trans::cabi_arm;
2425
use middle::trans::build::*;
2526
use middle::trans::callee::*;
2627
use middle::trans::common::*;
@@ -42,7 +43,8 @@ use syntax::parse::token::special_idents;
4243

4344
fn abi_info(arch: session::arch) -> cabi::ABIInfo {
4445
return match arch {
45-
arch_x86_64 | arch_arm => x86_64_abi_info(),
46+
arch_x86_64 => x86_64_abi_info(),
47+
arch_arm => cabi_arm::abi_info(),
4648
_ => cabi::llvm_abi_info()
4749
}
4850
}

branches/snap-stage3/src/librustc/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub mod middle {
6868
pub mod meth;
6969
pub mod cabi;
7070
pub mod cabi_x86_64;
71+
pub mod cabi_arm;
7172
pub mod foreign;
7273
pub mod reflect;
7374
pub mod shape;

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,18 @@ pub impl Parser {
748748
}
749749
}
750750

751+
fn parse_capture_item_or(parse_arg_fn: fn(Parser) -> arg_or_capture_item)
752+
-> arg_or_capture_item
753+
{
754+
if self.eat_keyword(~"copy") {
755+
// XXX outdated syntax now that moves-based-on-type has gone in
756+
self.parse_ident();
757+
either::Right(())
758+
} else {
759+
parse_arg_fn(self)
760+
}
761+
}
762+
751763
// This version of parse arg doesn't necessarily require
752764
// identifier names.
753765
fn parse_arg_general(require_name: bool) -> arg {
@@ -776,26 +788,32 @@ pub impl Parser {
776788
either::Left(self.parse_arg_general(true))
777789
}
778790
791+
fn parse_arg_or_capture_item() -> arg_or_capture_item {
792+
self.parse_capture_item_or(|p| p.parse_arg())
793+
}
794+
779795
fn parse_fn_block_arg() -> arg_or_capture_item {
780-
let m = self.parse_arg_mode();
781-
let is_mutbl = self.eat_keyword(~"mut");
782-
let pat = self.parse_pat(false);
783-
let t = if self.eat(token::COLON) {
784-
self.parse_ty(false)
785-
} else {
786-
@Ty {
787-
id: self.get_id(),
788-
node: ty_infer,
789-
span: mk_sp(self.span.lo, self.span.hi),
790-
}
791-
};
792-
either::Left(ast::arg {
793-
mode: m,
794-
is_mutbl: is_mutbl,
795-
ty: t,
796-
pat: pat,
797-
id: self.get_id()
798-
})
796+
do self.parse_capture_item_or |p| {
797+
let m = p.parse_arg_mode();
798+
let is_mutbl = self.eat_keyword(~"mut");
799+
let pat = p.parse_pat(false);
800+
let t = if p.eat(token::COLON) {
801+
p.parse_ty(false)
802+
} else {
803+
@Ty {
804+
id: p.get_id(),
805+
node: ty_infer,
806+
span: mk_sp(p.span.lo, p.span.hi),
807+
}
808+
};
809+
either::Left(ast::arg {
810+
mode: m,
811+
is_mutbl: is_mutbl,
812+
ty: t,
813+
pat: pat,
814+
id: p.get_id()
815+
})
816+
}
799817
}
800818

801819
fn maybe_parse_fixed_vstore_with_star() -> Option<uint> {
@@ -1704,7 +1722,7 @@ pub impl Parser {
17041722

17051723
// if we want to allow fn expression argument types to be inferred in
17061724
// the future, just have to change parse_arg to parse_fn_block_arg.
1707-
let decl = self.parse_fn_decl(|p| p.parse_arg());
1725+
let decl = self.parse_fn_decl(|p| p.parse_arg_or_capture_item());
17081726

17091727
let body = self.parse_block();
17101728

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern: warning: Captured variable 'y' not used in closure
12+
pub fn main() {
13+
let x = 5;
14+
let _y = fn~(copy x) { };
15+
}

0 commit comments

Comments
 (0)