From 63fdabf191b8ac1031fb25da61ab2526d4bb6d05 Mon Sep 17 00:00:00 2001
From: Ali Saidi <saidi@eecs.umich.edu>
Date: Fri, 26 Jan 2007 18:48:51 -0500
Subject: make our code a little more standards compliant pretty close to
 compiling w/ suns compiler

briefly:
add dummy return after panic()/fatal()
split out flags by compiler vendor
include cstring and cmath where appropriate
use std namespace for string ops

SConstruct:
    Add code to detect compiler and choose cflags based on detected compiler
    Fix zlib check to work with suncc
src/SConscript:
    split out flags by compiler vendor
src/arch/sparc/isa/decoder.isa:
    use correct namespace for sqrt
src/arch/sparc/isa/formats/basic.isa:
    add dummy return around panic
src/arch/sparc/isa/formats/integerop.isa:
    use correct namespace for stringops
src/arch/sparc/isa/includes.isa:
    include cstring and cmath where appropriate
src/arch/sparc/isa_traits.hh:
    remove dangling comma
src/arch/sparc/system.cc:
    dummy return to make sun cc front end happy
src/arch/sparc/tlb.cc:
src/base/compression/lzss_compression.cc:
    use std namespace for string ops
src/arch/sparc/utility.hh:
    no reason to say something is unsigned unsigned int
src/base/compression/null_compression.hh:
    dummy returns to for suncc front end
src/base/cprintf.hh:
    use standard variadic argument syntax instead of gnuc specefic renaming
src/base/hashmap.hh:
    don't need to define hash for suncc
src/base/hostinfo.cc:
    need stdio.h for sprintf
src/base/loader/object_file.cc:
    munmap is in std namespace not null
src/base/misc.hh:
    use M5 generic noreturn macros
    use standard variadic macro __VA_ARGS__
src/base/pollevent.cc:
    we need file.h for file flags
src/base/random.cc:
    mess with include files to make suncc happy
src/base/remote_gdb.cc:
    malloc memory for function instead of having a non-constant in an array size
src/base/statistics.hh:
    use std namespace for floor
src/base/stats/text.cc:
    include math.h for rint (cmath won't work)
src/base/time.cc:
    use suncc version of ctime_r
src/base/time.hh:
    change macro to work with both gcc and suncc
src/base/timebuf.hh:
    include cstring from memset and use std::
src/base/trace.hh:
    change variadic macros to be normal format
src/cpu/SConscript:
    add dummy returns where appropriate
src/cpu/activity.cc:
    include cstring for memset
src/cpu/exetrace.hh:
    include cstring fro memcpy
src/cpu/simple/base.hh:
    add dummy return for panic
src/dev/baddev.cc:
src/dev/pciconfigall.cc:
src/dev/platform.cc:
src/dev/sparc/t1000.cc:
    add dummy return where appropriate
src/dev/ide_atareg.h:
    make define work for both gnuc and suncc
src/dev/io_device.hh:
    add dummy returns where approirate
src/dev/pcidev.hh:
src/mem/cache/cache_impl.hh:
src/mem/cache/miss/blocking_buffer.cc:
src/mem/cache/tags/lru.hh:
src/mem/cache/tags/split.hh:
src/mem/cache/tags/split_lifo.hh:
src/mem/cache/tags/split_lru.hh:
src/mem/dram.cc:
src/mem/packet.cc:
src/mem/port.cc:
    include cstring for string ops
src/dev/sparc/mm_disk.cc:
    add dummy return where appropriate
    include cstring for string ops
src/mem/cache/miss/blocking_buffer.hh:
src/mem/port.hh:
    Add dummy return where appropriate
src/mem/cache/tags/iic.cc:
    cast hastSets to double for log() call
src/mem/physical.cc:
    cast pmemAddr to char* for munmap
src/sim/byteswap.hh:
    make define work for suncc and gnuc

--HG--
extra : convert_revision : ef8a1f1064e43b6c39838a85c01aee4f795497bd
---
 src/base/compression/lzss_compression.cc |  6 ++---
 src/base/compression/null_compression.hh |  2 ++
 src/base/cprintf.hh                      | 24 ++++++++---------
 src/base/hashmap.hh                      |  2 +-
 src/base/hostinfo.cc                     |  1 +
 src/base/loader/object_file.cc           |  4 +--
 src/base/misc.hh                         | 45 ++++++++++++++++++--------------
 src/base/pollevent.cc                    |  2 +-
 src/base/random.cc                       | 13 ++++++---
 src/base/remote_gdb.cc                   |  5 +++-
 src/base/statistics.hh                   |  5 +++-
 src/base/stats/text.cc                   |  4 +++
 src/base/time.cc                         |  4 +++
 src/base/time.hh                         |  2 +-
 src/base/timebuf.hh                      |  5 ++--
 src/base/trace.hh                        | 28 ++++++++++----------
 16 files changed, 91 insertions(+), 61 deletions(-)

(limited to 'src/base')

diff --git a/src/base/compression/lzss_compression.cc b/src/base/compression/lzss_compression.cc
index eb35fb8f1..bd16d82c9 100644
--- a/src/base/compression/lzss_compression.cc
+++ b/src/base/compression/lzss_compression.cc
@@ -32,8 +32,8 @@
  * LZSSCompression definitions.
  */
 
-#include <assert.h>
-
+#include <cassert>
+#include <cstring>
 #include "base/compression/lzss_compression.hh"
 
 #include "base/misc.hh" //for fatal
@@ -134,7 +134,7 @@ LZSSCompression::compress(uint8_t *dest, uint8_t *src, int size)
 
     if (dest_index >= size) {
         // Have expansion instead of compression, just copy.
-        memcpy(dest,src,size);
+        std::memcpy(dest,src,size);
         return size;
     }
     return dest_index;
diff --git a/src/base/compression/null_compression.hh b/src/base/compression/null_compression.hh
index ff110807a..798acb77a 100644
--- a/src/base/compression/null_compression.hh
+++ b/src/base/compression/null_compression.hh
@@ -50,11 +50,13 @@ class NullCompression : public CompressionAlgorithm
     int uncompress(uint8_t * dest, uint8_t *src, int size)
     {
         fatal("Can't uncompress data");
+        M5_DUMMY_RETURN
     }
 
     int compress(uint8_t *dest, uint8_t *src, int size)
     {
         fatal("Can't compress data");
+        M5_DUMMY_RETURN
     }
 };
 
