Nearly CC
An educational compiler skeleton
Public Member Functions | List of all members
Formatter Class Referenceabstract

A Formatter turns Operand and Instruction objects into strings, which in turn allows high-level and low-level code to be printed. More...

#include "formatter.h"

Inheritance diagram for Formatter:
Inheritance graph
[legend]

Public Member Functions

virtual std::string format_operand (const Operand &operand) const
 Convert an Operand to a formatted string. More...
 
virtual std::string format_instruction (const Instruction *ins) const =0
 Convert an Instruction to a formatted string. More...
 

Detailed Description

A Formatter turns Operand and Instruction objects into strings, which in turn allows high-level and low-level code to be printed.

Member Function Documentation

◆ format_instruction()

virtual std::string Formatter::format_instruction ( const Instruction ins) const
pure virtual

Convert an Instruction to a formatted string.

Parameters
insthe Instruction to format
Returns
the string formatted from the Instruction

Implemented in LowLevelFormatter, and HighLevelFormatter.

◆ format_operand()

std::string Formatter::format_operand ( const Operand operand) const
virtual

Convert an Operand to a formatted string.

The default implementation of format_operand is useful for immediate values and labels. Subclasses should override to implement more specific kinds of operands (registers, memory references, etc.)

Parameters
operandthe Operand to format
Returns
the string formatted from the Operand

Reimplemented in LowLevelFormatter, and HighLevelFormatter.


The documentation for this class was generated from the following files: