Averest


IO Module

This module implements functions for parsing MiniC, Cmd, and Abacus programs and also for printing these programs to streams.

Types

Type Description

ParseError

Functions and values

Function or value Description

ParseAbacusProgram ostr sL

Full Usage: ParseAbacusProgram ostr sL

Parameters:
Returns: AbcParamsType * AbacusInstr[]

Function ParseProgram parses an Abacus program from the list of strings sL that are the lines of an Abacus file. If a syntax error occurs, error messages are written to ostr. The result is an Abacus program, i.e., an array of Abacus instructions where branch and jump instructions refer to indices of this array. For the syntax of the expected Abacus program, see the comments of function ParseProgramFromFile.

ostr : TextWriter
sL : string list
Returns: AbcParamsType * AbacusInstr[]

ParseAbacusProgramFromFile ostr filename

Full Usage: ParseAbacusProgramFromFile ostr filename

Parameters:
Returns: AbcParamsType * AbacusInstr[]

Function ParseAbacusProgramFromFile parses an Abacus program from the contents of the file with the given filename, and writes error messages to the output TextWriter ostr. In addition to the Abacus instructions, the file may also contain in a header before the values of the parameters of the Abacus computer. In total, the following syntax is assumed:

  • "//" denotes the beginning of a comment that ends with the line
  • "#const MemSize n" defines the size of the main memory to words
  • "#const CacheSize n" defines the size of the data cache in words
  • "#const BlockSize n" defines the size of cache blocks in words
  • "#const SetAssoc n" defines the set associativity of the cache
  • lines holding an instruction must have the following form with an optional label l:

    l: instr p1,...,pn // comment

The result is an Abacus program, i.e., an array of Abacus instructions where branch and jump instructions refer to indices of this array.

ostr : TextWriter
filename : string
Returns: AbcParamsType * AbacusInstr[]

ParseDeclFromStream stream

Full Usage: ParseDeclFromStream stream

Parameters:
Returns: (string * TypeC) list

parsing a MiniC declaration from a stream

stream : TextReader
Returns: (string * TypeC) list

ParseDeclFromString s

Full Usage: ParseDeclFromString s

Parameters:
    s : string

Returns: (string * TypeC) list

parsing a MiniC declaration from a string

s : string
Returns: (string * TypeC) list

ParseExprFromStream decls stream

Full Usage: ParseExprFromStream decls stream

Parameters:
Returns: ExprC

parsing a MiniC expression from a stream where types are determined according to the given declaration of variables

decls : (string * TypeC)[]
stream : TextReader
Returns: ExprC

ParseExprFromString decls s

Full Usage: ParseExprFromString decls s

Parameters:
    decls : (string * TypeC)[]
    s : string

Returns: ExprC

parsing a MiniC expression from a string where types are determined according to the given declaration of variables

decls : (string * TypeC)[]
s : string
Returns: ExprC

ParseMiniCFromFile optOstr filename

Full Usage: ParseMiniCFromFile optOstr filename

Parameters:
    optOstr : 'a option
    filename : string

Returns: MiniCProgram

parsing a program from a file (errors are written to output stream optOstr, if that is not None).

optOstr : 'a option
filename : string
Returns: MiniCProgram

ParseMiniCFromStream optOstr instr

Full Usage: ParseMiniCFromStream optOstr instr

Parameters:
Returns: MiniCProgram

ParseMiniCFromStream parses a MiniC program from a given input stream instr (errors are written to output stream optOstr, if that is not None).

optOstr : 'a option
instr : TextReader
Returns: MiniCProgram

ParseMiniCFromString optOstr s

Full Usage: ParseMiniCFromString optOstr s

Parameters:
    optOstr : 'a option
    s : string

Returns: MiniCProgram

ParseMiniCFromString parses a MiniC program from a given string s (errors are written to output stream optOstr, if that is not None).

optOstr : 'a option
s : string
Returns: MiniCProgram

ParseUntypedExprFromStream stream

Full Usage: ParseUntypedExprFromStream stream

Parameters:
Returns: ExprC

parsing a MiniC expression from a stream where Cnat is used for all numeric types

stream : TextReader
Returns: ExprC

ParseUntypedExprFromString s

Full Usage: ParseUntypedExprFromString s

Parameters:
    s : string

Returns: ExprC

parsing a MiniC expression from a string where Cnat is used for all numeric types

s : string
Returns: ExprC

PrintAbacusProgram indent ostr abcp cmt

Full Usage: PrintAbacusProgram indent ostr abcp cmt

Parameters:

PrintAbacusProgram prints an Abacus program p to output stream ostr with an indentation string indent and additional comments cmt.

indent : string
ostr : TextWriter
abcp : Map<int, AbacusInstr>
cmt : Map<int, string>

PrintCmdProg ostr cmdp

Full Usage: PrintCmdProg ostr cmdp

Parameters:

PrintCmdProg prints a CmdType program to TextWriter ostr.

ostr : TextWriter
cmdp : Map<int, CmdType>

ReadLines filename

Full Usage: ReadLines filename

Parameters:
    filename : string

Returns: string list

filename : string
Returns: string list

ReadTokens filename

Full Usage: ReadTokens filename

Parameters:
    filename : string

Returns: token list

filename : string
Returns: token list

getSvgGraph dotExe dotGraphWriter

Full Usage: getSvgGraph dotExe dotGraphWriter

Parameters:
Returns: string

getSvgGraph converts dot graphs to a svg graphic which is returned as a string. Expected arguments are dotExe which is the path of the executable of dot like "/usr/bin/dot" and dotGraphWriter which is a function that will write a dot graph to a stream.

dotExe : string
dotGraphWriter : StreamWriter -> unit
Returns: string