Enum sway_ir::instruction::Instruction
source · pub enum Instruction {
Show 22 variants
AddrOf(Value),
AsmBlock(AsmBlock, Vec<AsmArg>),
BinaryOp {
op: BinaryOpKind,
arg1: Value,
arg2: Value,
},
BitCast(Value, Type),
Branch(BranchToWithArgs),
Call(Function, Vec<Value>),
CastPtr(Value, Type, u64),
Cmp(Predicate, Value, Value),
ConditionalBranch {
cond_value: Value,
true_block: BranchToWithArgs,
false_block: BranchToWithArgs,
},
ContractCall {
return_type: Type,
name: String,
params: Value,
coins: Value,
asset_id: Value,
gas: Value,
},
ExtractElement {
array: Value,
ty: Type,
index_val: Value,
},
ExtractValue {
aggregate: Value,
ty: Type,
indices: Vec<u64>,
},
FuelVm(FuelVmInstruction),
GetLocal(LocalVar),
InsertElement {
array: Value,
ty: Type,
value: Value,
index_val: Value,
},
InsertValue {
aggregate: Value,
ty: Type,
value: Value,
indices: Vec<u64>,
},
IntToPtr(Value, Type),
Load(Value),
MemCopy {
dst_val: Value,
src_val: Value,
byte_len: u64,
},
Nop,
Ret(Value, Type),
Store {
dst_val: Value,
stored_val: Value,
},
}
Variants§
AddrOf(Value)
Address of a non-copy (memory) value
AsmBlock(AsmBlock, Vec<AsmArg>)
An opaque list of ASM instructions passed directly to codegen.
BinaryOp
Binary arithmetic operations
BitCast(Value, Type)
Cast the type of a value without changing its actual content.
Branch(BranchToWithArgs)
An unconditional jump.
Call(Function, Vec<Value>)
A function call with a list of arguments.
CastPtr(Value, Type, u64)
Temporary! Cast between ‘pointers’ to reference types. At this intermediate stage, where
we have removed the old get_ptr
instruction, we have no way to do the casting and
offsetting it did, which was used almost exclusively by storage accesses. When we
reintroduce pointers we can make them untyped/opaque which removes the need for casting,
and we can introduce GEP which will allow indexing into aggregates.
Until then we can replicate the get_ptr
functionality with CastPtr
.
The Value
here should always be a get_local
and the types must be non-copy.
Cmp(Predicate, Value, Value)
Comparison between two values using various comparators and returning a boolean.
ConditionalBranch
A conditional jump with the boolean condition value and true or false destinations.
ContractCall
A contract call with a list of arguments
ExtractElement
Reading a specific element from an array.
ExtractValue
Reading a specific field from (nested) structs.
FuelVm(FuelVmInstruction)
Umbrella instruction variant for FuelVM-specific instructions
GetLocal(LocalVar)
Return a local variable.
InsertElement
Writing a specific value to an array.
InsertValue
Writing a specific value to a (nested) struct field.
IntToPtr(Value, Type)
Re-interpret an integer value as pointer of some type
Load(Value)
Read a value from a memory pointer.
MemCopy
Copy a specified number of bytes between pointers.
Nop
No-op, handy as a placeholder instruction.
Ret(Value, Type)
Return from a function.
Store
Write a value to a memory pointer.
Implementations§
source§impl Instruction
impl Instruction
sourcepub fn get_type(&self, context: &Context) -> Option<Type>
pub fn get_type(&self, context: &Context) -> Option<Type>
Some Instruction
s can return a value, but for some a return value doesn’t make sense.
Those which perform side effects such as writing to memory and also terminators such as
Ret
do not have a type.
sourcepub fn get_aggregate(&self, context: &Context) -> Option<Type>
pub fn get_aggregate(&self, context: &Context) -> Option<Type>
Some Instruction
s may have struct arguments. Return it if so for this instruction.
pub fn get_operands(&self) -> Vec<Value> ⓘ
sourcepub fn replace_values(&mut self, replace_map: &FxHashMap<Value, Value>)
pub fn replace_values(&mut self, replace_map: &FxHashMap<Value, Value>)
Replace old_val
with new_val
if it is referenced by this instruction’s arguments.
pub fn may_have_side_effect(&self) -> bool
pub fn is_terminator(&self) -> bool
Trait Implementations§
source§impl Clone for Instruction
impl Clone for Instruction
source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more