Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_ConfigObject.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: SS_ConfigObject.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 <stdio.h>
#include <stdlib.h>
#include "SS_ConfigObject.h"
SS_ConfigVariable::SS_ConfigVariable( const char* _value )/*{{{*/
:
SS_ConfigValue(CFG_VAR),
value(_value)
{}
/*}}}*/
void SS_ConfigVariable::reflect()/*{{{*/
{
printf("%s",value.data());
}
/*}}}*/
SS_ConfigString::SS_ConfigString( const char* _value )/*{{{*/
:
SS_ConfigValue(CFG_STR),
value(_value)
{
value.assign(value,1,value.size() - 2);
}
/*}}}*/
void SS_ConfigString::reflect()/*{{{*/
{
printf("\"%s\"",value.data());
}
/*}}}*/
SS_ConfigNumber::SS_ConfigNumber( uint64_t _value )/*{{{*/
:
SS_ConfigValue(CFG_NUM),
value(_value)
{}
/*}}}*/
void SS_ConfigNumber::reflect()/*{{{*/
{
printf("0x%llx",value);
}
/*}}}*/
SS_ConfigValueList::~SS_ConfigValueList()/*{{{*/
{
for (std::list<SS_ConfigValue*>::iterator i = value.begin(); i != value.end(); i++)
delete (*i);
}
/*}}}*/
void SS_ConfigValueList::reflect()/*{{{*/
{
putchar('(');
std::list<SS_ConfigValue*>::iterator i = value.begin();
while (i != value.end())
{
(*i)->reflect();
i++;
if (i != value.end())
putchar(',');
}
putchar(')');
}
/*}}}*/
SS_ConfigFieldList::~SS_ConfigFieldList()/*{{{*/
{
for (std::map<std::string,SS_ConfigValue*>::iterator i = field.begin(); i != field.end(); i++)
delete i->second;
}
/*}}}*/
void SS_ConfigFieldList::reflect()/*{{{*/
{
for (std::map<std::string,SS_ConfigValue*>::iterator i = field.begin(); i != field.end(); i++)
{
printf(" %s: ",i->first.data());
i->second->reflect();
putchar('\n');
}
}
/*}}}*/
SS_ConfigObject::SS_ConfigObject( const std::string& _name, const std::string& _type, SS_ConfigFieldList* _prop )/*{{{*/
:
name(_name),
type(_type),
prop(_prop)
{}
/*}}}*/
SS_ConfigObject::~SS_ConfigObject()/*{{{*/
{
if (prop)
delete prop;
}
/*}}}*/
void SS_ConfigObject::reflect()/*{{{*/
{
printf("OBJECT %s TYPE %s {\n",name.data(),type.data());
prop->reflect();
printf("}\n");
}
/*}}}*/
SS_ConfigObjectList::~SS_ConfigObjectList()/*{{{*/
{
for (std::map<std::string,SS_ConfigObject*>::iterator i = object.begin(); i != object.end(); i++)
delete i->second;
}
/*}}}*/
void SS_ConfigObjectList::reflect()/*{{{*/
{
for (std::map<std::string,SS_ConfigObject*>::iterator i = object.begin(); i != object.end(); i++)
{
printf("OBJECT %s\n",i->first.data());
i->second->reflect();
}
}
/*}}}*/
extern SS_ConfigObjectList* config_parse( const char* filename );
extern int yyparse();
extern FILE *yyin;
extern SS_ConfigObjectList* config_objects;
SS_ConfigReader::SS_ConfigReader( const char* filename )/*{{{*/
:
config(0)
{
yyin = fopen(filename,"r");
if (!yyin)
{
perror(filename);
exit(-1);
}
int e = yyparse();
fclose(yyin);
if (!e)
config = config_objects;
}
/*}}}*/
SS_ConfigReader::~SS_ConfigReader()/*{{{*/
{
delete config;
}
/*}}}*/
SS_ConfigValue* SS_ConfigReader::value( const char* object, const char* field )/*{{{*/
{
std::map<std::string,SS_ConfigObject*>::const_iterator o = config->object.find(object);
if (o == config->object.end())
return 0;
std::map<std::string,SS_ConfigValue*>::const_iterator f = o->second->prop->field.find(field);
if (f == o->second->prop->field.end())
return 0;
return o->second->prop->field[field];
}
/*}}}*/
void SS_ConfigReader::reflect()/*{{{*/
{
if (config)
config->reflect();
}
/*}}}*/