Skip to content

Commit a0dc27a

Browse files
committed
---
yaml --- r: 4519 b: refs/heads/master c: adce35a h: refs/heads/master i: 4517: 50a7831 4515: 95fcfa6 4511: 9fb0867 v: v3
1 parent f427498 commit a0dc27a

File tree

6 files changed

+118
-131
lines changed

6 files changed

+118
-131
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 40ae704ff2fc419c162527345bad63dd06394afe
2+
refs/heads/master: adce35acd481d6ecc087c5957601b0a680e936a8

trunk/src/comp/back/upcall.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ import lib::llvm::llvm::TypeRef;
2626

2727
type upcalls =
2828
{grow_task: ValueRef,
29-
log_int: ValueRef,
30-
log_float: ValueRef,
31-
log_double: ValueRef,
32-
log_str: ValueRef,
33-
log_istr: ValueRef,
3429
trace_word: ValueRef,
3530
trace_str: ValueRef,
3631
new_port: ValueRef,
@@ -67,7 +62,8 @@ type upcalls =
6762
ivec_spill: ValueRef,
6863
ivec_resize_shared: ValueRef,
6964
ivec_spill_shared: ValueRef,
70-
cmp_type: ValueRef};
65+
cmp_type: ValueRef,
66+
log_type: ValueRef};
7167

7268
fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
7369
taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls {
@@ -89,11 +85,6 @@ fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
8985

9086
let empty_vec: [TypeRef] = ~[];
9187
ret @{grow_task: dv("grow_task", ~[T_size_t()]),
92-
log_int: dv("log_int", ~[T_i32(), T_i32()]),
93-
log_float: dv("log_float", ~[T_i32(), T_f32()]),
94-
log_double: dv("log_double", ~[T_i32(), T_ptr(T_f64())]),
95-
log_str: dv("log_str", ~[T_i32(), T_ptr(T_str())]),
96-
log_istr: dv("log_istr", ~[T_i32(), T_ptr(T_ivec(T_i8()))]),
9788
trace_word: dv("trace_word", ~[T_int()]),
9889
trace_str: dv("trace_str", ~[T_ptr(T_i8())]),
9990
new_port: d("new_port", ~[T_size_t()], T_opaque_port_ptr()),
@@ -159,6 +150,10 @@ fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
159150
dr("cmp_type", ~[T_ptr(T_i1()), taskptr_type,
160151
T_ptr(tydesc_type), T_ptr(T_ptr(tydesc_type)),
161152
T_ptr(T_i8()), T_ptr(T_i8()), T_i8()],
153+
T_void()),
154+
log_type:
155+
dr("log_type", ~[taskptr_type, T_ptr(tydesc_type),
156+
T_ptr(T_i8()), T_i32()],
162157
T_void())};
163158
}
164159
//

trunk/src/comp/middle/trans.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,48 +5190,18 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
51905190
let sub = trans_expr(log_cx, e);
51915191
let e_ty = ty::expr_ty(bcx_tcx(cx), e);
51925192
let log_bcx = sub.bcx;
5193-
if ty::type_is_fp(bcx_tcx(cx), e_ty) {
5194-
let tr: TypeRef;
5195-
let is32bit: bool = false;
5196-
alt ty::struct(bcx_tcx(cx), e_ty) {
5197-
ty::ty_machine(ast::ty_f32.) { tr = T_f32(); is32bit = true; }
5198-
ty::ty_machine(ast::ty_f64.) { tr = T_f64(); }
5199-
_ { tr = T_float(); }
5200-
}
5201-
if is32bit {
5202-
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_float,
5203-
~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
5204-
} else {
5205-
// FIXME: Eliminate this level of indirection.
52065193

5207-
let tmp = alloca(log_bcx, tr);
5208-
sub.bcx.build.Store(sub.val, tmp);
5209-
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_double,
5210-
~[log_bcx.fcx.lltaskptr, C_int(lvl), tmp]);
5211-
}
5212-
} else if (ty::type_is_integral(bcx_tcx(cx), e_ty) ||
5213-
ty::type_is_bool(bcx_tcx(cx), e_ty)) {
5214-
// FIXME: Handle signedness properly.
5215-
5216-
let llintval =
5217-
int_cast(log_bcx, T_int(), val_ty(sub.val), sub.val, false);
5218-
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_int,
5219-
~[log_bcx.fcx.lltaskptr, C_int(lvl), llintval]);
5220-
} else {
5221-
alt ty::struct(bcx_tcx(cx), e_ty) {
5222-
ty::ty_str. {
5223-
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_str,
5224-
~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
5225-
}
5226-
_ {
5227-
// FIXME: Support these types.
5194+
let ti = none[@tydesc_info];
5195+
let r = get_tydesc(log_bcx, e_ty, false, ti);
5196+
log_bcx = r.bcx;
5197+
5198+
// Call the polymorphic log function.
5199+
let llvalptr = spill_if_immediate(log_bcx, sub.val, e_ty);
5200+
let llval_i8 = log_bcx.build.PointerCast(llvalptr, T_ptr(T_i8()));
5201+
5202+
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_type,
5203+
~[log_bcx.fcx.lltaskptr, r.val, llval_i8, C_int(lvl)]);
52285204

5229-
bcx_ccx(cx).sess.span_fatal(e.span,
5230-
"log called on unsupported type " +
5231-
ty_to_str(bcx_tcx(cx), e_ty));
5232-
}
5233-
}
5234-
}
52355205
log_bcx = trans_block_cleanups(log_bcx, log_cx);
52365206
log_bcx.build.Br(after_cx.llbb);
52375207
ret rslt(after_cx, C_nil());

