LLVM  15.0.0git
CSKYELFStreamer.h
Go to the documentation of this file.
1 //===-- CSKYELFStreamer.h - CSKY ELF Target Streamer -----------*- C++ -*--===//
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 #ifndef LLVM_LIB_TARGET_CSKY_CSKYELFSTREAMER_H
10 #define LLVM_LIB_TARGET_CSKY_CSKYELFSTREAMER_H
11 
12 #include "CSKYTargetStreamer.h"
13 #include "llvm/MC/MCCodeEmitter.h"
14 #include "llvm/MC/MCELFStreamer.h"
15 #include "llvm/MC/MCObjectWriter.h"
16 
17 namespace llvm {
18 
20 private:
21  enum class AttributeType { Hidden, Numeric, Text, NumericAndText };
22 
23  struct AttributeItem {
24  AttributeType Type;
25  unsigned Tag;
26  unsigned IntValue;
27  std::string StringValue;
28  };
29 
30  StringRef CurrentVendor;
32 
33  MCSection *AttributeSection = nullptr;
34 
35  AttributeItem *getAttributeItem(unsigned Attribute) {
36  for (size_t i = 0; i < Contents.size(); ++i)
37  if (Contents[i].Tag == Attribute)
38  return &Contents[i];
39  return nullptr;
40  }
41 
42  void setAttributeItem(unsigned Attribute, unsigned Value,
43  bool OverwriteExisting) {
44  // Look for existing attribute item.
45  if (AttributeItem *Item = getAttributeItem(Attribute)) {
46  if (!OverwriteExisting)
47  return;
48  Item->Type = AttributeType::Numeric;
49  Item->IntValue = Value;
50  return;
51  }
52 
53  // Create new attribute item.
54  Contents.push_back({AttributeType::Numeric, Attribute, Value, ""});
55  }
56 
57  void setAttributeItem(unsigned Attribute, StringRef Value,
58  bool OverwriteExisting) {
59  // Look for existing attribute item.
60  if (AttributeItem *Item = getAttributeItem(Attribute)) {
61  if (!OverwriteExisting)
62  return;
63  Item->Type = AttributeType::Text;
64  Item->StringValue = std::string(Value);
65  return;
66  }
67 
68  // Create new attribute item.
69  Contents.push_back({AttributeType::Text, Attribute, 0, std::string(Value)});
70  }
71 
72  void setAttributeItems(unsigned Attribute, unsigned IntValue,
73  StringRef StringValue, bool OverwriteExisting) {
74  // Look for existing attribute item.
75  if (AttributeItem *Item = getAttributeItem(Attribute)) {
76  if (!OverwriteExisting)
77  return;
78  Item->Type = AttributeType::NumericAndText;
79  Item->IntValue = IntValue;
80  Item->StringValue = std::string(StringValue);
81  return;
82  }
83 
84  // Create new attribute item.
85  Contents.push_back({AttributeType::NumericAndText, Attribute, IntValue,
86  std::string(StringValue)});
87  }
88 
89  void emitAttribute(unsigned Attribute, unsigned Value) override;
90  void emitTextAttribute(unsigned Attribute, StringRef String) override;
91  void finishAttributeSection() override;
92  size_t calculateContentSize() const;
93 
94  void emitTargetAttributes(const MCSubtargetInfo &STI) override;
95 
96 public:
99 };
100 
102  int64_t MappingSymbolCounter = 0;
103 
104  void EmitMappingSymbol(StringRef Name);
105 
106 public:
107  friend class CSKYTargetELFStreamer;
108 
110 
112 
113  CSKYELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
114  std::unique_ptr<MCObjectWriter> OW,
115  std::unique_ptr<MCCodeEmitter> Emitter)
116  : MCELFStreamer(Context, std::move(TAB), std::move(OW),
117  std::move(Emitter)),
118  State(EMS_None) {}
119 
120  ~CSKYELFStreamer() override = default;
121 
122  void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
123  SMLoc Loc) override {
124  EmitMappingSymbol("$d");
125  MCObjectStreamer::emitFill(NumBytes, FillValue, Loc);
126  }
127  void emitBytes(StringRef Data) override {
128  EmitMappingSymbol("$d");
130  }
131  void emitInstruction(const MCInst &Inst,
132  const MCSubtargetInfo &STI) override {
133  EmitMappingSymbol("$t");
135  }
136  void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override {
137  EmitMappingSymbol("$d");
139  }
140  void reset() override {
141  MappingSymbolCounter = 0;
142  State = EMS_None;
144  }
145 };
146 
147 } // namespace llvm
148 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
i
i
Definition: README.txt:29
llvm::CSKYTargetELFStreamer
Definition: CSKYELFStreamer.h:19
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::CSKYELFStreamer::EMS_None
@ EMS_None
Definition: CSKYELFStreamer.h:109
llvm::CSKYELFStreamer::emitBytes
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
Definition: CSKYELFStreamer.h:127
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::Attribute
Definition: Attributes.h:65
MCCodeEmitter.h
llvm::SmallVector< AttributeItem, 64 >
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:105
llvm::MCELFStreamer::reset
void reset() override
state management
Definition: MCELFStreamer.h:40
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
MCELFStreamer.h
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::MCELFStreamer
Definition: MCELFStreamer.h:31
llvm::CSKYTargetELFStreamer::getStreamer
MCELFStreamer & getStreamer()
Definition: CSKYELFStreamer.cpp:68
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCObjectStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: MCObjectStreamer.cpp:409
llvm::CSKYELFStreamer::reset
void reset() override
state management
Definition: CSKYELFStreamer.h:140
CSKYTargetStreamer.h
llvm::CSKYTargetStreamer
Definition: CSKYTargetStreamer.h:45
uint64_t
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1675
llvm::MCELFStreamer::emitValueImpl
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
Definition: MCELFStreamer.cpp:358
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::CSKYTargetELFStreamer::CSKYTargetELFStreamer
CSKYTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: CSKYELFStreamer.cpp:31
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCObjectStreamer::emitFill
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
Definition: MCObjectStreamer.cpp:848
MCObjectWriter.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::CSKYELFStreamer::ElfMappingSymbol
ElfMappingSymbol
Definition: CSKYELFStreamer.h:109
llvm::CSKYELFStreamer::emitValueImpl
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Emit the expression Value into the output as a native integer of the given Size bytes.
Definition: CSKYELFStreamer.h:136
llvm::MCObjectStreamer::emitBytes
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
Definition: MCObjectStreamer.cpp:637
llvm::CSKYELFStreamer::CSKYELFStreamer
CSKYELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition: CSKYELFStreamer.h:113
llvm::CSKYELFStreamer::emitFill
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override
Emit Size bytes worth of the value specified by FillValue.
Definition: CSKYELFStreamer.h:122
llvm::CSKYELFStreamer::State
ElfMappingSymbol State
Definition: CSKYELFStreamer.h:111
llvm::CSKYELFStreamer
Definition: CSKYELFStreamer.h:101
llvm::CSKYELFStreamer::~CSKYELFStreamer
~CSKYELFStreamer() override=default
llvm::CSKYELFStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: CSKYELFStreamer.h:131
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::CSKYELFStreamer::EMS_Text
@ EMS_Text
Definition: CSKYELFStreamer.h:109
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::CSKYELFStreamer::EMS_Data
@ EMS_Data
Definition: CSKYELFStreamer.h:109