\section{Problems}

This section contains problem-reporting utilities for Machine SUIF.

\subsection{Progress diagnostics and warning messages}

\paragraph{Function [[debug]].}

[[debug]] prints diagnostic messages provided the user has set [[debuglvl]]
to the appropriate level of verbosity.  Most Machine-SUIF passes take a
command-line option for setting this variable.

The first argument must be less than or equal to the current value of
[[debuglvl]] for the call on [[debug]] to have any effect.  If that
condition holds, the second and subsequent arguments are used as they would
be in a call to [[fprintf]] with [[stderr]] as the output stream.

<<function [[debug]]>>=
extern int debuglvl;		/* user defined diagnostic print level */
extern void debug(const int, const char * ...);
@

\paragraph{Function [[warn]].}

[[warn]] is similar to [[debug]] except that it is unconditional.

<<function [[warn]]>>=
extern void warn(const char * ...);
@

\subsection{Assertions}

In Machine SUIF, the assertion primitive is called [[claim]].  You
state your assertion as a [[claim]] that a given Boolean expression holds.
If the expression evaluates to [[false]] the program prints a message,
optionally containing formatted text supplied with the claim, and it
aborts.%
\footnote{Our assertion machinery is adapted from an earlier version of SUIF.}

<<function [[claim]]>>=
extern void claim(bool assertion);
extern void claim(bool assertion, const char *format, ...);
@

The implementation adds source-code location information to help identify a
claim that is violated.

<<function [[claim]]>>=

extern char *__assertion_file_name;
extern int __assertion_line_num;
extern char *__assertion_module_name;

extern void _internal_assertion_failure(void);
extern void _internal_assertion_failure(const char *format, va_list ap);

inline void __do_assertion(bool assertion)
  {  if (!(assertion))  _internal_assertion_failure(); }

inline void __do_assertion(bool assertion, const char *format, ...)
  {
    if (!(assertion))
      {
        va_list ap;
        va_start(ap, format);
        _internal_assertion_failure(format, ap);
        va_end(ap);
      }
  }

#ifndef _MODULE_
#define _MODULE_ NULL
#endif

#define claim  __assertion_file_name = __FILE__, \
               __assertion_line_num = __LINE__, \
               __assertion_module_name = _MODULE_, \
               __do_assertion
@


\subsection{Header file [[problems.h]]}

The header file for module [[problems]] has the following layout.

<<problems.h>>=
/* file "machine/problems.h" */

<<Machine-SUIF copyright>>

#ifndef MACHINE_PROBLEMS_H
#define MACHINE_PROBLEMS_H

#include <machine/copyright.h>

#ifndef SUPPRESS_PRAGMA_INTERFACE
#pragma interface "machine/problems.h"
#endif

#include <machine/substrate.h>

<<function [[debug]]>>

<<function [[warn]]>>

<<function [[claim]]>>

#endif /* MACHINE_PROBLEMS_H */
