Skip to content

Commit ea2953b

Browse files
committed
---
yaml --- r: 174004 b: refs/heads/batch c: c055d99 h: refs/heads/master v: v3
1 parent 8eb0ef0 commit ea2953b

File tree

6 files changed

+189
-3
lines changed

6 files changed

+189
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/issue-18208-method-dispatch-2: 9e1eae4fb9b6527315b4441cf8a0f5ca911d1671
3030
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
32-
refs/heads/batch: 33cd9cf9f463b6eb6153d0698ca8d209ab95efec
32+
refs/heads/batch: c055d995261203f9869399120a4174824481a305
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928

branches/batch/src/librustc_back/target/powerpc_unknown_linux_gnu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn target() -> Target {
1818
data_layout: "E-S8-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
1919
llvm_target: "powerpc-unknown-linux-gnu".to_string(),
2020
target_endian: "big".to_string(),
21-
target_word_size: "32".to_string(),
21+
target_pointer_width: "32".to_string(),
2222
arch: "powerpc".to_string(),
2323
target_os: "linux".to_string(),
2424
options: base,

branches/batch/src/librustc_trans/trans/asm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
164164
#[cfg(any(target_arch = "arm",
165165
target_arch = "aarch64",
166166
target_arch = "mips",
167-
target_arch = "mipsel"))]
167+
target_arch = "mipsel",
168+
target_arch = "powerpc"))]
168169
fn get_clobbers() -> String {
169170
"".to_string()
170171
}

branches/batch/src/librustc_trans/trans/cabi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use trans::cabi_x86_64;
1818
use trans::cabi_x86_win64;
1919
use trans::cabi_arm;
2020
use trans::cabi_aarch64;
21+
use trans::cabi_powerpc;
2122
use trans::cabi_mips;
2223
use trans::type_::Type;
2324

