\section{C-language printing}
\label{sec-cprinting}

Class [[CPrinterSuifVm]], which refines [[CPrinter]], is the analogue of
[[PrinterSuifVm]] for generating C output files instead of assembly
language.  The methods that it overrides are those for printing SUIFvm
instructions and global directives.%
\footnote{At present, the only global directive is a [[#include]] which
introduces a few useful abbreviations.}


<<class [[CPrinterSuifVm]]>>=
class CPrinterSuifVm : public CPrinter {
  public:
    CPrinterSuifVm();
    virtual ~CPrinterSuifVm() { delete [] print_instr_table; }

    virtual void print_instr(Instr *mi);
    virtual void print_global_decl(FileBlock *fb);

<<[[CPrinterSuifVm]] protected parts>>
};
@

The printing method for a particular instruction is selected from a
dispatch table that is indexed by opcode.  The following methods
are used as elements in that table.

<<[[CPrinterSuifVm]] protected parts>>=
  protected:
    virtual void print_instr_alm(Instr *);
    virtual void print_instr_cti(Instr *);
    virtual void print_instr_dot(Instr *);
    virtual void print_instr_mbr(Instr *);
    virtual void print_instr_cal(Instr *);
@

These other methods defined at this level:

<<[[CPrinterSuifVm]] protected parts>>=

    virtual void print_instr_user_defd(Instr *) { }
    virtual void print_opcode(Instr *mi);
    virtual void print_addr_binop(Instr *mi);
@

[[print_user_defd]] allows further derivation from this class: it deals
with opcodes that are out of range for the target.


[[print_opcode]] simply prints the opcode of an instruction in C syntax,
and [[print_add_binop]] prints an address as a binary expression.


\subsection{Header file for module [[cprinter.h]]}

The interface file has the following layout:

<<c\_printer.h>>=
/* file "suifvm/c_printer.h" */

<<Machine-SUIF copyright>>

#ifndef SUIFVM_CPRINTER_H
#define SUIFVM_CPRINTER_H

#include <machine/copyright.h>

#ifndef SUPPRESS_PRAGMA_INTERFACE
#pragma interface "suifvm/cprinter.h"
#endif

#include <machine/machine.h>

<<class [[CPrinterSuifVm]]>>

#endif /* SUIFVM_CPRINTER_H */
@