trunk/src/comp/middle/trans_dps.rs

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -343,36 +343,6 @@ fn trans_log(cx: &@block_ctxt, sp: &span, level: int, expr: &@ast::expr) ->
343343
ret lllevelptr;
344344
}
345345

346-
tag upcall_style { us_imm; us_imm_i32_zext; us_alias; us_alias_istr; }
347-
fn get_upcall(ccx: &@crate_ctxt, sp: &span, t: ty::t) ->
348-
{val: ValueRef, st: upcall_style} {
349-
alt ty::struct(ccx_tcx(ccx), t) {
350-
ty::ty_machine(ast::ty_f32.) {
351-
ret {val: ccx.upcalls.log_float, st: us_imm};
352-
}
353-
ty::ty_machine(ast::ty_f64.) | ty::ty_float. {
354-
// TODO: We have to spill due to legacy calling conventions that
355-
// should probably be modernized.
356-
ret {val: ccx.upcalls.log_double, st: us_alias};
357-
}
358-
ty::ty_bool. | ty::ty_machine(ast::ty_i8.) |
359-
ty::ty_machine(ast::ty_i16.) | ty::ty_machine(ast::ty_u8.) |
360-
ty::ty_machine(ast::ty_u16.) {
361-
ret {val: ccx.upcalls.log_int, st: us_imm_i32_zext};
362-
}
363-
ty::ty_int. | ty::ty_machine(ast::ty_i32.) |
364-
ty::ty_machine(ast::ty_u32.) {
365-
ret {val: ccx.upcalls.log_int, st: us_imm};
366-
}
367-
ty::ty_istr. { ret {val: ccx.upcalls.log_istr, st: us_alias_istr}; }
368-
_ {
369-
ccx.sess.span_unimpl(sp,
370-
"logging for values of type " +
371-
ppaux::ty_to_str(ccx_tcx(ccx), t));
372-
}
373-
}
374-
}
375-
376346
let bcx = cx;
377347

378348
let lllevelptr = trans_log_level(bcx_lcx(bcx));
@@ -386,34 +356,20 @@ fn trans_log(cx: &@block_ctxt, sp: &span, level: int, expr: &@ast::expr) ->
386356
bcx.build.CondBr(should_log, log_bcx.llbb, next_bcx.llbb);
387357

388358
let expr_t = ty::expr_ty(bcx_tcx(log_bcx), expr);
389-
let r = get_upcall(bcx_ccx(bcx), sp, expr_t);
390-
let llupcall = r.val;
391-
let style = r.st;
392-
393-
let arg_dest;
394-
alt style {
395-
us_imm. | us_imm_i32_zext. {
396-
arg_dest = dest_imm(bcx_tcx(log_bcx), expr_t);
397-
}
398-
us_alias. | us_alias_istr. {
399-
arg_dest = dest_alias(bcx_tcx(log_bcx), expr_t);
400-
}
401-
}
359+
let arg_dest = dest_alias(bcx_tcx(log_bcx), expr_t);
402360
log_bcx = trans_expr(log_bcx, arg_dest, expr);
403361

