Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5edbe1f5
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5edbe1f5
编写于
1月 15, 2015
作者:
H
Huon Wilson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `Type::int_width` for retrieving integer's bit width.
上级
3d59a476
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
41 addition
and
77 deletion
+41
-77
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+15
-17
src/librustc_trans/trans/cabi_aarch64.rs
src/librustc_trans/trans/cabi_aarch64.rs
+2
-11
src/librustc_trans/trans/cabi_arm.rs
src/librustc_trans/trans/cabi_arm.rs
+3
-16
src/librustc_trans/trans/cabi_mips.rs
src/librustc_trans/trans/cabi_mips.rs
+2
-10
src/librustc_trans/trans/cabi_x86_64.rs
src/librustc_trans/trans/cabi_x86_64.rs
+2
-11
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/expr.rs
+10
-12
src/librustc_trans/trans/type_.rs
src/librustc_trans/trans/type_.rs
+7
-0
未找到文件。
src/librustc_trans/trans/base.rs
浏览文件 @
5edbe1f5
...
...
@@ -847,26 +847,24 @@ pub fn cast_shift_rhs<F, G>(op: ast::BinOp,
G
:
FnOnce
(
ValueRef
,
Type
)
->
ValueRef
,
{
// Shifts may have any size int on the rhs
unsafe
{
if
ast_util
::
is_shift_binop
(
op
)
{
let
mut
rhs_llty
=
val_ty
(
rhs
);
let
mut
lhs_llty
=
val_ty
(
lhs
);
if
rhs_llty
.kind
()
==
Vector
{
rhs_llty
=
rhs_llty
.element_type
()
}
if
lhs_llty
.kind
()
==
Vector
{
lhs_llty
=
lhs_llty
.element_type
()
}
let
rhs_sz
=
llvm
::
LLVMGetIntTypeWidth
(
rhs_llty
.to_ref
());
let
lhs_sz
=
llvm
::
LLVMGetIntTypeWidth
(
lhs_llty
.to_ref
());
if
lhs_sz
<
rhs_sz
{
trunc
(
rhs
,
lhs_llty
)
}
else
if
lhs_sz
>
rhs_sz
{
// FIXME (#1877: If shifting by negative
// values becomes not undefined then this is wrong.
zext
(
rhs
,
lhs_llty
)
}
else
{
rhs
}
if
ast_util
::
is_shift_binop
(
op
)
{
let
mut
rhs_llty
=
val_ty
(
rhs
);
let
mut
lhs_llty
=
val_ty
(
lhs
);
if
rhs_llty
.kind
()
==
Vector
{
rhs_llty
=
rhs_llty
.element_type
()
}
if
lhs_llty
.kind
()
==
Vector
{
lhs_llty
=
lhs_llty
.element_type
()
}
let
rhs_sz
=
rhs_llty
.int_width
();
let
lhs_sz
=
lhs_llty
.int_width
();
if
lhs_sz
<
rhs_sz
{
trunc
(
rhs
,
lhs_llty
)
}
else
if
lhs_sz
>
rhs_sz
{
// FIXME (#1877: If shifting by negative
// values becomes not undefined then this is wrong.
zext
(
rhs
,
lhs_llty
)
}
else
{
rhs
}
}
else
{
rhs
}
}
...
...
src/librustc_trans/trans/cabi_aarch64.rs
浏览文件 @
5edbe1f5
...
...
@@ -10,7 +10,6 @@
#![allow(non_upper_case_globals)]
use
llvm
;
use
llvm
::{
Integer
,
Pointer
,
Float
,
Double
,
Struct
,
Array
,
Vector
};
use
llvm
::{
StructRetAttribute
,
ZExtAttribute
};
use
trans
::
cabi
::{
FnType
,
ArgType
};
...
...
@@ -30,11 +29,7 @@ fn align(off: uint, ty: Type) -> uint {
fn
ty_align
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
8
,
Float
=>
4
,
Double
=>
8
,
...
...
@@ -61,11 +56,7 @@ fn ty_align(ty: Type) -> uint {
fn
ty_size
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
8
,
Float
=>
4
,
Double
=>
8
,
...
...
src/librustc_trans/trans/cabi_arm.rs
浏览文件 @
5edbe1f5
...
...
@@ -10,7 +10,6 @@
#![allow(non_upper_case_globals)]
use
llvm
;
use
llvm
::{
Integer
,
Pointer
,
Float
,
Double
,
Struct
,
Array
,
Vector
};
use
llvm
::{
StructRetAttribute
,
ZExtAttribute
};
use
trans
::
cabi
::{
FnType
,
ArgType
};
...
...
@@ -37,11 +36,7 @@ fn align(off: uint, ty: Type, align_fn: TyAlignFn) -> uint {
fn
general_ty_align
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
4
,
Float
=>
4
,
Double
=>
8
,
...
...
@@ -75,11 +70,7 @@ fn general_ty_align(ty: Type) -> uint {
// /iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html
fn
ios_ty_align
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
cmp
::
min
(
4
,
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
)
}
}
Integer
=>
cmp
::
min
(
4
,
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
),
Pointer
=>
4
,
Float
=>
4
,
Double
=>
4
,
...
...
@@ -106,11 +97,7 @@ fn ios_ty_align(ty: Type) -> uint {
fn
ty_size
(
ty
:
Type
,
align_fn
:
TyAlignFn
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
4
,
Float
=>
4
,
Double
=>
8
,
...
...
src/librustc_trans/trans/cabi_mips.rs
浏览文件 @
5edbe1f5
...
...
@@ -30,11 +30,7 @@ fn align(off: uint, ty: Type) -> uint {
fn
ty_align
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
4
,
Float
=>
4
,
Double
=>
8
,
...
...
@@ -61,11 +57,7 @@ fn ty_align(ty: Type) -> uint {
fn
ty_size
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
4
,
Float
=>
4
,
Double
=>
8
,
...
...
src/librustc_trans/trans/cabi_x86_64.rs
浏览文件 @
5edbe1f5
...
...
@@ -14,7 +14,6 @@
#![allow(non_upper_case_globals)]
use
self
::
RegClass
::
*
;
use
llvm
;
use
llvm
::{
Integer
,
Pointer
,
Float
,
Double
};
use
llvm
::{
Struct
,
Array
,
Attribute
,
Vector
};
use
llvm
::{
StructRetAttribute
,
ByValAttribute
,
ZExtAttribute
};
...
...
@@ -94,11 +93,7 @@ fn align(off: uint, ty: Type) -> uint {
fn
ty_align
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
((
ty
.int_width
()
as
uint
)
+
7
)
/
8
,
Pointer
=>
8
,
Float
=>
4
,
Double
=>
8
,
...
...
@@ -125,11 +120,7 @@ fn ty_align(ty: Type) -> uint {
fn
ty_size
(
ty
:
Type
)
->
uint
{
match
ty
.kind
()
{
Integer
=>
{
unsafe
{
((
llvm
::
LLVMGetIntTypeWidth
(
ty
.to_ref
())
as
uint
)
+
7
)
/
8
}
}
Integer
=>
(
ty
.int_width
()
as
uint
+
7
)
/
8
,
Pointer
=>
8
,
Float
=>
4
,
Double
=>
8
,
...
...
src/librustc_trans/trans/expr.rs
浏览文件 @
5edbe1f5
...
...
@@ -1906,18 +1906,16 @@ fn int_cast(bcx: Block,
signed
:
bool
)
->
ValueRef
{
let
_
icx
=
push_ctxt
(
"int_cast"
);
unsafe
{
let
srcsz
=
llvm
::
LLVMGetIntTypeWidth
(
llsrctype
.to_ref
());
let
dstsz
=
llvm
::
LLVMGetIntTypeWidth
(
lldsttype
.to_ref
());
return
if
dstsz
==
srcsz
{
BitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
if
srcsz
>
dstsz
{
TruncOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
if
signed
{
SExtOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
{
ZExtOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
};
let
srcsz
=
llsrctype
.int_width
();
let
dstsz
=
lldsttype
.int_width
();
return
if
dstsz
==
srcsz
{
BitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
if
srcsz
>
dstsz
{
TruncOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
if
signed
{
SExtOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
}
else
{
ZExtOrBitCast
(
bcx
,
llsrc
,
lldsttype
)
}
}
...
...
src/librustc_trans/trans/type_.rs
浏览文件 @
5edbe1f5
...
...
@@ -333,6 +333,13 @@ pub fn float_width(&self) -> uint {
_
=>
panic!
(
"llvm_float_width called on a non-float type"
)
}
}
/// Retrieve the bit width of the integer type `self`.
pub
fn
int_width
(
&
self
)
->
u64
{
unsafe
{
llvm
::
LLVMGetIntTypeWidth
(
self
.to_ref
())
as
u64
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录