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

Language.QBE.Simulator.Memory

Description

This module provides an implementation of a simple byte-addressable memory based on Data.Array.

Synopsis

Type Aliases

type Address = Word64 Source #

Type used to represent an address in memory.

type Size = Word64 Source #

Type used to represent the memory's size.

showAddr :: Address -> String Source #

Represent an address as a hexadecimal string.

Value Representation

class Storable valTy byteTy where Source #

Type class for types that can be stored in memory. That is, types whose values can be converted to the given byte representation and vice versa.

Methods

toBytes :: valTy -> [byteTy] Source #

Convert a value type to a list of byte types.

fromBytes :: LoadType -> [byteTy] -> Maybe valTy Source #

Convert a list of bytes to a value type of LoadType. Returns Nothing if the length of the list is incompatible with the given LoadType.

Instances

Instances details
Storable RegVal Word8 Source # 
Instance details

Defined in Language.QBE.Simulator.Default.Expression

Memory Representation

data Memory (a :: Type -> k -> Type) (v :: k) Source #

Memory parameterized over the Array type (e.g. IOUArray) and a byte polymorphic representation (e.g. Word8).

mkMemory :: forall (t :: Type -> Type -> Type) a. MArray t a IO => Address -> Size -> IO (Memory t a) Source #

Create a new Memory which starts at the given base address and has a maximum capacity (i.e., can store up to the given amount of bytes). The memory is not initialized, reading an uninitialized values results in an error.

memSize :: forall (t :: Type -> Type -> Type) a. MArray t a IO => Memory t a -> IO Size Source #

Returns the size of the memory in bytes.

loadBytes :: forall (t :: Type -> Type -> Type) a. MArray t a IO => Memory t a -> Address -> Size -> IO [a] Source #

Load the given amount of bytes at the given address.

storeBytes :: forall (t :: Type -> Type -> Type) a. MArray t a IO => Memory t a -> Address -> [a] -> IO () Source #

Write the list of bytes to memory at the given address.

Memory Address

toMemAddr :: forall {k} (t :: Type -> k -> Type) (a :: k). Memory t a -> Address -> Address Source #

Translate global address to a memory-local address. That is, performs address translation relative to the base address of the Memory.

addrOverlap :: Address -> Address -> Size -> Bool Source #

Returns true if the given addresses, passed in the first and second argument, overlap in the given range (i.e., the given amount of bytes).

alignAddr :: Address -> Size -> Address Source #

Align an address upwards for the given alignment.