404362
let llarg = dest_llval(arg_dest);
405-
alt style {
406-
us_imm. | us_alias. {/* no-op */ }
407-
us_imm_i32_zext. { llarg = log_bcx.build.ZExt(llarg, tc::T_i32()); }
408-
us_alias_istr. {
409-
llarg =
410-
log_bcx.build.PointerCast(llarg,
411-
tc::T_ptr(tc::T_ivec(tc::T_i8())));
412-
}
413-
}
363+
let llarg_i8 = bcx.build.PointerCast(llarg, T_ptr(T_i8()));
364+
365+
let ti = none;
366+
let r2 = trans::get_tydesc(bcx, expr_t, false, ti);
367+
bcx = r2.bcx;
368+
let lltydesc = r2.val;
414369

415-
log_bcx.build.Call(llupcall,
416-
~[bcx_fcx(bcx).lltaskptr, tc::C_int(level), llarg]);
370+
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_type,
371+
~[bcx_fcx(bcx).lltaskptr, lltydesc, llarg_i8,
372+
tc::C_int(level)]);
417373

418374
log_bcx =
419375
trans::trans_block_cleanups(log_bcx, tc::find_scope_cx(log_bcx));

trunk/src/rt/rust_shape.cpp

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <algorithm>
55
#include <iostream>
6+
#include <sstream>
67
#include <utility>
78
#include <cassert>
89
#include <cstdio>
@@ -76,20 +77,6 @@ align_to(T size, size_t alignment) {
7677
return x;
7778
}
7879

79-
template<typename T>
80-
static inline T
81-
bump_dp(uint8_t *&dp) {
82-
T x = *((T *)dp);
83-
dp += sizeof(T);
84-
return x;
85-
}
86-
87-
template<typename T>
88-
static inline T
89-
get_dp(uint8_t *dp) {
90-
return *((T *)dp);
91-
}
92-
9380
// Utility classes
9481

