String constant const-ness changes to placate g++ 4.2.

Also some bug fixes in MIPS ISA uncovered by g++ warnings
(Python string compares don't work in C++!).

--HG--
extra : convert_revision : b347cc0108f23890e9b73b3ee96059f0cea96cf6
This commit is contained in:
Steve Reinhardt 2007-10-31 18:04:22 -07:00
parent 71b033f4dc
commit 4b49bd47f4
14 changed files with 34 additions and 24 deletions

View file

@ -82,7 +82,7 @@ output decoder {{
// Need to find standard way to not print // Need to find standard way to not print
// this info. Maybe add bool variable to // this info. Maybe add bool variable to
// class? // class?
if (mnemonic != "syscall") { if (strcmp(mnemonic, "syscall") != 0) {
if(_numDestRegs > 0){ if(_numDestRegs > 0){
printReg(ss, _destRegIdx[0]); printReg(ss, _destRegIdx[0]);
} }
@ -100,7 +100,7 @@ output decoder {{
// Should we define a separate inst. class // Should we define a separate inst. class
// just for two insts? // just for two insts?
if(mnemonic == "sll" || mnemonic == "sra"){ if (strcmp(mnemonic, "sll") == 0 || strcmp(mnemonic, "sra") == 0) {
ccprintf(ss,", %d",SA); ccprintf(ss,", %d",SA);
} }

View file

@ -196,7 +196,7 @@ output decoder {{
ccprintf(ss, "%-10s ", mnemonic); ccprintf(ss, "%-10s ", mnemonic);
if ( mnemonic == "jal" ) { if (strcmp(mnemonic, "jal") == 0) {
Addr npc = pc + 4; Addr npc = pc + 4;
ccprintf(ss,"0x%x",(npc & 0xF0000000) | disp); ccprintf(ss,"0x%x",(npc & 0xF0000000) | disp);
} else if (_numSrcRegs == 0) { } else if (_numSrcRegs == 0) {

View file

@ -119,7 +119,7 @@ output header {{
{ {
//If Bit 15 is 1 then Sign Extend //If Bit 15 is 1 then Sign Extend
int32_t temp = sextImm & 0x00008000; int32_t temp = sextImm & 0x00008000;
if (temp > 0 && mnemonic != "lui") { if (temp > 0 && strcmp(mnemonic, "lui") != 0) {
sextImm |= 0xFFFF0000; sextImm |= 0xFFFF0000;
} }
} }
@ -313,7 +313,7 @@ output decoder {{
ss << ", "; ss << ", ";
} }
if( mnemonic == "lui") if (strcmp(mnemonic, "lui") == 0)
ccprintf(ss, "0x%x ", sextImm); ccprintf(ss, "0x%x ", sextImm);
else else
ss << (int) sextImm; ss << (int) sextImm;

View file

@ -72,9 +72,9 @@ output decoder {{
{ {
std::stringstream ss; std::stringstream ss;
if (mnemonic == "mttc0" || mnemonic == "mftc0") { if (strcmp(mnemonic, "mttc0") == 0 || strcmp(mnemonic, "mftc0") == 0) {
ccprintf(ss, "%-10s r%d, r%d, %d", mnemonic, RT, RD, SEL); ccprintf(ss, "%-10s r%d, r%d, %d", mnemonic, RT, RD, SEL);
} else if (mnemonic == "mftgpr") { } else if (strcmp(mnemonic, "mftgpr") == 0) {
ccprintf(ss, "%-10s r%d, r%d", mnemonic, RD, RT); ccprintf(ss, "%-10s r%d, r%d", mnemonic, RD, RT);
} else { } else {
ccprintf(ss, "%-10s r%d, r%d", mnemonic, RT, RD); ccprintf(ss, "%-10s r%d, r%d", mnemonic, RT, RD);

View file

@ -87,7 +87,7 @@ output header {{
FOrdered=0xF FOrdered=0xF
}; };
extern char * CondTestAbbrev[]; extern const char *CondTestAbbrev[];
/** /**
* Base class for all SPARC static instructions. * Base class for all SPARC static instructions.
@ -126,7 +126,7 @@ output header {{
output decoder {{ output decoder {{
char * CondTestAbbrev[] = const char *CondTestAbbrev[] =
{ {
"nev", //Never "nev", //Never
"e", //Equal "e", //Equal

View file

@ -126,7 +126,7 @@ namespace X86ISA
{"", "t%db", "t%dw", "", "t%dd", "", "", "", "t%d"}; {"", "t%db", "t%dw", "", "t%dd", "", "", "", "t%d"};
if (reg < FP_Base_DepTag) { if (reg < FP_Base_DepTag) {
char * suffix = ""; const char * suffix = "";
bool fold = reg & (1 << 6); bool fold = reg & (1 << 6);
reg &= ~(1 << 6); reg &= ~(1 << 6);

View file

@ -60,7 +60,7 @@ hostname()
} }
uint64_t uint64_t
procInfo(char *filename, char *target) procInfo(const char *filename, const char *target)
{ {
int done = 0; int done = 0;
char line[80]; char line[80];

View file

@ -37,7 +37,7 @@
std::string &hostname(); std::string &hostname();
uint64_t procInfo(char *filename, char *target); uint64_t procInfo(const char *filename, const char *target);
inline uint64_t memUsage() inline uint64_t memUsage()
{ return procInfo("/proc/self/status", "VmSize:"); } { return procInfo("/proc/self/status", "VmSize:"); }

View file

@ -111,7 +111,7 @@ IniFile::loadCPP(const string &file, vector<char *> &cppArgs)
int arg_count = cppArgs.size(); int arg_count = cppArgs.size();
char **args = new char *[arg_count + 20]; const char **args = new const char *[arg_count + 20];
int nextArg = 0; int nextArg = 0;
args[nextArg++] = "g++"; args[nextArg++] = "g++";
@ -136,7 +136,9 @@ IniFile::loadCPP(const string &file, vector<char *> &cppArgs)
if (dup2(tmp_fd, STDOUT_FILENO) == -1) if (dup2(tmp_fd, STDOUT_FILENO) == -1)
exit(1); exit(1);
execvp("g++", args); // execvp signature is intentionally broken wrt const-ness for
// backwards compatibility... see man page
execvp("g++", const_cast<char * const *>(args));
exit(0); exit(0);
} }

View file

@ -100,7 +100,7 @@ setupSharedData()
// Utility methods for pretty printing a report about a difference // Utility methods for pretty printing a report about a difference
// //
inline char * genCenteredLabel(int length, char * buffer, char * label) inline char * genCenteredLabel(int length, char * buffer, const char * label)
{ {
int labelLength = strlen(label); int labelLength = strlen(label);
assert(labelLength <= length); assert(labelLength <= length);
@ -127,7 +127,7 @@ inline void printColumnLabels(ostream & os)
ccprintf(os, "--------------------+-----------------------+-----------------------\n"); ccprintf(os, "--------------------+-----------------------+-----------------------\n");
} }
inline void printSectionHeader(ostream & os, char * name) inline void printSectionHeader(ostream & os, const char * name)
{ {
char sectionString[70]; char sectionString[70];
genCenteredLabel(69, sectionString, name); genCenteredLabel(69, sectionString, name);

View file

@ -168,7 +168,7 @@ Printk(stringstream &out, Arguments args)
break; break;
case 's': { case 's': {
char *s = (char *)args; const char *s = (const char *)args;
if (!s) if (!s)
s = "<NULL>"; s = "<NULL>";

View file

@ -176,7 +176,7 @@ Printf(Arguments args)
break; break;
case 's': { case 's': {
char *s = (char *)args; const char *s = (const char *)args;
if (!s) if (!s)
s = "<NULL>"; s = "<NULL>";

View file

@ -147,20 +147,28 @@ inifile()
*/ */
extern "C" SimObject *convertSwigSimObjectPtr(PyObject *); extern "C" SimObject *convertSwigSimObjectPtr(PyObject *);
// Python.h is notoriously not const-correct (for 2.4, anyway)... make
// a little define here to reduce the noise and make it easier to
// #ifdef away if Python.h gets fixed. Note there are a couple of
// these in sim/main.cc as well that are handled without this define.
#define PCC(s) const_cast<char *>(s)
SimObject * SimObject *
resolveSimObject(const string &name) resolveSimObject(const string &name)
{ {
PyObject *module = PyImport_ImportModule("m5.SimObject"); PyObject *module = PyImport_ImportModule(PCC("m5.SimObject"));
if (module == NULL) if (module == NULL)
panic("Could not import m5.SimObject"); panic("Could not import m5.SimObject");
PyObject *resolver = PyObject_GetAttrString(module, "resolveSimObject"); PyObject *resolver =
PyObject_GetAttrString(module, PCC("resolveSimObject"));
if (resolver == NULL) { if (resolver == NULL) {
PyErr_Print(); PyErr_Print();
panic("resolveSimObject: failed to find resolveSimObject"); panic("resolveSimObject: failed to find resolveSimObject");
} }
PyObject *ptr = PyObject_CallFunction(resolver, "(s)", name.c_str()); PyObject *ptr = PyObject_CallFunction(resolver, PCC("(s)"), name.c_str());
if (ptr == NULL) { if (ptr == NULL) {
PyErr_Print(); PyErr_Print();
panic("resolveSimObject: failure on call to Python for %s", name); panic("resolveSimObject: failure on call to Python for %s", name);

View file

@ -82,7 +82,7 @@ python_main()
PyObject *dict; PyObject *dict;
PyObject *result; PyObject *result;
module = PyImport_AddModule("__main__"); module = PyImport_AddModule(const_cast<char*>("__main__"));
if (module == NULL) if (module == NULL)
fatal("Could not import __main__"); fatal("Could not import __main__");
@ -135,10 +135,10 @@ main(int argc, char **argv)
if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1) if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1)
fatal("setenv: %s\n", strerror(errno)); fatal("setenv: %s\n", strerror(errno));
char *python_home = getenv("PYTHONHOME"); const char *python_home = getenv("PYTHONHOME");
if (!python_home) if (!python_home)
python_home = PYTHONHOME; python_home = PYTHONHOME;
Py_SetPythonHome(python_home); Py_SetPythonHome(const_cast<char*>(python_home));
// initialize embedded Python interpreter // initialize embedded Python interpreter
Py_Initialize(); Py_Initialize();