Skip to content

Commit fc39b94

Browse files
committed
[lldb][NFC] Move [SU]Int64ValueIsValidForByteSize to RegisterValue
These functions are an implementation detail of RegisterValue, so it doesn't make a lot of sense to implement them in a totally unrelated class.
1 parent daee549 commit fc39b94

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

lldb/include/lldb/Utility/Args.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,6 @@ class Args {
252252
// For re-setting or blanking out the list of arguments.
253253
void Clear();
254254

255-
static bool UInt64ValueIsValidForByteSize(uint64_t uval64,
256-
size_t total_byte_size) {
257-
if (total_byte_size > 8)
258-
return false;
259-
260-
if (total_byte_size == 8)
261-
return true;
262-
263-
const uint64_t max = (static_cast<uint64_t>(1)
264-
<< static_cast<uint64_t>(total_byte_size * 8)) -
265-
1;
266-
return uval64 <= max;
267-
}
268-
269-
static bool SInt64ValueIsValidForByteSize(int64_t sval64,
270-
size_t total_byte_size) {
271-
if (total_byte_size > 8)
272-
return false;
273-
274-
if (total_byte_size == 8)
275-
return true;
276-
277-
const int64_t max = (static_cast<int64_t>(1)
278-
<< static_cast<uint64_t>(total_byte_size * 8 - 1)) -
279-
1;
280-
const int64_t min = ~(max);
281-
return min <= sval64 && sval64 <= max;
282-
}
283-
284255
static lldb::Encoding
285256
StringToEncoding(llvm::StringRef s,
286257
lldb::Encoding fail_value = lldb::eEncodingInvalid);

lldb/source/Utility/RegisterValue.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "lldb/Utility/RegisterValue.h"
1010

11-
#include "lldb/Utility/Args.h"
1211
#include "lldb/Utility/DataExtractor.h"
1312
#include "lldb/Utility/Scalar.h"
1413
#include "lldb/Utility/Status.h"
@@ -330,6 +329,35 @@ static bool ParseVectorEncoding(const RegisterInfo *reg_info,
330329
return true;
331330
}
332331

332+
static bool UInt64ValueIsValidForByteSize(uint64_t uval64,
333+
size_t total_byte_size) {
334+
if (total_byte_size > 8)
335+
return false;
336+
337+
if (total_byte_size == 8)
338+
return true;
339+
340+
const uint64_t max =
341+
(static_cast<uint64_t>(1) << static_cast<uint64_t>(total_byte_size * 8)) -
342+
1;
343+
return uval64 <= max;
344+
}
345+
346+
static bool SInt64ValueIsValidForByteSize(int64_t sval64,
347+
size_t total_byte_size) {
348+
if (total_byte_size > 8)
349+
return false;
350+
351+
if (total_byte_size == 8)
352+
return true;
353+
354+
const int64_t max = (static_cast<int64_t>(1)
355+
<< static_cast<uint64_t>(total_byte_size * 8 - 1)) -
356+
1;
357+
const int64_t min = ~(max);
358+
return min <= sval64 && sval64 <= max;
359+
}
360+
333361
Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info,
334362
llvm::StringRef value_str) {
335363
Status error;
@@ -368,7 +396,7 @@ Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info,
368396
break;
369397
}
370398

371-
if (!Args::UInt64ValueIsValidForByteSize(uval64, byte_size)) {
399+
if (!UInt64ValueIsValidForByteSize(uval64, byte_size)) {
372400
error.SetErrorStringWithFormat(
373401
"value 0x%" PRIx64
374402
" is too large to fit in a %u byte unsigned integer value",
@@ -397,7 +425,7 @@ Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info,
397425
break;
398426
}
399427

400-
if (!Args::SInt64ValueIsValidForByteSize(ival64, byte_size)) {
428+
if (!SInt64ValueIsValidForByteSize(ival64, byte_size)) {
401429
error.SetErrorStringWithFormat(
402430
"value 0x%" PRIx64
403431
" is too large to fit in a %u byte signed integer value",

0 commit comments

Comments
 (0)