Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9a63bb66
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,发现更多精彩内容 >>
提交
9a63bb66
编写于
11月 27, 2015
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move ConstVal -> ValueRef translation to trans::consts
上级
8864f2c8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
42 deletion
+40
-42
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+34
-0
src/librustc_trans/trans/mir/constant.rs
src/librustc_trans/trans/mir/constant.rs
+6
-42
未找到文件。
src/librustc_trans/trans/consts.rs
浏览文件 @
9a63bb66
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
use
trans
::
base
::{
self
,
push_ctxt
};
use
trans
::
base
::{
self
,
push_ctxt
};
use
trans
::
common
::{
self
,
type_is_sized
,
ExprOrMethodCall
,
node_id_substs
,
C_nil
,
const_get_elt
};
use
trans
::
common
::{
self
,
type_is_sized
,
ExprOrMethodCall
,
node_id_substs
,
C_nil
,
const_get_elt
};
use
trans
::
common
::{
CrateContext
,
C_integral
,
C_floating
,
C_bool
,
C_str_slice
,
C_bytes
,
val_ty
};
use
trans
::
common
::{
CrateContext
,
C_integral
,
C_floating
,
C_bool
,
C_str_slice
,
C_bytes
,
val_ty
};
use
trans
::
common
::
C_floating_f64
;
use
trans
::
common
::{
C_struct
,
C_undef
,
const_to_opt_int
,
const_to_opt_uint
,
VariantInfo
,
C_uint
};
use
trans
::
common
::{
C_struct
,
C_undef
,
const_to_opt_int
,
const_to_opt_uint
,
VariantInfo
,
C_uint
};
use
trans
::
common
::{
type_is_fat_ptr
,
Field
,
C_vector
,
C_array
,
C_null
,
ExprId
,
MethodCallKey
};
use
trans
::
common
::{
type_is_fat_ptr
,
Field
,
C_vector
,
C_array
,
C_null
,
ExprId
,
MethodCallKey
};
use
trans
::
declare
;
use
trans
::
declare
;
...
@@ -107,6 +108,39 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
...
@@ -107,6 +108,39 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
}
}
}
}
pub
fn
trans_constval
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
cv
:
&
ConstVal
,
ty
:
Ty
<
'tcx
>
,
param_substs
:
&
'tcx
Substs
<
'tcx
>
)
->
ValueRef
{
let
llty
=
type_of
::
type_of
(
ccx
,
ty
);
match
*
cv
{
ConstVal
::
Float
(
v
)
=>
C_floating_f64
(
v
,
llty
),
ConstVal
::
Bool
(
v
)
=>
C_bool
(
ccx
,
v
),
ConstVal
::
Int
(
v
)
=>
C_integral
(
llty
,
v
as
u64
,
true
),
ConstVal
::
Uint
(
v
)
=>
C_integral
(
llty
,
v
,
false
),
ConstVal
::
Str
(
ref
v
)
=>
C_str_slice
(
ccx
,
v
.clone
()),
ConstVal
::
ByteStr
(
ref
v
)
=>
addr_of
(
ccx
,
C_bytes
(
ccx
,
v
),
1
,
"byte_str"
),
ConstVal
::
Struct
(
id
)
|
ConstVal
::
Tuple
(
id
)
=>
{
let
expr
=
ccx
.tcx
()
.map
.expect_expr
(
id
);
match
const_expr
(
ccx
,
expr
,
param_substs
,
None
,
TrueConst
::
Yes
)
{
Ok
((
val
,
_
))
=>
val
,
Err
(
e
)
=>
panic!
(
"const eval failure: {}"
,
e
.description
()),
}
},
ConstVal
::
Function
(
_
)
=>
{
unimplemented!
()
},
ConstVal
::
Array
(
..
)
=>
{
unimplemented!
()
},
ConstVal
::
Repeat
(
..
)
=>
{
unimplemented!
()
},
}
}
pub
fn
ptrcast
(
val
:
ValueRef
,
ty
:
Type
)
->
ValueRef
{
pub
fn
ptrcast
(
val
:
ValueRef
,
ty
:
Type
)
->
ValueRef
{
unsafe
{
unsafe
{
llvm
::
LLVMConstPointerCast
(
val
,
ty
.to_ref
())
llvm
::
LLVMConstPointerCast
(
val
,
ty
.to_ref
())
...
...
src/librustc_trans/trans/mir/constant.rs
浏览文件 @
9a63bb66
...
@@ -11,10 +11,8 @@
...
@@ -11,10 +11,8 @@
use
middle
::
ty
::{
Ty
,
HasTypeFlags
};
use
middle
::
ty
::{
Ty
,
HasTypeFlags
};
use
rustc
::
middle
::
const_eval
::
ConstVal
;
use
rustc
::
middle
::
const_eval
::
ConstVal
;
use
rustc
::
mir
::
repr
as
mir
;
use
rustc
::
mir
::
repr
as
mir
;
use
trans
::
consts
::{
self
,
TrueConst
}
;
use
trans
::
consts
;
use
trans
::
common
::{
self
,
Block
};
use
trans
::
common
::{
self
,
Block
};
use
trans
::
common
::{
C_bool
,
C_bytes
,
C_floating_f64
,
C_integral
,
C_str_slice
};
use
trans
::
type_of
;
use
super
::
operand
::
OperandRef
;
use
super
::
operand
::
OperandRef
;
use
super
::
MirContext
;
use
super
::
MirContext
;
...
@@ -29,45 +27,11 @@ pub fn trans_constval(&mut self,
...
@@ -29,45 +27,11 @@ pub fn trans_constval(&mut self,
use
super
::
operand
::
OperandValue
::{
Ref
,
Immediate
};
use
super
::
operand
::
OperandValue
::{
Ref
,
Immediate
};
let
ccx
=
bcx
.ccx
();
let
ccx
=
bcx
.ccx
();
let
llty
=
type_of
::
type_of
(
ccx
,
ty
);
let
val
=
consts
::
trans_constval
(
ccx
,
cv
,
ty
,
bcx
.fcx.param_substs
);
let
val
=
match
*
cv
{
let
val
=
if
common
::
type_is_immediate
(
ccx
,
ty
)
{
ConstVal
::
Float
(
v
)
=>
Immediate
(
C_floating_f64
(
v
,
llty
)),
Immediate
(
val
)
ConstVal
::
Bool
(
v
)
=>
Immediate
(
C_bool
(
ccx
,
v
)),
}
else
{
ConstVal
::
Int
(
v
)
=>
Immediate
(
C_integral
(
llty
,
v
as
u64
,
true
)),
Ref
(
val
)
ConstVal
::
Uint
(
v
)
=>
Immediate
(
C_integral
(
llty
,
v
,
false
)),
ConstVal
::
Str
(
ref
v
)
=>
Immediate
(
C_str_slice
(
ccx
,
v
.clone
())),
ConstVal
::
ByteStr
(
ref
v
)
=>
{
Immediate
(
consts
::
addr_of
(
ccx
,
C_bytes
(
ccx
,
v
),
1
,
"byte_str"
))
}
ConstVal
::
Struct
(
id
)
|
ConstVal
::
Tuple
(
id
)
=>
{
let
expr
=
bcx
.tcx
()
.map
.expect_expr
(
id
);
let
(
llval
,
_
)
=
match
consts
::
const_expr
(
ccx
,
expr
,
bcx
.fcx.param_substs
,
None
,
TrueConst
::
Yes
)
{
Ok
(
v
)
=>
v
,
Err
(
_
)
=>
panic!
(
"constant eval failure"
),
};
if
common
::
type_is_immediate
(
bcx
.ccx
(),
ty
)
{
Immediate
(
llval
)
}
else
{
Ref
(
llval
)
}
}
ConstVal
::
Function
(
_
)
=>
{
unimplemented!
()
}
ConstVal
::
Array
(
..
)
=>
{
unimplemented!
()
}
ConstVal
::
Repeat
(
..
)
=>
{
unimplemented!
()
}
};
};
assert
!
(
!
ty
.has_erasable_regions
());
assert
!
(
!
ty
.has_erasable_regions
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录