cranelift_codegen_meta/
gen_types.rsuse crate::cdsl::types as cdsl_types;
use crate::error;
use crate::srcgen;
fn emit_type(ty: &cdsl_types::ValueType, fmt: &mut srcgen::Formatter) {
let name = ty.to_string().to_uppercase();
let number = ty.number();
fmt.doc_comment(&ty.doc());
fmtln!(fmt, "pub const {}: Type = Type({:#x});\n", name, number);
}
fn emit_vectors(bits: u64, fmt: &mut srcgen::Formatter) {
let vec_size: u64 = bits / 8;
for vec in cdsl_types::ValueType::all_lane_types()
.map(|ty| (ty, cdsl_types::ValueType::from(ty).membytes()))
.filter(|&(_, lane_size)| lane_size != 0 && lane_size < vec_size)
.map(|(ty, lane_size)| (ty, vec_size / lane_size))
.map(|(ty, lanes)| cdsl_types::VectorType::new(ty, lanes))
{
emit_type(&cdsl_types::ValueType::from(vec), fmt);
}
}
fn emit_dynamic_vectors(bits: u64, fmt: &mut srcgen::Formatter) {
let vec_size: u64 = bits / 8;
for vec in cdsl_types::ValueType::all_lane_types()
.map(|ty| (ty, cdsl_types::ValueType::from(ty).membytes()))
.filter(|&(_, lane_size)| lane_size != 0 && lane_size < vec_size)
.map(|(ty, lane_size)| (ty, vec_size / lane_size))
.map(|(ty, lanes)| cdsl_types::DynamicVectorType::new(ty, lanes))
{
emit_type(&cdsl_types::ValueType::from(vec), fmt);
}
}
fn emit_types(fmt: &mut srcgen::Formatter) {
for ty in cdsl_types::ValueType::all_lane_types().map(cdsl_types::ValueType::from) {
emit_type(&ty, fmt);
}
for ty in cdsl_types::ValueType::all_reference_types().map(cdsl_types::ValueType::from) {
emit_type(&ty, fmt);
}
for vec_size in &[16_u64, 32, 64, 128, 256, 512] {
emit_vectors(*vec_size, fmt);
emit_dynamic_vectors(*vec_size, fmt);
}
}
pub(crate) fn generate(filename: &str, out_dir: &std::path::Path) -> Result<(), error::Error> {
let mut fmt = srcgen::Formatter::new();
emit_types(&mut fmt);
fmt.update_file(filename, out_dir)?;
Ok(())
}