summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-09-30 22:18:54 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-09-30 22:18:54 +0000
commitb7359e384f7d15d3e24b3763ed66546e497fe213 (patch)
treec56aa85556890cbbed6a63797624364650a36176 /utils
parente27e1ca3c90b69e78242c98a669337f84ccded7f (diff)
downloadllvm-b7359e384f7d15d3e24b3763ed66546e497fe213.tar.gz
llvm-b7359e384f7d15d3e24b3763ed66546e497fe213.tar.bz2
llvm-b7359e384f7d15d3e24b3763ed66546e497fe213.tar.xz
Extract a slightly more general BitVector printer.
This one can also print 32-bit groups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140897 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/RegisterInfoEmitter.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp
index b784e738e0..c00c7aa62d 100644
--- a/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/utils/TableGen/RegisterInfoEmitter.cpp
@@ -205,6 +205,21 @@ RegisterInfoEmitter::EmitRegMapping(raw_ostream &OS,
}
}
+// Print a BitVector as a sequence of hex numbers using a little-endian mapping.
+// Width is the number of bits per hex number.
+static void printBitVectorAsHex(raw_ostream &OS,
+ const BitVector &Bits,
+ unsigned Width) {
+ assert(Width <= 32 && "Width too large");
+ unsigned Digits = (Width + 3) / 4;
+ for (unsigned i = 0, e = Bits.size(); i < e; i += Width) {
+ unsigned Value = 0;
+ for (unsigned j = 0; j != Width && i + j != e; ++j)
+ Value |= Bits.test(i + j) << j;
+ OS << format("0x%0*x, ", Digits, Value);
+ }
+}
+
// Helper to emit a set of bits into a constant byte array.
class BitVectorEmitter {
BitVector Values;
@@ -216,13 +231,7 @@ public:
}
void print(raw_ostream &OS) {
- for (unsigned i = 0, e = Values.size() / 8; i != e; ++i) {
- unsigned char out = 0;
- for (unsigned j = 0; j != 8; ++j)
- if (Values[i * 8 + j])
- out |= 1 << j;
- OS << format("0x%02x, ", out);
- }
+ printBitVectorAsHex(OS, Values, 8);
}
};