@@ -25,7 +25,12 @@ use core::u32;
25
25
#[ cfg( feature = "enable-serde" ) ]
26
26
use serde:: { Deserialize , Serialize } ;
27
27
28
- /// An opaque reference to an extended basic block in a function.
28
+ /// An opaque reference to an [extended basic
29
+ /// block](https://en.wikipedia.org/wiki/Extended_basic_block) in a
30
+ /// [`Function`](super::function::Function).
31
+ ///
32
+ /// You can get an `Ebb` using
33
+ /// [`FunctionBuilder::create_ebb`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.create_ebb)
29
34
#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
30
35
pub struct Ebb ( u32 ) ;
31
36
entity_impl ! ( Ebb , "ebb" ) ;
@@ -44,6 +49,18 @@ impl Ebb {
44
49
}
45
50
46
51
/// An opaque reference to an SSA value.
52
+ ///
53
+ /// You can get a constant `Value` from the following
54
+ /// [`InstBuilder`](super::InstBuilder) instructions:
55
+ ///
56
+ /// - [`iconst`](super::InstBuilder::iconst) for integer constants
57
+ /// - [`f32const`](super::InstBuilder::f32const) for 32-bit float constants
58
+ /// - [`f64const`](super::InstBuilder::f64const) for 64-bit float constants
59
+ /// - [`bconst`](super::InstBuilder::bconst) for boolean constants
60
+ /// - [`vconst`](super::InstBuilder::vconst) for vector constants
61
+ /// - [`null`](super::InstBuilder::null) for null reference constants
62
+ ///
63
+ /// Any `InstBuilder` instruction that has an output will also return a `Value`.
47
64
#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
48
65
pub struct Value ( u32 ) ;
49
66
entity_impl ! ( Value , "v" ) ;
@@ -62,12 +79,34 @@ impl Value {
62
79
}
63
80
}
64
81
65
- /// An opaque reference to an instruction in a function.
82
+ /// An opaque reference to an instruction in a [`Function`](super::Function).
83
+ ///
84
+ /// Most usage of `Inst` is internal. `Inst`ructions are returned by
85
+ /// [`InstBuilder`](super::InstBuilder) instructions that do not return a
86
+ /// [`Value`], such as control flow and trap instructions.
87
+ ///
88
+ /// If you look around the API, you can find many inventive uses for `Inst`,
89
+ /// such as [annotating specific instructions with a comment][inst_comment]
90
+ /// or [performing reflection at compile time](super::DataFlowGraph::analyze_branch)
91
+ /// on the type of instruction.
92
+ ///
93
+ /// [inst_comment]: https://github.com/bjorn3/rustc_codegen_cranelift/blob/0f8814fd6da3d436a90549d4bb19b94034f2b19c/src/pretty_clif.rs
66
94
#[ derive( Copy , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
67
95
pub struct Inst ( u32 ) ;
68
96
entity_impl ! ( Inst , "inst" ) ;
69
97
70
98
/// An opaque reference to a stack slot.
99
+ ///
100
+ /// Stack slots represent an address on the
101
+ /// [call stack](https://en.wikipedia.org/wiki/Call_stack).
102
+ ///
103
+ /// `StackSlot`s can be created with
104
+ /// [`FunctionBuilder::create_stackslot`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.create_stack_slot).
105
+ ///
106
+ /// `StackSlot`s are most often used with
107
+ /// [`stack_addr`](super::InstBuilder::stack_addr),
108
+ /// [`stack_load`](super::InstBuilder::stack_load), and
109
+ /// [`stack_store`](super::InstBuilder::stack_store).
71
110
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
72
111
#[ cfg_attr( feature = "enable-serde" , derive( Serialize , Deserialize ) ) ]
73
112
pub struct StackSlot ( u32 ) ;
@@ -87,6 +126,22 @@ impl StackSlot {
87
126
}
88
127
89
128
/// An opaque reference to a global value.
129
+ ///
130
+ /// A `GlobalValue` is a [`Value`](Value) that will be live across the entire
131
+ /// function lifetime. It can be preloaded from other global values.
132
+ ///
133
+ /// You can create a `GlobalValue` in the following ways:
134
+ ///
135
+ /// - When compiling to WASM, you can use it to load values from a
136
+ /// [`VmContext`](super::GlobalValueData::VMContext) using
137
+ /// [`FuncEnvironment::make_global`](https://docs.rs/cranelift-wasm/*/cranelift_wasm/trait.FuncEnvironment.html#tymethod.make_global).
138
+ /// - When compiling to native code, you can use it for objects in static memory with
139
+ /// [`Module::declare_data_in_func`](https://docs.rs/cranelift-module/*/cranelift_module/struct.Module.html#method.declare_data_in_func).
140
+ /// - For any compilation target, it can be registered with
141
+ /// [`FunctionBuilder::create_global_value`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.create_global_value).
142
+ ///
143
+ /// `GlobalValue`s can be retrieved with
144
+ /// [`InstBuilder:global_value`](super::InstBuilder::global_value).
90
145
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
91
146
pub struct GlobalValue ( u32 ) ;
92
147
entity_impl ! ( GlobalValue , "gv" ) ;
@@ -104,7 +159,11 @@ impl GlobalValue {
104
159
}
105
160
}
106
161
107
- /// An opaque reference to a constant
162
+ /// An opaque reference to a constant.
163
+ ///
164
+ /// You can store [`ConstantData`](super::ConstantData) in a
165
+ /// [`ConstantPool`](super::ConstantPool) for efficient storage and retrieval.
166
+ /// See [`ConstantPool::insert`](super::ConstantPool::insert).
108
167
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Ord , PartialOrd ) ]
109
168
pub struct Constant ( u32 ) ;
110
169
entity_impl ! ( Constant , "const" ) ;
@@ -122,7 +181,16 @@ impl Constant {
122
181
}
123
182
}
124
183
125
- /// An opaque reference to a jump table.
184
+ /// An opaque reference to a [jump table](https://en.wikipedia.org/wiki/Branch_table).
185
+ ///
186
+ /// `JumpTable`s are used for indirect branching and are specialized for dense,
187
+ /// 0-based jump offsets. If you want a jump table which doesn't start at 0,
188
+ /// or is not contiguous, consider using a [`Switch`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.Switch.html) instead.
189
+ ///
190
+ /// `JumpTable` are used with [`br_table`](super::InstBuilder::br_table).
191
+ ///
192
+ /// `JumpTable`s can be created with
193
+ /// [`create_jump_table`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.create_jump_table).
126
194
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
127
195
#[ cfg_attr( feature = "enable-serde" , derive( Serialize , Deserialize ) ) ]
128
196
pub struct JumpTable ( u32 ) ;
@@ -141,7 +209,22 @@ impl JumpTable {
141
209
}
142
210
}
143
211
144
- /// A reference to an external function.
212
+ /// An opaque reference to another [`Function`](super::Function).
213
+ ///
214
+ /// `FuncRef`s are used for [direct](super::InstBuilder::call) function calls
215
+ /// and by [`func_addr`](super::InstBuilder::func_addr) for use in
216
+ /// [indirect](super::InstBuilder::call_indirect) function calls.
217
+ ///
218
+ /// `FuncRef`s can be created with
219
+ ///
220
+ /// - [`FunctionBuilder::import_function`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.import_function)
221
+ /// for external functions
222
+ /// - [`Module::declare_func_in_func`](https://docs.rs/cranelift-module/*/cranelift_module/struct.Module.html#method.declare_func_in_func)
223
+ /// for functions declared elsewhere in the same native
224
+ /// [`Module`](https://docs.rs/cranelift-module/*/cranelift_module/struct.Module.html)
225
+ /// - [`FuncEnvironment::make_direct_func`](https://docs.rs/cranelift-wasm/*/cranelift_wasm/trait.FuncEnvironment.html#tymethod.make_direct_func)
226
+ /// for functions declared in the same WebAssembly
227
+ /// [`FuncEnvironment`](https://docs.rs/cranelift-wasm/*/cranelift_wasm/trait.FuncEnvironment.html#tymethod.make_direct_func)
145
228
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
146
229
pub struct FuncRef ( u32 ) ;
147
230
entity_impl ! ( FuncRef , "fn" ) ;
@@ -159,7 +242,18 @@ impl FuncRef {
159
242
}
160
243
}
161
244
162
- /// A reference to a function signature.
245
+ /// An opaque reference to a function [`Signature`](super::Signature).
246
+ ///
247
+ /// `SigRef`s are used to declare a function with
248
+ /// [`FunctionBuiler::import_function`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.import_function)
249
+ /// as well as to make an [indirect function call](super::InstBuilder::call_indirect).
250
+ ///
251
+ /// `SigRef`s can be created with
252
+ /// [`FunctionBuilder::import_signature`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.import_signature).
253
+ ///
254
+ /// You can retrieve the [`Signature`](super::Signature) that was used to create a `SigRef` with
255
+ /// [`FunctionBuilder::signature`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.signature) or
256
+ /// [`func.dfg.signatures`](super::dfg::DataFlowGraph::signatures).
163
257
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
164
258
pub struct SigRef ( u32 ) ;
165
259
entity_impl ! ( SigRef , "sig" ) ;
@@ -177,7 +271,12 @@ impl SigRef {
177
271
}
178
272
}
179
273
180
- /// A reference to a heap.
274
+ /// An opaque reference to a [heap](https://en.wikipedia.org/wiki/Memory_management#DYNAMIC).
275
+ ///
276
+ /// Heaps are used to access dynamically allocated memory through
277
+ /// [`heap_addr`](super::InstBuilder::heap_addr).
278
+ ///
279
+ /// To create a heap, use [`FunctionBuilder::create_heap`](https://docs.rs/cranelift-frontend/*/cranelift_frontend/struct.FunctionBuilder.html#method.create_heap).
181
280
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
182
281
pub struct Heap ( u32 ) ;
183
282
entity_impl ! ( Heap , "heap" ) ;
@@ -195,7 +294,13 @@ impl Heap {
195
294
}
196
295
}
197
296
198
- /// A reference to a table.
297
+ /// An opaque reference to a [WebAssembly
298
+ /// table](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables).
299
+ ///
300
+ /// `Table`s are used to store a list of function references.
301
+ /// They can be created with [`FuncEnvironment::make_table`](https://docs.rs/cranelift-wasm/*/cranelift_wasm/trait.FuncEnvironment.html#tymethod.make_table).
302
+ /// They can be used with
303
+ /// [`FuncEnvironment::translate_call_indirect`](https://docs.rs/cranelift-wasm/*/cranelift_wasm/trait.FuncEnvironment.html#tymethod.translate_call_indirect).
199
304
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
200
305
pub struct Table ( u32 ) ;
201
306
entity_impl ! ( Table , "table" ) ;
@@ -213,7 +318,7 @@ impl Table {
213
318
}
214
319
}
215
320
216
- /// A reference to any of the entities defined in this module that can appear in CLIF IR.
321
+ /// An opaque reference to any of the entities defined in this module that can appear in CLIF IR.
217
322
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
218
323
pub enum AnyEntity {
219
324
/// The whole function.
0 commit comments