blob: af669222c63bf2fa24a7034d35c1ecbc6d50eaf0 [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
use ir::{self, CcType, Func, FuncParam, Identifier, Item, MappedType, Record, RsType, IR};
/// Creates an identifier
pub fn ir_id(name: &str) -> Identifier {
Identifier { identifier: name.to_string() }
}
/// Creates a simple type instance for `int`/`i32`
pub fn ir_int() -> MappedType {
MappedType {
rs_type: RsType { name: "i32".to_string(), type_params: vec![] },
cc_type: CcType { name: "int".to_string(), type_params: vec![], is_const: false },
}
}
/// Creates a simple `FuncParam` with a given name and `int`/`i32` type
pub fn ir_int_param(name: &str) -> FuncParam {
FuncParam { identifier: ir_id(name), type_: ir_int() }
}
/// Creates a simple `Item::Func` with a given name
pub fn ir_func(name: &str) -> Item {
Item::Func(Func {
identifier: ir_id(name),
is_inline: true,
mangled_name: name.to_string(),
return_type: ir_int(),
params: vec![],
})
}
/// Creates a simple `Item::Record` with a given name.
pub fn ir_record(name: &str) -> Item {
let public_trivial_special = ir::SpecialMemberFunc {
definition: ir::SpecialMemberDefinition::Trivial,
access: ir::AccessSpecifier::Public,
};
Item::Record(Record {
identifier: ir_id(name),
alignment: 0,
size: 0,
fields: vec![],
copy_constructor: public_trivial_special.clone(),
move_constructor: public_trivial_special.clone(),
destructor: public_trivial_special.clone(),
is_trivial_abi: true,
})
}
// Creates a full `IR` data structure from a list of items
pub fn ir_items(items: Vec<Item>) -> IR {
IR { used_headers: vec![], items }
}