Skip to content

Commit cf2fc2c

Browse files
committed
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.
1 parent 37abcda commit cf2fc2c

File tree

10 files changed

+84
-74
lines changed

10 files changed

+84
-74
lines changed

src/rustc/back/link.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import syntax::attr;
66
import middle::ty;
77
import metadata::{encoder, cstore};
88
import middle::trans::common::crate_ctxt;
9+
import metadata::common::link_meta;
910
import std::map::hashmap;
1011
import std::sha1::sha1;
1112
import syntax::ast;
1213
import syntax::print::pprust;
13-
import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
14+
import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
15+
FileType};
1416
import util::filesearch;
1517
import middle::ast_map::{path, path_mod, path_name};
1618

@@ -125,8 +127,6 @@ mod write {
125127
}
126128
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
127129
if is_object_or_assembly_or_exe(opts.output_type) {
128-
let LLVMAssemblyFile = 0 as c_int;
129-
let LLVMObjectFile = 1 as c_int;
130130
let LLVMOptNone = 0 as c_int; // -O0
131131
let LLVMOptLess = 1 as c_int; // -O1
132132
let LLVMOptDefault = 2 as c_int; // -O2, -Os
@@ -143,8 +143,8 @@ mod write {
143143
let mut FileType;
144144
if opts.output_type == output_type_object ||
145145
opts.output_type == output_type_exe {
146-
FileType = LLVMObjectFile;
147-
} else { FileType = LLVMAssemblyFile; }
146+
FileType = lib::llvm::ObjectFile;
147+
} else { FileType = lib::llvm::AssemblyFile; }
148148
// Write optimized bitcode if --save-temps was on.
149149

150150
if opts.save_temps {
@@ -169,7 +169,7 @@ mod write {
169169
llmod,
170170
buf_t,
171171
buf_o,
172-
LLVMAssemblyFile,
172+
lib::llvm::AssemblyFile as c_uint,
173173
CodeGenOptLevel,
174174
true)})});
175175
}
@@ -189,7 +189,7 @@ mod write {
189189
llmod,
190190
buf_t,
191191
buf_o,
192-
LLVMObjectFile,
192+
lib::llvm::ObjectFile as c_uint,
193193
CodeGenOptLevel,
194194
true)})});
195195
}
@@ -207,7 +207,7 @@ mod write {
207207
llmod,
208208
buf_t,
209209
buf_o,
210-
FileType,
210+
FileType as c_uint,
211211
CodeGenOptLevel,
212212
true)})});
213213
}
@@ -288,7 +288,7 @@ mod write {
288288
*/
289289

290290
fn build_link_meta(sess: session, c: ast::crate, output: str,
291-
sha: sha1) -> encoder::link_meta {
291+
sha: sha1) -> link_meta {
292292

293293
type provided_metas =
294294
{name: option<str>,
@@ -412,7 +412,7 @@ fn truncated_sha1_result(sha: sha1) -> str unsafe {
412412

413413
// This calculates STH for a symbol, as defined above
414414
fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t,
415-
link_meta: encoder::link_meta) -> str {
415+
link_meta: link_meta) -> str {
416416
// NB: do *not* use abbrevs here as we want the symbol names
417417
// to be independent of one another in the crate.
418418

@@ -525,7 +525,7 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
525525
fn link_binary(sess: session,
526526
obj_filename: str,
527527
out_filename: str,
528-
lm: encoder::link_meta) {
528+
lm: link_meta) {
529529
// Converts a library file name into a cc -l argument
530530
fn unlib(config: @session::config, filename: str) -> str unsafe {
531531
let rmlib = fn@(filename: str) -> str {

src/rustc/lib/llvm.rs

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
44

55
type Opcode = u32;
66
type Bool = c_uint;
7-
const True: Bool = 1u32; // FIXME: should be '1 as Bool'
8-
const False: Bool = 0u32;
7+
const True: Bool = 1 as Bool;
8+
const False: Bool = 0 as Bool;
99

1010
// Consts for the LLVM CallConv type, pre-cast to uint.
1111

@@ -75,9 +75,7 @@ enum Attribute {
7575
NonLazyBindAttribute = 2147483648,
7676
}
7777

78-
// Consts for the LLVM IntPredicate type, pre-cast to uint.
79-
// FIXME: as above.
80-
78+
// enum for the LLVM IntPredicate type
8179
enum IntPredicate {
8280
IntEQ = 32,
8381
IntNE = 33,
@@ -91,9 +89,7 @@ enum IntPredicate {
9189
IntSLE = 41,
9290
}
9391

94-
// Consts for the LLVM RealPredicate type, pre-case to uint.
95-
// FIXME: as above.
96-
92+
// enum for the LLVM RealPredicate type
9793
enum RealPredicate {
9894
RealOEQ = 1,
9995
RealOGT = 2,
@@ -111,6 +107,34 @@ enum RealPredicate {
111107
RealUNE = 14,
112108
}
113109

110+
// enum for the LLVM TypeKind type - must stay in sync with the def of
111+
// LLVMTypeKind in llvm/include/llvm-c/Core.h
112+
enum TypeKind {
113+
Void = 0,
114+
Half = 1,
115+
Float = 2,
116+
Double = 3,
117+
X86_FP80 = 4,
118+
FP128 = 5,
119+
PPC_FP128 = 6,
120+
Label = 7,
121+
Integer = 8,
122+
Function = 9,
123+
Struct = 10,
124+
Array = 11,
125+
Pointer = 12,
126+
Vector = 13,
127+
Metadata = 14,
128+
X86_MMX = 15
129+
}
130+
131+
// FIXME: Not used right now, but will be once #2334 is fixed
132+
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
133+
enum FileType {
134+
AssemblyFile = 0,
135+
ObjectFile = 1
136+
}
137+
114138
// Opaque pointer types
115139
enum Module_opaque {}
116140
type ModuleRef = *Module_opaque;
@@ -171,12 +195,7 @@ native mod llvm {
171195
fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
172196

173197
/** See llvm::LLVMTypeKind::getTypeID. */
174-
175-
// FIXME: returning int rather than TypeKind because
176-
// we directly inspect the values, and casting from
177-
// a native doesn't work yet (only *to* a native).
178-
179-
fn LLVMGetTypeKind(Ty: TypeRef) -> c_int;
198+
fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
180199

181200
/** See llvm::LLVMType::getContext. */
182201
fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
@@ -294,9 +313,7 @@ native mod llvm {
294313
/* Operations on scalar constants */
295314
fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) ->
296315
ValueRef;
297-
// FIXME: radix is actually u8, but our native layer can't handle this
298-
// yet. lucky for us we're little-endian. Small miracles.
299-
fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: c_int) ->
316+
fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8) ->
300317
ValueRef;
301318
fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
302319
SLen: c_uint,
@@ -764,8 +781,8 @@ native mod llvm {
764781
/** Adds the target data to the given pass manager. The pass manager
765782
references the target data only weakly. */
766783
fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
767-
/** Returns the size of a type. FIXME: rv is actually a C_Ulonglong! */
768-
fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
784+
/** Returns the size of a type. */
785+
fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
769786
fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
770787
/** Returns the preferred alignment of a type. */
771788
fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
@@ -879,10 +896,11 @@ native mod llvm {
879896
fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
880897
MemoryBufferRef;
881898

882-
/* FIXME: The FileType is an enum.*/
883899
fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
884900
Triple: *c_char,
885-
Output: *c_char, FileType: c_int,
901+
// FIXME: When #2334 is fixed, change
902+
// c_uint to FileType
903+
Output: *c_char, FileType: c_uint,
886904
OptLevel: c_int,
887905
EnableSegmentedStacks: bool);
888906

@@ -896,10 +914,6 @@ native mod llvm {
896914
/** Parses LLVM asm in the given file */
897915
fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
898916

899-
/** FiXME: Hacky adaptor for lack of c_ulonglong in FFI: */
900-
fn LLVMRustConstInt(IntTy: TypeRef, N_hi: c_uint, N_lo: c_uint,
901-
SignExtend: Bool) -> ValueRef;
902-
903917
fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
904918
Output: *c_char);
905919

@@ -970,7 +984,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
970984

971985
let outer = outer0 + [ty];
972986

973-
let kind: int = llvm::LLVMGetTypeKind(ty) as int;
987+
let kind = llvm::LLVMGetTypeKind(ty);
974988

975989
fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str {
976990
let mut s: str = "";
@@ -983,20 +997,18 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
983997
}
984998

985999
alt kind {
986-
// FIXME: more enum-as-int constants determined from Core::h;
987-
// horrible, horrible. Complete as needed.
988-
0 { ret "Void"; }
989-
1 { ret "Half"; }
990-
2 { ret "Float"; }
991-
3 { ret "Double"; }
992-
4 { ret "X86_FP80"; }
993-
5 { ret "FP128"; }
994-
6 { ret "PPC_FP128"; }
995-
7 { ret "Label"; }
996-
8 {
1000+
Void { ret "Void"; }
1001+
Half { ret "Half"; }
1002+
Float { ret "Float"; }
1003+
Double { ret "Double"; }
1004+
X86_FP80 { ret "X86_FP80"; }
1005+
FP128 { ret "FP128"; }
1006+
PPC_FP128 { ret "PPC_FP128"; }
1007+
Label { ret "Label"; }
1008+
Integer {
9971009
ret "i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
9981010
}
999-
9 {
1011+
Function {
10001012
let mut s = "fn(";
10011013
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
10021014
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
@@ -1009,7 +1021,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
10091021
s += type_to_str_inner(names, outer, out_ty);
10101022
ret s;
10111023
}
1012-
10 {
1024+
Struct {
10131025
let mut s: str = "{";
10141026
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
10151027
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) ->
10201032
s += "}";
10211033
ret s;
10221034
}
1023-
11 {
1035+
Array {
10241036
let el_ty = llvm::LLVMGetElementType(ty);
10251037
ret "[" + type_to_str_inner(names, outer, el_ty) + " x " +
10261038
uint::str(llvm::LLVMGetArrayLength(ty) as uint) + "]";
10271039
}
1028-
12 {
1040+
Pointer {
10291041
let mut i: uint = 0u;
10301042
for outer0.each {|tout|
10311043
i += 1u;
@@ -1045,10 +1057,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
10451057
ret addrstr + "*" +
10461058
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
10471059
}
1048-
13 { ret "Vector"; }
1049-
14 { ret "Metadata"; }
1050-
15 { ret "X86_MMAX"; }
1051-
_ { #error("unknown TypeKind %d", kind as int); fail; }
1060+
Vector { ret "Vector"; }
1061+
Metadata { ret "Metadata"; }
1062+
X86_MMX { ret "X86_MMAX"; }
10521063
}
10531064
}
10541065

src/rustc/metadata/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ fn hash_path(&&s: str) -> uint {
132132
for str::each(s) {|ch| h = (h << 5u) + h ^ (ch as uint); }
133133
ret h;
134134
}
135+
136+
type link_meta = {name: str, vers: str, extras_hash: str};
137+

src/rustc/metadata/creader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ fn resolve_crate_deps(e: env, cdata: @[u8]) -> cstore::cnum_map {
239239
#debug("need to load it");
240240
// This is a new one so we've got to load it
241241
// FIXME: Need better error reporting than just a bogus span
242+
// #2404
242243
let fake_span = ast_util::dummy_sp();
243244
let local_cnum =
244245
resolve_crate(e, cname, cmetas, dep.hash, fake_span);

src/rustc/metadata/csearch.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
141141
decoder::get_type(cdata, def.node, tcx)
142142
}
143143

144-
/* FIXME: Refactor */
145144
fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
146145
def: ast::def_id) -> ty::ty_param_bounds_and_ty {
147146
let cstore = tcx.sess.cstore;

src/rustc/metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ fn get_meta_items(md: ebml::doc) -> [@ast::meta_item] {
578578
let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
579579
let n = str::from_bytes(ebml::doc_data(nd));
580580
let v = str::from_bytes(ebml::doc_data(vd));
581-
// FIXME (#611): Should be able to decode meta_name_value variants,
582-
// but currently they can't be encoded
581+
// FIXME (#623): Should be able to decode meta_name_value variants,
582+
// but currently the encoder just drops them
583583
items += [attr::mk_name_value_item_str(n, v)];
584584
};
585585
ebml::tagged_docs(md, tag_meta_item_list) {|meta_item_doc|

src/rustc/metadata/encoder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import std::ebml::serializer;
2020
import syntax::ast;
2121
import syntax::diagnostic::span_handler;
2222

23-
export link_meta;
2423
export encode_parms;
2524
export encode_metadata;
2625
export encoded_ty;
@@ -33,9 +32,6 @@ export encode_ctxt;
3332
export write_type;
3433
export encode_def_id;
3534

36-
// FIXME: This probably belongs somewhere else
37-
type link_meta = {name: str, vers: str, extras_hash: str};
38-
3935
type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
4036

4137
type encode_inlined_item = fn@(ecx: @encode_ctxt,
@@ -916,7 +912,7 @@ fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
916912
ebml_w.end_tag();
917913
ebml_w.end_tag();
918914
}
919-
_ {/* FIXME (#611) */ }
915+
_ {/* FIXME (#623): encode other variants */ }
920916
}
921917
}
922918
meta_list(name, items) {

src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import link::{mangle_internal_name_by_type_only,
3939
mangle_internal_name_by_path_and_seq,
4040
mangle_exported_name};
4141
import metadata::{csearch, cstore, encoder};
42+
import metadata::common::link_meta;
4243
import util::ppaux::{ty_to_str, ty_to_short_str};
4344

4445
import common::*;
@@ -5150,7 +5151,7 @@ fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
51505151
}
51515152

51525153

5153-
fn decl_crate_map(sess: session::session, mapmeta: encoder::link_meta,
5154+
fn decl_crate_map(sess: session::session, mapmeta: link_meta,
51545155
llmod: ModuleRef) -> ValueRef {
51555156
let targ_cfg = sess.targ_cfg;
51565157
let int_type = T_int(targ_cfg);
@@ -5274,7 +5275,7 @@ fn write_abi_version(ccx: @crate_ctxt) {
52745275
fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
52755276
output: str, emap: resolve::exp_map,
52765277
maps: astencode::maps)
5277-
-> (ModuleRef, encoder::link_meta) {
5278+
-> (ModuleRef, link_meta) {
52785279
let sha = std::sha1::sha1();
52795280
let link_meta = link::build_link_meta(sess, *crate, output, sha);
52805281
let reachable = reachable::find_reachable(crate.node.module, emap, tcx,

0 commit comments

Comments
 (0)