1use crate::signatures::SignatureCollection;
2use std::sync::Arc;
3#[cfg(feature = "component-model")]
4use wasmtime_environ::component::ComponentTypes;
5use wasmtime_environ::ModuleTypes;
6use wasmtime_jit::CodeMemory;
7
8pub struct CodeObject {
16 mmap: Arc<CodeMemory>,
24
25 signatures: SignatureCollection,
31
32 types: Types,
37}
38
39impl CodeObject {
40 pub fn new(mmap: Arc<CodeMemory>, signatures: SignatureCollection, types: Types) -> CodeObject {
41 crate::module::register_code(&mmap);
44
45 CodeObject {
46 mmap,
47 signatures,
48 types,
49 }
50 }
51
52 pub fn code_memory(&self) -> &Arc<CodeMemory> {
53 &self.mmap
54 }
55
56 #[cfg(feature = "component-model")]
57 pub fn types(&self) -> &Types {
58 &self.types
59 }
60
61 pub fn module_types(&self) -> &ModuleTypes {
62 self.types.module_types()
63 }
64
65 pub fn signatures(&self) -> &SignatureCollection {
66 &self.signatures
67 }
68}
69
70impl Drop for CodeObject {
71 fn drop(&mut self) {
72 crate::module::unregister_code(&self.mmap);
73 }
74}
75
76pub enum Types {
77 Module(ModuleTypes),
78 #[cfg(feature = "component-model")]
79 Component(Arc<ComponentTypes>),
80}
81
82impl Types {
83 fn module_types(&self) -> &ModuleTypes {
84 match self {
85 Types::Module(m) => m,
86 #[cfg(feature = "component-model")]
87 Types::Component(c) => c.module_types(),
88 }
89 }
90}
91
92impl From<ModuleTypes> for Types {
93 fn from(types: ModuleTypes) -> Types {
94 Types::Module(types)
95 }
96}
97
98#[cfg(feature = "component-model")]
99impl From<Arc<ComponentTypes>> for Types {
100 fn from(types: Arc<ComponentTypes>) -> Types {
101 Types::Component(types)
102 }
103}