diff --git a/src/base/cprintf.hh b/src/base/cprintf.hh
index 9967b0578..dd2256e69 100644
--- a/src/base/cprintf.hh
+++ b/src/base/cprintf.hh
@@ -136,10 +136,10 @@ operator,(ArgList &alist, ArgListNull)
 inline void
 __cprintf(const std::string &format, ArgList &args)
 { args.dump(format); delete &args; }
-#define __cprintf__(format, args...) \
-    cp::__cprintf(format, (*(new cp::ArgList), args))
-#define cprintf(args...) \
-    __cprintf__(args, cp::ArgListNull())
+#define __cprintf__(format, ...) \
+    cp::__cprintf(format, (*(new cp::ArgList), __VA_ARGS__))
+#define cprintf(...) \
+    __cprintf__(__VA_ARGS__, cp::ArgListNull())
 
 //
 // ccprintf(stream, format, args, ...) prints to the specified stream
@@ -148,10 +148,10 @@ __cprintf(const std::string &format, ArgList &args)
 inline void
 __ccprintf(std::ostream &stream, const std::string &format, ArgList &args)
 { args.dump(stream, format); delete &args; }
-#define __ccprintf__(stream, format, args...) \
-    cp::__ccprintf(stream, format, (*(new cp::ArgList), args))
-#define ccprintf(stream, args...) \
-    __ccprintf__(stream, args, cp::ArgListNull())
+#define __ccprintf__(stream, format, ...) \
+    cp::__ccprintf(stream, format, (*(new cp::ArgList), __VA_ARGS__))
+#define ccprintf(stream, ...) \
+    __ccprintf__(stream, __VA_ARGS__, cp::ArgListNull())
 
 //
 // csprintf(format, args, ...) returns a string
@@ -160,10 +160,10 @@ __ccprintf(std::ostream &stream, const std::string &format, ArgList &args)
 inline std::string
 __csprintf(const std::string &format, ArgList &args)
 { std::string s = args.dumpToString(format); delete &args; return s; }
-#define __csprintf__(format, args...) \
-    cp::__csprintf(format, (*(new cp::ArgList), args))
-#define csprintf(args...) \
-    __csprintf__(args, cp::ArgListNull())
+#define __csprintf__(format, ...) \
+    cp::__csprintf(format, (*(new cp::ArgList), __VA_ARGS__))
+#define csprintf(...) \
+    __csprintf__(__VA_ARGS__, cp::ArgListNull())
 
 }
 
