strnumtest.cc revision 1762
14202Sbinkertn@umich.edu/* 212966SMatteo.Andreozzi@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312966SMatteo.Andreozzi@arm.com * All rights reserved. 412966SMatteo.Andreozzi@arm.com * 512966SMatteo.Andreozzi@arm.com * Redistribution and use in source and binary forms, with or without 612966SMatteo.Andreozzi@arm.com * modification, are permitted provided that the following conditions are 712966SMatteo.Andreozzi@arm.com * met: redistributions of source code must retain the above copyright 812966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer; 912966SMatteo.Andreozzi@arm.com * redistributions in binary form must reproduce the above copyright 1012966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer in the 1112966SMatteo.Andreozzi@arm.com * documentation and/or other materials provided with the distribution; 1212966SMatteo.Andreozzi@arm.com * neither the name of the copyright holders nor the names of its 1312966SMatteo.Andreozzi@arm.com * contributors may be used to endorse or promote products derived from 1412966SMatteo.Andreozzi@arm.com * this software without specific prior written permission. 154202Sbinkertn@umich.edu * 164202Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174202Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184202Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194202Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214202Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264202Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274202Sbinkertn@umich.edu */ 284202Sbinkertn@umich.edu 294202Sbinkertn@umich.edu#include <iostream.h> 304202Sbinkertn@umich.edu 314202Sbinkertn@umich.edu#include <string> 324202Sbinkertn@umich.edu#include <vector> 334202Sbinkertn@umich.edu 344202Sbinkertn@umich.edu#include "base/str.hh" 354202Sbinkertn@umich.edu 364202Sbinkertn@umich.eduusing namespace std; 374202Sbinkertn@umich.edu 384202Sbinkertn@umich.eduint 394202Sbinkertn@umich.edumain(int argc, char *argv[]) 404202Sbinkertn@umich.edu{ 414202Sbinkertn@umich.edu if (argc != 2) { 424202Sbinkertn@umich.edu cout << "Usage: " << argv[0] << " <number>\n"; 434202Sbinkertn@umich.edu exit(1); 444202Sbinkertn@umich.edu } 4510996Sandreas.sandberg@arm.com 4610996Sandreas.sandberg@arm.com string s = argv[1]; 479398Sandreas.hansson@arm.com 489850Sandreas.hansson@arm.com#define OUTVAL(valtype, type) do { \ 499259SAli.Saidi@ARM.com valtype value; \ 504486Sbinkertn@umich.edu cout << "TYPE = " #valtype "\n"; \ 5110146Sandreas.hansson@arm.com if (to_number(s, value)) { \ 5210478SAndrew.Bardsley@arm.com cout << "Number(" << s << ") = " << dec \ 5310478SAndrew.Bardsley@arm.com << (unsigned long long)(unsigned type)value << "\n" \ 546165Ssanchezd@stanford.edu << "Number(" << s << ") = " << dec \ 559850Sandreas.hansson@arm.com << (signed long long)(signed type)value << "\n" \ 5610405Sandreas.hansson@arm.com << "Number(" << s << ") = 0x" << hex \ 5711184Serfan.azarkhish@unibo.it << (unsigned long long)(unsigned type)value << "\n" \ 5811185Serfan.azarkhish@unibo.it << "Number(" << s << ") = 0" << oct \ 5912802Sandreas.sandberg@arm.com << (unsigned long long)(unsigned type)value << "\n\n"; \ 606168Snate@binkert.org } else \ 619850Sandreas.hansson@arm.com cout << "Number(" << s << ") is invalid\n\n"; \ 629259SAli.Saidi@ARM.com } while (0) 634202Sbinkertn@umich.edu 6410405Sandreas.hansson@arm.com OUTVAL(signed long long, long long); 6510431SOmar.Naji@arm.com OUTVAL(unsigned long long, long long); 6610146Sandreas.hansson@arm.com OUTVAL(signed long, long); 6710478SAndrew.Bardsley@arm.com OUTVAL(unsigned long, long); 6810478SAndrew.Bardsley@arm.com OUTVAL(signed int, int); 694202Sbinkertn@umich.edu OUTVAL(unsigned int, int); 708761Sgblack@eecs.umich.edu OUTVAL(signed short, short); 7110405Sandreas.hansson@arm.com OUTVAL(unsigned short, short); 724202Sbinkertn@umich.edu OUTVAL(signed char, char); 734202Sbinkertn@umich.edu OUTVAL(unsigned char, char); 748914Sandreas.hansson@arm.com 7510405Sandreas.hansson@arm.com return 0; 7610405Sandreas.hansson@arm.com} 7714007Sgabeblack@google.com