@@ -4,8 +4,8 @@ import libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
4
4
5
5
type Opcode = u32 ;
6
6
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 ;
9
9
10
10
// Consts for the LLVM CallConv type, pre-cast to uint.
11
11
@@ -75,9 +75,7 @@ enum Attribute {
75
75
NonLazyBindAttribute = 2147483648 ,
76
76
}
77
77
78
- // Consts for the LLVM IntPredicate type, pre-cast to uint.
79
- // FIXME: as above.
80
-
78
+ // enum for the LLVM IntPredicate type
81
79
enum IntPredicate {
82
80
IntEQ = 32 ,
83
81
IntNE = 33 ,
@@ -91,9 +89,7 @@ enum IntPredicate {
91
89
IntSLE = 41 ,
92
90
}
93
91
94
- // Consts for the LLVM RealPredicate type, pre-case to uint.
95
- // FIXME: as above.
96
-
92
+ // enum for the LLVM RealPredicate type
97
93
enum RealPredicate {
98
94
RealOEQ = 1 ,
99
95
RealOGT = 2 ,
@@ -111,6 +107,34 @@ enum RealPredicate {
111
107
RealUNE = 14 ,
112
108
}
113
109
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
+
114
138
// Opaque pointer types
115
139
enum Module_opaque { }
116
140
type ModuleRef = * Module_opaque ;
@@ -171,12 +195,7 @@ native mod llvm {
171
195
fn LLVMSetModuleInlineAsm ( M : ModuleRef , Asm : * c_char ) ;
172
196
173
197
/** 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 ;
180
199
181
200
/** See llvm::LLVMType::getContext. */
182
201
fn LLVMGetTypeContext ( Ty : TypeRef ) -> ContextRef ;
@@ -294,9 +313,7 @@ native mod llvm {
294
313
/* Operations on scalar constants */
295
314
fn LLVMConstInt ( IntTy : TypeRef , N : c_ulonglong , SignExtend : Bool ) ->
296
315
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 ) ->
300
317
ValueRef ;
301
318
fn LLVMConstIntOfStringAndSize ( IntTy : TypeRef , Text : * c_char ,
302
319
SLen : c_uint ,
@@ -764,8 +781,8 @@ native mod llvm {
764
781
/** Adds the target data to the given pass manager. The pass manager
765
782
references the target data only weakly. */
766
783
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 ;
769
786
fn LLVMABISizeOfType ( TD : TargetDataRef , Ty : TypeRef ) -> c_uint ;
770
787
/** Returns the preferred alignment of a type. */
771
788
fn LLVMPreferredAlignmentOfType ( TD : TargetDataRef ,
@@ -879,10 +896,11 @@ native mod llvm {
879
896
fn LLVMRustCreateMemoryBufferWithContentsOfFile ( Path : * c_char ) ->
880
897
MemoryBufferRef ;
881
898
882
- /* FIXME: The FileType is an enum.*/
883
899
fn LLVMRustWriteOutputFile ( PM : PassManagerRef , M : ModuleRef ,
884
900
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 ,
886
904
OptLevel : c_int ,
887
905
EnableSegmentedStacks : bool ) ;
888
906
@@ -896,10 +914,6 @@ native mod llvm {
896
914
/** Parses LLVM asm in the given file */
897
915
fn LLVMRustParseAssemblyFile ( Filename : * c_char ) -> ModuleRef ;
898
916
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
-
903
917
fn LLVMRustAddPrintModulePass ( PM : PassManagerRef , M : ModuleRef ,
904
918
Output : * c_char ) ;
905
919
@@ -970,7 +984,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
970
984
971
985
let outer = outer0 + [ ty] ;
972
986
973
- let kind: int = llvm:: LLVMGetTypeKind ( ty) as int ;
987
+ let kind = llvm:: LLVMGetTypeKind ( ty) ;
974
988
975
989
fn tys_str ( names : type_names , outer : [ TypeRef ] , tys : [ TypeRef ] ) -> str {
976
990
let mut s: str = "" ;
@@ -983,20 +997,18 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
983
997
}
984
998
985
999
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 {
997
1009
ret "i" + int:: str ( llvm:: LLVMGetIntTypeWidth ( ty) as int ) ;
998
1010
}
999
- 9 {
1011
+ Function {
1000
1012
let mut s = "fn(" ;
1001
1013
let out_ty: TypeRef = llvm:: LLVMGetReturnType ( ty) ;
1002
1014
let n_args = llvm:: LLVMCountParamTypes ( ty) as uint ;
@@ -1009,7 +1021,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
1009
1021
s += type_to_str_inner ( names, outer, out_ty) ;
1010
1022
ret s;
1011
1023
}
1012
- 10 {
1024
+ Struct {
1013
1025
let mut s: str = "{" ;
1014
1026
let n_elts = llvm:: LLVMCountStructElementTypes ( ty) as uint ;
1015
1027
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) ->
1020
1032
s += "}" ;
1021
1033
ret s;
1022
1034
}
1023
- 11 {
1035
+ Array {
1024
1036
let el_ty = llvm:: LLVMGetElementType ( ty) ;
1025
1037
ret "[" + type_to_str_inner ( names, outer, el_ty) + " x " +
1026
1038
uint:: str ( llvm:: LLVMGetArrayLength ( ty) as uint ) + "]" ;
1027
1039
}
1028
- 12 {
1040
+ Pointer {
1029
1041
let mut i: uint = 0 u;
1030
1042
for outer0. each { |tout|
1031
1043
i += 1 u;
@@ -1045,10 +1057,9 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
1045
1057
ret addrstr + "*" +
1046
1058
type_to_str_inner ( names, outer, llvm:: LLVMGetElementType ( ty) ) ;
1047
1059
}
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" ; }
1052
1063
}
1053
1064
}
1054
1065
0 commit comments