Support negative bit indexes.

Allow arbitrary characters in symbols (to make '-' work.)
Final merge from negative_lsb branch.
This commit is contained in:
Wilson Snyder
2008-10-06 09:59:22 -04:00
parent cdd6ea8e60
commit 3b1929259a
18 changed files with 230 additions and 114 deletions
+10 -4
View File
@@ -470,10 +470,16 @@ uint32_t V3Number::toUInt() const {
}
vlsint32_t V3Number::toSInt() const {
uint32_t v = toUInt();
uint32_t signExtend = (-(v & (1UL<<(width()-1))));
uint32_t extended = v | signExtend;
return (vlsint32_t)(extended);
if (isSigned()) {
uint32_t v = toUInt();
uint32_t signExtend = (-(v & (1UL<<(width()-1))));
uint32_t extended = v | signExtend;
return (vlsint32_t)(extended);
} else {
// Where we use this (widths, etc) and care about signedness,
// we can reasonably assume the MSB isn't set on unsigned numbers.
return (vlsint32_t)toUInt();
}
}
vluint64_t V3Number::toUQuad() const {