util: Add stub unit tests for the call types in the m5 utility.
[gem5.git] / util / m5 / src / args.cc
index 96689b8023f93a16c6a5da6d9ca56b513b0a7624..1caad43941723bba47220cb4921bb4aaff659b6e 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <cinttypes>
-#include <cstdlib>
 #include <cstring>
 
 #include "args.hh"
 
-int
-parse_int_args(Args *args, uint64_t ints[], int len)
-{
-    if (args->argc > len)
-        return 0;
-
-// On 32 bit platforms we need to use strtoull to do the conversion
-#ifdef __LP64__
-#define strto64 strtoul
-#else
-#define strto64 strtoull
-#endif
-    for (int i = 0; i < len; ++i) {
-        const char *arg = pop_arg(args);
-        ints[i] = arg ? strto64(arg, NULL, 0) : 0;
-    }
-
-#undef strto64
-    return 1;
-}
-
-int
-pack_arg_into_regs(Args *args, uint64_t regs[], int num_regs)
+bool
+Args::pack(const std::string &str, uint64_t regs[], int num_regs)
 {
     const size_t RegSize = sizeof(regs[0]);
     const size_t MaxLen = num_regs * RegSize;
-    const char *arg = pop_arg(args);
+    const char *arg = str.c_str();
 
     memset(regs, 0, MaxLen);
 
-    size_t len = arg ? strlen(arg) : 0;
+    size_t len = str.size();
 
     if (len > MaxLen)
-        return 0;
+        return false;
 
     while (len) {
         for (int offset = 0; offset < RegSize && len; offset++, len--) {
@@ -86,5 +63,5 @@ pack_arg_into_regs(Args *args, uint64_t regs[], int num_regs)
         }
         regs++;
     }
-    return 1;
+    return true;
 }