LLVM 17.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"
16
17namespace llvm {
18
20private:
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
96public:
99};
100
102 int64_t MappingSymbolCounter = 0;
103
104 void EmitMappingSymbol(StringRef Name);
105
106public:
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
dxil DXContainer Global Emitter
std::string Name
uint64_t Size
LLVMContext & Context
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
CSKYELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
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.
ElfMappingSymbol State
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override
Emit Size bytes worth of the value specified by FillValue.
~CSKYELFStreamer() override=default
void reset() override
state management
Context object for machine code objects.
Definition: MCContext.h:76
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.
void reset() override
state management
Definition: MCELFStreamer.h:40
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Generic base class for all target subtargets.
Represents a location in source code.
Definition: SMLoc.h:23
size_t size() const
Definition: SmallVector.h:91
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1862
Definition: BitVector.h:851