aboutsummaryrefslogtreecommitdiff
path: root/src/comp/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/lib')
-rw-r--r--src/comp/lib/llvm.rs94
1 files changed, 83 insertions, 11 deletions
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index 624c56f9..f75bdbe1 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -76,6 +76,25 @@ const uint LLVMIntSLT = 40u;
const uint LLVMIntSLE = 41u;
+// Consts for the LLVM RealPredicate type, pre-case to uint.
+// FIXME: as above.
+
+const uint LLVMRealOEQ = 1u;
+const uint LLVMRealOGT = 2u;
+const uint LLVMRealOGE = 3u;
+const uint LLVMRealOLT = 4u;
+const uint LLVMRealOLE = 5u;
+const uint LLVMRealONE = 6u;
+
+const uint LLVMRealORD = 7u;
+const uint LLVMRealUNO = 8u;
+const uint LLVMRealUEQ = 9u;
+const uint LLVMRealUGT = 10u;
+const uint LLVMRealUGE = 11u;
+const uint LLVMRealULT = 12u;
+const uint LLVMRealULE = 13u;
+const uint LLVMRealUNE = 14u;
+
native mod llvm = llvm_lib {
type ModuleRef;
@@ -657,7 +676,7 @@ native mod llvm = llvm_lib {
fn LLVMBuildICmp(BuilderRef B, uint Op,
ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
- fn LLVMBuildFCmp(BuilderRef B, RealPredicate Op,
+ fn LLVMBuildFCmp(BuilderRef B, uint Op,
ValueRef LHS, ValueRef RHS,
sbuf Name) -> ValueRef;
@@ -1034,7 +1053,7 @@ obj builder(BuilderRef B) {
ret llvm.LLVMBuildICmp(B, Op, LHS, RHS, _str.buf(""));
}
- fn FCmp(RealPredicate Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FCmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
ret llvm.LLVMBuildFCmp(B, Op, LHS, RHS, _str.buf(""));
}
@@ -1151,18 +1170,70 @@ fn mk_type_handle() -> type_handle {
ret rec(llth=th, dtor=type_handle_dtor(th));
}
-fn type_to_str(TypeRef ty) -> str {
+
+state obj type_names(std.map.hashmap[TypeRef, str] type_names,
+ std.map.hashmap[str, TypeRef] named_types) {
+
+ fn associate(str s, TypeRef t) {
+ check (!named_types.contains_key(s));
+ check (!type_names.contains_key(t));
+ type_names.insert(t, s);
+ named_types.insert(s, t);
+ }
+
+ fn type_has_name(TypeRef t) -> bool {
+ ret type_names.contains_key(t);
+ }
+
+ fn get_name(TypeRef t) -> str {
+ ret type_names.get(t);
+ }
+
+ fn name_has_type(str s) -> bool {
+ ret named_types.contains_key(s);
+ }
+
+ fn get_type(str s) -> TypeRef {
+ ret named_types.get(s);
+ }
+}
+
+fn mk_type_names() -> type_names {
+ auto nt = util.common.new_str_hash[TypeRef]();
+
+ fn hash(&TypeRef t) -> uint {
+ ret t as uint;
+ }
+
+ fn eq(&TypeRef a, &TypeRef b) -> bool {
+ ret (a as uint) == (b as uint);
+ }
+
+ let std.map.hashfn[TypeRef] hasher = hash;
+ let std.map.eqfn[TypeRef] eqer = eq;
+ auto tn = std.map.mk_hashmap[TypeRef,str](hasher, eqer);
+
+ ret type_names(tn, nt);
+}
+
+fn type_to_str(type_names names, TypeRef ty) -> str {
let vec[TypeRef] v = vec();
- ret type_to_str_inner(v, ty);
+ ret type_to_str_inner(names, v, ty);
}
-fn type_to_str_inner(vec[TypeRef] outer0, TypeRef ty) -> str {
+fn type_to_str_inner(type_names names,
+ vec[TypeRef] outer0, TypeRef ty) -> str {
+
+ if (names.type_has_name(ty)) {
+ ret names.get_name(ty);
+ }
auto outer = outer0 + vec(ty);
let int kind = llvm.LLVMGetTypeKind(ty);
- fn tys_str(vec[TypeRef] outer, vec[TypeRef] tys) -> str {
+ fn tys_str(type_names names,
+ vec[TypeRef] outer, vec[TypeRef] tys) -> str {
let str s = "";
let bool first = true;
for (TypeRef t in tys) {
@@ -1171,7 +1242,7 @@ fn type_to_str_inner(vec[TypeRef] outer0, TypeRef ty) -> str {
} else {
s += ", ";
}
- s += type_to_str_inner(outer, t);
+ s += type_to_str_inner(names, outer, t);
}
ret s;
}
@@ -1200,9 +1271,9 @@ fn type_to_str_inner(vec[TypeRef] outer0, TypeRef ty) -> str {
let vec[TypeRef] args =
_vec.init_elt[TypeRef](0 as TypeRef, n_args);
llvm.LLVMGetParamTypes(ty, _vec.buf[TypeRef](args));
- s += tys_str(outer, args);
+ s += tys_str(names, outer, args);
s += ") -> ";
- s += type_to_str_inner(outer, out_ty);
+ s += type_to_str_inner(names, outer, out_ty);
ret s;
}
@@ -1212,7 +1283,7 @@ fn type_to_str_inner(vec[TypeRef] outer0, TypeRef ty) -> str {
let vec[TypeRef] elts =
_vec.init_elt[TypeRef](0 as TypeRef, n_elts);
llvm.LLVMGetStructElementTypes(ty, _vec.buf[TypeRef](elts));
- s += tys_str(outer, elts);
+ s += tys_str(names, outer, elts);
s += "}";
ret s;
}
@@ -1228,7 +1299,8 @@ fn type_to_str_inner(vec[TypeRef] outer0, TypeRef ty) -> str {
ret "*\\" + util.common.istr(n as int);
}
}
- ret "*" + type_to_str_inner(outer, llvm.LLVMGetElementType(ty));
+ ret "*" + type_to_str_inner(names, outer,
+ llvm.LLVMGetElementType(ty));
}
case (12) { ret "Opaque"; }