Skip to content

Commit 03e9dac

Browse files
committed
Move various trans_ modules under a trans:: umbrella module
Closes #1304
1 parent b3f06c7 commit 03e9dac

16 files changed

+203
-212
lines changed

src/comp/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import lib::llvm::llvm;
55
import front::attr;
66
import middle::ty;
77
import metadata::{encoder, cstore};
8-
import middle::trans_common::crate_ctxt;
8+
import middle::trans::common::crate_ctxt;
99
import str;
1010
import std::fs;
1111
import vec;

src/comp/back/upcall.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
import driver::session;
3-
import middle::trans;
4-
import middle::trans_common::{T_fn, T_i1, T_i8, T_i32,
5-
T_int, T_nil, T_dict,
6-
T_opaque_vec, T_ptr,
7-
T_size_t, T_void};
3+
import middle::trans::base;
4+
import middle::trans::common::{T_fn, T_i1, T_i8, T_i32,
5+
T_int, T_nil, T_dict,
6+
T_opaque_vec, T_ptr,
7+
T_size_t, T_void};
88
import lib::llvm::type_names;
99
import lib::llvm::llvm::ModuleRef;
1010
import lib::llvm::llvm::ValueRef;
@@ -42,7 +42,7 @@ fn declare_upcalls(targ_cfg: @session::config,
4242
let arg_tys: [TypeRef] = [];
4343
for t: TypeRef in tys { arg_tys += [t]; }
4444
let fn_ty = T_fn(arg_tys, rv);
45-
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
45+
ret base::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
4646
}
4747
let d = bind decl(llmod, _, _, _);
4848
let dv = bind decl(llmod, _, _, T_void());

src/comp/driver/driver.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
177177

178178
let (llmod, link_meta) =
179179
time(time_passes, "translation",
180-
bind trans::trans_crate(sess, crate, ty_cx,
181-
outputs.obj_filename, exp_map, ast_map,
182-
mut_map, copy_map, last_uses, impl_map,
183-
method_map, dict_map));
180+
bind trans::base::trans_crate(
181+
sess, crate, ty_cx, outputs.obj_filename, exp_map, ast_map,
182+
mut_map, copy_map, last_uses, impl_map, method_map,
183+
dict_map));
184184
time(time_passes, "LLVM passes",
185185
bind link::write::run_passes(sess, llmod, outputs.obj_filename));
186186

src/comp/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import syntax::ast::*;
66
import syntax::ast_util;
77
import syntax::ast_util::local_def;
88
import common::*;
9-
import middle::trans_common::crate_ctxt;
9+
import middle::trans::common::crate_ctxt;
1010
import middle::ty;
1111
import middle::ty::node_id_to_monotype;
1212
import front::attr;

src/comp/middle/debuginfo.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import std::fs;
33
import std::map::hashmap;
44
import lib::llvm::llvm;
55
import lib::llvm::llvm::ValueRef;
6-
import middle::trans_common::*;
7-
import middle::trans_build::B;
6+
import trans::common::*;
7+
import trans::base;
8+
import trans::build::B;
89
import middle::ty;
910
import syntax::{ast, codemap};
1011
import codemap::span;
@@ -84,7 +85,7 @@ fn add_named_metadata(cx: @crate_ctxt, name: str, val: ValueRef) {
8485

8586
type debug_ctxt = {
8687
llmetadata: metadata_cache,
87-
names: trans_common::namegen
88+
names: namegen
8889
};
8990

9091
fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) {
@@ -239,8 +240,8 @@ fn create_block(cx: @block_ctxt, sp: span) -> @metadata<block_md> {
239240
}
240241

241242
let parent = alt cx.parent {
242-
trans_common::parent_none { create_function(cx.fcx, sp).node }
243-
trans_common::parent_some(bcx) { create_block(cx, sp).node }
243+
parent_none { create_function(cx.fcx, sp).node }
244+
parent_some(bcx) { create_block(cx, sp).node }
244245
};
245246
let file_node = create_file(bcx_ccx(cx), fname);
246247
let unique_id = alt cache.find(LexicalBlockTag) {
@@ -637,12 +638,12 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
637638
});
638639
let loc = codemap::lookup_char_pos(cx.sess.codemap,
639640
local.span.lo);
640-
let ty = trans::node_id_type(cx, local.node.id);
641+
let ty = base::node_id_type(cx, local.node.id);
641642
let tymd = create_ty(cx, ty, local.node.ty);
642643
let filemd = create_file(cx, loc.filename);
643644
let context = alt bcx.parent {
644-
trans_common::parent_none { create_function(bcx.fcx, local.span).node }
645-
trans_common::parent_some(_) { create_block(bcx, local.span).node }
645+
parent_none { create_function(bcx.fcx, local.span).node }
646+
parent_some(_) { create_block(bcx, local.span).node }
646647
};
647648
let mdnode = create_var(tg, context, name, filemd.node,
648649
loc.line as int, tymd.node);
@@ -658,8 +659,8 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
658659
}
659660
};
660661
let declargs = [llmdnode([llptr]), mdnode];
661-
trans_build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
662-
declargs);
662+
trans::build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
663+
declargs);
663664
ret mdval;
664665
}
665666

