diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2018-05-18 19:46:24 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2018-05-18 19:46:24 +0000 |
| commit | e3f652973e6e4fb7074b0bdc2291493e6cb8fae5 (patch) | |
| tree | 4fba9f86235380483550bf1268b185f9aa2865f5 /llvm/lib/Target/BPF | |
| parent | 1fa76cc3ea1f3361dd4e6091ac6a5c0e833de6a4 (diff) | |
| download | bcm5719-llvm-e3f652973e6e4fb7074b0bdc2291493e6cb8fae5.tar.gz bcm5719-llvm-e3f652973e6e4fb7074b0bdc2291493e6cb8fae5.zip | |
Support: Simplify endian stream interface. NFCI.
Provide some free functions to reduce verbosity of endian-writing
a single value, and replace the endianness template parameter with
a field.
Part of PR37466.
Differential Revision: https://reviews.llvm.org/D47032
llvm-svn: 332757
Diffstat (limited to 'llvm/lib/Target/BPF')
| -rw-r--r-- | llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp index b4ecfdee7bf..437f658caf6 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp @@ -122,44 +122,35 @@ void BPFMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, computeAvailableFeatures(STI.getFeatureBits())); unsigned Opcode = MI.getOpcode(); - support::endian::Writer<support::little> LE(OS); - support::endian::Writer<support::big> BE(OS); + support::endian::Writer OSE(OS, + IsLittleEndian ? support::little : support::big); if (Opcode == BPF::LD_imm64 || Opcode == BPF::LD_pseudo) { uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI); - LE.write<uint8_t>(Value >> 56); + OS << char(Value >> 56); if (IsLittleEndian) - LE.write<uint8_t>((Value >> 48) & 0xff); + OS << char((Value >> 48) & 0xff); else - LE.write<uint8_t>(SwapBits((Value >> 48) & 0xff)); - LE.write<uint16_t>(0); - if (IsLittleEndian) - LE.write<uint32_t>(Value & 0xffffFFFF); - else - BE.write<uint32_t>(Value & 0xffffFFFF); + OS << char(SwapBits((Value >> 48) & 0xff)); + OSE.write<uint16_t>(0); + OSE.write<uint32_t>(Value & 0xffffFFFF); const MCOperand &MO = MI.getOperand(1); uint64_t Imm = MO.isImm() ? MO.getImm() : 0; - LE.write<uint8_t>(0); - LE.write<uint8_t>(0); - LE.write<uint16_t>(0); - if (IsLittleEndian) - LE.write<uint32_t>(Imm >> 32); - else - BE.write<uint32_t>(Imm >> 32); + OSE.write<uint8_t>(0); + OSE.write<uint8_t>(0); + OSE.write<uint16_t>(0); + OSE.write<uint32_t>(Imm >> 32); } else { // Get instruction encoding and emit it uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI); - LE.write<uint8_t>(Value >> 56); - if (IsLittleEndian) { - LE.write<uint8_t>((Value >> 48) & 0xff); - LE.write<uint16_t>((Value >> 32) & 0xffff); - LE.write<uint32_t>(Value & 0xffffFFFF); - } else { - LE.write<uint8_t>(SwapBits((Value >> 48) & 0xff)); - BE.write<uint16_t>((Value >> 32) & 0xffff); - BE.write<uint32_t>(Value & 0xffffFFFF); - } + OS << char(Value >> 56); + if (IsLittleEndian) + OS << char((Value >> 48) & 0xff); + else + OS << char(SwapBits((Value >> 48) & 0xff)); + OSE.write<uint16_t>((Value >> 32) & 0xffff); + OSE.write<uint32_t>(Value & 0xffffFFFF); } } |

