Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_ConfigObject.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: SS_ConfigObject.cc
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "SS_ConfigObject.h"
25
26SS_ConfigVariable::SS_ConfigVariable( const char* _value )/*{{{*/
27 :
28 SS_ConfigValue(CFG_VAR),
29 value(_value)
30{}
31/*}}}*/
32void SS_ConfigVariable::reflect()/*{{{*/
33{
34 printf("%s",value.data());
35}
36/*}}}*/
37
38SS_ConfigString::SS_ConfigString( const char* _value )/*{{{*/
39 :
40 SS_ConfigValue(CFG_STR),
41 value(_value)
42{
43 value.assign(value,1,value.size() - 2);
44}
45/*}}}*/
46void SS_ConfigString::reflect()/*{{{*/
47{
48 printf("\"%s\"",value.data());
49}
50/*}}}*/
51
52SS_ConfigNumber::SS_ConfigNumber( uint64_t _value )/*{{{*/
53 :
54 SS_ConfigValue(CFG_NUM),
55 value(_value)
56{}
57/*}}}*/
58void SS_ConfigNumber::reflect()/*{{{*/
59{
60 printf("0x%llx",value);
61}
62/*}}}*/
63
64SS_ConfigValueList::~SS_ConfigValueList()/*{{{*/
65{
66 for (std::list<SS_ConfigValue*>::iterator i = value.begin(); i != value.end(); i++)
67 delete (*i);
68}
69/*}}}*/
70void SS_ConfigValueList::reflect()/*{{{*/
71{
72 putchar('(');
73 std::list<SS_ConfigValue*>::iterator i = value.begin();
74 while (i != value.end())
75 {
76 (*i)->reflect();
77 i++;
78 if (i != value.end())
79 putchar(',');
80 }
81 putchar(')');
82}
83/*}}}*/
84
85SS_ConfigFieldList::~SS_ConfigFieldList()/*{{{*/
86{
87 for (std::map<std::string,SS_ConfigValue*>::iterator i = field.begin(); i != field.end(); i++)
88 delete i->second;
89}
90/*}}}*/
91void SS_ConfigFieldList::reflect()/*{{{*/
92{
93 for (std::map<std::string,SS_ConfigValue*>::iterator i = field.begin(); i != field.end(); i++)
94 {
95 printf(" %s: ",i->first.data());
96 i->second->reflect();
97 putchar('\n');
98 }
99}
100/*}}}*/
101
102SS_ConfigObject::SS_ConfigObject( const std::string& _name, const std::string& _type, SS_ConfigFieldList* _prop )/*{{{*/
103 :
104 name(_name),
105 type(_type),
106 prop(_prop)
107{}
108/*}}}*/
109SS_ConfigObject::~SS_ConfigObject()/*{{{*/
110{
111 if (prop)
112 delete prop;
113}
114/*}}}*/
115void SS_ConfigObject::reflect()/*{{{*/
116{
117 printf("OBJECT %s TYPE %s {\n",name.data(),type.data());
118 prop->reflect();
119 printf("}\n");
120}
121/*}}}*/
122
123SS_ConfigObjectList::~SS_ConfigObjectList()/*{{{*/
124{
125 for (std::map<std::string,SS_ConfigObject*>::iterator i = object.begin(); i != object.end(); i++)
126 delete i->second;
127}
128/*}}}*/
129void SS_ConfigObjectList::reflect()/*{{{*/
130{
131 for (std::map<std::string,SS_ConfigObject*>::iterator i = object.begin(); i != object.end(); i++)
132 {
133 printf("OBJECT %s\n",i->first.data());
134 i->second->reflect();
135 }
136}
137/*}}}*/
138
139extern SS_ConfigObjectList* config_parse( const char* filename );
140
141extern int yyparse();
142extern FILE *yyin;
143
144extern SS_ConfigObjectList* config_objects;
145
146SS_ConfigReader::SS_ConfigReader( const char* filename )/*{{{*/
147 :
148 config(0)
149{
150 yyin = fopen(filename,"r");
151 if (!yyin)
152 {
153 perror(filename);
154 exit(-1);
155 }
156
157 int e = yyparse();
158 fclose(yyin);
159
160 if (!e)
161 config = config_objects;
162}
163/*}}}*/
164SS_ConfigReader::~SS_ConfigReader()/*{{{*/
165{
166 delete config;
167}
168/*}}}*/
169SS_ConfigValue* SS_ConfigReader::value( const char* object, const char* field )/*{{{*/
170{
171 std::map<std::string,SS_ConfigObject*>::const_iterator o = config->object.find(object);
172
173 if (o == config->object.end())
174 return 0;
175
176 std::map<std::string,SS_ConfigValue*>::const_iterator f = o->second->prop->field.find(field);
177
178 if (f == o->second->prop->field.end())
179 return 0;
180
181 return o->second->prop->field[field];
182}
183/*}}}*/
184void SS_ConfigReader::reflect()/*{{{*/
185{
186 if (config)
187 config->reflect();
188}
189/*}}}*/
190
191