@@ -680,7 +681,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
680681
};*/
681682
let loc = codemap::lookup_char_pos(cx.sess.codemap,
682683
sp.lo);
683-
let ty = trans::node_id_type(cx, arg.id);
684+
let ty = base::node_id_type(cx, arg.id);
684685
let tymd = create_ty(cx, ty, arg.ty);
685686
let filemd = create_file(cx, loc.filename);
686687
let context = create_function(bcx.fcx, sp);
@@ -693,8 +694,8 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
693694
local_mem(v) | local_imm(v) { v }
694695
};
695696
let declargs = [llmdnode([llptr]), mdnode];
696-
trans_build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
697-
declargs);
697+
trans::build::Call(bcx, cx.intrinsics.get("llvm.dbg.declare"),
698+
declargs);
698699
ret mdval;
699700
}
700701

@@ -710,7 +711,7 @@ fn update_source_pos(cx: @block_ctxt, s: span) {
710711
blockmd.node,
711712
llnull()];
712713
let dbgscope = llmdnode(scopedata);
713-
llvm::LLVMSetCurrentDebugLocation(trans_build::B(cx), dbgscope);
714+
llvm::LLVMSetCurrentDebugLocation(trans::build::B(cx), dbgscope);
714715
}
715716

716717
fn create_function(fcx: @fn_ctxt, sp: span) -> @metadata<subprogram_md> {

src/comp/middle/gc.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import lib::llvm::True;
44
import lib::llvm::llvm::ValueRef;
5-
import middle::trans;
6-
import middle::trans::get_tydesc;
7-
import middle::trans_common::*;
8-
import middle::ty;
5+
import trans::base::get_tydesc;
6+
import trans::common::*;
7+
import trans::base;
98
import option::none;
109
import str;
1110
import driver::session::session;
1211

1312
import lll = lib::llvm::llvm;
14-
import bld = trans_build;
13+
import bld = trans::build;
1514

1615
type ctxt = @{mutable next_tydesc_num: uint};
1716

@@ -40,7 +39,7 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
4039

4140
// FIXME (issue #839): For now, we are unconditionally zeroing out all
4241
// GC-relevant types. Eventually we should use typestate for this.
43-
bcx = trans::zero_alloca(bcx, llval, ty);
42+
bcx = base::zero_alloca(bcx, llval, ty);
4443

4544
let ti = none;
4645
let td_r = get_tydesc(bcx, ty, false, ti);
@@ -53,10 +52,10 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
5352
alt td_r.kind {
5453
tk_derived {
5554
// It's a derived type descriptor. First, spill it.
56-
let lltydescptr = trans::alloca(bcx, val_ty(lltydesc));
55+
let lltydescptr = base::alloca(bcx, val_ty(lltydesc));
5756

5857
let llderivedtydescs =
59-
trans::llderivedtydescs_block_ctxt(bcx_fcx(bcx));
58+
base::llderivedtydescs_block_ctxt(bcx_fcx(bcx));
6059
bld::Store(llderivedtydescs, lltydesc, lltydescptr);
6160

6261
let number = gc_cx.next_tydesc_num;

src/comp/middle/shape.rs

+26-29
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import lib::llvm::{True, False};
66
import lib::llvm::llvm::{ModuleRef, TypeRef, ValueRef};
77
import driver::session;
88
import driver::session::session;
9-
import middle::{trans, trans_common};
10-
import middle::trans_common::{crate_ctxt, val_ty, C_bytes, C_int,
11-
C_named_struct, C_struct, T_enum_variant,
12-
block_ctxt, result, rslt, bcx_ccx, bcx_tcx,
13-
type_has_static_size, umax, umin, align_to,
14-
tydesc_info};
9+
import trans::base;
10+
import middle::trans::common::{crate_ctxt, val_ty, C_bytes, C_int,
11+
C_named_struct, C_struct, T_enum_variant,
12+
block_ctxt, result, rslt, bcx_ccx, bcx_tcx,
13+
type_has_static_size, umax, umin, align_to,
14+
tydesc_info};
1515
import back::abi;
1616
import middle::ty;
1717
import middle::ty::field;
1818
import syntax::ast;
1919
import syntax::ast_util::dummy_sp;
2020
import syntax::util::interner;
2121
import util::common;
22-
import trans_build::{Load, Store, Add, GEPi};
22+
import trans::build::{Load, Store, Add, GEPi};
2323
import syntax::codemap::span;
2424

2525
import core::{vec, str};
@@ -68,7 +68,7 @@ const shape_tydesc: u8 = 28u8;
6868
const shape_send_tydesc: u8 = 29u8;
6969

7070
// FIXME: This is a bad API in trans_common.
71-
fn C_u8(n: u8) -> ValueRef { ret trans_common::C_u8(n as uint); }
71+
fn C_u8(n: u8) -> ValueRef { ret trans::common::C_u8(n as uint); }
7272

7373
fn hash_res_info(ri: res_info) -> uint {
7474
let h = 5381u;
@@ -134,8 +134,8 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
134134
// follow from how elem_t doesn't contain params.
135135
// (Could add a postcondition to type_contains_params,
136136
// once we implement Issue #586.)
137-
check (trans_common::type_has_static_size(ccx, elem_t));
138-
let llty = trans::type_of(ccx, elem_t);
137+
check (trans::common::type_has_static_size(ccx, elem_t));
138+
let llty = base::type_of(ccx, elem_t);
139139
min_size += llsize_of_real(ccx, llty);
140140
min_align += llalign_of_real(ccx, llty);
141141
}
@@ -213,11 +213,11 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
213213
// FIXME: there should really be a postcondition
214214
// on enum_variants that would obviate the need for
215215
// this check. (Issue #586)
216-
check (trans_common::type_has_static_size(ccx, typ));
217-
lltys += [trans::type_of(ccx, typ)];
216+
check (trans::common::type_has_static_size(ccx, typ));
217+
lltys += [base::type_of(ccx, typ)];
218218
}
219219

220-
let llty = trans_common::T_struct(lltys);
220+
let llty = trans::common::T_struct(lltys);
221221
let dp = llsize_of_real(ccx, llty) as u16;
222222
let variant_align = llalign_of_real(ccx, llty) as u8;
223223

@@ -294,13 +294,10 @@ fn s_send_tydesc(_tcx: ty_ctxt) -> u8 {
294294
}
295295

296296
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
297-
let llshapetablesty = trans_common::T_named_struct("shapes");
298-
let llshapetables =
299-
str::as_buf("shapes",
300-
{|buf|
301-
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty,
302-
buf)
303-
});
297+
let llshapetablesty = trans::common::T_named_struct("shapes");
298+
let llshapetables = str::as_buf("shapes", {|buf|
299+
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty, buf)
300+
});
304301

