Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
789a1ae3
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
789a1ae3
编写于
2月 21, 2012
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up a number of TODOs in the trans modules
Rename the ones that I didn't handle to FIXME
上级
9691ce18
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
272 addition
and
297 deletion
+272
-297
src/comp/middle/trans/alt.rs
src/comp/middle/trans/alt.rs
+7
-7
src/comp/middle/trans/base.rs
src/comp/middle/trans/base.rs
+147
-153
src/comp/middle/trans/build.rs
src/comp/middle/trans/build.rs
+5
-6
src/comp/middle/trans/closure.rs
src/comp/middle/trans/closure.rs
+15
-19
src/comp/middle/trans/common.rs
src/comp/middle/trans/common.rs
+16
-19
src/comp/middle/trans/debuginfo.rs
src/comp/middle/trans/debuginfo.rs
+25
-32
src/comp/middle/trans/impl.rs
src/comp/middle/trans/impl.rs
+11
-10
src/comp/middle/trans/native.rs
src/comp/middle/trans/native.rs
+2
-2
src/comp/middle/trans/shape.rs
src/comp/middle/trans/shape.rs
+15
-19
src/comp/middle/trans/tvec.rs
src/comp/middle/trans/tvec.rs
+28
-29
src/comp/middle/trans/uniq.rs
src/comp/middle/trans/uniq.rs
+1
-1
未找到文件。
src/comp/middle/trans/alt.rs
浏览文件 @
789a1ae3
...
...
@@ -38,12 +38,12 @@ enum opt_result {
range_result
(
result
,
result
),
}
fn
trans_opt
(
bcx
:
block
,
o
:
opt
)
->
opt_result
{
let
ccx
=
bcx
_ccx
(
bcx
),
bcx
=
bcx
;
let
ccx
=
bcx
.ccx
(
),
bcx
=
bcx
;
alt
o
{
lit
(
l
)
{
alt
l
.node
{
ast
::
expr_lit
(
@
{
node
:
ast
::
lit_str
(
s
),
_
})
{
let
strty
=
ty
::
mk_str
(
bcx
_tcx
(
bcx
));
let
strty
=
ty
::
mk_str
(
bcx
.tcx
(
));
let
cell
=
empty_dest_cell
();
bcx
=
tvec
::
trans_str
(
bcx
,
s
,
by_val
(
cell
));
add_clean_temp
(
bcx
,
*
cell
,
strty
);
...
...
@@ -526,7 +526,7 @@ enum branch_kind { no_branch, single, switch, compare, }
llvm
::
LLVMAddCase
(
sw
,
r
.val
,
opt_cx
.llbb
);
bcx
=
r
.bcx
;
}
_
{
bcx
_tcx
(
bcx
)
.sess
.bug
(
"Someone forgot to
\
_
{
bcx
.tcx
(
)
.sess
.bug
(
"Someone forgot to
\
document an invariant in compile_submatch"
);
}
}
}
...
...
@@ -599,10 +599,10 @@ fn make_phi_bindings(bcx: block, map: [exit_node],
if
success
{
// Copy references that the alias analysis considered unsafe
ids
.values
{|
node_id
|
if
bcx
_ccx
(
bcx
)
.copy_map
.contains_key
(
node_id
)
{
if
bcx
.ccx
(
)
.copy_map
.contains_key
(
node_id
)
{
let
local
=
alt
bcx
.fcx.lllocals
.find
(
node_id
)
{
some
(
local_mem
(
x
))
{
x
}
_
{
bcx
_tcx
(
bcx
)
.sess
.bug
(
"Someone
\
_
{
bcx
.tcx
(
)
.sess
.bug
(
"Someone
\
forgot to document an invariant in
\
make_phi_bindings"
);
}
};
...
...
@@ -628,7 +628,7 @@ fn trans_alt(bcx: block, expr: @ast::expr, arms: [ast::arm],
fn
trans_alt_inner
(
scope_cx
:
block
,
expr
:
@
ast
::
expr
,
arms
:
[
ast
::
arm
],
dest
:
dest
)
->
block
{
let
bcx
=
scope_cx
,
tcx
=
bcx
_tcx
(
bcx
);
let
bcx
=
scope_cx
,
tcx
=
bcx
.tcx
(
);
let
bodies
=
[],
match
=
[];
let
{
bcx
,
val
,
_
}
=
trans_temp_expr
(
bcx
,
expr
);
...
...
@@ -690,7 +690,7 @@ fn bind_irrefutable_pat(bcx: block, pat: @ast::pat, val: ValueRef,
let
ccx
=
bcx
.fcx.ccx
,
bcx
=
bcx
;
// Necessary since bind_irrefutable_pat is called outside trans_alt
alt
normalize_pat
(
bcx
_tcx
(
bcx
),
pat
)
.node
{
alt
normalize_pat
(
bcx
.tcx
(
),
pat
)
.node
{
ast
::
pat_ident
(
_
,
inner
)
{
if
make_copy
||
ccx
.copy_map
.contains_key
(
pat
.id
)
{
let
ty
=
node_id_type
(
bcx
,
pat
.id
);
...
...
src/comp/middle/trans/base.rs
浏览文件 @
789a1ae3
此差异已折叠。
点击以展开。
src/comp/middle/trans/build.rs
浏览文件 @
789a1ae3
...
...
@@ -6,8 +6,7 @@
import
lib
::
llvm
::{
ValueRef
,
TypeRef
,
BasicBlockRef
,
BuilderRef
,
ModuleRef
};
import
lib
::
llvm
::{
Opcode
,
IntPredicate
,
RealPredicate
,
True
,
False
,
CallConv
};
import
common
::{
block
,
T_ptr
,
T_nil
,
T_i8
,
T_i1
,
T_void
,
T_fn
,
val_ty
,
bcx_ccx
,
C_i32
,
val_str
};
import
common
::
*
;
fn
B
(
cx
:
block
)
->
BuilderRef
{
let
b
=
*
cx
.fcx.ccx.builder
;
...
...
@@ -95,8 +94,8 @@ fn Invoke(cx: block, Fn: ValueRef, Args: [ValueRef],
assert
(
!
cx
.terminated
);
cx
.terminated
=
true
;
#
debug
[
"Invoke(%s with arguments (%s))"
,
val_str
(
bcx_ccx
(
cx
)
.tn
,
Fn
),
str
::
connect
(
vec
::
map
(
Args
,
{|
a
|
val_str
(
bcx_ccx
(
cx
)
.tn
,
a
)}),
val_str
(
cx
.ccx
(
)
.tn
,
Fn
),
str
::
connect
(
vec
::
map
(
Args
,
{|
a
|
val_str
(
cx
.ccx
(
)
.tn
,
a
)}),
", "
)];
unsafe
{
llvm
::
LLVMBuildInvoke
(
B
(
cx
),
Fn
,
vec
::
to_ptr
(
Args
),
...
...
@@ -518,7 +517,7 @@ fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef {
}
fn
add_span_comment
(
bcx
:
block
,
sp
:
span
,
text
:
str
)
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
(
!
ccx
.sess.opts.no_asm_comments
)
{
let
s
=
text
+
" ("
+
codemap
::
span_to_str
(
sp
,
ccx
.sess.codemap
)
+
")"
;
...
...
@@ -528,7 +527,7 @@ fn add_span_comment(bcx: block, sp: span, text: str) {
}
fn
add_comment
(
bcx
:
block
,
text
:
str
)
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
(
!
ccx
.sess.opts.no_asm_comments
)
{
check
str
::
is_not_empty
(
"$"
);
let
sanitized
=
str
::
replace
(
text
,
"$"
,
""
);
...
...
src/comp/middle/trans/closure.rs
浏览文件 @
789a1ae3
...
...
@@ -167,12 +167,11 @@ fn allocate_cbox(bcx: block,
cdata_ty
:
ty
::
t
)
->
(
block
,
ValueRef
,
[
ValueRef
])
{
// let ccx = bcx_ccx(bcx);
let
ccx
=
bcx_ccx
(
bcx
),
tcx
=
ccx
.tcx
;
let
ccx
=
bcx
.ccx
(),
tcx
=
ccx
.tcx
;
fn
nuke_ref_count
(
bcx
:
block
,
box
:
ValueRef
)
{
// Initialize ref count to arbitrary value for debugging:
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
box
=
PointerCast
(
bcx
,
box
,
T_opaque_box_ptr
(
ccx
));
let
ref_cnt
=
GEPi
(
bcx
,
box
,
[
0
,
abi
::
box_field_refcnt
]);
let
rc
=
C_int
(
ccx
,
0x12345678
);
...
...
@@ -183,7 +182,7 @@ fn store_uniq_tydesc(bcx: block,
cdata_ty
:
ty
::
t
,
box
:
ValueRef
,
&
ti
:
option
::
t
<@
tydesc_info
>
)
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
bound_tydesc
=
GEPi
(
bcx
,
box
,
[
0
,
abi
::
box_field_tydesc
]);
let
{
bcx
,
val
:
td
}
=
base
::
get_tydesc
(
bcx
,
cdata_ty
,
true
,
ti
);
let
td
=
Call
(
bcx
,
ccx
.upcalls.create_shared_type_desc
,
[
td
]);
...
...
@@ -228,7 +227,7 @@ fn store_uniq_tydesc(bcx: block,
};
fn
cast_if_we_can
(
bcx
:
block
,
llbox
:
ValueRef
,
t
:
ty
::
t
)
->
ValueRef
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
check
type_has_static_size
(
ccx
,
t
)
{
let
llty
=
type_of
(
ccx
,
t
);
ret
PointerCast
(
bcx
,
llbox
,
llty
);
...
...
@@ -255,13 +254,12 @@ fn maybe_clone_tydesc(bcx: block,
td
}
ty
::
ck_uniq
{
Call
(
bcx
,
bcx
_ccx
(
bcx
)
.upcalls.create_shared_type_desc
,
[
td
])
Call
(
bcx
,
bcx
.ccx
(
)
.upcalls.create_shared_type_desc
,
[
td
])
}
};
}
let
ccx
=
bcx_ccx
(
bcx
);
let
tcx
=
bcx_tcx
(
bcx
);
let
ccx
=
bcx
.ccx
(),
tcx
=
ccx
.tcx
;
// compute the shape of the closure
let
(
cdata_ty
,
bound_tys
)
=
...
...
@@ -356,7 +354,7 @@ fn build_closure(bcx0: block,
// If we need to, package up the iterator body to call
let
env_vals
=
[];
let
bcx
=
bcx0
;
let
tcx
=
bcx
_tcx
(
bcx
);
let
tcx
=
bcx
.tcx
(
);
// Package up the captured upvars
vec
::
iter
(
cap_vars
)
{
|
cap_var
|
...
...
@@ -449,7 +447,7 @@ fn trans_expr_fn(bcx: block,
cap_clause
:
ast
::
capture_clause
,
dest
:
dest
)
->
block
{
if
dest
==
ignore
{
ret
bcx
;
}
let
ccx
=
bcx
_ccx
(
bcx
),
bcx
=
bcx
;
let
ccx
=
bcx
.ccx
(
),
bcx
=
bcx
;
let
fty
=
node_id_type
(
bcx
,
id
);
let
llfnty
=
type_of_fn_from_ty
(
ccx
,
fty
,
[]);
let
sub_path
=
bcx
.fcx.path
+
[
path_name
(
"anon"
)];
...
...
@@ -493,7 +491,7 @@ fn trans_bind_1(cx: block, outgoing_fty: ty::t,
f_res
:
lval_maybe_callee
,
args
:
[
option
<@
ast
::
expr
>
],
pair_ty
:
ty
::
t
,
dest
:
dest
)
->
block
{
let
ccx
=
bcx_ccx
(
cx
);
let
ccx
=
cx
.ccx
(
);
let
bound
:
[
@
ast
::
expr
]
=
[];
for
argopt
:
option
<@
ast
::
expr
>
in
args
{
alt
argopt
{
none
{
}
some
(
e
)
{
bound
+=
[
e
];
}
}
...
...
@@ -579,7 +577,7 @@ fn make_fn_glue(
glue_fn
:
fn
@
(
block
,
v
:
ValueRef
,
t
:
ty
::
t
)
->
block
)
->
block
{
let
bcx
=
cx
;
let
tcx
=
bcx_tcx
(
cx
);
let
tcx
=
cx
.tcx
(
);
let
fn_env
=
fn
@
(
ck
:
ty
::
closure_kind
)
->
block
{
let
box_cell_v
=
GEPi
(
cx
,
v
,
[
0
,
abi
::
fn_field_box
]);
...
...
@@ -613,8 +611,7 @@ fn make_opaque_cbox_take_glue(
}
// Hard case, a deep copy:
let
ccx
=
bcx_ccx
(
bcx
);
let
tcx
=
bcx_tcx
(
bcx
);
let
ccx
=
bcx
.ccx
(),
tcx
=
ccx
.tcx
;
let
llopaquecboxty
=
T_opaque_box_ptr
(
ccx
);
let
cbox_in
=
Load
(
bcx
,
cboxptr
);
with_cond
(
bcx
,
IsNotNull
(
bcx
,
cbox_in
))
{|
bcx
|
...
...
@@ -657,11 +654,11 @@ fn make_opaque_cbox_drop_glue(
ty
::
ck_block
{
bcx
}
ty
::
ck_box
{
decr_refcnt_maybe_free
(
bcx
,
Load
(
bcx
,
cboxptr
),
ty
::
mk_opaque_closure_ptr
(
bcx
_tcx
(
bcx
),
ck
))
ty
::
mk_opaque_closure_ptr
(
bcx
.tcx
(
),
ck
))
}
ty
::
ck_uniq
{
free_ty
(
bcx
,
Load
(
bcx
,
cboxptr
),
ty
::
mk_opaque_closure_ptr
(
bcx
_tcx
(
bcx
),
ck
))
ty
::
mk_opaque_closure_ptr
(
bcx
.tcx
(
),
ck
))
}
}
}
...
...
@@ -676,8 +673,7 @@ fn make_opaque_cbox_free_glue(
ty
::
ck_box
|
ty
::
ck_uniq
{
/* hard cases: */
}
}
let
ccx
=
bcx_ccx
(
bcx
);
let
tcx
=
bcx_tcx
(
bcx
);
let
ccx
=
bcx
.ccx
(),
tcx
=
ccx
.tcx
;
with_cond
(
bcx
,
IsNotNull
(
bcx
,
cbox
))
{|
bcx
|
// Load the type descr found in the cbox
let
lltydescty
=
T_ptr
(
ccx
.tydesc_type
);
...
...
@@ -862,7 +858,7 @@ fn trans_bind_thunk(ccx: @crate_ctxt,
fcx
.lltyparams
+=
[{
desc
:
dsc
,
dicts
:
dicts
}];
}
let
a
:
uint
=
2u
;
// retptr, env come first
let
a
:
uint
=
first_tp_arg
;
// retptr, env come first
let
b
:
int
=
starting_idx
;
let
outgoing_arg_index
:
uint
=
0u
;
let
llout_arg_tys
:
[
TypeRef
]
=
...
...
src/comp/middle/trans/common.rs
浏览文件 @
789a1ae3
...
...
@@ -68,10 +68,6 @@ fn new_namegen() -> namegen {
// Crate context. Every crate we compile has one of these.
type
crate_ctxt
=
// A mapping from the def_id of each item in this crate to the address
// of the first instruction of the item's definition in the executable
// we're generating.
// TODO: hashmap<tup(tag_id,subtys), @tag_info>
{
sess
:
session
::
session
,
llmod
:
ModuleRef
,
td
:
target_data
,
...
...
@@ -233,14 +229,14 @@ fn scope_clean_changed(info: scope_info) {
}
fn
add_clean
(
cx
:
block
,
val
:
ValueRef
,
ty
:
ty
::
t
)
{
if
!
ty
::
type_needs_drop
(
bcx_tcx
(
cx
),
ty
)
{
ret
;
}
if
!
ty
::
type_needs_drop
(
cx
.tcx
(
),
ty
)
{
ret
;
}
in_scope_cx
(
cx
)
{|
info
|
info
.cleanups
+=
[
clean
(
bind
drop_ty
(
_
,
val
,
ty
))];
scope_clean_changed
(
info
);
}
}
fn
add_clean_temp
(
cx
:
block
,
val
:
ValueRef
,
ty
:
ty
::
t
)
{
if
!
ty
::
type_needs_drop
(
bcx_tcx
(
cx
),
ty
)
{
ret
;
}
if
!
ty
::
type_needs_drop
(
cx
.tcx
(
),
ty
)
{
ret
;
}
fn
do_drop
(
bcx
:
block
,
val
:
ValueRef
,
ty
:
ty
::
t
)
->
block
{
if
ty
::
type_is_immediate
(
ty
)
{
...
...
@@ -255,7 +251,7 @@ fn do_drop(bcx: block, val: ValueRef, ty: ty::t) ->
}
}
fn
add_clean_temp_mem
(
cx
:
block
,
val
:
ValueRef
,
ty
:
ty
::
t
)
{
if
!
ty
::
type_needs_drop
(
bcx_tcx
(
cx
),
ty
)
{
ret
;
}
if
!
ty
::
type_needs_drop
(
cx
.tcx
(
),
ty
)
{
ret
;
}
in_scope_cx
(
cx
)
{|
info
|
info
.cleanups
+=
[
clean_temp
(
val
,
bind
drop_ty
(
_
,
val
,
ty
))];
scope_clean_changed
(
info
);
...
...
@@ -365,6 +361,9 @@ enum loop_cont { cont_self, cont_other(block), }
fcx
:
@
fn_ctxt
};
// First two args are retptr, env
const
first_tp_arg
:
uint
=
2u
;
// FIXME: we should be able to use option<@block_parent> here but
// the infinite-enum check in rustboot gets upset.
enum
block_parent
{
parent_none
,
parent_some
(
block
),
}
...
...
@@ -409,14 +408,12 @@ fn block_parent(cx: block) -> block {
}
// Accessors
// TODO: When we have overloading, simplify these names!
pure
fn
bcx_tcx
(
bcx
:
block
)
->
ty
::
ctxt
{
ret
bcx
.fcx.ccx.tcx
;
}
pure
fn
bcx_ccx
(
bcx
:
block
)
->
@
crate_ctxt
{
ret
bcx
.fcx.ccx
;
}
pure
fn
bcx_fcx
(
bcx
:
block
)
->
@
fn_ctxt
{
ret
bcx
.fcx
;
}
pure
fn
fcx_ccx
(
fcx
:
@
fn_ctxt
)
->
@
crate_ctxt
{
ret
fcx
.ccx
;
}
pure
fn
fcx_tcx
(
fcx
:
@
fn_ctxt
)
->
ty
::
ctxt
{
ret
fcx
.ccx.tcx
;
}
pure
fn
ccx_tcx
(
ccx
:
@
crate_ctxt
)
->
ty
::
ctxt
{
ret
ccx
.tcx
;
}
impl
bxc_cxs
for
block
{
fn
ccx
()
->
@
crate_ctxt
{
self
.fcx.ccx
}
fn
tcx
()
->
ty
::
ctxt
{
self
.fcx.ccx.tcx
}
fn
sess
()
->
session
{
self
.fcx.ccx.sess
}
}
// LLVM type constructors.
fn
T_void
()
->
TypeRef
{
...
...
@@ -611,7 +608,7 @@ fn T_array(t: TypeRef, n: uint) -> TypeRef {
// Interior vector.
//
//
TODO
: Support user-defined vector sizes.
//
FIXME
: Support user-defined vector sizes.
fn
T_vec2
(
targ_cfg
:
@
session
::
config
,
t
:
TypeRef
)
->
TypeRef
{
ret
T_struct
([
T_int
(
targ_cfg
),
// fill
T_int
(
targ_cfg
),
// alloc
...
...
@@ -850,7 +847,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
// change. (We're not adding new variants during trans.)
unchecked
{
let
variant
=
ty
::
enum_variant_with_id
(
bcx_tcx
(
cx
),
enum_id
,
variant_id
);
ty
::
enum_variant_with_id
(
cx
.tcx
(
),
enum_id
,
variant_id
);
ix
<
variant
.args
.len
()
}
}
...
...
@@ -897,7 +894,7 @@ fn umin(cx: block, a: ValueRef, b: ValueRef) -> ValueRef {
}
fn
align_to
(
cx
:
block
,
off
:
ValueRef
,
align
:
ValueRef
)
->
ValueRef
{
let
mask
=
build
::
Sub
(
cx
,
align
,
C_int
(
bcx_ccx
(
cx
),
1
));
let
mask
=
build
::
Sub
(
cx
,
align
,
C_int
(
cx
.ccx
(
),
1
));
let
bumped
=
build
::
Add
(
cx
,
off
,
mask
);
ret
build
::
And
(
cx
,
bumped
,
build
::
Not
(
cx
,
mask
));
}
...
...
@@ -915,7 +912,7 @@ fn path_str(p: path) -> str {
}
fn
node_id_type
(
bcx
:
block
,
id
:
ast
::
node_id
)
->
ty
::
t
{
let
tcx
=
bcx
_tcx
(
bcx
);
let
tcx
=
bcx
.tcx
(
);
let
t
=
ty
::
node_id_to_type
(
tcx
,
id
);
alt
bcx
.fcx.param_substs
{
some
(
substs
)
{
ty
::
substitute_type_params
(
tcx
,
substs
.tys
,
t
)
}
...
...
@@ -926,7 +923,7 @@ fn expr_ty(bcx: block, ex: @ast::expr) -> ty::t {
node_id_type
(
bcx
,
ex
.id
)
}
fn
node_id_type_params
(
bcx
:
block
,
id
:
ast
::
node_id
)
->
[
ty
::
t
]
{
let
tcx
=
bcx
_tcx
(
bcx
);
let
tcx
=
bcx
.tcx
(
);
let
params
=
ty
::
node_id_to_type_params
(
tcx
,
id
);
alt
bcx
.fcx.param_substs
{
some
(
substs
)
{
...
...
src/comp/middle/trans/debuginfo.rs
浏览文件 @
789a1ae3
...
...
@@ -225,7 +225,7 @@ fn line_from_span(cm: codemap::codemap, sp: span) -> uint {
}
fn
create_block
(
cx
:
block
)
->
@
metadata
<
block_md
>
{
let
cache
=
get_cache
(
bcx_ccx
(
cx
));
let
cache
=
get_cache
(
cx
.ccx
(
));
let
cx
=
cx
;
while
option
::
is_none
(
cx
.block_span
)
{
alt
cx
.parent
{
...
...
@@ -235,10 +235,10 @@ fn create_block(cx: block) -> @metadata<block_md> {
}
let
sp
=
option
::
get
(
cx
.block_span
);
let
start
=
codemap
::
lookup_char_pos
(
bcx_ccx
(
cx
)
.sess
.codemap
,
let
start
=
codemap
::
lookup_char_pos
(
cx
.sess
()
.codemap
,
sp
.lo
);
let
fname
=
start
.file.name
;
let
end
=
codemap
::
lookup_char_pos
(
bcx_ccx
(
cx
)
.sess
.codemap
,
let
end
=
codemap
::
lookup_char_pos
(
cx
.sess
()
.codemap
,
sp
.hi
);
let
tg
=
LexicalBlockTag
;
/*alt cached_metadata::<@metadata<block_md>>(
...
...
@@ -252,7 +252,7 @@ fn create_block(cx: block) -> @metadata<block_md> {
parent_none
{
create_function
(
cx
.fcx
)
.node
}
parent_some
(
bcx
)
{
create_block
(
bcx
)
.node
}
};
let
file_node
=
create_file
(
bcx_ccx
(
cx
),
fname
);
let
file_node
=
create_file
(
cx
.ccx
(
),
fname
);
let
unique_id
=
alt
cache
.find
(
LexicalBlockTag
)
{
option
::
some
(
v
)
{
vec
::
len
(
v
)
as
int
}
option
::
none
{
0
}
...
...
@@ -434,11 +434,10 @@ fn create_boxed_type(cx: @crate_ctxt, outer: ty::t, _inner: ty::t,
let
fname
=
filename_from_span
(
cx
,
span
);
let
file_node
=
create_file
(
cx
,
fname
);
//let cu_node = create_compile_unit_metadata(cx, fname);
let
tcx
=
ccx_tcx
(
cx
);
let
uint_t
=
ty
::
mk_uint
(
tcx
);
let
uint_t
=
ty
::
mk_uint
(
cx
.tcx
);
let
refcount_type
=
create_basic_type
(
cx
,
uint_t
,
ast
::
ty_uint
(
ast
::
ty_u
),
span
);
let
scx
=
create_structure
(
file_node
,
ty_to_str
(
c
cx_tcx
(
cx
)
,
outer
),
0
);
let
scx
=
create_structure
(
file_node
,
ty_to_str
(
c
x
.tcx
,
outer
),
0
);
add_member
(
scx
,
"refcnt"
,
0
,
sys
::
size_of
::
<
uint
>
()
as
int
,
sys
::
align_of
::
<
uint
>
()
as
int
,
refcount_type
.node
);
add_member
(
scx
,
"boxed"
,
0
,
8
,
//XXX member_size_and_align(??)
...
...
@@ -487,16 +486,15 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
let
fname
=
filename_from_span
(
cx
,
vec_ty_span
);
let
file_node
=
create_file
(
cx
,
fname
);
let
elem_ty_md
=
create_ty
(
cx
,
elem_t
,
elem_ty
);
let
tcx
=
ccx_tcx
(
cx
);
let
scx
=
create_structure
(
file_node
,
ty_to_str
(
tcx
,
vec_t
),
0
);
let
size_t_type
=
create_basic_type
(
cx
,
ty
::
mk_uint
(
tcx
),
let
scx
=
create_structure
(
file_node
,
ty_to_str
(
cx
.tcx
,
vec_t
),
0
);
let
size_t_type
=
create_basic_type
(
cx
,
ty
::
mk_uint
(
cx
.tcx
),
ast
::
ty_uint
(
ast
::
ty_u
),
vec_ty_span
);
add_member
(
scx
,
"fill"
,
0
,
sys
::
size_of
::
<
ctypes
::
size_t
>
()
as
int
,
sys
::
align_of
::
<
ctypes
::
size_t
>
()
as
int
,
size_t_type
.node
);
add_member
(
scx
,
"alloc"
,
0
,
sys
::
size_of
::
<
ctypes
::
size_t
>
()
as
int
,
sys
::
align_of
::
<
ctypes
::
size_t
>
()
as
int
,
size_t_type
.node
);
let
subrange
=
llmdnode
([
lltag
(
SubrangeTag
),
lli64
(
0
),
lli64
(
0
)]);
let
(
arr_size
,
arr_align
)
=
member_size_and_align
(
tcx
,
elem_ty
);
let
(
arr_size
,
arr_align
)
=
member_size_and_align
(
cx
.
tcx
,
elem_ty
);
let
data_ptr
=
create_composite_type
(
ArrayTypeTag
,
""
,
file_node
.node
,
0
,
arr_size
,
arr_align
,
0
,
option
::
some
(
elem_ty_md
.node
),
...
...
@@ -640,14 +638,14 @@ fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: span) -> @ast::ty {
}
ast::ty_vec(mt) {
let inner_t = ty::sequence_element_type(c
cx_tcx(cx)
, t);
let inner_t = ty::sequence_element_type(c
x.tcx
, t);
let inner_ast_t = t_to_ty(cx, inner_t, mt.ty.span);
let v = create_vec(cx, t, inner_t, ty.span, inner_ast_t);
ret create_pointer_type(cx, t, ty.span, v);
}
ast::ty_path(_, id) {
alt c
cx_tcx(cx)
.def_map.get(id) {
alt c
x.tcx
.def_map.get(id) {
ast::def_prim_ty(pty) {
ret create_basic_type(cx, t, pty, ty.span);
}
...
...
@@ -679,7 +677,7 @@ fn create_var(type_tag: int, context: ValueRef, name: str, file: ValueRef,
fn
create_local_var
(
bcx
:
block
,
local
:
@
ast
::
local
)
->
@
metadata
<
local_var_md
>
unsafe
{
let
cx
=
bcx
_ccx
(
bcx
);
let
cx
=
bcx
.ccx
(
);
let
cache
=
get_cache
(
cx
);
let
tg
=
AutoVariableTag
;
alt
cached_metadata
::
<@
metadata
<
local_var_md
>>
(
...
...
@@ -688,10 +686,10 @@ fn create_local_var(bcx: block, local: @ast::local)
option
::
none
{}
}
let
name
=
path_to_ident
(
alt
pat_util
::
normalize_pat
(
bcx
_tcx
(
bcx
),
let
name
=
path_to_ident
(
alt
pat_util
::
normalize_pat
(
bcx
.tcx
(
),
local
.node.pat
)
.node
{
ast
::
pat_ident
(
ident
,
_
)
{
ident
/*XXX deal w/ optional node binding*/
}
_
{
bcx
_tcx
(
bcx
)
.sess
.span_bug
(
local
.span
,
"create_local_var:
\
_
{
bcx
.tcx
(
)
.sess
.span_bug
(
local
.span
,
"create_local_var:
\
weird pattern in local"
);
}
});
let
loc
=
codemap
::
lookup_char_pos
(
cx
.sess.codemap
,
...
...
@@ -711,13 +709,13 @@ fn create_local_var(bcx: block, local: @ast::local)
let
llptr
=
alt
bcx
.fcx.lllocals
.find
(
local
.node.id
)
{
option
::
some
(
local_mem
(
v
))
{
v
}
option
::
some
(
_
)
{
bcx
_tcx
(
bcx
)
.sess
.span_bug
(
local
.span
,
"local is bound to
\
bcx
.tcx
(
)
.sess
.span_bug
(
local
.span
,
"local is bound to
\
something weird"
);
}
option
::
none
{
alt
bcx
.fcx.lllocals
.get
(
local
.node.pat.id
)
{
local_imm
(
v
)
{
v
}
_
{
bcx
_tcx
(
bcx
)
.sess
.span_bug
(
local
.span
,
"local is bound to
\
_
{
bcx
.tcx
(
)
.sess
.span_bug
(
local
.span
,
"local is bound to
\
something weird"
);
}
}
}
...
...
@@ -730,8 +728,7 @@ fn create_local_var(bcx: block, local: @ast::local)
fn
create_arg
(
bcx
:
block
,
arg
:
ast
::
arg
,
sp
:
span
)
->
@
metadata
<
argument_md
>
unsafe
{
let
fcx
=
bcx_fcx
(
bcx
);
let
cx
=
fcx_ccx
(
fcx
);
let
fcx
=
bcx
.fcx
,
cx
=
fcx
.ccx
;
let
cache
=
get_cache
(
cx
);
let
tg
=
ArgVariableTag
;
alt
cached_metadata
::
<@
metadata
<
argument_md
>>
(
...
...
@@ -740,9 +737,6 @@ fn create_arg(bcx: block, arg: ast::arg, sp: span)
option
::
none
{}
}
/*let arg_n = alt cx.ast_map.get(arg.id) {
ast_map::node_arg(_, n) { n - 2u }
};*/
let
loc
=
codemap
::
lookup_char_pos
(
cx
.sess.codemap
,
sp
.lo
);
let
ty
=
node_id_type
(
bcx
,
arg
.id
);
...
...
@@ -764,10 +758,10 @@ fn create_arg(bcx: block, arg: ast::arg, sp: span)
}
fn
update_source_pos
(
cx
:
block
,
s
:
span
)
{
if
!
bcx_ccx
(
cx
)
.sess
.opts.debuginfo
{
if
!
cx
.sess
()
.opts.debuginfo
{
ret
;
}
let
cm
=
bcx_ccx
(
cx
)
.sess
.codemap
;
let
cm
=
cx
.sess
()
.codemap
;
let
blockmd
=
create_block
(
cx
);
let
loc
=
codemap
::
lookup_char_pos
(
cm
,
s
.lo
);
let
scopedata
=
[
lli32
(
loc
.line
as
int
),
...
...
@@ -779,7 +773,7 @@ fn update_source_pos(cx: block, s: span) {
}
fn
create_function
(
fcx
:
@
fn_ctxt
)
->
@
metadata
<
subprogram_md
>
{
let
cx
=
fcx
_ccx
(
fcx
)
;
let
cx
=
fcx
.ccx
;
let
dbg_cx
=
option
::
get
(
cx
.dbg_cx
);
#
debug
(
"~~"
);
...
...
@@ -794,7 +788,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
ast
::
item_fn
(
decl
,
_
,
_
)
|
ast
::
item_res
(
decl
,
_
,
_
,
_
,
_
)
{
(
item
.ident
,
decl
.output
,
item
.id
)
}
_
{
fcx
_tcx
(
fcx
)
.sess
.span_bug
(
item
.span
,
"create_function: item
\
_
{
fcx
.ccx
.sess
.span_bug
(
item
.span
,
"create_function: item
\
bound to non-function"
);
}
}
}
...
...
@@ -806,7 +800,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
ast
::
item_res
(
decl
,
_
,
_
,
_
,
ctor_id
)
{
(
item
.ident
,
decl
.output
,
ctor_id
)
}
_
{
fcx
_tcx
(
fcx
)
.sess
.span_bug
(
item
.span
,
"create_function:
\
_
{
fcx
.ccx
.sess
.span_bug
(
item
.span
,
"create_function:
\
expected an item_res here"
);
}
}
}
...
...
@@ -818,11 +812,11 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
ast
::
expr_fn_block
(
decl
,
_
)
{
(
dbg_cx
.names
(
"fn"
),
decl
.output
,
expr
.id
)
}
_
{
fcx
_tcx
(
fcx
)
.sess
.span_bug
(
expr
.span
,
"create_function:
\
_
{
fcx
.ccx
.sess
.span_bug
(
expr
.span
,
"create_function:
\
expected an expr_fn or fn_block here"
);
}
}
}
_
{
fcx
_tcx
(
fcx
)
.sess
.bug
(
"create_function: unexpected
\
_
{
fcx
.ccx
.sess
.bug
(
"create_function: unexpected
\
sort of node"
);
}
};
...
...
@@ -846,8 +840,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
let
ty_node
=
if
cx
.sess.opts.extra_debuginfo
{
alt
ret_ty
.node
{
ast
::
ty_nil
{
llnull
()
}
_
{
create_ty
(
cx
,
ty
::
node_id_to_type
(
ccx_tcx
(
cx
),
id
),
ret_ty
)
.node
}
_
{
create_ty
(
cx
,
ty
::
node_id_to_type
(
cx
.tcx
,
id
),
ret_ty
)
.node
}
}
}
else
{
llnull
()
...
...
src/comp/middle/trans/impl.rs
浏览文件 @
789a1ae3
...
...
@@ -63,7 +63,7 @@ fn trans_self_arg(bcx: block, base: @ast::expr) -> result {
let
basety
=
expr_ty
(
bcx
,
base
);
let
m_by_ref
=
ast
::
expl
(
ast
::
by_ref
);
trans_arg_expr
(
bcx
,
{
mode
:
m_by_ref
,
ty
:
basety
},
T_ptr
(
type_of_or_i8
(
bcx
_ccx
(
bcx
),
basety
)),
base
)
T_ptr
(
type_of_or_i8
(
bcx
.ccx
(
),
basety
)),
base
)
}
fn
trans_method_callee
(
bcx
:
block
,
callee_id
:
ast
::
node_id
,
...
...
@@ -110,7 +110,7 @@ fn wrapper_fn_ty(ccx: @crate_ctxt, dict_ty: TypeRef, fty: ty::t,
fn
trans_vtable_callee
(
bcx
:
block
,
env
:
callee_env
,
dict
:
ValueRef
,
callee_id
:
ast
::
node_id
,
iface_id
:
ast
::
def_id
,
n_method
:
uint
)
->
lval_maybe_callee
{
let
bcx
=
bcx
,
ccx
=
bcx
_ccx
(
bcx
),
tcx
=
ccx
.tcx
;
let
bcx
=
bcx
,
ccx
=
bcx
.ccx
(
),
tcx
=
ccx
.tcx
;
let
method
=
ty
::
iface_methods
(
tcx
,
iface_id
)[
n_method
];
let
{
ty
:
fty
,
llty
:
llfty
}
=
wrapper_fn_ty
(
ccx
,
val_ty
(
dict
),
node_id_type
(
bcx
,
callee_id
),
...
...
@@ -146,7 +146,7 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
substs
:
param_substs
)
->
lval_maybe_callee
{
alt
find_dict_in_fn_ctxt
(
substs
,
n_param
,
n_bound
)
{
typeck
::
dict_static
(
impl_did
,
tys
,
sub_origins
)
{
let
tcx
=
bcx
_tcx
(
bcx
);
let
tcx
=
bcx
.tcx
(
);
if
impl_did
.crate
!=
ast
::
local_crate
{
ret
trans_param_callee
(
bcx
,
callee_id
,
base
,
iface_id
,
n_method
,
n_param
,
n_bound
);
...
...
@@ -296,8 +296,9 @@ fn trans_impl_wrapper(ccx: @crate_ctxt, pt: path,
let
env_ty
=
T_ptr
(
T_struct
([
T_ptr
(
T_i8
())]
+
extra_ptrs
));
let
n_extra_ptrs
=
extra_ptrs
.len
();
let
wrap_args
=
[
T_ptr
(
T_dict
())]
+
vec
::
slice
(
real_args
,
0u
,
2u
)
+
vec
::
slice
(
real_args
,
2u
+
n_extra_ptrs
,
real_args
.len
());
let
wrap_args
=
[
T_ptr
(
T_dict
())]
+
vec
::
slice
(
real_args
,
0u
,
first_tp_arg
)
+
vec
::
slice
(
real_args
,
first_tp_arg
+
n_extra_ptrs
,
real_args
.len
());
let
llfn_ty
=
T_fn
(
wrap_args
,
real_ret
);
trans_wrapper
(
ccx
,
pt
,
llfn_ty
,
{|
llfn
,
bcx
|
let
dict
=
PointerCast
(
bcx
,
LLVMGetParam
(
llfn
,
0
as
c_uint
),
env_ty
);
...
...
@@ -397,7 +398,7 @@ fn dict_is_static(tcx: ty::ctxt, origin: typeck::dict_origin) -> bool {
}
fn
get_dict
(
bcx
:
block
,
origin
:
typeck
::
dict_origin
)
->
result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
alt
origin
{
typeck
::
dict_static
(
impl_did
,
tys
,
sub_origins
)
{
if
dict_is_static
(
ccx
.tcx
,
origin
)
{
...
...
@@ -455,7 +456,7 @@ fn dict_id(tcx: ty::ctxt, origin: typeck::dict_origin) -> dict_id {
fn
get_static_dict
(
bcx
:
block
,
origin
:
typeck
::
dict_origin
)
->
ValueRef
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
id
=
dict_id
(
ccx
.tcx
,
origin
);
alt
ccx
.dicts
.find
(
id
)
{
some
(
d
)
{
ret
d
;
}
...
...
@@ -476,7 +477,7 @@ fn get_static_dict(bcx: block, origin: typeck::dict_origin)
fn
get_dict_ptrs
(
bcx
:
block
,
origin
:
typeck
::
dict_origin
)
->
{
bcx
:
block
,
ptrs
:
[
ValueRef
]}
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
fn
get_vtable
(
ccx
:
@
crate_ctxt
,
did
:
ast
::
def_id
)
->
ValueRef
{
if
did
.crate
==
ast
::
local_crate
{
ccx
.item_ids
.get
(
did
.node
)
...
...
@@ -512,7 +513,7 @@ fn get_vtable(ccx: @crate_ctxt, did: ast::def_id) -> ValueRef {
{
bcx
:
bcx
,
ptrs
:
[
get_vtable
(
ccx
,
did
)]}
}
_
{
bcx
_tcx
(
bcx
)
.sess
.bug
(
"Unexpected dict_param in get_dict_ptrs"
);
bcx
.tcx
(
)
.sess
.bug
(
"Unexpected dict_param in get_dict_ptrs"
);
}
}
}
...
...
@@ -520,7 +521,7 @@ fn get_vtable(ccx: @crate_ctxt, did: ast::def_id) -> ValueRef {
fn
trans_cast
(
bcx
:
block
,
val
:
@
ast
::
expr
,
id
:
ast
::
node_id
,
dest
:
dest
)
->
block
{
if
dest
==
ignore
{
ret
trans_expr
(
bcx
,
val
,
ignore
);
}
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
v_ty
=
expr_ty
(
bcx
,
val
);
let
{
bcx
,
box
,
body
}
=
trans_malloc_boxed
(
bcx
,
v_ty
);
add_clean_free
(
bcx
,
box
,
false
);
...
...
src/comp/middle/trans/native.rs
浏览文件 @
789a1ae3
...
...
@@ -214,7 +214,7 @@ fn build_args(bcx: block, tys: @c_stack_tys,
llwrapfn
:
ValueRef
,
llargbundle
:
ValueRef
,
num_tps
:
uint
)
{
let
i
=
0u
,
n
=
vec
::
len
(
tys
.arg_tys
);
let
implicit_args
=
2u
+
num_tps
;
// ret + env
let
implicit_args
=
first_tp_arg
+
num_tps
;
// ret + env
while
i
<
n
{
let
llargval
=
llvm
::
LLVMGetParam
(
llwrapfn
,
...
...
@@ -290,7 +290,7 @@ fn build_args(bcx: block, tys: @c_stack_tys,
let
n
=
vec
::
len
(
tys
.arg_tys
);
let
llretptr
=
load_inbounds
(
bcx
,
llargbundle
,
[
0
,
n
as
int
]);
llargvals
+=
[
llretptr
];
let
llenvptr
=
C_null
(
T_opaque_box_ptr
(
bcx
_ccx
(
bcx
)));
let
llenvptr
=
C_null
(
T_opaque_box_ptr
(
bcx
.ccx
(
)));
llargvals
+=
[
llenvptr
];
while
i
<
n
{
let
llargval
=
load_inbounds
(
bcx
,
llargbundle
,
[
0
,
i
as
int
]);
...
...
src/comp/middle/trans/shape.rs
浏览文件 @
789a1ae3
...
...
@@ -6,11 +6,7 @@
import
driver
::
session
;
import
driver
::
session
::
session
;
import
trans
::
base
;
import
middle
::
trans
::
common
::{
crate_ctxt
,
val_ty
,
C_bytes
,
C_int
,
C_named_struct
,
C_struct
,
T_enum_variant
,
block
,
result
,
rslt
,
bcx_ccx
,
bcx_tcx
,
type_has_static_size
,
umax
,
umin
,
align_to
,
tydesc_info
};
import
middle
::
trans
::
common
::
*
;
import
back
::
abi
;
import
middle
::
ty
;
import
middle
::
ty
::
field
;
...
...
@@ -102,12 +98,12 @@ fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
// alignment at least as large as any other variant of the enum. This is an
// important performance optimization.
//
//
TODO
: Use this in dynamic_size_of() as well.
//
FIXME
: Use this in dynamic_size_of() as well.
fn
largest_variants
(
ccx
:
@
crate_ctxt
,
tag_id
:
ast
::
def_id
)
->
[
uint
]
{
// Compute the minimum and maximum size and alignment for each variant.
//
//
TODO
: We could do better here; e.g. we know that any variant that
//
FIXME
: We could do better here; e.g. we know that any variant that
// contains (T,T) must be as least as large as any variant that contains
// just T.
let
ranges
=
[];
...
...
@@ -117,7 +113,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
let
{
a
:
min_size
,
b
:
min_align
}
=
{
a
:
0u
,
b
:
0u
};
for
elem_t
:
ty
::
t
in
variant
.args
{
if
ty
::
type_has_params
(
elem_t
)
{
//
TODO
: We could do better here; this causes us to
//
FIXME
: We could do better here; this causes us to
// conservatively assume that (int, T) has minimum size 0,
// when in fact it has minimum size sizeof(int).
bounded
=
false
;
...
...
@@ -183,7 +179,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
// Computes the static size of a enum, without using mk_tup(), which is
// bad for performance.
//
//
TODO
: Migrate trans over to use this.
//
FIXME
: Migrate trans over to use this.
fn
round_up
(
size
:
u16
,
align
:
u8
)
->
u16
{
assert
(
align
>=
1u8
);
...
...
@@ -606,7 +602,7 @@ fn gen_shape_tables(ccx: @crate_ctxt) {
};
fn
size_of
(
bcx
:
block
,
t
:
ty
::
t
)
->
result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
check
type_has_static_size
(
ccx
,
t
)
{
rslt
(
bcx
,
llsize_of
(
ccx
,
base
::
type_of
(
ccx
,
t
)))
}
else
{
...
...
@@ -616,7 +612,7 @@ fn size_of(bcx: block, t: ty::t) -> result {
}
fn
align_of
(
bcx
:
block
,
t
:
ty
::
t
)
->
result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
check
type_has_static_size
(
ccx
,
t
)
{
rslt
(
bcx
,
llalign_of
(
ccx
,
base
::
type_of
(
ccx
,
t
)))
}
else
{
...
...
@@ -626,7 +622,7 @@ fn align_of(bcx: block, t: ty::t) -> result {
}
fn
metrics
(
bcx
:
block
,
t
:
ty
::
t
)
->
metrics
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
if
check
type_has_static_size
(
ccx
,
t
)
{
let
llty
=
base
::
type_of
(
ccx
,
t
);
{
bcx
:
bcx
,
sz
:
llsize_of
(
ccx
,
llty
),
align
:
llalign_of
(
ccx
,
llty
)
}
...
...
@@ -699,8 +695,8 @@ fn align_elements(cx: block, elts: [ty::t]) -> metrics {
// is aligned to max alignment of interior.
//
let
off
=
C_int
(
bcx_ccx
(
cx
),
0
);
let
max_align
=
C_int
(
bcx_ccx
(
cx
),
1
);
let
off
=
C_int
(
cx
.ccx
(
),
0
);
let
max_align
=
C_int
(
cx
.ccx
(
),
1
);
let
bcx
=
cx
;
for
e
:
ty
::
t
in
elts
{
let
elt_align
=
align_of
(
bcx
,
e
);
...
...
@@ -734,17 +730,17 @@ fn align_elements(cx: block, elts: [ty::t]) -> metrics {
}
ty
::
ty_enum
(
tid
,
tps
)
{
let
bcx
=
cx
;
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
compute_max_variant_size
=
fn
@
(
bcx
:
block
)
->
result
{
// Compute max(variant sizes).
let
bcx
=
bcx
;
let
max_size
:
ValueRef
=
C_int
(
ccx
,
0
);
let
variants
=
ty
::
enum_variants
(
bcx
_tcx
(
bcx
),
tid
);
let
variants
=
ty
::
enum_variants
(
bcx
.tcx
(
),
tid
);
for
variant
:
ty
::
variant_info
in
*
variants
{
// Perform type substitution on the raw argument types.
let
tys
=
vec
::
map
(
variant
.args
)
{|
raw_ty
|
ty
::
substitute_type_params
(
bcx_tcx
(
cx
),
tps
,
raw_ty
)
ty
::
substitute_type_params
(
cx
.tcx
(
),
tps
,
raw_ty
)
};
let
rslt
=
align_elements
(
bcx
,
tys
);
bcx
=
rslt
.bcx
;
...
...
@@ -766,7 +762,7 @@ fn align_elements(cx: block, elts: [ty::t]) -> metrics {
}
_
{
// Precondition?
bcx_tcx
(
cx
)
.sess
.bug
(
"dynamic_metrics: type has static
\
cx
.tcx
(
)
.sess
.bug
(
"dynamic_metrics: type has static
\
size"
);
}
}
...
...
@@ -802,7 +798,7 @@ fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
//fn tag_payload_offs(bcx: block, tag_id: ast::def_id, tps: [ty::t])
// -> ValueRef {
// alt tag_kind(tag_id) {
// tk_unit | tk_enum | tk_newtype { C_int(bcx
_ccx(bcx
), 0) }
// tk_unit | tk_enum | tk_newtype { C_int(bcx
.ccx(
), 0) }
// tk_complex {
// compute_tag_metrics(tag_id, tps)
// }
...
...
src/comp/middle/trans/tvec.rs
浏览文件 @
789a1ae3
...
...
@@ -26,7 +26,7 @@ fn pointer_add(bcx: block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
}
fn
alloc_raw
(
bcx
:
block
,
fill
:
ValueRef
,
alloc
:
ValueRef
)
->
result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
llvecty
=
ccx
.opaque_vec_type
;
let
vecsize
=
Add
(
bcx
,
alloc
,
llsize_of
(
ccx
,
llvecty
));
let
{
bcx
:
bcx
,
val
:
vecptr
}
=
...
...
@@ -44,8 +44,8 @@ fn alloc_raw(bcx: block, fill: ValueRef, alloc: ValueRef) -> result {
llunitty
:
TypeRef
};
fn
alloc
(
bcx
:
block
,
vec_ty
:
ty
::
t
,
elts
:
uint
)
->
alloc_result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
_tcx
(
bcx
),
vec_ty
);
let
ccx
=
bcx
.ccx
(
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(
),
vec_ty
);
let
llunitty
=
type_of_or_i8
(
ccx
,
unit_ty
);
let
llvecty
=
T_vec
(
ccx
,
llunitty
);
let
{
bcx
:
bcx
,
val
:
unit_sz
}
=
size_of
(
bcx
,
unit_ty
);
...
...
@@ -67,22 +67,22 @@ fn alloc(bcx: block, vec_ty: ty::t, elts: uint) -> alloc_result {
}
fn
duplicate
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
)
->
result
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
fill
=
get_fill
(
bcx
,
vptr
);
let
size
=
Add
(
bcx
,
fill
,
llsize_of
(
ccx
,
ccx
.opaque_vec_type
));
let
{
bcx
:
bcx
,
val
:
newptr
}
=
trans_shared_malloc
(
bcx
,
val_ty
(
vptr
),
size
);
let
bcx
=
call_memmove
(
bcx
,
newptr
,
vptr
,
size
)
.bcx
;
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
_tcx
(
bcx
),
vec_ty
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(
),
vec_ty
);
Store
(
bcx
,
fill
,
GEPi
(
bcx
,
newptr
,
[
0
,
abi
::
vec_elt_alloc
]));
if
ty
::
type_needs_drop
(
bcx
_tcx
(
bcx
),
unit_ty
)
{
if
ty
::
type_needs_drop
(
bcx
.tcx
(
),
unit_ty
)
{
bcx
=
iter_vec
(
bcx
,
newptr
,
vec_ty
,
base
::
take_ty
);
}
ret
rslt
(
bcx
,
newptr
);
}
fn
make_free_glue
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
)
->
block
{
let
tcx
=
bcx
_tcx
(
bcx
),
unit_ty
=
ty
::
sequence_element_type
(
tcx
,
vec_ty
);
let
tcx
=
bcx
.tcx
(
),
unit_ty
=
ty
::
sequence_element_type
(
tcx
,
vec_ty
);
base
::
with_cond
(
bcx
,
IsNotNull
(
bcx
,
vptr
))
{|
bcx
|
let
bcx
=
if
ty
::
type_needs_drop
(
tcx
,
unit_ty
)
{
iter_vec
(
bcx
,
vptr
,
vec_ty
,
base
::
drop_ty
)
...
...
@@ -93,7 +93,7 @@ fn make_free_glue(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
fn
trans_vec
(
bcx
:
block
,
args
:
[
@
ast
::
expr
],
id
:
ast
::
node_id
,
dest
:
dest
)
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
),
bcx
=
bcx
;
let
ccx
=
bcx
.ccx
(
),
bcx
=
bcx
;
if
dest
==
base
::
ignore
{
for
arg
in
args
{
bcx
=
base
::
trans_expr
(
bcx
,
arg
,
base
::
ignore
);
...
...
@@ -113,7 +113,7 @@ fn trans_vec(bcx: block, args: [@ast::expr], id: ast::node_id,
let
dataptr
=
get_dataptr
(
bcx
,
vptr
,
llunitty
);
let
i
=
0u
,
temp_cleanups
=
[
vptr
];
for
e
in
args
{
let
lleltptr
=
if
ty
::
type_has_dynamic_size
(
bcx
_tcx
(
bcx
),
unit_ty
)
{
let
lleltptr
=
if
ty
::
type_has_dynamic_size
(
bcx
.tcx
(
),
unit_ty
)
{
InBoundsGEP
(
bcx
,
dataptr
,
[
Mul
(
bcx
,
C_uint
(
ccx
,
i
),
llunitsz
)])
}
else
{
InBoundsGEP
(
bcx
,
dataptr
,
[
C_uint
(
ccx
,
i
)])
};
bcx
=
base
::
trans_expr_save_in
(
bcx
,
e
,
lleltptr
);
...
...
@@ -128,9 +128,9 @@ fn trans_vec(bcx: block, args: [@ast::expr], id: ast::node_id,
fn
trans_str
(
bcx
:
block
,
s
:
str
,
dest
:
dest
)
->
block
{
let
veclen
=
str
::
len_bytes
(
s
)
+
1u
;
// +1 for \0
let
{
bcx
:
bcx
,
val
:
sptr
,
_
}
=
alloc
(
bcx
,
ty
::
mk_str
(
bcx
_tcx
(
bcx
)),
veclen
);
alloc
(
bcx
,
ty
::
mk_str
(
bcx
.tcx
(
)),
veclen
);
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
llcstr
=
C_cstr
(
ccx
,
s
);
let
bcx
=
call_memmove
(
bcx
,
get_dataptr
(
bcx
,
sptr
,
T_i8
()),
llcstr
,
...
...
@@ -141,9 +141,9 @@ fn trans_str(bcx: block, s: str, dest: dest) -> block {
fn
trans_append
(
cx
:
block
,
vec_ty
:
ty
::
t
,
lhsptr
:
ValueRef
,
rhs
:
ValueRef
)
->
block
{
// Cast to opaque interior vector types if necessary.
let
ccx
=
bcx_ccx
(
cx
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx_tcx
(
cx
),
vec_ty
);
let
dynamic
=
ty
::
type_has_dynamic_size
(
bcx_tcx
(
cx
),
unit_ty
);
let
ccx
=
cx
.ccx
(
);
let
unit_ty
=
ty
::
sequence_element_type
(
cx
.tcx
(
),
vec_ty
);
let
dynamic
=
ty
::
type_has_dynamic_size
(
cx
.tcx
(
),
unit_ty
);
let
(
lhsptr
,
rhs
)
=
if
!
dynamic
{
(
lhsptr
,
rhs
)
...
...
@@ -156,7 +156,7 @@ fn trans_append(cx: block, vec_ty: ty::t, lhsptr: ValueRef,
ty
::
ty_vec
(
_
)
{
false
}
_
{
// precondition?
bcx_tcx
(
cx
)
.sess
.bug
(
"Bad argument type in trans_append"
);
cx
.tcx
(
)
.sess
.bug
(
"Bad argument type in trans_append"
);
}
};
...
...
@@ -171,7 +171,7 @@ fn trans_append(cx: block, vec_ty: ty::t, lhsptr: ValueRef,
if
strings
{
new_fill
=
Sub
(
bcx
,
new_fill
,
C_int
(
ccx
,
1
));
}
let
opaque_lhs
=
PointerCast
(
bcx
,
lhsptr
,
T_ptr
(
T_ptr
(
ccx
.opaque_vec_type
)));
Call
(
bcx
,
bcx_ccx
(
cx
)
.upcalls.vec_grow
,
Call
(
bcx
,
cx
.ccx
(
)
.upcalls.vec_grow
,
[
opaque_lhs
,
new_fill
]);
// Was overwritten if we resized
let
lhs
=
Load
(
bcx
,
lhsptr
);
...
...
@@ -204,8 +204,8 @@ fn trans_append(cx: block, vec_ty: ty::t, lhsptr: ValueRef,
fn
trans_append_literal
(
bcx
:
block
,
vptrptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
vals
:
[
@
ast
::
expr
])
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
elt_ty
=
ty
::
sequence_element_type
(
bcx
_tcx
(
bcx
),
vec_ty
);
let
ccx
=
bcx
.ccx
(
);
let
elt_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(
),
vec_ty
);
let
ti
=
none
;
let
{
bcx
:
bcx
,
val
:
td
}
=
get_tydesc
(
bcx
,
elt_ty
,
false
,
ti
);
base
::
lazily_emit_tydesc_glue
(
ccx
,
abi
::
tydesc_field_take_glue
,
ti
);
...
...
@@ -217,7 +217,7 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
let
r
=
base
::
spill_if_immediate
(
bcx
,
elt
,
elt_ty
);
let
spilled
=
r
.val
;
bcx
=
r
.bcx
;
Call
(
bcx
,
bcx
_ccx
(
bcx
)
.upcalls.vec_push
,
Call
(
bcx
,
bcx
.ccx
(
)
.upcalls.vec_push
,
[
opaque_v
,
td
,
PointerCast
(
bcx
,
spilled
,
T_ptr
(
T_i8
()))]);
}
ret
bcx
;
...
...
@@ -225,12 +225,12 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
fn
trans_add
(
bcx
:
block
,
vec_ty
:
ty
::
t
,
lhs
:
ValueRef
,
rhs
:
ValueRef
,
dest
:
dest
)
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
strings
=
alt
ty
::
get
(
vec_ty
)
.struct
{
ty
::
ty_str
{
true
}
_
{
false
}
};
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
_tcx
(
bcx
),
vec_ty
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(
),
vec_ty
);
let
llunitty
=
type_of_or_i8
(
ccx
,
unit_ty
);
let
{
bcx
:
bcx
,
val
:
llunitsz
}
=
size_of
(
bcx
,
unit_ty
);
...
...
@@ -245,12 +245,12 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
(
bcx
,
get_dataptr
(
bcx
,
new_vec_ptr
,
llunitty
));
let
copy_fn
=
fn
@
(
bcx
:
block
,
addr
:
ValueRef
,
_
ty
:
ty
::
t
)
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
ccx
=
bcx
.ccx
(
);
let
write_ptr
=
Load
(
bcx
,
write_ptr_ptr
);
let
bcx
=
copy_val
(
bcx
,
INIT
,
write_ptr
,
load_if_immediate
(
bcx
,
addr
,
unit_ty
),
unit_ty
);
let
incr
=
if
ty
::
type_has_dynamic_size
(
bcx
_tcx
(
bcx
),
unit_ty
)
{
if
ty
::
type_has_dynamic_size
(
bcx
.tcx
(
),
unit_ty
)
{
llunitsz
}
else
{
C_int
(
ccx
,
1
)
...
...
@@ -271,15 +271,15 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
fn
iter_vec_raw
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
fill
:
ValueRef
,
f
:
iter_vec_block
)
->
block
{
let
ccx
=
bcx
_ccx
(
bcx
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
_tcx
(
bcx
),
vec_ty
);
let
ccx
=
bcx
.ccx
(
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(
),
vec_ty
);
let
llunitty
=
type_of_or_i8
(
ccx
,
unit_ty
);
let
{
bcx
:
bcx
,
val
:
unit_sz
}
=
size_of
(
bcx
,
unit_ty
);
let
vptr
=
PointerCast
(
bcx
,
vptr
,
T_ptr
(
T_vec
(
ccx
,
llunitty
)));
let
data_ptr
=
get_dataptr
(
bcx
,
vptr
,
llunitty
);
// Calculate the last pointer address we want to handle.
//
TODO
: Optimize this when the size of the unit type is statically
//
FIXME
: Optimize this when the size of the unit type is statically
// known to not use pointer casts, which tend to confuse LLVM.
let
data_end_ptr
=
pointer_add
(
bcx
,
data_ptr
,
fill
);
...
...
@@ -294,7 +294,7 @@ fn iter_vec_raw(bcx: block, vptr: ValueRef, vec_ty: ty::t,
CondBr
(
header_cx
,
not_yet_at_end
,
body_cx
.llbb
,
next_cx
.llbb
);
body_cx
=
f
(
body_cx
,
data_ptr
,
unit_ty
);
let
increment
=
if
ty
::
type_has_dynamic_size
(
bcx
_tcx
(
bcx
),
unit_ty
)
{
if
ty
::
type_has_dynamic_size
(
bcx
.tcx
(
),
unit_ty
)
{
unit_sz
}
else
{
C_int
(
ccx
,
1
)
};
AddIncomingToPhi
(
data_ptr
,
InBoundsGEP
(
body_cx
,
data_ptr
,
[
increment
]),
...
...
@@ -305,8 +305,7 @@ fn iter_vec_raw(bcx: block, vptr: ValueRef, vec_ty: ty::t,
fn
iter_vec
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
f
:
iter_vec_block
)
->
block
{
let
ccx
=
bcx_ccx
(
bcx
);
let
vptr
=
PointerCast
(
bcx
,
vptr
,
T_ptr
(
ccx
.opaque_vec_type
));
let
vptr
=
PointerCast
(
bcx
,
vptr
,
T_ptr
(
bcx
.ccx
()
.opaque_vec_type
));
ret
iter_vec_raw
(
bcx
,
vptr
,
vec_ty
,
get_fill
(
bcx
,
vptr
),
f
);
}
...
...
src/comp/middle/trans/uniq.rs
浏览文件 @
789a1ae3
...
...
@@ -24,7 +24,7 @@ fn alloc_uniq(cx: block, uniq_ty: ty::t) -> result {
bcx
=
r
.bcx
;
let
llsz
=
r
.val
;
let
llptrty
=
T_ptr
(
type_of
(
bcx
_ccx
(
bcx
),
contents_ty
));
let
llptrty
=
T_ptr
(
type_of
(
bcx
.ccx
(
),
contents_ty
));
r
=
trans_shared_malloc
(
bcx
,
llptrty
,
llsz
);
bcx
=
r
.bcx
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录