Skip to content

Commit

Permalink
Refactor type_f16|32|128 functions. Common type_kind()
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Zakrzewski committed Jun 21, 2024
1 parent 55788e4 commit 0d05848
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,47 +125,32 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.isize_type
}

#[cfg(feature = "master")]
fn type_f16(&self) -> Type<'gcc> {
#[cfg(feature = "master")]
if self.supports_f16_type {
return self.context.new_c_type(CType::Float16);
}
unimplemented!("f16")
}

#[cfg(not(feature = "master"))]
fn type_f16(&self) -> Type<'gcc> {
unimplemented!("f16")
bug!("unsupported float width 16")
}

#[cfg(feature = "master")]
fn type_f32(&self) -> Type<'gcc> {
#[cfg(feature = "master")]
if self.supports_f32_type {
return self.context.new_c_type(CType::Float32);
}
self.float_type
}

#[cfg(not(feature = "master"))]
fn type_f32(&self) -> Type<'gcc> {
self.float_type
}

fn type_f64(&self) -> Type<'gcc> {
self.double_type
}

#[cfg(feature = "master")]
fn type_f128(&self) -> Type<'gcc> {
#[cfg(feature = "master")]
if self.supports_f128_type {
return self.context.new_c_type(CType::Float128);
}
unimplemented!("f128")
}

#[cfg(not(feature = "master"))]
fn type_f128(&self) -> Type<'gcc> {
unimplemented!("f128")
bug!("unsupported float width 128")
}

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

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

#[cfg(not(feature = "master"))]
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
if self.is_int_type_or_bool(typ) {
TypeKind::Integer
} else if typ.is_compatible_with(self.float_type) {
TypeKind::Float
} else if typ.is_compatible_with(self.double_type) {
TypeKind::Double
} else if typ.is_vector() {
TypeKind::Vector
} else if typ.get_pointee().is_some() {
TypeKind::Pointer
} else if typ.dyncast_array().is_some() {
TypeKind::Array
} else if typ.is_struct().is_some() {
TypeKind::Struct
} else if typ.dyncast_function_ptr_type().is_some() {
TypeKind::Function
} else if typ == self.type_void() {
TypeKind::Void
} else {
// TODO(antoyo): support other types.
unimplemented!();
}
}

fn type_ptr(&self) -> Type<'gcc> {
self.type_ptr_to(self.type_void())
}
Expand Down

0 comments on commit 0d05848

Please sign in to comment.