305302
ret {mutable next_tag_id: 0u16,
306303
pad: 0u16,
@@ -584,7 +581,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
584581
let len = interner::len(ccx.shape_cx.resources);
585582
while i < len {
586583
let ri = interner::get(ccx.shape_cx.resources, i);
587-
dtors += [trans_common::get_res_dtor(ccx, ri.did, ri.t)];
584+
dtors += [trans::common::get_res_dtor(ccx, ri.did, ri.t)];
588585
i += 1u;
589586
}
590587

@@ -594,9 +591,9 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
594591
fn gen_shape_tables(ccx: @crate_ctxt) {
595592
let lltagstable = gen_enum_shapes(ccx);
596593
let llresourcestable = gen_resource_shapes(ccx);
597-
trans_common::set_struct_body(ccx.shape_cx.llshapetablesty,
598-
[val_ty(lltagstable),
599-
val_ty(llresourcestable)]);
594+
trans::common::set_struct_body(ccx.shape_cx.llshapetablesty,
595+
[val_ty(lltagstable),
596+
val_ty(llresourcestable)]);
600597

601598
let lltables =
602599
C_named_struct(ccx.shape_cx.llshapetablesty,
@@ -627,7 +624,7 @@ type tag_metrics = {
627624
fn size_of(bcx: @block_ctxt, t: ty::t) -> result {
628625
let ccx = bcx_ccx(bcx);
629626
if check type_has_static_size(ccx, t) {
630-
rslt(bcx, llsize_of(ccx, trans::type_of(ccx, t)))
627+
rslt(bcx, llsize_of(ccx, base::type_of(ccx, t)))
631628
} else {
632629
let { bcx, sz, align: _ } = dynamic_metrics(bcx, t);
633630
rslt(bcx, sz)
@@ -637,7 +634,7 @@ fn size_of(bcx: @block_ctxt, t: ty::t) -> result {
637634
fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
638635
let ccx = bcx_ccx(bcx);
639636
if check type_has_static_size(ccx, t) {
640-
rslt(bcx, llalign_of(ccx, trans::type_of(ccx, t)))
637+
rslt(bcx, llalign_of(ccx, base::type_of(ccx, t)))
641638
} else {
642639
let { bcx, sz: _, align } = dynamic_metrics(bcx, t);
643640
rslt(bcx, align)
@@ -647,7 +644,7 @@ fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
647644
fn metrics(bcx: @block_ctxt, t: ty::t) -> metrics {
648645
let ccx = bcx_ccx(bcx);
649646
if check type_has_static_size(ccx, t) {
650-
let llty = trans::type_of(ccx, t);
647+
let llty = base::type_of(ccx, t);
651648
{ bcx: bcx, sz: llsize_of(ccx, llty), align: llalign_of(ccx, llty) }
652649
} else {
653650
dynamic_metrics(bcx, t)
@@ -696,7 +693,7 @@ fn static_size_of_enum(cx: @crate_ctxt, t: ty::t)
696693
// express that with constrained types.
697694
check (type_has_static_size(cx, tup_ty));
698695
let this_size =
699-
llsize_of_real(cx, trans::type_of(cx, tup_ty));
696+
llsize_of_real(cx, base::type_of(cx, tup_ty));
700697
if max_size < this_size { max_size = this_size; }
701698
}
702699
cx.enum_sizes.insert(t, max_size);
@@ -735,7 +732,7 @@ fn dynamic_metrics(cx: @block_ctxt, t: ty::t) -> metrics {
735732
alt ty::struct(bcx_tcx(cx), t) {
736733
ty::ty_param(p, _) {
737734
let ti = none::<@tydesc_info>;
738-
let {bcx, val: tydesc} = trans::get_tydesc(cx, t, false, ti).result;
735+
let {bcx, val: tydesc} = base::get_tydesc(cx, t, false, ti).result;
739736
let szptr = GEPi(bcx, tydesc, [0, abi::tydesc_field_size]);
740737
let aptr = GEPi(bcx, tydesc, [0, abi::tydesc_field_align]);
741738
{bcx: bcx, sz: Load(bcx, szptr), align: Load(bcx, aptr)}

0 commit comments

Comments
 (0)