Skip to content

Commit 0d05848

Browse files
author
Robert Zakrzewski
committed
Refactor type_f16|32|128 functions. Common type_kind()
1 parent 55788e4 commit 0d05848

File tree

1 file changed

+5
-47
lines changed

1 file changed

+5
-47
lines changed

src/type_.rs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -125,47 +125,32 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
125125
self.isize_type
126126
}
127127

128-
#[cfg(feature = "master")]
129128
fn type_f16(&self) -> Type<'gcc> {
129+
#[cfg(feature = "master")]
130130
if self.supports_f16_type {
131131
return self.context.new_c_type(CType::Float16);
132132
}
133-
unimplemented!("f16")
134-
}
135-
136-
#[cfg(not(feature = "master"))]
137-
fn type_f16(&self) -> Type<'gcc> {
138-
unimplemented!("f16")
133+
bug!("unsupported float width 16")
139134
}
140135

141-
#[cfg(feature = "master")]
142136
fn type_f32(&self) -> Type<'gcc> {
137+
#[cfg(feature = "master")]
143138
if self.supports_f32_type {
144139
return self.context.new_c_type(CType::Float32);
145140
}
146141
self.float_type
147142
}
148143

149-
#[cfg(not(feature = "master"))]
150-
fn type_f32(&self) -> Type<'gcc> {
151-
self.float_type
152-
}
153-
154144
fn type_f64(&self) -> Type<'gcc> {
155145
self.double_type
156146
}
157147

158-
#[cfg(feature = "master")]
159148
fn type_f128(&self) -> Type<'gcc> {
149+
#[cfg(feature = "master")]
160150
if self.supports_f128_type {
161151
return self.context.new_c_type(CType::Float128);
162152
}
163-
unimplemented!("f128")
164-
}
165-
166-
#[cfg(not(feature = "master"))]
167-
fn type_f128(&self) -> Type<'gcc> {
168-
unimplemented!("f128")
153+
bug!("unsupported float width 128")
169154
}
170155

171156
fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
@@ -193,7 +178,6 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
193178
typ
194179
}
195180

196-
#[cfg(feature = "master")]
197181
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
198182
if self.is_int_type_or_bool(typ) {
199183
TypeKind::Integer
@@ -227,32 +211,6 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
227211
}
228212
}
229213

230-
#[cfg(not(feature = "master"))]
231-
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
232-
if self.is_int_type_or_bool(typ) {
233-
TypeKind::Integer
234-
} else if typ.is_compatible_with(self.float_type) {
235-
TypeKind::Float
236-
} else if typ.is_compatible_with(self.double_type) {
237-
TypeKind::Double
238-
} else if typ.is_vector() {
239-
TypeKind::Vector
240-
} else if typ.get_pointee().is_some() {
241-
TypeKind::Pointer
242-
} else if typ.dyncast_array().is_some() {
243-
TypeKind::Array
244-
} else if typ.is_struct().is_some() {
245-
TypeKind::Struct
246-
} else if typ.dyncast_function_ptr_type().is_some() {
247-
TypeKind::Function
248-
} else if typ == self.type_void() {
249-
TypeKind::Void
250-
} else {
251-
// TODO(antoyo): support other types.
252-
unimplemented!();
253-
}
254-
}
255-
256214
fn type_ptr(&self) -> Type<'gcc> {
257215
self.type_ptr_to(self.type_void())
258216
}

0 commit comments

Comments
 (0)