Expand description
This module defines and implements functions for working with the Jib IR (intermediate representation) that is produced by Sail. It is a simple goto/conditional branch language, where each function can declare and use an arbitrary amount of variables.
All the IR types are parametric in the identifier type. They are
initially parsed as e.g. Def<String> but then the names are
interned into a symbol table (Symtab) and they are replaced by
values of type Name, which is a wrapper around u32.
To conveniently initialize the IR for a Sail architecture specification see the crate::init module.
Modules§
- linearize
- This module provides a function linearize() that converts IR from function bodies containing loops and other IR, into a linear sequence of instructions without any control flow.
- serialize
- This module provides serde-based serialization support for the
IR. Note that the various
Primop*instruction constructors cannot be serialized, as they are direct function pointers to the primop implementations. As such this module is intended to serialize and deserialize the AST only before the primops have been inserted. - ssa
- This module provides a control flow graph type CFG for IR analysis and transforms, and additionally supports conversion of that CFG into single static assignment (SSA) form via CFG::ssa().
Structs§
- Enum
Member - Name
- Shared
State - All symbolic evaluation happens over some (immutable) IR. The SharedState provides each worker that is performing symbolic evaluation with a convenient view into that IR.
- Symtab
- A Symtab is a symbol table that maps each
u32identifier used in the IR to it’s&strname and vice-versa. - Variables
- An iterator over the Variable type for modifying variable usages and declarations.
Enums§
- Assertion
Mode - There are two ways to handle assertions in the Sail code, the first being to assume that they succeed (essentially treating them like assumptions in the SMT) - this is the optimistic mode. The other way is to assume that they might fail, and check each assertion to ensure that it can never fail - this is the pessimistic mode.
- Def
- Exp
- Instr
- Labeled
Instr - By default each jump or goto just contains a
usizeoffset into the instruction vector. This representation is efficient but hard to work with, so we support mapping this representation into one where any instruction can have an explicit label, and jumps point to those explicit labels, and then going back to the offset based representation for execution. - Loc
- A Loc is a location that can be assigned to.
- Op
- Ty
- UVal
- A UVal is a potentially uninitialized Val.
- Val
- A value is either a symbolic value, represented as
Symbolic(n)for where n is the identifier of the variable in the SMT solver, or one of the concrete values in this enum. - Variable
- A reference to either the declaration of a variable or a usage location.
Constants§
- BITVECTOR_
UPDATE - Special primitive for
update_fbits - BV_
BIT_ LEFT - BV_BIT_LEFT is the field name for the left element of a bitvector,bit pair
- BV_
BIT_ RIGHT - BV_BIT_RIGHT is the field name for the right element of a bitvector,bit pair
- CURRENT_
EXCEPTION - CURRENT_EXCEPTION is a global variable containing an exception
with the sail type
exception. It is only defined when HAVE_EXCEPTION is true. - ELF_
ENTRY - The function id for the
elf_entryfunction. - HAVE_
EXCEPTION - HAVE_EXCEPTION is a global boolean variable which is true if an exception is being thrown.
- INTERNAL_
VECTOR_ INIT - Special primitive that initializes a generic vector
- INTERNAL_
VECTOR_ UPDATE - Special primitive used while initializing a generic vector
- NULL
- NULL is a global letbinding which contains the empty list
- REG_
DEREF - Is the function id of the
reg_derefprimop, that implements register dereferencing*Rin Sail. - RESET_
REGISTERS - RESET_REGISTERS is a special function that resets register values according to the ISA config
- RETURN
- When a function returns via the Instr::End instruction, the value returned is contained in the special RETURN variable.
- SAIL_
ASSERT - Function id for the primop implementing the
assertconstruct in Sail. - SAIL_
ASSUME - Function id for the
assumeprimop, which is like a Sail assert but always corresponds to an raw SMT assert. - SAIL_
EXCEPTION - SAIL_EXCEPTION is the Sail
exceptiontype - SAIL_
EXIT - Function id for the primop implementing the
exitconstruct in Sail. - THROW_
LOCATION - THROW_LOCATION is a global variable which contains a string describing the location of the last thrown exeception.
- TOP_
LEVEL_ LET - TOP_LEVEL_LET is a name used in backtraces when evaluating a top-level let definition
Functions§
- append_
instrs - Append instructions from rhs into the lhs vector, leaving rhs
empty (the same behavior as
Vec::append). - label_
instrs - Rewrites an instruction sequence with implicit offset based labels into a vector where the labels are explicit. Note that this just adds a label to every instruction which is equal to its offset. Use prune_labels to remove any labels which are not the target of any jump or goto instruction.
- prune_
labels - Remove labels which are not the targets of any jump or goto.
- unlabel_
instrs - Remove the explicit labels from instructions, and go back to using offset based jumps and gotos.