@@ -125,6 +126,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
125126
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def, flavor)
126127
},
127128
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
129+
"powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
128130
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)
129131
[]),
130132
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// Copyright 2014-2015 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 llvm;
12+
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
13+
use llvm::{StructRetAttribute, ZExtAttribute};
14+
use trans::cabi::{FnType, ArgType};
15+
use trans::context::CrateContext;
16+
use trans::type_::Type;
17+
18+
use std::cmp;
19+
20+
fn align_up_to(off: uint, a: uint) -> uint {
21+
return (off + a - 1u) / a * a;
22+
}
23+
24+
fn align(off: uint, ty: Type) -> uint {
25+
let a = ty_align(ty);
26+
return align_up_to(off, a);
27+
}
28+
29+
fn ty_align(ty: Type) -> uint {
30+
match ty.kind() {
31+
Integer => {
32+
unsafe {
33+
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
34+
}
35+
}
36+
Pointer => 4,
37+
Float => 4,
38+
Double => 8,
39+
Struct => {
40+
if ty.is_packed() {
41+
1
42+
} else {
43+
let str_tys = ty.field_types();
44+
str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
45+
}
46+
}
47+
Array => {
48+
let elt = ty.element_type();
49+
ty_align(elt)
50+
}
51+
_ => panic!("ty_size: unhandled type")
52+
}
53+
}
54+
55+
fn ty_size(ty: Type) -> uint {
56+
match ty.kind() {
57+
Integer => {
58+
unsafe {
59+
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
60+
}
61+
}
62+
Pointer => 4,
63+
Float => 4,
64+
Double => 8,
65+
Struct => {
66+
if ty.is_packed() {
67+
let str_tys = ty.field_types();
68+
str_tys.iter().fold(0, |s, t| s + ty_size(*t))
69+
} else {
70+
let str_tys = ty.field_types();
71+
let size = str_tys.iter().fold(0, |s, t| align(s, *t) + ty_size(*t));
72+
align(size, ty)
73+
}
74+
}
75+
Array => {
76+
let len = ty.array_length();
77+
let elt = ty.element_type();
78+
let eltsz = ty_size(elt);
79+
len * eltsz
80+
}
81+
_ => panic!("ty_size: unhandled type")
82+
}
83+
}
84+
85+
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
86+
if is_reg_ty(ty) {
87+
let attr = if ty == Type::i1(ccx) { Some(ZExtAttribute) } else { None };
88+
ArgType::direct(ty, None, None, attr)
89+
} else {
90+
ArgType::indirect(ty, Some(StructRetAttribute))
91+
}
92+
}
93+
94+
fn classify_arg_ty(ccx: &CrateContext, ty: Type, offset: &mut uint) -> ArgType {
95+
let orig_offset = *offset;
96+
let size = ty_size(ty) * 8;
97+
let mut align = ty_align(ty);
98+
99+
align = cmp::min(cmp::max(align, 4), 8);
100+
*offset = align_up_to(*offset, align);
101+
*offset += align_up_to(size, align * 8) / 8;
102+
103+
if is_reg_ty(ty) {
104+
let attr = if ty == Type::i1(ccx) { Some(ZExtAttribute) } else { None };
105+
ArgType::direct(ty, None, None, attr)
106+
} else {
107+
ArgType::direct(
108+
ty,
109+
Some(struct_ty(ccx, ty)),
110+
padding_ty(ccx, align, orig_offset),
111+
None
112+
)
113+
}
114+
}
115+
116+
fn is_reg_ty(ty: Type) -> bool {
117+
return match ty.kind() {
118+
Integer
119+
| Pointer
120+
| Float
121+
| Double => true,
122+
_ => false
123+
};
124+
}
125+
126+
fn padding_ty(ccx: &CrateContext, align: uint, offset: uint) -> Option<Type> {
127+
if ((align - 1 ) & offset) > 0 {
128+
Some(Type::i32(ccx))
129+
} else {
130+
None
131+
}
132+
}
133+
134+
fn coerce_to_int(ccx: &CrateContext, size: uint) -> Vec<Type> {
135+
let int_ty = Type::i32(ccx);
136+
let mut args = Vec::new();
137+
138+
let mut n = size / 32;
139+
while n > 0 {
140+
args.push(int_ty);
141+
n -= 1;
142+
}
143+
144+
let r = size % 32;
145+
if r > 0 {
146+
unsafe {
147+
args.push(Type::from_ref(llvm::LLVMIntTypeInContext(ccx.llcx(), r as c_uint)));
148+
}
149+
}
150+
151+
args
152+
}
153+
154+
fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
155+
let size = ty_size(ty) * 8;
156+
Type::struct_(ccx, coerce_to_int(ccx, size).as_slice(), false)
157+
}
158+
159+
pub fn compute_abi_info(ccx: &CrateContext,
160+
atys: &[Type],
161+
rty: Type,
162+
ret_def: bool) -> FnType {
163+
let ret_ty = if ret_def {
164+
classify_ret_ty(ccx, rty)
165+
} else {
166+
ArgType::direct(Type::void(ccx), None, None, None)
167+
};
168+
169+
let sret = ret_ty.is_indirect();
170+
let mut arg_tys = Vec::new();
171+
let mut offset = if sret { 4 } else { 0 };
172+
173+
for aty in atys.iter() {
174+
let ty = classify_arg_ty(ccx, *aty, &mut offset);
175+
arg_tys.push(ty);
176+
};
177+
178+
return FnType {
179+
arg_tys: arg_tys,
180+
ret_ty: ret_ty,
181+
};
182+
}

branches/batch/src/librustc_trans/trans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod cabi_x86_win64;
4545
mod cabi_arm;
4646
mod cabi_aarch64;
4747
mod cabi_mips;
48+
mod cabi_powerpc;
4849
mod foreign;
4950
mod intrinsic;
5051
mod debuginfo;

0 commit comments

Comments
 (0)