@@ -3188,6 +3188,11 @@ impl ConstExpr {
3188
3188
Self { bytes }
3189
3189
}
3190
3190
3191
+ fn with_insn ( mut self , insn : Instruction ) -> Self {
3192
+ insn. encode ( & mut self . bytes ) ;
3193
+ self
3194
+ }
3195
+
3191
3196
/// Create a constant expression containing a single `global.get` instruction.
3192
3197
pub fn global_get ( index : u32 ) -> Self {
3193
3198
Self :: new_insn ( Instruction :: GlobalGet ( index) )
@@ -3227,6 +3232,76 @@ impl ConstExpr {
3227
3232
pub fn v128_const ( value : i128 ) -> Self {
3228
3233
Self :: new_insn ( Instruction :: V128Const ( value) )
3229
3234
}
3235
+
3236
+ /// Add a `global.get` instruction to this constant expression.
3237
+ pub fn with_global_get ( self , index : u32 ) -> Self {
3238
+ self . with_insn ( Instruction :: GlobalGet ( index) )
3239
+ }
3240
+
3241
+ /// Add a `ref.null` instruction to this constant expression.
3242
+ pub fn with_ref_null ( self , ty : HeapType ) -> Self {
3243
+ self . with_insn ( Instruction :: RefNull ( ty) )
3244
+ }
3245
+
3246
+ /// Add a `ref.func` instruction to this constant expression.
3247
+ pub fn with_ref_func ( self , func : u32 ) -> Self {
3248
+ self . with_insn ( Instruction :: RefFunc ( func) )
3249
+ }
3250
+
3251
+ /// Add an `i32.const` instruction to this constant expression.
3252
+ pub fn with_i32_const ( self , value : i32 ) -> Self {
3253
+ self . with_insn ( Instruction :: I32Const ( value) )
3254
+ }
3255
+
3256
+ /// Add an `i64.const` instruction to this constant expression.
3257
+ pub fn with_i64_const ( self , value : i64 ) -> Self {
3258
+ self . with_insn ( Instruction :: I64Const ( value) )
3259
+ }
3260
+
3261
+ /// Add a `f32.const` instruction to this constant expression.
3262
+ pub fn with_f32_const ( self , value : f32 ) -> Self {
3263
+ self . with_insn ( Instruction :: F32Const ( value) )
3264
+ }
3265
+
3266
+ /// Add a `f64.const` instruction to this constant expression.
3267
+ pub fn with_f64_const ( self , value : f64 ) -> Self {
3268
+ self . with_insn ( Instruction :: F64Const ( value) )
3269
+ }
3270
+
3271
+ /// Add a `v128.const` instruction to this constant expression.
3272
+ pub fn with_v128_const ( self , value : i128 ) -> Self {
3273
+ self . with_insn ( Instruction :: V128Const ( value) )
3274
+ }
3275
+
3276
+ /// Add an `i32.add` instruction to this constant expression.
3277
+ pub fn with_i32_add ( self ) -> Self {
3278
+ self . with_insn ( Instruction :: I32Add )
3279
+ }
3280
+
3281
+ /// Add an `i32.sub` instruction to this constant expression.
3282
+ pub fn with_i32_sub ( self ) -> Self {
3283
+ self . with_insn ( Instruction :: I32Sub )
3284
+ }
3285
+
3286
+ /// Add an `i32.mul` instruction to this constant expression.
3287
+ pub fn with_i32_mul ( self ) -> Self {
3288
+ self . with_insn ( Instruction :: I32Mul )
3289
+ }
3290
+
3291
+ /// Add an `i64.add` instruction to this constant expression.
3292
+ pub fn with_i64_add ( self ) -> Self {
3293
+ self . with_insn ( Instruction :: I64Add )
3294
+ }
3295
+
3296
+ /// Add an `i64.sub` instruction to this constant expression.
3297
+ pub fn with_i64_sub ( self ) -> Self {
3298
+ self . with_insn ( Instruction :: I64Sub )
3299
+ }
3300
+
3301
+ /// Add an `i64.mul` instruction to this constant expression.
3302
+ pub fn with_i64_mul ( self ) -> Self {
3303
+ self . with_insn ( Instruction :: I64Mul )
3304
+ }
3230
3305
}
3231
3306
3232
3307
impl Encode for ConstExpr {
0 commit comments