Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / system / blaze / ui.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: ui.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
//
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
//
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// ========== Copyright Header End ============================================
#include "ui.h"
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
UserInterface* ui = new UserInterface();
FILE* UserInterface::log_file = 0;
UserInterface::UserInterface( const char* module_name_ )/*{{{*/
:
module_name(module_name_ ? strdup(module_name) : 0)
{}
/*}}}*/
void UserInterface::output( const char* format, ... )/*{{{*/
{
va_list ap;
va_start(ap, fmt);
vfprintf(stdout,format,ap);
va_end(ap);
if (log_file)
{
va_start(ap, fmt);
vfprintf(log_file,format,ap);
va_end(ap);
}
}
/*}}}*/
void UserInterface::verbose( const char* format, ... )/*{{{*/
{
va_list ap;
if (log_file)
{
va_start(ap, fmt);
vfprintf(log_file,format,ap);
va_end(ap);
}
}
/*}}}*/
void UserInterface::warning( const char* format, ... )/*{{{*/
{
va_list ap;
va_start(ap, fmt);
fprintf(stdout,"WARNING: ");
if (module_name)
fprintf(stdout,"%s: ",module_name);
vfprintf(stdout,format,ap);
va_end(ap);
if (log_file)
{
va_start(ap, fmt);
fprintf(log_file,"WARNING: ");
if (module_name)
fprintf(stdout,"%s: ",module_name);
vfprintf(log_file,format,ap);
va_end(ap);
}
}
/*}}}*/
void UserInterface::error( const char* format, ... )/*{{{*/
{
va_list ap;
va_start(ap, fmt);
fprintf(stdout,"ERROR: ");
if (module_name)
fprintf(stdout,"%s: ",module_name);
vfprintf(stdout,format,ap);
va_end(ap);
if (log_file)
{
va_start(ap, fmt);
fprintf(log_file,"ERROR: ");
if (module_name)
fprintf(stdout,"%s: ",module_name);
vfprintf(log_file,format,ap);
va_end(ap);
}
}
/*}}}*/
void UserInterface::fatal( const char* format, ... )/*{{{*/
{
va_list ap;
va_start(ap, fmt);
fprintf(stdout,"FATAL: ");
if (module_name)
fprintf(stdout,"%s: ",module_name);
vfprintf(stdout,format,ap);
va_end(ap);
fprintf(stdout,"FATAL: forcing core dump.\n");
fflush(stdout);
if (log_file)
{
va_start(ap, fmt);
fprintf(log_file,"FATAL: ");
if (module_name)
fprintf(log_file,"%s: ",module_name);
vfprintf(log_file,format,ap);
va_end(ap);
fprintf(log_file,"FATAL: forcing core dump.\n");
fflush(log_file);
}
abort();
*(int*)0=0;
}
/*}}}*/
void UserInterface::perror( const char* s )/*{{{*/
{
error("s: %s",strerror(errno));
}
/*}}}*/
void UserInterface::input( const char* s )/*{{{*/
{
if (log_file)
fprintf(log_file,s);
}
/*}}}*/
void UserInterface::flush()/*{{{*/
{
fflush(stdout);
if (log_file)
fflush(log_file);
}
/*}}}*/
void UserInterface::set_log_file( FILE* log_file_ )/*{{{*/
{
if (log_file)
fflush(log_file);
log_file = log_file_;
}
/*}}}*/
FILE* UserInterface::get_output_file()/*{{{*/
{
return stdout;
}
/*}}}*/