diff options
author | Nathan Binkert <nate@binkert.org> | 2010-03-10 16:22:26 -0800 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2010-03-10 16:22:26 -0800 |
commit | 226eaf9ddf8beabb8fd8ca0ed10ee8be02f03489 (patch) | |
tree | 29ae2c55a6d0ba3675992de7d06b653843903cb1 /src/mem/gems_common | |
parent | cf86532857ba1e199db6ff16541e7242c6225ff0 (diff) | |
download | gem5-226eaf9ddf8beabb8fd8ca0ed10ee8be02f03489.tar.xz |
ruby: get rid of the ioutil stuff since it isn't used anymore
Diffstat (limited to 'src/mem/gems_common')
-rw-r--r-- | src/mem/gems_common/SConscript | 9 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/FakeSimicsDataTypes.hh | 63 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/SConscript | 36 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/attrlex.ll | 194 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/attrparse.yy | 196 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/confio.cc | 444 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/confio.hh | 192 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/embedtext.py | 54 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/initvar.cc | 585 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/initvar.hh | 172 | ||||
-rw-r--r-- | src/mem/gems_common/ioutil/vardecl.hh | 75 |
11 files changed, 0 insertions, 2020 deletions
diff --git a/src/mem/gems_common/SConscript b/src/mem/gems_common/SConscript index 1f3032646..851aa412f 100644 --- a/src/mem/gems_common/SConscript +++ b/src/mem/gems_common/SConscript @@ -33,15 +33,6 @@ Import('*') if not env['RUBY']: Return() -#benv['LEXCOM'] = "$LEX $LEXFLAGS -o$TARGET $SOURCES" -benv = env.Clone() -benv.Append(YACCFLAGS=["-pat"]) -benv.Append(LEXFLAGS=["-Pat"]) -benv.CXXFile('ioutil/attrlex.ll') -benv.CXXFile('ioutil/attrparse.yy') - -Source('ioutil/attrlex.cc', Werror=False) -Source('ioutil/attrparse.cc', Werror=False) Source('util.cc') TraceFlag('GemsCommon') diff --git a/src/mem/gems_common/ioutil/FakeSimicsDataTypes.hh b/src/mem/gems_common/ioutil/FakeSimicsDataTypes.hh deleted file mode 100644 index b6fcda95c..000000000 --- a/src/mem/gems_common/ioutil/FakeSimicsDataTypes.hh +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef FAKE_SIMICS_DATA_TYPES_H -#define FAKE_SIMICS_DATA_TYPES_H - -typedef struct attr_value attr_value_t; - -typedef enum { - Sim_Val_Invalid = 0, - Sim_Val_String = 1, - Sim_Val_Integer = 2, - Sim_Val_Floating = 3, - Sim_Val_List = 4, - Sim_Val_Data = 5, - Sim_Val_Nil = 6, - Sim_Val_Object = 7 -} attr_kind_t; - -typedef struct attr_list attr_list_t; - -struct attr_list { - int size; - struct attr_value *vector; -}; - -struct attr_value { - attr_kind_t kind; - union { - const char *string; /* Sim_Val_String */ - unsigned long long integer; /* Sim_Val_Integer */ - double floating; /* Sim_Val_Floating */ - void *object; /* Sim_Val_Object */ - attr_list_t list; /* Sim_Val_List */ - } u; -}; - -typedef enum { -Sim_Set_Ok, -Sim_Set_Need_Integer, -Sim_Set_Need_Floating, -Sim_Set_Need_String, -Sim_Set_Need_List, -Sim_Set_Need_Data, -Sim_Set_Need_Object, -Sim_Set_Object_Not_Found, -Sim_Set_Interface_Not_Found, -Sim_Set_Illegal_Value, -Sim_Set_Illegal_Type, -Sim_Set_Illegal_Index, -Sim_Set_Attribute_Not_Found, -Sim_Set_Not_Writable, -Sim_Set_Ignored -} set_error_t; - - -typedef attr_value_t (*get_attr_t)(void *ptr, - void *obj, - attr_value_t *idx); - -typedef set_error_t (*set_attr_t)(void *ptr, - void *obj, - attr_value_t *val, - attr_value_t *idx); - -#endif // #ifndef FAKE_SIMICS_DATA_TYPES_H diff --git a/src/mem/gems_common/ioutil/SConscript b/src/mem/gems_common/ioutil/SConscript deleted file mode 100644 index ea605a361..000000000 --- a/src/mem/gems_common/ioutil/SConscript +++ /dev/null @@ -1,36 +0,0 @@ -# -*- mode:python -*- - -# Copyright (c) 2009 The Hewlett-Packard Development Company -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Authors: Nathan Binkert - -Import('*') - -if not env['RUBY']: - Return() - -Source('confio.cc') diff --git a/src/mem/gems_common/ioutil/attrlex.ll b/src/mem/gems_common/ioutil/attrlex.ll deleted file mode 100644 index d3a5b35dd..000000000 --- a/src/mem/gems_common/ioutil/attrlex.ll +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -%option noyywrap - -ALPHADIGIT [^\:\,\(\)\n\t\(\) \0\#] -HEXDIGIT [0-9a-fA-Fx] -NEWLINE [\n] -WHITESPACE [ \t] - -%{ - -#include "mem/ruby/common/Global.hh" - -using namespace std; -#include <string> -#include <map> -#include <stdlib.h> - -// Maurice -// extern "C" { -// #include "simics/api.hh" -// }; - -#include "mem/gems_common/ioutil/FakeSimicsDataTypes.hh" - -// CM: simics 1.6.5 API redefines fwrite, much to my chagrin -#undef fwrite -#undef printf -#include "mem/gems_common/ioutil/attrparse.hh" - -#define MAX_INCLUDE_DEPTH 10 - -/** global result of parsing file */ -extern attr_value_t g_attr_map; - -extern int atparse(void); - -static int linenum=1; /* the current line number */ -static int colnum=1; /* the current column number */ -static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; -static int include_stack_ptr = 0; -static char g_relative_include_path[256]; - - -// forward declaration of aterror -void aterror(const char *msg); -%} - -%x SLASHCOMMENT INCLUDE - -%% - -%{ /* PATTERNS FOR STRING TOKENS */ -%} - -"//".*[\n] { linenum++; colnum=1; } /* C++ style comments */ - -\#include { colnum+=yyleng; BEGIN(INCLUDE); } -<INCLUDE>{WHITESPACE}* { colnum+=yyleng; } -<INCLUDE>[^ \t\n]+ { - // should really be FILEIO_MAX_FILENAME or MAX_NAME - char str[256]; - if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) - { - ERROR_OUT( "Includes nested too deeply" ); - exit( 1 ); - } - include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; - - yyin = fopen( yytext, "r" ); - if ( ! yyin ) { - sprintf( str, "%s%s", g_relative_include_path, yytext ); - yyin = fopen( str, "r" ); - } - if ( ! yyin ) { - sprintf( str, "%s%s%s", g_relative_include_path, "config/", yytext ); - yyin = fopen( str, "r" ); - } - if ( ! yyin ) { - ERROR_OUT("unable to open included file: %s or %s\n", yytext, str); - aterror("file open error.\n"); - } - yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE )); - BEGIN(INITIAL); - } -<<EOF>> { - if ( --include_stack_ptr < 0 ) { - yyterminate(); - } else { - yy_delete_buffer( YY_CURRENT_BUFFER ); - fclose(yyin); - yy_switch_to_buffer(include_stack[include_stack_ptr] ); - } - } - -\( { colnum+=yyleng; return (LPAREN); } -\) { colnum+=yyleng; return (RPAREN); } -\: { colnum+=yyleng; return (':'); } -\, { colnum+=yyleng; return (','); } -{HEXDIGIT}+ { - colnum+=yyleng; - attr_value_t *val = (attr_value_t *) - malloc( sizeof(attr_value_t) ); - memset( val, 0, sizeof(attr_value_t) ); - atlval.attrval = val; - val->kind = Sim_Val_Integer; - val->u.integer = strtoull( yytext, NULL, 0 ); - return (INTEGER); } -{ALPHADIGIT}+ { - colnum+=yyleng; - attr_value_t *val = (attr_value_t *) - malloc( sizeof(attr_value_t) ); - memset( val, 0, sizeof(attr_value_t) ); - atlval.attrval = val; - val->kind = Sim_Val_String; - val->u.string = strdup(yytext); - return (STRING); } - -%{ /* OTHER PATTERNS */ -%} - -{WHITESPACE}+ {colnum += yyleng;} -{NEWLINE} {linenum++; colnum = 1;} - -%% - -extern "C" void parseInitialize( void ) -{ - // since no global variables are set in simics, we must do it manually - // this is also necessary now that the parser can be used more than once. - // (it is used to parse the defaults, and can be used after that) - linenum = 1; - colnum = 1; - include_stack_ptr = 0; -} - -extern "C" int parseAttrFile( FILE *inputFile, const char *relative_include_path, attr_value_t *myTable ) -{ - parseInitialize(); - strncpy( g_relative_include_path, relative_include_path, 255 ); - - int result; - yyin = inputFile; - YY_BUFFER_STATE scan_state = yy_create_buffer( yyin, YY_BUF_SIZE ); - yy_switch_to_buffer( scan_state ); - result = atparse(); - *myTable = g_attr_map; - yy_delete_buffer( scan_state ); - return (result); -} - -extern "C" int parseAttrString( const char *str, attr_value_t *myTable ) -{ - parseInitialize(); - - int result; - YY_BUFFER_STATE scan_state = yy_scan_string( str ); - result = atparse(); - *myTable = g_attr_map; - yy_delete_buffer( scan_state ); - return (result); -} - -extern void aterror(const char *msg) -{ - ERROR_OUT("%d:%d: ERROR while parsing config file%s\n", linenum, colnum, msg ); -} - diff --git a/src/mem/gems_common/ioutil/attrparse.yy b/src/mem/gems_common/ioutil/attrparse.yy deleted file mode 100644 index 4301717fa..000000000 --- a/src/mem/gems_common/ioutil/attrparse.yy +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -%{ -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -#include "mem/ruby/common/Global.hh" - -using namespace std; -#include <string> -#include <map> -#include <stdlib.h> - -// Maurice -// extern "C" { -// #include "simics/api.hh" -// }; - -#include "mem/gems_common/ioutil/FakeSimicsDataTypes.hh" - -#include "mem/gems_common/ioutil/confio.hh" - -// CM FIX: if I wasn't working on a paper: I'd re-write the grammer to -// be left (or right) recursive, which ever is more efficient -// This only affects extremely large cache sizes / BP sizes on read in. -#define YYMAXDEPTH 100000 - -extern char* attext; - -extern void aterror(const char *); -extern int atlex(); -attr_value_t g_attr_map; - -extern void fprintAttr( FILE *fp, attr_value_t attr ); - -%} - -/*------------------------------------------------------------------------*/ -/* Union declarations */ -/*------------------------------------------------------------------------*/ -// The types of the tokens and nonterminals -%union { - attr_value_t *attrval; -}; - -%token <attrval> STRING INTEGER -%token MY_END LPAREN RPAREN - -%type <attrval> confmapping confpair attributes attrlist -%% - -conffile : confmapping -{ - g_attr_map = *($1); - free( $1 ) -} - -confmapping : confmapping confpair -{ - attr_value_t *newattr = mallocAttribute(1); - newattr->kind = Sim_Val_List; - if ( $1 == NULL ) { - newattr->u.list.size = 1; - newattr->u.list.vector = $2; - } else { - // add the latest mapping to the return mapping - uint32 newsize = $1->u.list.size + 1; - attr_value_t *vector = mallocAttribute( newsize ); - newattr->u.list.size = newsize; - newattr->u.list.vector = vector; - for (uint32 i = 0; i < newsize - 1; i++) { - vector[i] = $1->u.list.vector[i]; - } - vector[newsize - 1] = *($2); - free( $1->u.list.vector ); - free( $1 ); - free( $2 ); - } - $$ = newattr; -} - | // nothing -{ - $$ = NULL; -} - -confpair : STRING ':' attributes -{ - attr_value_t *newattr = mallocAttribute(1); - newattr->kind = Sim_Val_List; - newattr->u.list.size = 2; - newattr->u.list.vector = mallocAttribute(2); - newattr->u.list.vector[0] = *($1); - newattr->u.list.vector[1] = *($3); - free( $1 ); - free( $3 ); - $$ = newattr; -} - -attributes : INTEGER -{ - $$ = $1; -} - | STRING -{ - $$ = $1; -} - | LPAREN attrlist RPAREN -{ - attr_value_t *newattr = mallocAttribute(1); - newattr->kind = Sim_Val_List; - if ( $2->kind != CONF_ATTR_SINGLE && - $2->kind != CONF_ATTR_PAIR ) { - newattr->u.list.size = 1; - newattr->u.list.vector = $2; - } else { - newattr->u.list.size = $2->u.list.size; - newattr->u.list.vector = mallocAttribute(newattr->u.list.size); - attr_value_t *curattr = $2; - uint32 i = 0; - while ( i < newattr->u.list.size ) { - if (curattr->kind == CONF_ATTR_SINGLE) { - newattr->u.list.vector[i] = curattr->u.list.vector[0]; - i++; - - curattr = NULL; - } else if (curattr->kind == CONF_ATTR_PAIR) { - newattr->u.list.vector[i] = curattr->u.list.vector[0]; - i++; - if ( i < newattr->u.list.size ) - curattr = &(curattr->u.list.vector[1]); - else - curattr = NULL; - - } else { - ERROR_OUT("error: unknown kind in pair: %d\n", curattr->kind); - ASSERT(0); - } - } - // FIX memory leak: around 600 KB - // freeAttribute( $2 ); // with gcc-3.4 this free call tries to free memory from the stack - } - $$ = newattr; -} - -attrlist : attributes -{ - attr_value_t *newattr = mallocAttribute(1); - newattr->kind = CONF_ATTR_SINGLE; - newattr->u.list.size = 1; - newattr->u.list.vector = $1; - $$ = newattr; -} - | attributes ',' attrlist -{ - // allocate the pair ( x , y ) attribute - attr_value_t *newattr = mallocAttribute(1); - int newsize = $3->u.list.size + 1; - attr_value_t *vector = mallocAttribute(2); - newattr->kind = CONF_ATTR_PAIR; - newattr->u.list.size = newsize; - newattr->u.list.vector = vector; - - // assign the LH attribute - vector[0] = *($1); - vector[1] = *($3); - free( $1 ); - free( $3 ); - $$ = newattr; -} diff --git a/src/mem/gems_common/ioutil/confio.cc b/src/mem/gems_common/ioutil/confio.cc deleted file mode 100644 index a701473a7..000000000 --- a/src/mem/gems_common/ioutil/confio.cc +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * saves configuration information for later runs - */ - -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -#include "mem/ruby/common/Global.hh" -#define SIM_HALT ASSERT(0) - -using namespace std; -#include <string> -#include <map> -#include <stdlib.h> - -// Maurice -// extern "C" { -// #include "global.hh" -// #include "simics/api.hh" -// -// #ifdef SIMICS22X -// #include "sparc_api.hh" -// #endif -// #ifdef SIMICS30 -// #ifdef SPARC -// #include "sparc.hh" -// #else -// #include "x86.hh" -// #endif -// #endif -// }; - -#include "mem/gems_common/ioutil/confio.hh" - -/*------------------------------------------------------------------------*/ -/* Macro declarations */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Variable declarations */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Forward declarations */ -/*------------------------------------------------------------------------*/ - -// C++ Template: explicit instantiation -template class map<string, confnode_t *>; - -// These functions are defined in parser/attrlex.l -extern "C" int parseAttrFile( FILE *inputFile, const char *relative_include_path, attr_value_t *myTable ); -extern "C" int parseAttrString( const char *str, attr_value_t *myTable ); - -/*------------------------------------------------------------------------*/ -/* Constructor(s) / destructor */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -confio_t::confio_t( ) -{ - m_verbose = false; -} - -//************************************************************************** -confio_t::~confio_t( ) -{ - ConfTable::iterator iter; - - for ( iter = m_table.begin(); iter != m_table.end(); iter++ ) { - confnode_t *cfnode = (*iter).second; - free( cfnode ); - } -} - -/*------------------------------------------------------------------------*/ -/* Public methods */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Accessor(s) / mutator(s) */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -int confio_t::register_attribute( const char *name, - get_confio_t get_attr, void *get_attr_data, - set_confio_t set_attr, void *set_attr_data ) -{ - confnode_t *newnode; - if ( m_table.find(name) == m_table.end() ) { - if (m_verbose) - DEBUG_OUT(" registering checkpoint attribute: \"%s\"\n", name); - - // add a new entry to the table - newnode = (confnode_t *) malloc( sizeof( confnode_t ) ); - newnode->get_attr = get_attr; - newnode->set_attr = set_attr; - newnode->set_attr_data = set_attr_data; - newnode->get_attr_data = get_attr_data; - newnode->attr_is_set = false; - string key(name); - m_table[key] = newnode; - } else { - ERROR_OUT(" warning: confio: adding existing conf node: %s\n", name); - } - return 0; -} - -//************************************************************************** -void fprintAttr( FILE *fp, attr_value_t attr ) -{ - switch (attr.kind) { - case Sim_Val_Invalid: - fprintf(fp, "invalid"); - break; - - case Sim_Val_String: - fprintf(fp, "%s", attr.u.string); - break; - - case Sim_Val_Integer: - fprintf(fp, "0x%llx", attr.u.integer); - break; - - case Sim_Val_Floating: - fprintf(fp, "0x%llx", attr.u.integer); - break; - - case Sim_Val_List: - fprintf(fp, "("); - for (int i = 0; i < attr.u.list.size; i++) { - fprintAttr(fp, attr.u.list.vector[i]); - if (i != attr.u.list.size -1) { - fprintf(fp, ", "); - } - } - fprintf(fp, ")"); - break; - - default: - ERROR_OUT("fprintAttr: unknown/unimplemented attribute %d\n", attr.kind); - } -} - -//************************************************************************** -void freeAttribute( attr_value_t *attr ) -{ - switch (attr->kind) { - case Sim_Val_Invalid: - break; - - case Sim_Val_String: - free( (char *) attr->u.string ); - break; - - case Sim_Val_Integer: - break; - - case Sim_Val_Floating: - break; - - case Sim_Val_List: - for (int i = 0; i < attr->u.list.size; i++) { - freeAttribute( &(attr->u.list.vector[i]) ); - } - free( attr->u.list.vector ); - break; - - default: - ERROR_OUT("freeAttr: unknown/unimplemented attribute %d\n", attr->kind); - } -} - -/** - * Allocates, and initializes a attribute value. - * @param number The number of values to allocate. - * @return A pointer to the newly allocated structure. - */ -//************************************************************************** -attr_value_t *mallocAttribute( uint32 number ) -{ - attr_value_t *newattr = (attr_value_t *) malloc( number * - sizeof(attr_value_t) ); - if ( newattr == NULL ) { - ERROR_OUT( "confio: mallocAttribute: out of memory\n" ); - exit(1); - } - memset( newattr, 0, number*sizeof(attr_value_t) ); - return (newattr); -} - - -//************************************************************************** -void fprintMap( FILE *fp, attr_value_t attr ) -{ - attr_value_t name; - attr_value_t value; - - if (attr.kind != Sim_Val_List) - return; - - for (int i = 0; i < attr.u.list.size; i++) { - - if (attr.u.list.vector[i].kind != Sim_Val_List || - attr.u.list.vector[i].u.list.size != 2) - return; - - name = attr.u.list.vector[i].u.list.vector[0]; - value = attr.u.list.vector[i].u.list.vector[1]; - fprintf( fp, " %s: ", name.u.string); - fprintAttr( fp, value ); - fprintf( fp, "\n"); - } -} - -/** - * write a configuration file: e.g. save state - */ -//************************************************************************** -int confio_t::writeConfiguration( const char *outputFilename ) -{ - FILE *fp; - ConfTable::iterator iter; - confnode_t *cfnode; - attr_value_t attr; - - memset( &attr, 0, sizeof(attr_value_t) ); - if ( outputFilename == NULL ) { - fp = stdout; - } else { - fp = fopen( outputFilename, "w" ); - if ( fp == NULL ) { - ERROR_OUT("error: writeConfiguration: unable to open file %s\n", - outputFilename ); - return (-1); - } - } - - for (iter = m_table.begin(); iter != m_table.end(); iter++) { - fprintf( fp, " %s: ", (*iter).first.c_str() ); - cfnode = (*iter).second; - attr = (*(cfnode->get_attr))( cfnode->get_attr_data, NULL ); - fprintAttr( fp, attr ); - fprintf(fp, "\n"); - } - - if ( outputFilename != NULL ) { - // wrote to a file: now close it! - fclose( fp ); - } - return 0; -} - -/** - * read state from an existing configuration file - */ -//************************************************************************** -int confio_t::readConfiguration( const char *inputFilename, - const char *relativeIncludePath ) -{ - // parse the input stream - FILE *fp; - char relativeFilename[256]; - - fp = fopen( inputFilename, "r" ); - if ( fp == NULL ) { - sprintf( relativeFilename, "%s%s", relativeIncludePath, inputFilename ); - fp = fopen( relativeFilename, "r" ); - } - if ( fp == NULL ) { - sprintf( relativeFilename, "%s%s%s", relativeIncludePath, "config/", - inputFilename ); - fp = fopen( relativeFilename, "r" ); - } - if ( fp == NULL ) { - ERROR_OUT("error: readConfiguration: unable to open file %s or %s\n", - inputFilename, relativeFilename); - return (-1); - } - - attr_value_t *myattr = mallocAttribute(1); -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() parsing conf file\n"); -#endif - int rc = parseAttrFile( fp, relativeIncludePath, myattr ); -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() parse completed\n"); -#endif - if ( rc == 0 ) { - applyConfiguration( myattr ); - freeAttribute( myattr ); - free(myattr); - } - - fclose( fp ); -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() completed\n"); -#endif - return (rc); -} - -/** - * read state from a configuration string - */ -//************************************************************************** -int confio_t::readConfigurationString( const char *inputBuffer ) -{ - if ( inputBuffer == NULL ) { - ERROR_OUT( "error: readConfiguration: NULL inputBuffer\n" ); - return (-1); - } - - attr_value_t *myattr = mallocAttribute(1); -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() parsing conf string\n"); -#endif - - int rc = parseAttrString( inputBuffer, myattr ); -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() parse completed\n"); -#endif - if ( rc == 0 ) { - applyConfiguration( myattr ); - freeAttribute( myattr ); - free(myattr); - } - return (rc); -} - -//************************************************************************** -void confio_t::checkInitialization( void ) -{ - ConfTable::iterator iter; - confnode_t *cfnode; - - for (iter = m_table.begin(); iter != m_table.end(); iter++) { - cfnode = (*iter).second; - if ( !cfnode->attr_is_set ) { - DEBUG_OUT(" warning: %s is not set in configuration file.\n", (*iter).first.c_str() ); - } - } -} - -/*------------------------------------------------------------------------*/ -/* Private methods */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -int confio_t::applyConfiguration( attr_value_t *attr ) -{ - confnode_t *cfnode; - attr_value_t name; - attr_value_t value; - set_error_t seterr; - -#ifdef MODINIT_VERBOSE - DEBUG_OUT("confio_t() data in memory\n"); - fprintMap( stdout, *attr ); -#endif - - // apply the configuration the the m_table - if (attr->kind != Sim_Val_List || - attr->u.list.size <= 0) { - ERROR_OUT("readconfiguration: internal error #1\n"); - return -1; - } - - for (int i = 0; i < attr->u.list.size; i++) { - - if (attr->u.list.vector[i].kind != Sim_Val_List || - attr->u.list.vector[i].u.list.size != 2) { - ERROR_OUT("readconfiguration: illegal configuration kind:%d size:%lld\n", - attr->u.list.vector[i].kind, - attr->u.list.vector[i].u.list.size); - continue; - } - - name = attr->u.list.vector[i].u.list.vector[0]; - value = attr->u.list.vector[i].u.list.vector[1]; - string newstr((char *) name.u.string); - if ( m_table.find(newstr) != m_table.end()) { - - // set the value found in the configuration - cfnode = m_table[newstr]; - seterr = (*cfnode->set_attr)( cfnode->set_attr_data, NULL, - &(value) ); - if ( seterr == Sim_Set_Ok ) { - cfnode->attr_is_set = true; - if (m_verbose) - DEBUG_OUT("configuration set for: %s\n", name.u.string); - } else { - ERROR_OUT("error: \"%s\" unable to set value: %d\n", - name.u.string, (int) seterr); - } - } else { - ERROR_OUT("error: \"%s\" not found. unable to set value.\n", - name.u.string); - } - } - return 0; -} - -/*------------------------------------------------------------------------*/ -/* Static methods */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Global functions */ -/*------------------------------------------------------------------------*/ - - -/** [Memo]. - * [Internal Documentation] - */ -//************************************************************************** - diff --git a/src/mem/gems_common/ioutil/confio.hh b/src/mem/gems_common/ioutil/confio.hh deleted file mode 100644 index 1e9718c16..000000000 --- a/src/mem/gems_common/ioutil/confio.hh +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _CONFIO_H_ -#define _CONFIO_H_ - -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -#include "mem/gems_common/ioutil/FakeSimicsDataTypes.hh" - -/*------------------------------------------------------------------------*/ -/* Macro declarations */ -/*------------------------------------------------------------------------*/ - -/// constant for attribute parsing: a (x) single value -const attr_kind_t CONF_ATTR_SINGLE = (attr_kind_t) (Sim_Val_Object + 1); -/// constant for attribute parsing: a (x,y) pair of values -const attr_kind_t CONF_ATTR_PAIR = (attr_kind_t) (Sim_Val_Object + 2); - -/*------------------------------------------------------------------------*/ -/* Class declaration(s) */ -/*------------------------------------------------------------------------*/ - -/* - * Functions for modifying the micro-architectural configuation of - * a class. - */ - -/// function for getting the configuration value -typedef attr_value_t (*get_confio_t)( void *ptr, void *obj ); -/// function for setting the configuration value -typedef set_error_t (*set_confio_t)( void *ptr, void *obj, - attr_value_t *value ); - -/// a struture containing the functional callbacks for each conf node -typedef struct confnode { - get_confio_t get_attr; - set_confio_t set_attr; - void *set_attr_data; - void *get_attr_data; - bool attr_is_set; -} confnode_t; - -/// a mapping from a string to a configuration structure -typedef map<string, confnode_t *> ConfTable; - -/** -* Configuration state saving: allows the user to save the micro-architectural -* state in a text file for later runs. This file is also used to set -* globals during simulation. -* -* @author cmauer -* @version $Id$ -*/ -class confio_t { - -public: - - - /** - * @name Constructor(s) / destructor - */ - //@{ - - /** - * Constructor: creates object - */ - confio_t(); - - /** - * Destructor: frees object. - */ - ~confio_t(); - //@} - - /** - * @name Methods - */ - //@{ - //@} - - /** - * @name Accessor(s) / mutator(s) - */ - //@{ - /** - * register a configuration variable with the configuration manager. - * @param get_attr A function to get the attribute value - * @param get_attr_data Void pointer, available to get_attr - * @param set_attr A function to set the attribute value - * @param set_attr_data Void pointer, available to set_attr - * @return [Description of return value] - */ - int register_attribute( const char *name, - get_confio_t get_attr, void *get_attr_data, - set_confio_t set_attr, void *set_attr_data ); - - /** - * Set verbosity of the configuration - * @param verbose True causes more info to be printed out, False doesn't - */ - void setVerbosity( bool verbose ) { - m_verbose = verbose; - } - - /** - * write a configuration file: e.g. save state - */ - int writeConfiguration( const char *outputFilename ); - - /** - * read state from an existing configuration file - * @param inputFilename The file to read - * @param relativeIncludePath The path to search on 'include' statements - */ - int readConfiguration( const char *inputFilename, - const char *relativeIncludePath ); - - /** - * read state from a string - */ - int readConfigurationString( const char *inputBuffer ); - - /** - * check that each registered configuration is set (reports a warning if - * they are not.) - */ - void checkInitialization( void ); - //@} - -private: - /** - * Apply an attribute list to the configuration table - */ - int applyConfiguration( attr_value_t *attr ); - - /// configuration table: contains a map from a string -> conf node - ConfTable m_table; - - /// if false, nothing is printed under normal operation - bool m_verbose; -}; - -/*------------------------------------------------------------------------*/ -/* Global variables */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Global functions */ -/*------------------------------------------------------------------------*/ - -/** - * Allocates an array of attributes. - */ -attr_value_t *mallocAttribute( uint32 number ); - -/** - * Walks an attribute tree, freeing all memory under attr. Does not free - * attr itself. - */ -void freeAttribute( attr_value_t *attr ); - -#endif /* _CONFIO_H_ */ - - diff --git a/src/mem/gems_common/ioutil/embedtext.py b/src/mem/gems_common/ioutil/embedtext.py deleted file mode 100644 index 64e1c97f3..000000000 --- a/src/mem/gems_common/ioutil/embedtext.py +++ /dev/null @@ -1,54 +0,0 @@ - -import sys - -#--------------------------------------------------------------------------- - -class embedText: - """ - embedText converts a text file into a file that can be embedded in C - using an #include statement, that defines a \"const char *\" pointing - to the same text. - - This is useful to embed scripts and configuration files in object files. - """ - def __init__(self, filename): - self.filename = filename - self.escape = [ "\'", "\"", "\\", "\?" ] - - def write(self, outputfile, varname): - # reads the text file in, line by line, converting it to a C string - fin = open( self.filename, 'r' ) - fout= open( outputfile, 'w' ) - fout.write("static const char *%s =\n" % varname); - l = " " - while l != "": - l = fin.readline() - - # add escape sequences for the characters in escape - fout.write("\"") - for char in l: - if char == "\n": - break - if char in self.escape: - fout.write( "\\" ) - fout.write( char ) - else: - fout.write( char ) - fout.write("\\n\"\n"); - fout.write(";\n"); - fin.close() - fout.close() - -#--------------------------------------------------------------------------- - -if __name__ == "__main__": - if len(sys.argv) != 4: - print len(sys.argv) - print "usage:", sys.argv[0], " input-file output-file varname" - sys.exit(1) - inputfile = sys.argv[1] - outputfile = sys.argv[2] - varname = sys.argv[3] - print "generating embedded text file: %s from %s\n" % (outputfile, inputfile) - inc = embedText( inputfile ) - inc.write( outputfile, varname ) diff --git a/src/mem/gems_common/ioutil/initvar.cc b/src/mem/gems_common/ioutil/initvar.cc deleted file mode 100644 index 4388c0de4..000000000 --- a/src/mem/gems_common/ioutil/initvar.cc +++ /dev/null @@ -1,585 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - This file has been modified by Kevin Moore and Dan Nussbaum of the - Scalable Systems Research Group at Sun Microsystems Laboratories - (http://research.sun.com/scalable/) to support the Adaptive - Transactional Memory Test Platform (ATMTP). - - Please send email to atmtp-interest@sun.com with feedback, questions, or - to request future announcements about ATMTP. - - ---------------------------------------------------------------------- - - File modification date: 2008-02-23 - - ---------------------------------------------------------------------- -*/ - -/* - * FileName: initvar.C - * Synopsis: implementation of global variable initialization in simics - * Author: cmauer - * Version: $Id$ - */ - -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -using namespace std; -#include <string> -#include <map> -#include <stdlib.h> - -// Maurice -// extern "C" { -// #include "global.hh" -// #include "simics/api.hh" -// #ifdef SIMICS22X -// #include "configuration_api.hh" -// #endif -// #ifdef SIMICS30 -// #include "configuration.hh" -// #endif -// }; - -#include "mem/ruby/common/Global.hh" - -#include "mem/gems_common/ioutil/confio.hh" -#include "mem/gems_common/ioutil/initvar.hh" - -/*------------------------------------------------------------------------*/ -/* Variable declarations */ -/*------------------------------------------------------------------------*/ - -// define global "constants" using centralized file -#define PARAM( NAME ) \ - int32 NAME; -#define PARAM_UINT( NAME ) \ - uint32 NAME; -#define PARAM_ULONG( NAME ) \ - uint64 NAME; -#define PARAM_BOOL( NAME ) \ - bool NAME; -#define PARAM_DOUBLE( NAME ) \ - double NAME; -#define PARAM_STRING( NAME ) \ - char *NAME; -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - PTYPE NAME[ARRAY_SIZE]; -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - -/** global initvar object */ -initvar_t *initvar_t::m_inst = NULL; - -/*------------------------------------------------------------------------*/ -/* Forward declarations */ -/*------------------------------------------------------------------------*/ - -static attr_value_t initvar_get_attr( void *ptr, void *obj ); -static set_error_t initvar_set_attr( void *ptr, void *obj, - attr_value_t *value ); - -/*------------------------------------------------------------------------*/ -/* Constructor(s) / destructor */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -initvar_t::initvar_t( const char *name, const char *relativeIncludePath, - const char *initializingString, - void (*allocate_fn)(void), - void (*my_generate_fn)(void) ) -{ - m_is_init = false; - m_name = (char *) malloc( sizeof(char)*(strlen( name ) + 2) ); - m_rel_include_path = (char *) malloc( sizeof(char)*(strlen( relativeIncludePath ) + 2) ); - m_config_filename = NULL; - strcpy( m_name, name ); - strcpy( m_rel_include_path, relativeIncludePath ); - m_allocate_f = allocate_fn; - m_generate_values_f = my_generate_fn; - - initvar_t::m_inst = this; - init_config_reader( initializingString ); -} - -//************************************************************************** -initvar_t::~initvar_t( ) -{ -#define PARAM( NAME ) -#define PARAM_UINT( NAME ) -#define PARAM_ULONG( NAME ) -#define PARAM_BOOL( NAME ) -#define PARAM_DOUBLE( NAME ) -#define PARAM_STRING( NAME ) \ - if (NAME != NULL) { \ - free( NAME ); \ - NAME = NULL; \ - } -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - if (m_name) { - free( m_name ); - } - if (m_rel_include_path) { - free( m_rel_include_path ); - } - if (m_config_reader) { - delete m_config_reader; - } - if (m_config_filename) { - delete m_config_filename; - } -} - -//************************************************************************** -void initvar_t::init_config_reader( const char *initString ) -{ - int rc; - const char *name; - - m_config_reader = new confio_t(); - m_config_reader->setVerbosity( false ); - - // Initialize the config reader object to identify each parameter -#define PARAM_UINT PARAM -#define PARAM_ULONG PARAM -#define PARAM_BOOL PARAM -#define PARAM_DOUBLE PARAM -#define PARAM( NAME ) \ - name = #NAME; \ - rc = m_config_reader->register_attribute( name, \ - initvar_get_attr, (void *) name, \ - initvar_set_attr, (void *) name ); -#define PARAM_STRING( NAME ) \ - NAME = NULL; \ - name = #NAME; \ - rc = m_config_reader->register_attribute( name, \ - initvar_get_attr, (void *) name, \ - initvar_set_attr, (void *) name ); -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - name = #NAME; \ - rc = m_config_reader->register_attribute( name, \ - initvar_get_attr, (void *) name, \ - initvar_set_attr, (void *) name ); - -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - - // read the default configuration from the embedded text file - rc = m_config_reader->readConfigurationString( initString ); - (*m_generate_values_f)(); -} - -/*------------------------------------------------------------------------*/ -/* Public methods */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -void initvar_t::allocate( void ) -{ - if ( confirm_init() ) { - DEBUG_OUT("error: %s initvar::allocate() called twice\n", m_name); - return; - } - - (*m_generate_values_f)(); - (*m_allocate_f)(); - m_is_init = true; -} - -//************************************************************************** -void initvar_t::checkInitialization( void ) -{ - m_config_reader->checkInitialization(); -} - -//************************************************************************** -int initvar_t::dispatch_get( void *id, void *obj, - attr_value_t *idx ) -{ - const char *command = (const char *) id; - if ( !confirm_init() ) { - DEBUG_OUT("error: %s is uninitialized. unable to get \'%s\'\n", m_name, command); - DEBUG_OUT(" : you must initialize %s with a configuration file first.\n", m_name); - DEBUG_OUT(" : use the command \'%s0.init\'\n", m_name); - - return 0; - } - - std::cerr << __FILE__ << "(" << __LINE__ << "): Not implmented." << std::endl; - return 0; -} - - -//************************************************************************** -set_error_t initvar_t::dispatch_set( void *id, void *obj, - attr_value_t *val, attr_value_t *idx ) -{ - const char *command = (const char *) id; - - // DEBUG_OUT("set attribute: %s\n", command); - if (!strcmp(command, "init")) { - if (val->kind == Sim_Val_String) { - if (!strcmp( val->u.string, "" )) { - // update generated values, then allocate - allocate(); - } else { - read_config( val->u.string ); - allocate(); - } - return Sim_Set_Ok; - } else { - return Sim_Set_Need_String; - } - } else if (!strcmp(command, "readparam")) { - if (val->kind == Sim_Val_String) { - read_config( val->u.string ); - return Sim_Set_Ok; - } else { - return Sim_Set_Need_String; - } - } else if (!strcmp(command, "saveparam")) { - if (val->kind == Sim_Val_String) { - FILE *fp = fopen( val->u.string, "w" ); - if (fp == NULL) { - ERROR_OUT("error: unable to open file: %s\n", val->u.string); - return Sim_Set_Illegal_Value; - } - list_param( fp ); - if (fp != NULL) { - fclose( fp ); - } - return Sim_Set_Ok; - } else { - ERROR_OUT("error: saveparam given wrong type.\n"); - return Sim_Set_Illegal_Value; - } - } else if (!strcmp(command, "param")) { - if (val->kind == Sim_Val_Integer) { - list_param( stdout ); - return Sim_Set_Ok; - } else if ( val->kind == Sim_Val_List && - val->u.list.size == 2 && - val->u.list.vector[0].kind == Sim_Val_String ) { - return (set_param( val->u.list.vector[0].u.string, - &val->u.list.vector[1] )); - } else { - DEBUG_OUT("error: set parameter given wrong type.\n"); - return Sim_Set_Illegal_Value; - } - } - - if ( !confirm_init() ) { - DEBUG_OUT("error: %s is uninitialized. unable to set \'%s\'\n", m_name, id); - DEBUG_OUT(" : you must initialize %s with a configuration file first.\n", m_name); - DEBUG_OUT(" : use the command \'%s0.init\'\n", m_name); - return Sim_Set_Illegal_Value; - } - - - std::cerr << __FILE__ << "(" << __LINE__ << "): Not implmented." << std::endl; - return Sim_Set_Illegal_Value; -} - -/*------------------------------------------------------------------------*/ -/* Accessor(s) / mutator(s) */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Private methods */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Static methods */ -/*------------------------------------------------------------------------*/ - -//************************************************************************** -static attr_value_t initvar_get_attr( void *ptr, void *obj ) -{ - const char *name = (const char *) ptr; - attr_value_t ret; - memset( &ret, 0, sizeof(attr_value_t) ); - -#define PARAM_UINT PARAM -#define PARAM_ULONG PARAM -#define PARAM_BOOL PARAM -#define PARAM( NAME ) \ - if (!strcmp(name, #NAME)) { \ - ret.kind = Sim_Val_Integer; \ - ret.u.integer = NAME; \ - return (ret); \ - } -#define PARAM_DOUBLE( NAME ) \ - if (!strcmp(name, #NAME)) { \ - ret.kind = Sim_Val_Floating; \ - ret.u.floating = NAME; \ - return (ret); \ - } -#define PARAM_STRING( NAME ) \ - if (!strcmp(name, #NAME)) { \ - ret.kind = Sim_Val_String; \ - ret.u.string = NAME; \ - return (ret); \ - } -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - if (!strcmp(name, #NAME)) { \ - ret.kind = Sim_Val_List; \ - ret.u.list.size = ARRAY_SIZE; \ - ret.u.list.vector = mallocAttribute( ARRAY_SIZE ); \ - for (int i = 0; i < ARRAY_SIZE; i++) { \ - ret.u.list.vector[i].u.integer = NAME[i]; \ - } \ - return (ret); \ - } - -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - - DEBUG_OUT("error: %s not found.\n", name); - ret.kind = Sim_Val_Invalid; - return (ret); -} - -//*************************************************************************** -static set_error_t initvar_set_attr( void *ptr, void *obj, - attr_value_t *value ) -{ - const char *name = (const char *) ptr; - -#define PARAM_UINT PARAM -#define PARAM_ULONG PARAM -#define PARAM( NAME ) \ - if (!strcmp(name, #NAME)) { \ - if ( value->kind != Sim_Val_Integer ) { \ - ERROR_OUT("error: %s is not an integer\n", name );\ - return Sim_Set_Need_Integer; \ - } \ - NAME = value->u.integer; \ - return Sim_Set_Ok; \ - } -#define PARAM_BOOL( NAME ) \ - if (!strcmp(name, #NAME)) { \ - if ( value->kind != Sim_Val_String ) { \ - ERROR_OUT("error: %s is not an bool string\n", name );\ - return Sim_Set_Need_String; \ - } \ - if (!strcmp(value->u.string, "true")) { \ - NAME = true; \ - } else if (!strcmp(value->u.string, "false")) { \ - NAME = false; \ - } else { \ - ERROR_OUT("error: value %s for %s is not an bool string (set to false)\n", value->u.string, name );\ - NAME = false; \ - } \ - return Sim_Set_Ok; \ - } -#define PARAM_DOUBLE( NAME ) \ - if (!strcmp(name, #NAME)) { \ - if ( value->kind != Sim_Val_String ) { \ - ERROR_OUT("error: %s is not a float\n", name );\ - return Sim_Set_Need_Floating; \ - } \ - NAME = atof( value->u.string ); \ - return Sim_Set_Ok; \ - } -#define PARAM_STRING( NAME ) \ - if (!strcmp(name, #NAME)) { \ - if ( value->kind != Sim_Val_String ) { \ - ERROR_OUT("error: %s is not an string\n", name ); \ - return Sim_Set_Need_String; \ - } \ - if (NAME != NULL) { \ - free( NAME ); \ - } \ - NAME = strdup( value->u.string ); \ - return Sim_Set_Ok; \ - } -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - if (!strcmp(name, #NAME)) { \ - if ( value->kind != Sim_Val_List ) { \ - ERROR_OUT("error: %s is not an list\n", name ); \ - return Sim_Set_Need_List; \ - } \ - if ( value->u.list.size != ARRAY_SIZE ) { \ - ERROR_OUT("error: %s has %lld elements (should be %d)\n", name, value->u.list.size, ARRAY_SIZE); \ - return Sim_Set_Illegal_Value; \ - } \ - for (int i = 0; i < ARRAY_SIZE; i++) { \ - NAME[i] = value->u.list.vector[i].u.integer; \ - } \ - return Sim_Set_Ok; \ - } - -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - - ERROR_OUT("error: %s not a parameter\n", name); - return Sim_Set_Illegal_Value; -} - -//*************************************************************************** -void initvar_t::read_config( const char *parameterFile ) -{ - DEBUG_OUT("read configuration: %s\n", parameterFile ); - m_config_filename = strdup( parameterFile ); - int rc = m_config_reader->readConfiguration( parameterFile, - m_rel_include_path ); - if ( rc < 0 ) { - ERROR_OUT("fatal error in read configuration: unable to continue.\n"); - exit(1); - } - // update generated values - (*m_generate_values_f)(); -} - -/** sets one of the parameters */ -//************************************************************************** -set_error_t initvar_t::set_param( const char *name, attr_value_t *value ) -{ - - // [dann 2007-04-04] ATMTP VV - // - // HACK ALERT: allow setting REMOVE_SINGLE_CYCLE_DCACHE_FAST_PATH, - // PROFILE_EXCEPTIONS, PROFILE_XACT, ATMTP_DEBUG_LEVEL and - // ATMTP_ENABLED after initialization. This works is because ruby's - // m_generate_values_f() does nothing -- more particularly, nothing - // that depends on any of these parameters is pre-calculated - // anywhere. - // - if (strcmp(name, "REMOVE_SINGLE_CYCLE_DCACHE_FAST_PATH") != 0 && - strcmp(name, "PROFILE_EXCEPTIONS") != 0 && - strcmp(name, "PROFILE_XACT") != 0 && - strcmp(name, "ATMTP_DEBUG_LEVEL") != 0 && - strcmp(name, "ATMTP_ENABLED") != 0) { - // - // [dann 2007-04-04] ATMTP ^^ - if ( confirm_init() ) { - DEBUG_OUT("error: %s is already initialized.\n", m_name); - DEBUG_OUT(" : setting parameters after initialization is unsupported\n"); - return (Sim_Set_Illegal_Value); - } - // [dann 2007-04-04] ATMTP VV - // - } - // - // [dann 2007-04-04] ATMTP ^^ - - set_error_t result = initvar_set_attr( (void *) name, NULL, value ); - (*m_generate_values_f)(); - return (result); -} - -/** print out a list of valid parameters */ -//************************************************************************** -void initvar_t::list_param( FILE *fp ) -{ - if (!fp) - fp = stdout; - -#define PARAM( NAME ) \ - fprintf( fp, "%-44.44s: %26d\n", #NAME, NAME ); -#define PARAM_UINT( NAME ) \ - fprintf( fp, "%-44.44s: %26u\n", #NAME, NAME ); -#define PARAM_ULONG( NAME ) \ - fprintf( fp, "%-44.44s: %26llu\n", #NAME, (unsigned long long)NAME ); -#define PARAM_BOOL( NAME ) \ - if (NAME == true) { \ - fprintf( fp, "%-44.44s: %26.26s\n", #NAME, "true" ); \ - } else { \ - fprintf( fp, "%-44.44s: %26.26s\n", #NAME, "false" );\ - } -#define PARAM_DOUBLE( NAME ) \ - fprintf( fp, "%-44.44s: %26f\n", #NAME, NAME ); -#define PARAM_STRING( NAME ) \ - if ( NAME != NULL ) { \ - fprintf( fp, "%-44.44s: %26.26s\n", #NAME, NAME ); \ - } -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - fprintf( fp, "%-44.44s: (", #NAME ); \ - for (int i = 0; i < ARRAY_SIZE; i++) { \ - if ( i != 0 ) { \ - fprintf( fp, ", " ); \ - } \ - fprintf( fp, "%d", NAME[i] ); \ - } \ - fprintf( fp, ")\n" ); - -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY -} - -//************************************************************************** -const char *initvar_t::get_config_name( void ) -{ - if (m_config_filename == NULL) { - return "default"; - } - return m_config_filename; -} - diff --git a/src/mem/gems_common/ioutil/initvar.hh b/src/mem/gems_common/ioutil/initvar.hh deleted file mode 100644 index ac261f110..000000000 --- a/src/mem/gems_common/ioutil/initvar.hh +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _INCLUDE_H_ -#define _INCLUDE_H_ - -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Macro declarations */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Class declaration(s) */ -/*------------------------------------------------------------------------*/ - -/** -* This class deals with initializing the global variables in the object, -* setting the varibles (from the command line), printing the configuration, -* and saving it to a file. -* -* @see confio_t -* @author cmauer -* @version $Id$ -*/ -class initvar_t { -public: - /** - * @name Constructor(s) / destructor - */ - //@{ - - /** - * Constructor: creates object - * @param name The name of this object - * @param relativeIncludePath The relative path to config files - * @param initializingString A string (with value pairs) for initialization - * @param allocate_f A ptr to the allocate function - * @param generate_values A ptr to the generate values function - */ - initvar_t( const char *name, const char *relativeIncludePath, - const char *initializingString, - void (*allocate_fn)(void), - void (*my_generate_fn)(void) - ); - - /** - * Destructor: frees object. - */ - ~initvar_t(); - //@} - - /** - * @name Methods - */ - //@{ - /// calls the allocation routine explicitly (used by the tester) - void allocate( void ); - - /// checks to see if all vars have been initialized - void checkInitialization( void ); - - /// list all parameters: to a file (or stdout if file is NULL) - void list_param( FILE *fp ); - - /// returns the name of the last config file to be read ("default" is none) - const char *get_config_name( void ); - - /// calls through to the get_attr function, if object is initialized - int dispatch_get( void *id, void *obj, - attr_value_t *idx ); - - /** adds initialization attributes, calls through to the set_attr function, - * if object is initialized. - */ - set_error_t dispatch_set( void *id, void *obj, - attr_value_t *val, attr_value_t *idx ); - //@} - /// (single) instance of the init var object - static initvar_t *m_inst; - -protected: - ///returns true if the variables are initialized - bool confirm_init( void ) { - return m_is_init; - } - - ///read a configuration file - void read_config( const char *parameterFile ); - - /// set a parameter to be a particular value - set_error_t set_param( const char *name, attr_value_t *value ); - - /// initializes the configuration reader - void init_config_reader( const char *initString ); - - /// bool value (true if initialized) - bool m_is_init; - - /// configuration reader - confio_t *m_config_reader; - - /// a pointer to a string (corresponding to this objects name) - char *m_name; - - /// a pointer to a string (representing the last config file read) - char *m_config_filename; - - /// the relative include path to the configuration files - char *m_rel_include_path; - - /// a pointer to the allocation function - void (*m_allocate_f)(void); - - /// a pointer to the generate values function - void (*m_generate_values_f)(void); - -}; - - -/*------------------------------------------------------------------------*/ -/* Global variables */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Global functions */ -/*------------------------------------------------------------------------*/ - -#ifdef __cplusplus -extern "C" { -#endif - -///provides a dispatch mechanism that catches a few commands to get variables -attr_value_t initvar_dispatch_get( void *id, void *obj, - attr_value_t *idx ); - -///provides a dispatch mechanism that catches a few commands to set variables -set_error_t initvar_dispatch_set( void *id, void *obj, - attr_value_t *val, attr_value_t *idx ); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* _INCLUDE_H_ */ diff --git a/src/mem/gems_common/ioutil/vardecl.hh b/src/mem/gems_common/ioutil/vardecl.hh deleted file mode 100644 index 607bc54f6..000000000 --- a/src/mem/gems_common/ioutil/vardecl.hh +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 1999-2005 Mark D. Hill and David A. Wood - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _VARDECL_H_ -#define _VARDECL_H_ - -/*------------------------------------------------------------------------*/ -/* Includes */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Macro declarations */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Class declaration(s) */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* Global variables */ -/*------------------------------------------------------------------------*/ - -#define PARAM( NAME ) \ - extern int32 NAME; -#define PARAM_UINT( NAME ) \ - extern uint32 NAME; -#define PARAM_ULONG( NAME ) \ - extern uint64 NAME; -#define PARAM_BOOL( NAME ) \ - extern bool NAME; -#define PARAM_DOUBLE( NAME ) \ - extern double NAME; -#define PARAM_STRING( NAME ) \ - extern char *NAME; -#define PARAM_ARRAY( PTYPE, NAME, ARRAY_SIZE ) \ - extern PTYPE NAME[ARRAY_SIZE]; -#include "mem/ruby/config/config.hh" -#undef PARAM -#undef PARAM_UINT -#undef PARAM_ULONG -#undef PARAM_BOOL -#undef PARAM_DOUBLE -#undef PARAM_STRING -#undef PARAM_ARRAY - -/*------------------------------------------------------------------------*/ -/* Global functions */ -/*------------------------------------------------------------------------*/ - -#endif /* _VARDECL_H_ */ |