1 //===- AArch64TargetStreamer.cpp - AArch64TargetStreamer class ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the AArch64TargetStreamer class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "AArch64TargetStreamer.h"
14 #include "llvm/MC/ConstantPools.h"
15 #include "llvm/MC/MCSection.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17
18 using namespace llvm;
19
20 //
21 // AArch64TargetStreamer Implemenation
22 //
AArch64TargetStreamer(MCStreamer & S)23 AArch64TargetStreamer::AArch64TargetStreamer(MCStreamer &S)
24 : MCTargetStreamer(S), ConstantPools(new AssemblerConstantPools()) {}
25
26 AArch64TargetStreamer::~AArch64TargetStreamer() = default;
27
28 // The constant pool handling is shared by all AArch64TargetStreamer
29 // implementations.
addConstantPoolEntry(const MCExpr * Expr,unsigned Size,SMLoc Loc)30 const MCExpr *AArch64TargetStreamer::addConstantPoolEntry(const MCExpr *Expr,
31 unsigned Size,
32 SMLoc Loc) {
33 return ConstantPools->addEntry(Streamer, Expr, Size, Loc);
34 }
35
emitCurrentConstantPool()36 void AArch64TargetStreamer::emitCurrentConstantPool() {
37 ConstantPools->emitForCurrentSection(Streamer);
38 }
39
40 // finish() - write out any non-empty assembler constant pools.
finish()41 void AArch64TargetStreamer::finish() { ConstantPools->emitAll(Streamer); }
42
emitInst(uint32_t Inst)43 void AArch64TargetStreamer::emitInst(uint32_t Inst) {
44 char Buffer[4];
45
46 // We can't just use EmitIntValue here, as that will swap the
47 // endianness on big-endian systems (instructions are always
48 // little-endian).
49 for (unsigned I = 0; I < 4; ++I) {
50 Buffer[I] = uint8_t(Inst);
51 Inst >>= 8;
52 }
53
54 getStreamer().EmitBytes(StringRef(Buffer, 4));
55 }
56
57 namespace llvm {
58
59 MCTargetStreamer *
createAArch64ObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)60 createAArch64ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
61 const Triple &TT = STI.getTargetTriple();
62 if (TT.isOSBinFormatELF())
63 return new AArch64TargetELFStreamer(S);
64 if (TT.isOSBinFormatCOFF())
65 return new AArch64TargetWinCOFFStreamer(S);
66 return nullptr;
67 }
68
69 } // end namespace llvm
70