glove

Types

Function block with a label

pub type Block {
  Block(label: String, statements: List(Statement))
}

Constructors

  • Block(label: String, statements: List(Statement))

QBE Comparison Operators QBE Comparison Operators

pub type Comp {
  Sltw
  Sltl
  Slew
  Slel
  Sgtw
  Sgtl
  Sgew
  Sgel
  Cultw
  Cultl
  Culew
  Culel
  Cugtw
  Cugtl
  Cugew
  Cugel
  Ceqw
  Ceql
  Cnew
  Cnel
  Ceqs
  Ceqd
  Cnes
  Cned
  Clts
  Cltd
  Cles
  Cled
  Cgts
  Cgtd
  Cges
  Cged
  Cos
  Cod
  Cuos
  Cuod
  Slt
  Sle
  Sgt
  Sge
  Eq
  Ne
}

Constructors

  • Sltw

    Signed less than (word)

  • Sltl

    Signed less than (long)

  • Slew

    Signed less or equal (word)

  • Slel

    Signed less or equal (long)

  • Sgtw

    Signed greater than (word)

  • Sgtl

    Signed greater than (long)

  • Sgew

    Signed greater or equal (word)

  • Sgel

    Signed greater or equal (long)

  • Cultw

    Unsigned less than (word)

  • Cultl

    Unsigned less than (long)

  • Culew

    Unsigned less or equal (word)

  • Culel

    Unsigned less or equal (long)

  • Cugtw

    Unsigned greater than (word)

  • Cugtl

    Unsigned greater than (long)

  • Cugew

    Unsigned greater or equal (word)

  • Cugel

    Unsigned greater or equal (long)

  • Ceqw

    Equal (word)

  • Ceql

    Equal (long)

  • Cnew

    Not equal (word)

  • Cnel

    Not equal (long)

  • Ceqs

    Equal (single)

  • Ceqd

    Equal (double)

  • Cnes

    Not equal (single)

  • Cned

    Not equal (double)

  • Clts

    Less than (single)

  • Cltd

    Less than (double)

  • Cles

    Less or equal (single)

  • Cled

    Less or equal (double)

  • Cgts

    Greater than (single)

  • Cgtd

    Greater than (double)

  • Cges

    Greater or equal (single)

  • Cged

    Greater or equal (double)

  • Cos

    Ordered - no NaN (single)

  • Cod

    Ordered - no NaN (double)

  • Cuos

    Unordered - contains NaN (single)

  • Cuod

    Unordered - contains NaN (double)

  • Slt

    Legacy: Less Than (deprecated - use Sltw/Sltl)

  • Sle

    Legacy: Less or Equal (deprecated - use Slew/Slel)

  • Sgt

    Legacy: Greater than (deprecated - use Sgtw/Sgtl)

  • Sge

    Legacy: Greater or equal (deprecated - use Sgew/Sgel)

  • Eq

    Legacy: Equal (deprecated - use Ceqw/Ceql)

  • Ne

    Legacy: Not equal (deprecated - use Cnew/Cnel)

QBE data definition

