From 08b2b92fd2e90c59a5c0a8112f824c5d361d7c22 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 25 Jul 2019 11:44:25 -0700 Subject: 5474 --- subx/011run.cc | 31 ------------------------------- subx/030---operands.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'subx') diff --git a/subx/011run.cc b/subx/011run.cc index d9877c4d..b8ca52db 100644 --- a/subx/011run.cc +++ b/subx/011run.cc @@ -444,34 +444,3 @@ string to_string(const word& w) { out << " /" << w.metadata.at(i); return out.str(); } - -int32_t parse_int(const string& s) { - if (s.empty()) return 0; - istringstream in(s); - in >> std::hex; - if (s.at(0) == '-') { - int32_t result = 0; - in >> result; - if (!in || !in.eof()) { - raise << "not a number: " << s << '\n' << end(); - return 0; - } - return result; - } - uint32_t uresult = 0; - in >> uresult; - if (!in || !in.eof()) { - raise << "not a number: " << s << '\n' << end(); - return 0; - } - return static_cast(uresult); -} -:(before "End Unit Tests") -void test_parse_int() { - CHECK_EQ(0, parse_int("0")); - CHECK_EQ(0, parse_int("0x0")); - CHECK_EQ(0, parse_int("0x0")); - CHECK_EQ(16, parse_int("10")); // hex always - CHECK_EQ(-1, parse_int("-1")); - CHECK_EQ(-1, parse_int("0xffffffff")); -} diff --git a/subx/030---operands.cc b/subx/030---operands.cc index 5e6d6432..ec621017 100644 --- a/subx/030---operands.cc +++ b/subx/030---operands.cc @@ -489,3 +489,34 @@ string to_string(const line& inst) { } return out.str(); } + +int32_t parse_int(const string& s) { + if (s.empty()) return 0; + istringstream in(s); + in >> std::hex; + if (s.at(0) == '-') { + int32_t result = 0; + in >> result; + if (!in || !in.eof()) { + raise << "not a number: " << s << '\n' << end(); + return 0; + } + return result; + } + uint32_t uresult = 0; + in >> uresult; + if (!in || !in.eof()) { + raise << "not a number: " << s << '\n' << end(); + return 0; + } + return static_cast(uresult); +} +:(before "End Unit Tests") +void test_parse_int() { + CHECK_EQ(0, parse_int("0")); + CHECK_EQ(0, parse_int("0x0")); + CHECK_EQ(0, parse_int("0x0")); + CHECK_EQ(16, parse_int("10")); // hex always + CHECK_EQ(-1, parse_int("-1")); + CHECK_EQ(-1, parse_int("0xffffffff")); +} -- cgit 1.4.1-2-gfad0