9582
struct size_align {
@@ -220,6 +207,52 @@ get_dp(ptr_pair &ptr) {
220207
return data;
221208
}
222209

210+
// Pointer wrappers for data traversals
211+
212+
class ptr {
213+
private:
214+
uint8_t *p;
215+
216+
public:
217+
template<typename T>
218+
struct data { typedef T t; };
219+
220+
ptr(uint8_t *in_p)
221+
: p(in_p) {}
222+
223+
ptr(uintptr_t in_p)
224+
: p((uint8_t *)in_p) {}
225+
226+
inline ptr operator+(const size_t amount) const {
227+
return make(p + amount);
228+
}
229+
inline ptr &operator+=(const size_t amount) { p += amount; return *this; }
230+
231+
template<typename T>
232+
inline operator T *() { return (T *)p; }
233+
234+
inline operator uintptr_t() { return (uintptr_t)p; }
235+
236+
static inline ptr make(uint8_t *in_p) {
237+
ptr self(in_p);
238+
return self;
239+
}
240+
};
241+
242+
template<typename T>
243+
static inline T
244+
bump_dp(ptr &dp) {
245+
T x = *((T *)dp);
246+
dp += sizeof(T);
247+
return x;
248+
}
249+
250+
template<typename T>
251+
static inline T
252+
get_dp(ptr dp) {
253+
return *((T *)dp);
254+
}
255+
223256

224257
// Contexts
225258

@@ -852,8 +885,8 @@ class data : public ctxt< data<T,U> > {
852885
protected:
853886
void walk_variant(bool align, tag_info &tinfo, uint32_t variant);
854887

855-
static std::pair<uint8_t *,uint8_t *> get_evec_data_range(uint8_t *dp);
856-
static std::pair<uint8_t *,uint8_t *> get_ivec_data_range(uint8_t *dp);
888+
static std::pair<uint8_t *,uint8_t *> get_evec_data_range(ptr dp);
889+
static std::pair<uint8_t *,uint8_t *> get_ivec_data_range(ptr dp);
857890
static std::pair<ptr_pair,ptr_pair> get_evec_data_range(ptr_pair &dp);
858891
static std::pair<ptr_pair,ptr_pair> get_ivec_data_range(ptr_pair &dp);
859892

@@ -924,14 +957,14 @@ data<T,U>::walk_variant(bool align, tag_info &tinfo, uint32_t variant_id) {
924957

925958
template<typename T,typename U>
926959
std::pair<uint8_t *,uint8_t *>
927-
data<T,U>::get_evec_data_range(uint8_t *dp) {
960+
data<T,U>::get_evec_data_range(ptr dp) {
928961
rust_vec *vp = bump_dp<rust_vec *>(dp);
929962
return std::make_pair(vp->data, vp->data + vp->fill);
930963
}
931964

932965
template<typename T,typename U>
933966
std::pair<uint8_t *,uint8_t *>
934-
data<T,U>::get_ivec_data_range(uint8_t *dp) {
967+
data<T,U>::get_ivec_data_range(ptr dp) {
935968
size_t fill = bump_dp<size_t>(dp);
936969
bump_dp<size_t>(dp); // Skip over alloc.
937970
uint8_t *payload_dp = dp;
@@ -1009,6 +1042,8 @@ data<T,U>::walk_tag(bool align, tag_info &tinfo) {
10091042
tag_variant = 0;
10101043

10111044
static_cast<T *>(this)->walk_tag(align, tinfo, tag_variant);
1045+
1046+
dp = end_dp;
10121047
}
10131048

10141049

@@ -1187,13 +1222,20 @@ cmp::walk_variant(bool align, tag_info &tinfo, uint32_t variant_id,
11871222

11881223
// Polymorphic logging, for convenience
11891224

1190-
class log : public data<log,uint8_t *> {
1191-
friend class data<log,uint8_t *>;
1225+
class log : public data<log,ptr> {
1226+
friend class data<log,ptr>;
11921227

11931228
private:
11941229
std::ostream &out;
11951230
bool in_string;
11961231

1232+
log(log &other,
1233+
const uint8_t *in_sp,
1234+
const type_param *in_params,
1235+
const rust_shape_tables *in_tables)
1236+
: data<log,ptr>(other.task, in_sp, in_params, in_tables, other.dp),
1237+
out(other.out) {}
1238+
11971239
void walk_evec(bool align, bool is_pod, uint16_t sp_size) {
11981240
walk_vec(align, is_pod, get_evec_data_range(dp));
11991241
}
@@ -1202,8 +1244,14 @@ class log : public data<log,uint8_t *> {
12021244
walk_vec(align, is_pod, get_ivec_data_range(dp));
12031245
}
12041246

1205-
void walk_vec(bool align, bool is_pod,
1206-
const std::pair<uint8_t *,uint8_t *> &data);
1247+
void walk_tag(bool align, tag_info &tinfo, uint32_t tag_variant) {
1248+
out << "tag" << tag_variant;
1249+
// TODO: Print insides.
1250+
}
1251+
1252+
void walk_subcontext(bool align, log &sub) { sub.walk(align); }
1253+
1254+
void walk_vec(bool align, bool is_pod, const std::pair<ptr,ptr> &data);
12071255

12081256
template<typename T>
12091257
void walk_number() { out << get_dp<T>(dp); }
@@ -1215,13 +1263,12 @@ class log : public data<log,uint8_t *> {
12151263
const rust_shape_tables *in_tables,
12161264
uint8_t *in_data,
12171265
std::ostream &in_out)
1218-
: data<log,uint8_t *>(in_task, in_sp, in_params, in_tables, in_data),
1266+
: data<log,ptr>(in_task, in_sp, in_params, in_tables, in_data),
12191267
out(in_out) {}
12201268
};
12211269

12221270
void
1223-
log::walk_vec(bool align, bool is_pod,
1224-
const std::pair<uint8_t *,uint8_t *> &data) {
1271+
log::walk_vec(bool align, bool is_pod, const std::pair<ptr,ptr> &data) {
12251272
// TODO: Check to see whether this is a string (contains u8). If so,
12261273
// write the vector ""-style; otherwise [ ... , ... ] style.
12271274
}
@@ -1245,3 +1292,21 @@ upcall_cmp_type(int8_t *result, rust_task *task, type_desc *tydesc,
12451292
}
12461293
}
12471294

1295+
extern "C" void
1296+
upcall_log_type(rust_task *task, type_desc *tydesc, uint8_t *data,
1297+
uint32_t level) {
1298+
if (task->sched->log_lvl < level)
1299+
return; // TODO: Don't evaluate at all?
1300+
1301+
shape::arena arena;
1302+
shape::type_param *params = shape::type_param::make(tydesc, arena);
1303+
1304+
std::stringstream ss;
1305+
shape::log log(task, tydesc->shape, params, tydesc->shape_tables, data,
1306+
ss);
1307+
1308+
log.walk(true);
1309+
1310+
task->sched->log(task, level, "%s", ss.str().c_str());
1311+
}
1312+

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ upcall_log_float
9797
upcall_log_int
9898
upcall_log_istr
9999
upcall_log_str
100+
upcall_log_type
100101
upcall_malloc
101102
upcall_mark
102103
upcall_new_chan

0 commit comments

Comments
 (0)