pub type DataDef {
  DataDef(
    linkage: Linkage,
    name: String,
    align: option.Option(Int),
    items: List(#(Type, DataItem)),
  )
}

Constructors

QBE Data definition item

pub type DataItem {
  Symbol(String, option.Option(Int))
  Str(String)
  Constant(Int)
}

Constructors

  • Symbol(String, option.Option(Int))

    Symbol and offset

  • Str(String)

    String

  • Constant(Int)

    Integer

QBE Function

pub type Function {
  Function(
    linkage: Linkage,
    name: String,
    arguments: List(#(Type, Value)),
    return_ty: option.Option(Type),
    blocks: List(Block),
  )
}

Constructors

QBE instruction

pub type Inst {
  Add(Value, Value)
  Sub(Value, Value)
  Mul(Value, Value)
  Div(Value, Value)
  Udiv(Value, Value)
  Rem(Value, Value)
  Urem(Value, Value)
  Neg(Value)
  And(Value, Value)
  Or(Value, Value)
  Xor(Value, Value)
  Sar(Value, Value)
  Shr(Value, Value)
  Shl(Value, Value)
  Comp(Type, Comp, Value, Value)
  Alloc4(Int)
  Alloc8(Int)
  Alloc16(Int)
  Storew(Value, Value)
  Storel(Value, Value)
  Stores(Value, Value)
  Stored(Value, Value)
  Storeh(Value, Value)
  Storeb(Value, Value)
  Loadw(Value)
  Loadsw(Value)
  Loaduw(Value)
  Loadl(Value)
  Loads(Value)
  Loadd(Value)
  Loadsh(Value)
  Loaduh(Value)
  Loadsb(Value)
  Loadub(Value)
  Blit(Value, Value, Int)
  Extsw(Value)
  Extuw(Value)
  Extsh(Value)
  Extuh(Value)
  Extsb(Value)
  Extub(Value)
  Exts(Value)
  Truncd(Value)
  Stosi(Value)
  Stoui(Value)
  Dtosi(Value)
  Dtoui(Value)
  Swtof(Value)
  Uwtof(Value)
  Sltof(Value)
  Ultof(Value)
  Cast(Value)
  Copy(Value)
  Vastart(Value)
  Vaarg(Value)
  Ret(option.Option(Value))
  Jnz(Value, String, String)
  Jmp(String)
  Hlt
  Call(
    Value,
    List(#(Type, Value)),
    option.Option(List(#(Type, Value))),
  )
  Phi(List(#(String, Value)))
  Store(Type, Value, Value)
  Load(Type, Value)
}

Constructors

  • Add(Value, Value)

    Adds values

  • Sub(Value, Value)

    Substracts value(b) from value(a)

  • Mul(Value, Value)

    Multiplies values

  • Div(Value, Value)

    Divides value(a) by value(b) (signed)

  • Udiv(Value, Value)

    Unsigned division

  • Rem(Value, Value)

    Returns a remainder from division (signed)

  • Urem(Value, Value)

    Unsigned remainder

  • Neg(Value)

    Negation

  • And(Value, Value)

    Bitwise AND

  • Or(Value, Value)

    Bitwise OR

  • Xor(Value, Value)

    Bitwise XOR

  • Sar(Value, Value)

    Arithmetic right shift

  • Shr(Value, Value)

    Logical right shift

  • Shl(Value, Value)

    Left shift

  • Comp(Type, Comp, Value, Value)

    Perform a Comparison

  • Alloc4(Int)

    Allocates a 4-byte aligned area on the stack

  • Alloc8(Int)

    Allocates a 8-byte aligned area on the stack

  • Alloc16(Int)

    Allocates a 16-byte aligned area on the stack

  • Storew(Value, Value)

    Store word

  • Storel(Value, Value)

    Store long

  • Stores(Value, Value)

    Store single

  • Stored(Value, Value)

    Store double

  • Storeh(Value, Value)

    Store half-word

  • Storeb(Value, Value)

    Store byte

  • Loadw(Value)

    Load word (syntactic sugar - same as loadsw)

  • Loadsw(Value)

    Load word with sign extension

  • Loaduw(Value)

    Load word with zero extension

  • Loadl(Value)

    Load long

  • Loads(Value)

    Load single

  • Loadd(Value)

    Load double

  • Loadsh(Value)

    Load half-word signed

  • Loaduh(Value)

    Load half-word unsigned

  • Loadsb(Value)

    Load byte signed

  • Loadub(Value)

    Load byte unsigned

  • Blit(Value, Value, Int)

    Copy n bytes from source to destination address

  • Extsw(Value)

    Sign-extend word to long

  • Extuw(Value)

    Zero-extend word to long

  • Extsh(Value)

    Sign-extend half-word

  • Extuh(Value)

    Zero-extend half-word

  • Extsb(Value)

    Sign-extend byte

  • Extub(Value)

    Zero-extend byte

  • Exts(Value)

    Extend single to double

  • Truncd(Value)

    Truncate double to single

  • Stosi(Value)

    Single to signed integer

  • Stoui(Value)

    Single to unsigned integer

  • Dtosi(Value)

    Double to signed integer

  • Dtoui(Value)

    Double to unsigned integer

  • Swtof(Value)

    Signed word to float

  • Uwtof(Value)

    Unsigned word to float

  • Sltof(Value)

    Signed long to float

  • Ultof(Value)

    Unsigned long to float

  • Cast(Value)

    Bitwise reinterpret cast

  • Copy(Value)

    Copies either temporary or literal value

  • Vastart(Value)

    Initialize variable argument list

  • Vaarg(Value)

    Fetch next variadic argument

  • Return from a function, optionally with a value

  • Jnz(Value, String, String)

    Jumps to first label if a value is nonzero or to the second one otherwise

  • Jmp(String)

    Unconditionally jumps to a label

  • Hlt

    Program termination

  • Call(
      Value,
      List(#(Type, Value)),
      option.Option(List(#(Type, Value))),
    )

    Call(function, args, variadic_args)

  • Phi(List(#(String, Value)))

    SSA phi node - value selection from predecessors List of (label, value) pairs

  • Store(Type, Value, Value)

    Generic store (deprecated - use specific store instructions)

  • Load(Type, Value)

    Generic load (deprecated - use specific load instructions)

Linkage of a function or data defintion (e.g. section and private/public status)

pub type Linkage {
  Linkage(
    exported: Bool,
    section: option.Option(String),
    secflags: option.Option(String),
  )
}

Constructors

A complete IL file

pub type Module {
  Module(
    functions: List(Function),
    types: List(TypeDef),
    data: List(DataDef),
  )
}

Constructors

IR Statement

pub type Statement {
  Assign(Value, Type, Inst)
  Volatile(Inst)
}

Constructors

QBE Types

pub type Type {
  Word
  Long
  Single
  Double
  Byte
  Halfword
  Aggregate(TypeDef)
}

Constructors

  • Word

    Base Types

  • Long
  • Single
  • Double
  • Byte

    Extended Types

  • Halfword
  • Aggregate(TypeDef)

QBE aggregate type definition

pub type TypeDef {
  TypeDef(
    name: String,
    align: option.Option(Int),
    items: List(#(Type, Int)),
  )
}

Constructors

Bitwise operations Bitwise operations QBE Value for instructions

pub type Value {
  Temporary(name: String)
  Global(name: String)
  Const(value: Int)
}

Constructors

  • Temporary(name: String)

    %-temporary

  • Global(name: String)

    $-global

  • Const(value: Int)

    Constant

Values

pub fn add_block(label: String) -> Block

Adds a new empty block with a specified label and returns a reference to it

pub fn add_data(module: Module, data_def: DataDef) -> Module

Add Data to module

pub fn add_function(module: Module, function: Function) -> Module

Add function to module

pub fn add_inst(block: Block, inst: Inst) -> Block

Adds a new instruction to the block

pub fn add_type(module: Module, type_def: TypeDef) -> Module

Add type to module

pub fn align(self: Type) -> Int

Returns byte alignment for values of the type

pub fn assign_inst(
  block: Block,
  val: Value,
  typ: Type,
  inst: Inst,
) -> Block

Adds a new instruction assigned to a temporary

pub fn display_arguments(
  arguments: List(#(Type, Value)),
) -> String

Display functions Arguments

pub fn display_block(block: Block) -> String

Display function for block

pub fn display_blocks(blocks: List(Block)) -> String

Display blocks

pub fn display_data_def(def: DataDef) -> String

Display function for Datadef

pub fn display_data_item(item: DataItem) -> String

Display function for DataItem

pub fn display_function(func: Function) -> String

Display function for functions

pub fn display_inst(inst: Inst) -> String

Display function for Instructions

pub fn display_linkage(linkage: Linkage) -> String

Display function for Linkage

pub fn display_module(module: Module) -> String

Display function for Module

pub fn display_statement(stmt: Statement) -> String

Display function for Statement

pub fn display_type(ty: Type) -> String

Display Type function

pub fn display_type_def(def: TypeDef) -> String

Display function for TypeDef

pub fn display_value(value: Value) -> String

Display Value function

pub fn into_abi(self: Type) -> Type

Aggregate type with a specified name Returns a C ABI type. Extended types are converted to closest base types

pub fn into_base(self: Type) -> Type

Returns the closest base type

pub fn jumps(block: Block) -> Bool

Returns true if the block’s last instruction is a jump

pub fn last_block(blocks: List(Block)) -> option.Option(Block)

Returns a reference to the last block

pub fn new_datadef() -> DataDef
pub fn new_function() -> Function

Instantiates an empty function and returns it

pub fn new_module() -> Module

Creates a new module

pub fn private() -> Linkage

Returns the default configuration for private linkage

pub fn private_with_section(section: String) -> Linkage

Returns the configuration for private linkage with a provided section

pub fn public() -> Linkage

Returns the default configuration for public linkage

pub fn public_with_section(section: String) -> Linkage

Returns the configuration for public linkage with a provided section

pub fn size(self: Type) -> Int

Returns byte size for values of the type

Search Document