about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-05-17 16:17:11 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-05-17 20:39:17 -0700
commitcf2fc2c34e99d8acaa706da7d2f4afe3ee3e7dfc (patch)
treeb80dacbd9c1d1be724b3cb3ffe92dfa5517b4be1 /src
parent37abcda42b5060eafd65bf9fe6a6861efa5f0c15 (diff)
downloadrust-cf2fc2c34e99d8acaa706da7d2f4afe3ee3e7dfc.tar.gz
rust-cf2fc2c34e99d8acaa706da7d2f4afe3ee3e7dfc.zip
Annotate or fix FIXMEs in LLVM bindings and metadata code
Fixed up a few FIXMEs in lib/llvm to use more descriptive data
types. Covered FIXMEs in metadata::{creader, csearch, decoder} and
one in encoder.
Diffstat (limited to 'src')
-rw-r--r--src/rustc/back/link.rs22
-rw-r--r--src/rustc/lib/llvm.rs101
-rw-r--r--src/rustc/metadata/common.rs3
-rw-r--r--src/rustc/metadata/creader.rs1
-rw-r--r--src/rustc/metadata/csearch.rs1
-rw-r--r--src/rustc/metadata/decoder.rs4
-rw-r--r--src/rustc/metadata/encoder.rs6
-rw-r--r--src/rustc/middle/trans/base.rs5
-rw-r--r--src/rustc/middle/trans/build.rs6
-rw-r--r--src/rustc/middle/trans/common.rs9
10 files changed, 84 insertions, 74 deletions
diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs
index 0de0422ec6f..2f31fdfaebc 100644
--- a/src/rustc/back/link.rs
+++ b/src/rustc/back/link.rs
@@ -6,11 +6,13 @@ import syntax::attr;
 import middle::ty;
 import metadata::{encoder, cstore};
 import middle::trans::common::crate_ctxt;
+import metadata::common::link_meta;
 import std::map::hashmap;
 import std::sha1::sha1;
 import syntax::ast;
 import syntax::print::pprust;
-import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
+import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
+        FileType};
 import util::filesearch;
 import middle::ast_map::{path, path_mod, path_name};
 
@@ -125,8 +127,6 @@ mod write {
         }
         if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
         if is_object_or_assembly_or_exe(opts.output_type) {
-            let LLVMAssemblyFile  = 0 as c_int;
-            let LLVMObjectFile    = 1 as c_int;
             let LLVMOptNone       = 0 as c_int; // -O0
             let LLVMOptLess       = 1 as c_int; // -O1
             let LLVMOptDefault    = 2 as c_int; // -O2, -Os
@@ -143,8 +143,8 @@ mod write {
             let mut FileType;
             if opts.output_type == output_type_object ||
                    opts.output_type == output_type_exe {
-                FileType = LLVMObjectFile;
-            } else { FileType = LLVMAssemblyFile; }
+               FileType = lib::llvm::ObjectFile;
+            } else { FileType = lib::llvm::AssemblyFile; }
             // Write optimized bitcode if --save-temps was on.
 
             if opts.save_temps {
@@ -169,7 +169,7 @@ mod write {
                                     llmod,
                                     buf_t,
                                     buf_o,
-                                    LLVMAssemblyFile,
+                                    lib::llvm::AssemblyFile as c_uint,
                                     CodeGenOptLevel,
                                     true)})});
                 }
@@ -189,7 +189,7 @@ mod write {
                                         llmod,
                                         buf_t,
                                         buf_o,
-                                        LLVMObjectFile,
+                                        lib::llvm::ObjectFile as c_uint,
                                         CodeGenOptLevel,
                                         true)})});
                 }
@@ -207,7 +207,7 @@ mod write {
                                     llmod,
                                     buf_t,
                                     buf_o,
-                                    FileType,
+                                    FileType as c_uint,
                                     CodeGenOptLevel,
                                     true)})});
             }
