qute-0.1.0: A software analysis framework built around the QBE intermediate language.
Safe HaskellNone
LanguageGHC2021

Language.QBE.Simulator

Description

This module describes the semantics of the QBE intermediate representation using an abstract Simulator monad. Specifically, it abstractly describes the semantics of QBE's control-flow constructs (such as functions, statements, and blocks) and instructions using the primitives of this monad. The semantics can then be concretely instantiated (refer to the instance of the Simulator monad). This idea is inspired by the paper Flexible Instruction-Set Semantics via Abstract Monads.

Synopsis

Documentation

type BlockResult v = Either (Maybe v) Block Source #

Execution of a Block can either return (with an optional return value) or it can jump to another Block which will then be executed.

execInstr :: Simulator m v => BaseType -> Instr -> m v Source #

Execute a single Instr. The BaseType denotes the return value type. For example, as provided in the enclosing Assign.

execStmt :: Simulator m v => Statement -> m () Source #

Execute a Statement, usually a sequence of Instruction. Therefore, this function iteratively calls execInstr in the common case.

execBlock :: Simulator m v => Maybe BlockIdent -> Block -> m (BlockResult v) Source #

Execute a BasicBlock, as represented by Block, by iteratively invoking execStmt. If this isn't the first executed BasicBlock within a a Function, then the BlockIdent of the previously executed BasicBlock should be provided. This is required to properly execute phi instructions.

execFunc :: Simulator m v => FuncDef -> [v] -> m (Maybe v) Source #

Execute a FuncDef until function return. If the function requires arguments to be passed to it, these must be provided as a list. Limited sanity checking is performed to ensure that the provided arguments match the declared function parameters. The return value of execFunc is the return value of the executed FuncDef. If the function has no return value, Nothing is returned here.