use std::collections::BTreeMap;
use crate::context::FuncEntry;
use crate::cpp_gen::wrapper::cpp_wrapper_name;
pub fn generate_fill_table(
entries: &[FuncEntry],
_by_class: &BTreeMap<(String, String), Vec<&FuncEntry>>,
) -> String {
let mut out = String::with_capacity(entries.len() * 80 + 1024);
out.push_str("// Auto-generated by rusteal-codegen. Do not edit.\n\n");
out.push_str("#include \"RustealFuncIds.h\"\n\n");
out.push_str("// Forward declarations of wrapper functions\n");
for entry in entries {
let c_name = cpp_wrapper_name(&entry.class_name, &entry.func_name);
out.push_str(&format!("extern \"C\" uint32_t {c_name}(...);\n"));
}
out.push('\n');
out.push_str("static void* GRustealFuncTable[RustealFuncId::FUNC_COUNT];\n\n");
out.push_str("void RustealFillFuncTable() {\n");
for entry in entries {
let const_name =
crate::rust_gen::func_ids::func_id_const_name(&entry.class_name, &entry.func_name);
let c_name = cpp_wrapper_name(&entry.class_name, &entry.func_name);
out.push_str(&format!(
" GRustealFuncTable[RustealFuncId::{const_name}] = (void*)&{c_name};\n"
));
}
out.push_str("}\n\n");
out.push_str("void** RustealGetFuncTable() {\n");
out.push_str(" return GRustealFuncTable;\n");
out.push_str("}\n\n");
out.push_str("uint32_t RustealGetFuncCount() {\n return RustealFuncId::FUNC_COUNT;\n}\n");
out
}