diff --git a/src/base/hashmap.hh b/src/base/hashmap.hh
index 570cbc152..b78cc02e8 100644
--- a/src/base/hashmap.hh
+++ b/src/base/hashmap.hh
@@ -59,7 +59,7 @@ namespace m5 {
 //
 
 namespace __hash_namespace {
-#if !defined(__LP64__) && !defined(__alpha__)
+#if !defined(__LP64__) && !defined(__alpha__) && !defined(__SUNPRO_CC)
     template<>
     struct hash<uint64_t> {
         size_t operator()(uint64_t r) const {
diff --git a/src/base/hostinfo.cc b/src/base/hostinfo.cc
index a7c93e712..7cc07c11e 100644
--- a/src/base/hostinfo.cc
+++ b/src/base/hostinfo.cc
@@ -33,6 +33,7 @@
 #include <math.h>
 #include <unistd.h>
 
+#include <stdio.h>
 #include <cstdlib>
 #include <cstring>
 #include <string>
diff --git a/src/base/loader/object_file.cc b/src/base/loader/object_file.cc
index ad2cd34ba..2273b6c4e 100644
--- a/src/base/loader/object_file.cc
+++ b/src/base/loader/object_file.cc
@@ -101,7 +101,7 @@ ObjectFile::close()
     }
 
     if (fileData) {
-        ::munmap(fileData, len);
+        ::munmap((char*)fileData, len);
         fileData = NULL;
     }
 }
@@ -147,6 +147,6 @@ createObjectFile(const string &fname, bool raw)
 
     // don't know what it is
     close(fd);
-    munmap(fileData, len);
+    munmap((char*)fileData, len);
     return NULL;
 }
diff --git a/src/base/misc.hh b/src/base/misc.hh
index 1c5720ce1..c12c2fe20 100644
--- a/src/base/misc.hh
+++ b/src/base/misc.hh
@@ -33,8 +33,13 @@
 #define __MISC_HH__
 
 #include <assert.h>
+#include "base/compiler.hh"
 #include "base/cprintf.hh"
 
+#if defined(__SUNPRO_CC)
+#define __FUNCTION__ "how to fix me?"
+#endif
+
 //
 // This implements a cprintf based panic() function.  panic() should
 // be called when something happens that should never ever happen
@@ -43,12 +48,13 @@
 //
 //
 void __panic(const std::string&, cp::ArgList &, const char*, const char*, int)
-    __attribute__((noreturn));
-#define __panic__(format, args...) \
-    __panic(format, (*(new cp::ArgList), args), \
-        __FUNCTION__, __FILE__, __LINE__)
-#define panic(args...) \
-    __panic__(args, cp::ArgListNull())
+    M5_ATTR_NORETURN;
+#define __panic__(format, ...) \
+    __panic(format, (*(new cp::ArgList), __VA_ARGS__), \
+        __FUNCTION__ , __FILE__, __LINE__)
+#define panic(...) \
+    __panic__(__VA_ARGS__, cp::ArgListNull())
+M5_PRAGMA_NORETURN(__panic)
 
 //
 // This implements a cprintf based fatal() function.  fatal() should
@@ -59,32 +65,33 @@ void __panic(const std::string&, cp::ArgList &, const char*, const char*, int)
 // panic() does.
 //
 void __fatal(const std::string&, cp::ArgList &, const char*, const char*, int)
-    __attribute__((noreturn));
-#define __fatal__(format, args...) \
-    __fatal(format, (*(new cp::ArgList), args), \
-        __FUNCTION__, __FILE__, __LINE__)
-#define fatal(args...) \
-    __fatal__(args, cp::ArgListNull())
+    M5_ATTR_NORETURN;
+#define __fatal__(format, ...) \
+    __fatal(format, (*(new cp::ArgList), __VA_ARGS__), \
+        __FUNCTION__ , __FILE__, __LINE__)
+#define fatal(...) \
+    __fatal__(__VA_ARGS__, cp::ArgListNull())
+M5_PRAGMA_NORETURN(__fatal)
 
 //
 // This implements a cprintf based warn
 //
 void __warn(const std::string&, cp::ArgList &, const char*, const char*, int);
-#define __warn__(format, args...) \
-    __warn(format, (*(new cp::ArgList), args), \
-           __FUNCTION__, __FILE__, __LINE__)
-#define warn(args...) \
-    __warn__(args, cp::ArgListNull())
+#define __warn__(format, ...) \
+    __warn(format, (*(new cp::ArgList), __VA_ARGS__), \
+           __FUNCTION__ , __FILE__, __LINE__)
+#define warn(...) \
+    __warn__(__VA_ARGS__, cp::ArgListNull())
 
 // Only print the warning message the first time it is seen.  This
 // doesn't check the warning string itself, it just only lets one
 // warning come from the statement. So, even if the arguments change
 // and that would have resulted in a different warning message,
 // subsequent messages would still be supressed.
-#define warn_once(args...) do {                     \
+#define warn_once(...) do {                     \
         static bool once = false;                   \
         if (!once) {                                \
-            __warn__(args, cp::ArgListNull());      \
+            __warn__(__VA_ARGS__, cp::ArgListNull());      \
             once = true;                            \
         }                                           \
     } while (0)
diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc
index fd5b09d28..32724b74d 100644
--- a/src/base/pollevent.cc
+++ b/src/base/pollevent.cc
@@ -30,7 +30,7 @@
 
 #include <sys/ioctl.h>
 #include <sys/types.h>
-#if defined(__sun__)
+#if defined(__sun__) || defined(__SUNPRO_CC)
 #include <sys/file.h>
 #endif
 
diff --git a/src/base/random.cc b/src/base/random.cc
index 82c9e3566..0ccedcb00 100644
--- a/src/base/random.cc
+++ b/src/base/random.cc
@@ -29,12 +29,17 @@
  *          Ali Saidi
  */
 
+#if defined(__sun)
+#include <ieeefp.h>
+#endif
+#ifdef __SUNPRO_CC
+#include <stdlib.h>
+#include <math.h>
+#endif
+
 #include <cstdlib>
 #include <cmath>
 
-#if defined(__sun__)
-#include <ieeefp.h>
-#endif
 
 #include "sim/param.hh"
 #include "base/random.hh"
@@ -72,7 +77,7 @@ getLong()
 double
 m5round(double r)
 {
-#if defined(__sun__)
+#if defined(__sun)
     double val;
     fp_rnd oldrnd = fpsetround(FP_RN);
     val = rint(r);
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index 59a9b87d5..2c0da48f0 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -610,7 +610,7 @@ BaseRemoteGDB::trap(int type)
     uint64_t val;
     size_t datalen, len;
     char data[GDBPacketBufLen + 1];
-    char buffer[gdbregs.bytes() * 2 + 256];
+    char *buffer;
     const char *p;
     char command, subcmd;
     string var;
@@ -619,6 +619,8 @@ BaseRemoteGDB::trap(int type)
     if (!attached)
         return false;
 
+    buffer = (char*)malloc(gdbregs.bytes() * 2 + 256);
+
     DPRINTF(GDBMisc, "trap: PC=%#x NPC=%#x\n",
             context->readPC(), context->readNextPC());
 
@@ -916,6 +918,7 @@ BaseRemoteGDB::trap(int type)
     }
 
   out:
+    free(buffer);
     return true;
 }
 
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index 577ea5eab..d8e8b4c15 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -50,6 +50,9 @@
 
 #include <algorithm>
 #include <cassert>
+#ifdef __SUNPRO_CC
+#include <math.h>
+#endif
 #include <cmath>
 #include <functional>
 #include <iosfwd>
@@ -1410,7 +1413,7 @@ struct DistStor
         else if (val > params.max)
             overflow += number;
         else {
-            int index = (int)floor((val - params.min) / params.bucket_size);
+            int index = (int)std::floor((val - params.min) / params.bucket_size);
             assert(index < size(params));
             cvec[index] += number;
         }
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index c4448efc9..ae0d65537 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -32,6 +32,10 @@
 #define _GLIBCPP_USE_C99 1
 #endif
 
+#if defined(__sun)
+#include <math.h>
+#endif
+
 #include <iostream>
 #include <sstream>
 #include <fstream>
diff --git a/src/base/time.cc b/src/base/time.cc
index cbc7256ee..76ba355b7 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -105,7 +105,11 @@ Time::date(string format) const
     char buf[256];
 
     if (format.empty()) {
+#ifdef __SUNPRO_CC
+        ctime_r(&sec, buf, 256);
+#else
         ctime_r(&sec, buf);
+#endif
         buf[24] = '\0';
         return buf;
     }