@@ -288,7 +288,7 @@ mod write {
  */
 
 fn build_link_meta(sess: session, c: ast::crate, output: str,
-                   sha: sha1) -> encoder::link_meta {
+                   sha: sha1) -> link_meta {
 
     type provided_metas =
         {name: option<str>,
@@ -412,7 +412,7 @@ fn truncated_sha1_result(sha: sha1) -> str unsafe {
 
 // This calculates STH for a symbol, as defined above
 fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t,
-               link_meta: encoder::link_meta) -> str {
+               link_meta: link_meta) -> str {
     // NB: do *not* use abbrevs here as we want the symbol names
     // to be independent of one another in the crate.
 
@@ -525,7 +525,7 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
 fn link_binary(sess: session,
                obj_filename: str,
                out_filename: str,
-               lm: encoder::link_meta) {
+               lm: link_meta) {
     // Converts a library file name into a cc -l argument
     fn unlib(config: @session::config, filename: str) -> str unsafe {
         let rmlib = fn@(filename: str) -> str {
diff --git a/src/rustc/lib/llvm.rs b/src/rustc/lib/llvm.rs
index f984b0de63a..d06c65dcb19 100644
--- a/src/rustc/lib/llvm.rs
+++ b/src/rustc/lib/llvm.rs
@@ -4,8 +4,8 @@ import libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
 
 type Opcode = u32;
 type Bool = c_uint;
-const True: Bool = 1u32; // FIXME: should be '1 as Bool'
-const False: Bool = 0u32;
+const True: Bool = 1 as Bool;
+const False: Bool = 0 as Bool;
 
 // Consts for the LLVM CallConv type, pre-cast to uint.
 
@@ -75,9 +75,7 @@ enum Attribute {
     NonLazyBindAttribute = 2147483648,
 }
 
-// Consts for the LLVM IntPredicate type, pre-cast to uint.
-// FIXME: as above.
-
+// enum for the LLVM IntPredicate type
 enum IntPredicate {
     IntEQ = 32,
     IntNE = 33,
@@ -91,9 +89,7 @@ enum IntPredicate {
     IntSLE = 41,
 }
 
-// Consts for the LLVM RealPredicate type, pre-case to uint.
-// FIXME: as above.
-
+// enum for the LLVM RealPredicate type
 enum RealPredicate {
     RealOEQ = 1,
     RealOGT = 2,
@@ -111,6 +107,34 @@ enum RealPredicate {
     RealUNE = 14,
 }
 
+// enum for the LLVM TypeKind type - must stay in sync with the def of
+// LLVMTypeKind in llvm/include/llvm-c/Core.h
+enum TypeKind {
+    Void      = 0,
+    Half      = 1,
+    Float     = 2,
+    Double    = 3,
+    X86_FP80  = 4,
+    FP128     = 5,
+    PPC_FP128 = 6,
+    Label     = 7,
+    Integer   = 8,
+    Function  = 9,
+    Struct    = 10,
+    Array     = 11,
+    Pointer   = 12,
+    Vector    = 13,
+    Metadata  = 14,
+    X86_MMX   = 15
+}
+
+// FIXME: Not used right now, but will be once #2334 is fixed
+// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
+enum FileType {
+    AssemblyFile = 0,
+    ObjectFile = 1
+}
+
 // Opaque pointer types
 enum Module_opaque {}
 type ModuleRef = *Module_opaque;
@@ -171,12 +195,7 @@ native mod llvm {
     fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
 
     /** See llvm::LLVMTypeKind::getTypeID. */
-
-    // FIXME: returning int rather than TypeKind because
-    // we directly inspect the values, and casting from
-    // a native doesn't work yet (only *to* a native).
-
-    fn LLVMGetTypeKind(Ty: TypeRef) -> c_int;
+    fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
 
     /** See llvm::LLVMType::getContext. */
     fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
@@ -294,9 +313,7 @@ native mod llvm {
     /* Operations on scalar constants */
     fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) ->
        ValueRef;
-    // FIXME: radix is actually u8, but our native layer can't handle this
-    // yet.  lucky for us we're little-endian. Small miracles.
-    fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: c_int) ->
+    fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8) ->
        ValueRef;
     fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
                                    SLen: c_uint,
@@ -764,8 +781,8 @@ native mod llvm {
     /** Adds the target data to the given pass manager. The pass manager
         references the target data only weakly. */
     fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
-    /** Returns the size of a type. FIXME: rv is actually a C_Ulonglong! */
-    fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
+    /** Returns the size of a type. */
+    fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
     fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
     /** Returns the preferred alignment of a type. */
     fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
@@ -879,10 +896,11 @@ native mod llvm {
     fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
        MemoryBufferRef;
 
-    /* FIXME: The FileType is an enum.*/
     fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
                                Triple: *c_char,
-                               Output: *c_char, FileType: c_int,
+                               // FIXME: When #2334 is fixed, change
+                               // c_uint to FileType
+                               Output: *c_char, FileType: c_uint,
                                OptLevel: c_int,
                                EnableSegmentedStacks: bool);
 
@@ -896,10 +914,6 @@ native mod llvm {
     /** Parses LLVM asm in the given file */
     fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
 
-    /** FiXME: Hacky adaptor for lack of c_ulonglong in FFI: */
-    fn LLVMRustConstInt(IntTy: TypeRef, N_hi: c_uint, N_lo: c_uint,
-                        SignExtend: Bool) -> ValueRef;
-
     fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
                                   Output: *c_char);
 
@@ -970,7 +984,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
 
     let outer = outer0 + [ty];
 
-    let kind: int = llvm::LLVMGetTypeKind(ty) as int;
+    let kind = llvm::LLVMGetTypeKind(ty);
 
     fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str {
         let mut s: str = "";
@@ -983,20 +997,18 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
     }
 
     alt kind {
-      // FIXME: more enum-as-int constants determined from Core::h;
-      // horrible, horrible. Complete as needed.
-      0 { ret "Void"; }
-      1 { ret "Half"; }
-      2 { ret "Float"; }
-      3 { ret "Double"; }
-      4 { ret "X86_FP80"; }
-      5 { ret "FP128"; }
-      6 { ret "PPC_FP128"; }
-      7 { ret "Label"; }
-      8 {
+      Void { ret "Void"; }
+      Half { ret "Half"; }
+      Float { ret "Float"; }
+      Double { ret "Double"; }
+      X86_FP80 { ret "X86_FP80"; }
+      FP128 { ret "FP128"; }
+      PPC_FP128 { ret "PPC_FP128"; }
+      Label { ret "Label"; }
+      Integer {
         ret "i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
       }
-      9 {
+      Function {
         let mut s = "fn(";
         let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
         let n_args = llvm::LLVMCountParamTypes(ty) as uint;
@@ -1009,7 +1021,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
         s += type_to_str_inner(names, outer, out_ty);
         ret s;
       }
-      10 {
+      Struct {
         let mut s: str = "{";
         let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
         let elts: [TypeRef] = vec::from_elem::<TypeRef>(n_elts, 0 as TypeRef);
@@ -1020,12 +1032,12 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
         s += "}";
         ret s;
       }
-      11 {
+      Array {
         let el_ty = llvm::LLVMGetElementType(ty);
         ret "[" + type_to_str_inner(names, outer, el_ty) + " x " +
             uint::str(llvm::LLVMGetArrayLength(ty) as uint) + "]";
       }
-      12 {
+      Pointer {
         let mut i: uint = 0u;
         for outer0.each {|tout|
             i += 1u;
@@ -1045,10 +1057,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
         ret addrstr + "*" +
                 type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
       }
-      13 { ret "Vector"; }
-      14 { ret "Metadata"; }
-      15 { ret "X86_MMAX"; }
-      _ { #error("unknown TypeKind %d", kind as int); fail; }
+      Vector { ret "Vector"; }
+      Metadata { ret "Metadata"; }
+      X86_MMX { ret "X86_MMAX"; }
     }
 }
 
diff --git a/src/rustc/metadata/common.rs b/src/rustc/metadata/common.rs
index 35373bffd84..a754d4c11a2 100644
--- a/src/rustc/metadata/common.rs
+++ b/src/rustc/metadata/common.rs
@@ -132,3 +132,6 @@ fn hash_path(&&s: str) -> uint {
     for str::each(s) {|ch| h = (h << 5u) + h ^ (ch as uint); }
     ret h;
 }
+
+type link_meta = {name: str, vers: str, extras_hash: str};
+
diff --git a/src/rustc/metadata/creader.rs b/src/rustc/metadata/creader.rs
index 2cc3f1a5a4a..d7bf5819392 100644
--- a/src/rustc/metadata/creader.rs
+++ b/src/rustc/metadata/creader.rs
@@ -239,6 +239,7 @@ fn resolve_crate_deps(e: env, cdata: @[u8]) -> cstore::cnum_map {
             #debug("need to load it");
             // This is a new one so we've got to load it
             // FIXME: Need better error reporting than just a bogus span
+            // #2404
             let fake_span = ast_util::dummy_sp();
             let local_cnum =
                 resolve_crate(e, cname, cmetas, dep.hash, fake_span);
diff --git a/src/rustc/metadata/csearch.rs b/src/rustc/metadata/csearch.rs
index db758048bde..300b6681b2f 100644
--- a/src/rustc/metadata/csearch.rs
+++ b/src/rustc/metadata/csearch.rs
@@ -141,7 +141,6 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
     decoder::get_type(cdata, def.node, tcx)
 }
 
-/* FIXME: Refactor */
 fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
                   def: ast::def_id) -> ty::ty_param_bounds_and_ty {
     let cstore = tcx.sess.cstore;
diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs
index 41b743d8384..edcf9e18a42 100644
--- a/src/rustc/metadata/decoder.rs
+++ b/src/rustc/metadata/decoder.rs
@@ -578,8 +578,8 @@ fn get_meta_items(md: ebml::doc) -> [@ast::meta_item] {
         let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
         let n = str::from_bytes(ebml::doc_data(nd));
         let v = str::from_bytes(ebml::doc_data(vd));
-        // FIXME (#611): Should be able to decode meta_name_value variants,
-        // but currently they can't be encoded
+        // FIXME (#623): Should be able to decode meta_name_value variants,
+        // but currently the encoder just drops them
         items += [attr::mk_name_value_item_str(n, v)];
     };
     ebml::tagged_docs(md, tag_meta_item_list) {|meta_item_doc|
diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs
index a01af9c6c7f..17ce46094a5 100644
--- a/src/rustc/metadata/encoder.rs
+++ b/src/rustc/metadata/encoder.rs
@@ -20,7 +20,6 @@ import std::ebml::serializer;
 import syntax::ast;
 import syntax::diagnostic::span_handler;
 
-export link_meta;
 export encode_parms;
 export encode_metadata;
 export encoded_ty;
@@ -33,9 +32,6 @@ export encode_ctxt;
 export write_type;
 export encode_def_id;
 
-// FIXME: This probably belongs somewhere else
-type link_meta = {name: str, vers: str, extras_hash: str};
-
 type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
 
 type encode_inlined_item = fn@(ecx: @encode_ctxt,
@@ -916,7 +912,7 @@ fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
             ebml_w.end_tag();
             ebml_w.end_tag();
           }
-          _ {/* FIXME (#611) */ }
+          _ {/* FIXME (#623): encode other variants */ }
         }
       }
       meta_list(name, items) {
diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs
index 1d8355bffbf..c892c92be97 100644
--- a/src/rustc/middle/trans/base.rs
+++ b/src/rustc/middle/trans/base.rs
@@ -39,6 +39,7 @@ import link::{mangle_internal_name_by_type_only,
               mangle_internal_name_by_path_and_seq,
               mangle_exported_name};
 import metadata::{csearch, cstore, encoder};
+import metadata::common::link_meta;
 import util::ppaux::{ty_to_str, ty_to_short_str};
 
 import common::*;
@@ -5150,7 +5151,7 @@ fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
 }
 
 
-fn decl_crate_map(sess: session::session, mapmeta: encoder::link_meta,
+fn decl_crate_map(sess: session::session, mapmeta: link_meta,
                   llmod: ModuleRef) -> ValueRef {
     let targ_cfg = sess.targ_cfg;
     let int_type = T_int(targ_cfg);
@@ -5274,7 +5275,7 @@ fn write_abi_version(ccx: @crate_ctxt) {
 fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
                output: str, emap: resolve::exp_map,
                maps: astencode::maps)
-    -> (ModuleRef, encoder::link_meta) {
+    -> (ModuleRef, link_meta) {
     let sha = std::sha1::sha1();
     let link_meta = link::build_link_meta(sess, *crate, output, sha);
     let reachable = reachable::find_reachable(crate.node.module, emap, tcx,
diff --git a/src/rustc/middle/trans/build.rs b/src/rustc/middle/trans/build.rs
index 7bf86b7068a..4869450faed 100644
--- a/src/rustc/middle/trans/build.rs
+++ b/src/rustc/middle/trans/build.rs
@@ -5,7 +5,7 @@ import syntax::codemap;
 import codemap::span;
 import lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
 import lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False,
-                   CallConv};
+        CallConv, TypeKind};
 import common::*;
 
 fn B(cx: block) -> BuilderRef {
@@ -399,7 +399,7 @@ fn Load(cx: block, PointerVal: ValueRef) -> ValueRef {
     let ccx = cx.fcx.ccx;
     if cx.unreachable {
         let ty = val_ty(PointerVal);
-        let eltty = if llvm::LLVMGetTypeKind(ty) == 11 as c_int {
+        let eltty = if llvm::LLVMGetTypeKind(ty) == lib::llvm::Array {
             llvm::LLVMGetElementType(ty) } else { ccx.int_type };
         ret llvm::LLVMGetUndef(eltty);
     }
@@ -632,7 +632,7 @@ fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
 fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef {
     let ccx = cx.fcx.ccx;
     let ty = val_ty(Fn);
-    let retty = if llvm::LLVMGetTypeKind(ty) == 8 as c_int {
+    let retty = if llvm::LLVMGetTypeKind(ty) == lib::llvm::Integer {
         llvm::LLVMGetReturnType(ty) } else { ccx.int_type };
         count_insn(cx, "");
     ret llvm::LLVMGetUndef(retty);
diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs
index c76c48c321e..2e440ce860b 100644
--- a/src/rustc/middle/trans/common.rs
+++ b/src/rustc/middle/trans/common.rs
@@ -17,7 +17,8 @@ import lib::llvm::{llvm, target_data, type_names, associate_type,
                    name_has_type};
 import lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
 import lib::llvm::{True, False, Bool};
-import metadata::{csearch, encoder};
+import metadata::{csearch};
+import metadata::common::link_meta;
 import ast_map::path;
 import util::ppaux::ty_to_str;
 
@@ -77,7 +78,7 @@ type crate_ctxt = {
      reachable: reachable::map,
      item_symbols: hashmap<ast::node_id, str>,
      mut main_fn: option<ValueRef>,
-     link_meta: encoder::link_meta,
+     link_meta: link_meta,
      enum_sizes: hashmap<ty::t, uint>,
      discrims: hashmap<ast::def_id, ValueRef>,
      discrim_symbols: hashmap<ast::node_id, str>,
@@ -749,9 +750,7 @@ fn T_opaque_chan_ptr() -> TypeRef { ret T_ptr(T_i8()); }
 fn C_null(t: TypeRef) -> ValueRef { ret llvm::LLVMConstNull(t); }
 
 fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef {
-    let u_hi = (u >> 32u64) as c_uint;
-    let u_lo = u as c_uint;
-    ret llvm::LLVMRustConstInt(t, u_hi, u_lo, sign_extend);
+    ret llvm::LLVMConstInt(t, u, sign_extend);
 }
 
 fn C_floating(s: str, t: TypeRef) -> ValueRef {