LLVM  10.0.0svn
MCXCOFFStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCXCOFFStreamer.cpp - XCOFF Object Output -------------------===//
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 assembles .s files and emits XCOFF .o object files.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCCodeEmitter.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/MC/MCSymbolXCOFF.h"
20 
21 using namespace llvm;
22 
24  std::unique_ptr<MCAsmBackend> MAB,
25  std::unique_ptr<MCObjectWriter> OW,
26  std::unique_ptr<MCCodeEmitter> Emitter)
27  : MCObjectStreamer(Context, std::move(MAB), std::move(OW),
28  std::move(Emitter)) {}
29 
32  auto *Symbol = cast<MCSymbolXCOFF>(Sym);
34 
35  switch (Attribute) {
36  case MCSA_Global:
37  Symbol->setStorageClass(XCOFF::C_EXT);
38  Symbol->setExternal(true);
39  break;
40  default:
41  report_fatal_error("Not implemented yet.");
42  }
43  return true;
44 }
45 
47  unsigned ByteAlignment) {
48  getAssembler().registerSymbol(*Symbol);
49  Symbol->setExternal(cast<MCSymbolXCOFF>(Symbol)->getStorageClass() !=
51  Symbol->setCommon(Size, ByteAlignment);
52 
53  // Need to add this symbol to the current Fragment which will belong to the
54  // containing CSECT.
55  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
56  assert(F && "Expected a valid section with a fragment set.");
57  Symbol->setFragment(F);
58 
59  // Emit the alignment and storage for the variable to the section.
60  EmitValueToAlignment(ByteAlignment);
61  EmitZeros(Size);
62 }
63 
65  uint64_t Size, unsigned ByteAlignment,
66  SMLoc Loc) {
67  report_fatal_error("Zero fill not implemented for XCOFF.");
68 }
69 
71  const MCSubtargetInfo &STI) {
72  MCAssembler &Assembler = getAssembler();
74  SmallString<256> Code;
75  raw_svector_ostream VecOS(Code);
76  Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
77 
78  // TODO: Handle Fixups later
79 
81  DF->setHasInstructions(STI);
82  DF->getContents().append(Code.begin(), Code.end());
83 }
84 
86  std::unique_ptr<MCAsmBackend> &&MAB,
87  std::unique_ptr<MCObjectWriter> &&OW,
88  std::unique_ptr<MCCodeEmitter> &&CE,
89  bool RelaxAll) {
90  MCXCOFFStreamer *S = new MCXCOFFStreamer(Context, std::move(MAB),
91  std::move(OW), std::move(CE));
92  if (RelaxAll)
93  S->getAssembler().setRelaxAll(true);
94  return S;
95 }
96 
98  uint64_t Size,
99  unsigned ByteAlignment) {
100  EmitCommonSymbol(Symbol, Size, ByteAlignment);
101 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
LLVMContext & Context
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void setCommon(uint64_t Size, unsigned Align, bool Target=false)
Mark this symbol as being &#39;common&#39;.
Definition: MCSymbol.h:349
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:530
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
F(f)
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0, SMLoc Loc=SMLoc()) override
Emit the zerofill section and an optional symbol.
void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override
Definition: BitVector.h:937
void setExternal(bool Value) const
Definition: MCSymbol.h:406
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:294
MCStreamer * createXCOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
void setRelaxAll(bool Value)
Definition: MCAssembler.h:321
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:274
Context object for machine code objects.
Definition: MCContext.h:65
Streaming object file generation interface.
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:198
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:208
Streaming machine code generation interface.
Definition: MCStreamer.h:196
MCAssembler & getAssembler()
void setHasInstructions(const MCSubtargetInfo &STI)
Record that the fragment contains instructions with the MCSubtargetInfo in effect when the instructio...
Definition: MCFragment.h:178
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
MCSymbolAttr
Definition: MCDirectives.h:18
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
.type _foo,
Definition: MCDirectives.h:30
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
MCFragment * getCurrentFragment() const
Fragment for data and encoded instructions.
Definition: MCFragment.h:243
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCXCOFFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Represents a location in source code.
Definition: SMLoc.h:23
void EmitXCOFFLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlign) override
Emits an lcomm directive with XCOFF csect information.