diff --git a/src/base/time.hh b/src/base/time.hh
index 7aa4c50db..f10cc5d6c 100644
--- a/src/base/time.hh
+++ b/src/base/time.hh
@@ -97,7 +97,7 @@ std::ostream &operator<<(std::ostream &out, const Time &time);
  *	@(#)time.h	8.2 (Berkeley) 7/10/94
  */
 
-#if defined(__sun__)
+#if defined(__sun)
 #define timersub(tvp, uvp, vvp)                                         \
     do {                                                            \
             (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
diff --git a/src/base/timebuf.hh b/src/base/timebuf.hh
index 1d0de8278..348f7a673 100644
--- a/src/base/timebuf.hh
+++ b/src/base/timebuf.hh
@@ -33,6 +33,7 @@
 #define __BASE_TIMEBUF_HH__
 
 #include <cassert>
+#include <cstring>
 #include <vector>
 
 template <class T>
@@ -143,7 +144,7 @@ class TimeBuffer
         char *ptr = data;
         for (int i = 0; i < size; i++) {
             index[i] = ptr;
-            memset(ptr, 0, sizeof(T));
+            std::memset(ptr, 0, sizeof(T));
             new (ptr) T;
             ptr += sizeof(T);
         }
@@ -171,7 +172,7 @@ class TimeBuffer
         if (ptr >= size)
             ptr -= size;
         (reinterpret_cast<T *>(index[ptr]))->~T();
-        memset(index[ptr], 0, sizeof(T));
+        std::memset(index[ptr], 0, sizeof(T));
         new (index[ptr]) T;
     }
 
diff --git a/src/base/trace.hh b/src/base/trace.hh
index 9b053990c..a46643159 100644
--- a/src/base/trace.hh
+++ b/src/base/trace.hh
@@ -186,39 +186,39 @@ do { \
         Trace::dataDump(curTick, name(), data, count);	\
 } while (0)
 
-#define __dprintf(cycle, name, format, args...) \
-    Trace::dprintf(format, (*(new cp::ArgList), args), cycle, name)
+#define __dprintf(cycle, name, format, ...) \
+    Trace::dprintf(format, (*(new cp::ArgList), __VA_ARGS__), cycle, name)
 
-#define DPRINTF(x, args...) \
+#define DPRINTF(x, ...) \
 do { \
     if (Trace::IsOn(Trace::x)) \
-        __dprintf(curTick, name(), args, cp::ArgListNull()); \
+        __dprintf(curTick, name(), __VA_ARGS__, cp::ArgListNull()); \
 } while (0)
 
-#define DPRINTFR(x, args...) \
+#define DPRINTFR(x, ...) \
 do { \
     if (Trace::IsOn(Trace::x)) \
-        __dprintf((Tick)-1, std::string(), args, cp::ArgListNull());	\
+        __dprintf((Tick)-1, std::string(), __VA_ARGS__, cp::ArgListNull());	\
 } while (0)
 
-#define DPRINTFN(args...) \
+#define DPRINTFN(...) \
 do { \
-    __dprintf(curTick, name(), args, cp::ArgListNull()); \
+    __dprintf(curTick, name(), __VA_ARGS__, cp::ArgListNull()); \
 } while (0)
 
-#define DPRINTFNR(args...) \
+#define DPRINTFNR(...) \
 do { \
-    __dprintf((Tick)-1, string(), args, cp::ArgListNull()); \
+    __dprintf((Tick)-1, string(), __VA_ARGS__, cp::ArgListNull()); \
 } while (0)
 
 #else // !TRACING_ON
 
 #define DTRACE(x) (false)
 #define DCOUT(x) if (0) DebugOut()
-#define DPRINTF(x, args...) do {} while (0)
-#define DPRINTFR(args...) do {} while (0)
-#define DPRINTFN(args...) do {} while (0)
-#define DPRINTFNR(args...) do {} while (0)
+#define DPRINTF(x, ...) do {} while (0)
+#define DPRINTFR(...) do {} while (0)
+#define DPRINTFN(...) do {} while (0)
+#define DPRINTFNR(...) do {} while (0)
 #define DDUMP(x, data, count) do {} while (0)
 
 #endif	// TRACING_ON
-- 
cgit v1.2.3