strnumtest.cc revision 2665
112109SRekai.GonzalezAlberquilla@arm.com/* 212109SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312109SRekai.GonzalezAlberquilla@arm.com * All rights reserved. 412109SRekai.GonzalezAlberquilla@arm.com * 512109SRekai.GonzalezAlberquilla@arm.com * Redistribution and use in source and binary forms, with or without 612109SRekai.GonzalezAlberquilla@arm.com * modification, are permitted provided that the following conditions are 712109SRekai.GonzalezAlberquilla@arm.com * met: redistributions of source code must retain the above copyright 812109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer; 912109SRekai.GonzalezAlberquilla@arm.com * redistributions in binary form must reproduce the above copyright 1012109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer in the 1112109SRekai.GonzalezAlberquilla@arm.com * documentation and/or other materials provided with the distribution; 1212109SRekai.GonzalezAlberquilla@arm.com * neither the name of the copyright holders nor the names of its 134486Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 144486Sbinkertn@umich.edu * this software without specific prior written permission. 154486Sbinkertn@umich.edu * 164486Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174486Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184486Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194486Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204486Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214486Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224486Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234486Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244486Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254486Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264486Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274486Sbinkertn@umich.edu * 284486Sbinkertn@umich.edu * Authors: Nathan Binkert 294486Sbinkertn@umich.edu */ 304486Sbinkertn@umich.edu 314486Sbinkertn@umich.edu#include <iostream.h> 324486Sbinkertn@umich.edu 334486Sbinkertn@umich.edu#include <string> 344486Sbinkertn@umich.edu#include <vector> 354486Sbinkertn@umich.edu 364486Sbinkertn@umich.edu#include "base/str.hh" 374486Sbinkertn@umich.edu 384486Sbinkertn@umich.eduusing namespace std; 394486Sbinkertn@umich.edu 404486Sbinkertn@umich.eduint 416654Snate@binkert.orgmain(int argc, char *argv[]) 423102SN/A{ 433102SN/A if (argc != 2) { 441681SN/A cout << "Usage: " << argv[0] << " <number>\n"; 453223SN/A exit(1); 468887Sgeoffrey.blake@arm.com } 4710785Sgope@wisc.edu 484486Sbinkertn@umich.edu string s = argv[1]; 492817SN/A 502817SN/A#define OUTVAL(valtype, type) do { \ 519341SAndreas.Sandberg@arm.com valtype value; \ 529341SAndreas.Sandberg@arm.com cout << "TYPE = " #valtype "\n"; \ 539518SAndreas.Sandberg@ARM.com if (to_number(s, value)) { \ 549518SAndreas.Sandberg@ARM.com cout << "Number(" << s << ") = " << dec \ 559518SAndreas.Sandberg@ARM.com << (unsigned long long)(unsigned type)value << "\n" \ 569518SAndreas.Sandberg@ARM.com << "Number(" << s << ") = " << dec \ 579518SAndreas.Sandberg@ARM.com << (signed long long)(signed type)value << "\n" \ 589518SAndreas.Sandberg@ARM.com << "Number(" << s << ") = 0x" << hex \ 599518SAndreas.Sandberg@ARM.com << (unsigned long long)(unsigned type)value << "\n" \ 609518SAndreas.Sandberg@ARM.com << "Number(" << s << ") = 0" << oct \ 619518SAndreas.Sandberg@ARM.com << (unsigned long long)(unsigned type)value << "\n\n"; \ 629518SAndreas.Sandberg@ARM.com } else \ 639518SAndreas.Sandberg@ARM.com cout << "Number(" << s << ") is invalid\n\n"; \ 649518SAndreas.Sandberg@ARM.com } while (0) 652932SN/A 661681SN/A OUTVAL(signed long long, long long); 6711780Sarthur.perais@inria.fr OUTVAL(unsigned long long, long long); 6811780Sarthur.perais@inria.fr OUTVAL(signed long, long); 691681SN/A OUTVAL(unsigned long, long); 709184Sandreas.hansson@arm.com OUTVAL(signed int, int); 719184Sandreas.hansson@arm.com OUTVAL(unsigned int, int); 729184Sandreas.hansson@arm.com OUTVAL(signed short, short); 739184Sandreas.hansson@arm.com OUTVAL(unsigned short, short); 749184Sandreas.hansson@arm.com OUTVAL(signed char, char); 752932SN/A OUTVAL(unsigned char, char); 769982Satgutier@umich.edu 7710331Smitch.hayenga@arm.com return 0; 7810331Smitch.hayenga@arm.com} 792932SN/A