strnumtest.cc revision 56
111988Sandreas.sandberg@arm.com/* 28839Sandreas.hansson@arm.com * Copyright (c) 2003 The Regents of The University of Michigan 38839Sandreas.hansson@arm.com * All rights reserved. 48839Sandreas.hansson@arm.com * 58839Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68839Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78839Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88839Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98839Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108839Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118839Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128839Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 133101Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from 148579Ssteve.reinhardt@amd.com * this software without specific prior written permission. 153101Sstever@eecs.umich.edu * 163101Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173101Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183101Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193101Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203101Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213101Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223101Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233101Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243101Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253101Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263101Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273101Sstever@eecs.umich.edu */ 283101Sstever@eecs.umich.edu 293101Sstever@eecs.umich.edu#include <iostream.h> 303101Sstever@eecs.umich.edu 313101Sstever@eecs.umich.edu#include <string> 323101Sstever@eecs.umich.edu#include <vector> 333101Sstever@eecs.umich.edu 343101Sstever@eecs.umich.edu#include "base/str.hh" 353101Sstever@eecs.umich.edu 363101Sstever@eecs.umich.eduint 373101Sstever@eecs.umich.edumain(int argc, char *argv[]) 383101Sstever@eecs.umich.edu{ 393101Sstever@eecs.umich.edu if (argc != 2) { 403101Sstever@eecs.umich.edu cout << "Usage: " << argv[0] << " <number>\n"; 413101Sstever@eecs.umich.edu exit(1); 427778Sgblack@eecs.umich.edu } 438839Sandreas.hansson@arm.com 443101Sstever@eecs.umich.edu string s = argv[1]; 453101Sstever@eecs.umich.edu 463101Sstever@eecs.umich.edu#define OUTVAL(valtype, type) do { \ 473101Sstever@eecs.umich.edu valtype value; \ 483101Sstever@eecs.umich.edu cout << "TYPE = " #valtype "\n"; \ 493101Sstever@eecs.umich.edu if (to_number(s, value)) { \ 503101Sstever@eecs.umich.edu cout << "Number(" << s << ") = " << dec \ 513101Sstever@eecs.umich.edu << (unsigned long long)(unsigned type)value << "\n" \ 523101Sstever@eecs.umich.edu << "Number(" << s << ") = " << dec \ 533101Sstever@eecs.umich.edu << (signed long long)(signed type)value << "\n" \ 543101Sstever@eecs.umich.edu << "Number(" << s << ") = 0x" << hex \ 553101Sstever@eecs.umich.edu << (unsigned long long)(unsigned type)value << "\n" \ 563101Sstever@eecs.umich.edu << "Number(" << s << ") = 0" << oct \ 573101Sstever@eecs.umich.edu << (unsigned long long)(unsigned type)value << "\n\n"; \ 583101Sstever@eecs.umich.edu } else \ 593101Sstever@eecs.umich.edu cout << "Number(" << s << ") is invalid\n\n"; \ 603101Sstever@eecs.umich.edu } while (0) 613101Sstever@eecs.umich.edu 6212563Sgabeblack@google.com OUTVAL(signed long long, long long); 6312563Sgabeblack@google.com OUTVAL(unsigned long long, long long); 643885Sbinkertn@umich.edu OUTVAL(signed long, long); 653885Sbinkertn@umich.edu OUTVAL(unsigned long, long); 664762Snate@binkert.org OUTVAL(signed int, int); 673885Sbinkertn@umich.edu OUTVAL(unsigned int, int); 683885Sbinkertn@umich.edu OUTVAL(signed short, short); 697528Ssteve.reinhardt@amd.com OUTVAL(unsigned short, short); 703885Sbinkertn@umich.edu OUTVAL(signed char, char); 714380Sbinkertn@umich.edu OUTVAL(unsigned char, char); 724167Sbinkertn@umich.edu 733102Sstever@eecs.umich.edu return 0; 743101Sstever@eecs.umich.edu} 754762Snate@binkert.org