LLVM: lib/MC/MCWasmStreamer.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

30

31namespace llvm {

35}

36

37using namespace llvm;

38

40

42 auto *Symbol = cast(S);

44

48 Symbol->setTLS();

49}

50

53 auto *Symbol = cast(S);

55

59 Symbol->setTLS();

60}

61

63

65

66

68}

69

72 auto *SectionWasm = cast(Section);

73 const MCSymbol *Grp = SectionWasm->getGroup();

74 if (Grp)

75 Asm.registerSymbol(*Grp);

76

78 Asm.registerSymbol(*Section->getBeginSymbol());

79}

80

87}

88

91

92 auto *Symbol = cast(S);

93

94

95

96

98

110 return false;

111

113 Symbol->setHidden(true);

114 break;

115

118 Symbol->setWeak(true);

119 Symbol->setExternal(true);

120 break;

121

123 Symbol->setExternal(true);

124 break;

125

128 break;

129

131 Symbol->setTLS();

132 break;

133

136 break;

137

139 Symbol->setNoStrip();

140 break;

141

142 default:

143

145 return false;

146 }

147

148 return true;

149}

150

152 Align ByteAlignment) {

153 llvm_unreachable("Common symbols are not yet implemented for Wasm");

154}

155

157 cast(Symbol)->setSize(Value);

158}

159

161 Align ByteAlignment) {

162 llvm_unreachable("Local common symbols are not yet implemented for Wasm");

163}

164

166

167

168}

169

170void MCWasmStreamer::emitInstToFragment(const MCInst &Inst,

174

175 for (auto &Fixup : F.getFixups())

176 fixSymbolsInTLSFixups(Fixup.getValue());

177}

178

179void MCWasmStreamer::emitInstToData(const MCInst &Inst,

185

186 for (auto &Fixup : Fixups)

187 fixSymbolsInTLSFixups(Fixup.getValue());

188

189

190

192

193

194 for (unsigned I = 0, E = Fixups.size(); I != E; ++I) {

195 Fixups[I].setOffset(Fixups[I].getOffset() + DF->getContents().size());

196 DF->getFixups().push_back(Fixups[I]);

197 }

198 DF->setHasInstructions(STI);

199 DF->appendContents(Code);

200}

201

204

206}

207

208void MCWasmStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {

209 switch (expr->getKind()) {

212 break;

213

215 const MCBinaryExpr *be = cast(expr);

216 fixSymbolsInTLSFixups(be->getLHS());

217 fixSymbolsInTLSFixups(be->getRHS());

218 break;

219 }

220

222 const MCSymbolRefExpr &symRef = *cast(expr);

223 switch (symRef.getKind()) {

227 cast(symRef.getSymbol()).setTLS();

228 break;

229 default:

230 break;

231 }

232 break;

233 }

234

236 fixSymbolsInTLSFixups(cast(expr)->getSubExpr());

237 break;

238 }

239}

240

242 llvm_unreachable("Generic Wasm doesn't support this directive");

243}

244

247}

248

253}

254

258}

259

261 std::unique_ptr &&MAB,

262 std::unique_ptr &&OW,

263 std::unique_ptr &&CE) {

265 new MCWasmStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));

266 return S;

267}

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")

PowerPC TLS Dynamic Call Fixup

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallString class.

This file defines the SmallVector class.

virtual void handleAssemblerFlag(MCAssemblerFlag Flag)

Handle any target-specific assembler flags. By default, do nothing.

MCCodeEmitter & getEmitter() const

MCAsmBackend & getBackend() const

bool registerSymbol(const MCSymbol &Symbol)

Binary assembler expressions.

const MCExpr * getLHS() const

Get the left-hand side expression of the binary operator.

const MCExpr * getRHS() const

Get the right-hand side expression of the binary operator.

virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0

Encode the given Inst to bytes and append to CB.

Context object for machine code objects.

Fragment for data and encoded instructions.

Base class for the full range of assembler expressions which are needed for parsing.

@ Unary

Unary expressions.

@ Constant

Constant expressions.

@ SymbolRef

References to labels and assigned expressions.

@ Target

Target specific expression.

@ Binary

Binary expressions.

Instances of this class represent a single low-level machine instruction.

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.

MCAssembler & getAssembler()

virtual void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)

Emit an instruction to a special fragment, because this instruction can change its size during relaxa...

void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override

Emit a label for Symbol into the current section.

void finishImpl() override

Streamer specific finalization.

void changeSection(MCSection *Section, uint32_t Subsection=0) override

This is called by popSection and switchSection, if the current section changes.

void emitFrames(MCAsmBackend *MAB)

virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F, uint64_t Offset)

A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...

This represents a section on wasm.

Instances of this class represent a uniqued identifier for a section in the current translation unit.

Streaming machine code generation interface.

MCFragment * getCurrentFragment() const

MCContext & getContext() const

MCSection * getCurrentSectionOnly() const

Generic base class for all target subtargets.

Represent a reference to a symbol from inside an expression.

const MCSymbol & getSymbol() const

static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)

VariantKind getKind() const

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

void setVariableValue(const MCExpr *Value)

void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F, uint64_t Offset) override

void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override

Emit a common symbol.

void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override

Emit a local common (.lcomm) symbol.

void emitIdent(StringRef IdentString) override

Emit the "identifiers" directive.

void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override

Set the DescValue for the Symbol.

void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override

Emit a label for Symbol into the current section.

void emitThumbFunc(MCSymbol *Func) override

Note in the output that the specified Func is a Thumb mode function (ARM target only).

~MCWasmStreamer() override

void changeSection(MCSection *Section, uint32_t Subsection) override

This is called by popSection and switchSection, if the current section changes.

void finishImpl() override

Streamer specific finalization.

void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, Align ByteAlignment=Align(1)) override

Emit a thread local bss (.tbss) symbol.

void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override

Emit an ELF .size directive.

void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override

Emit an weak reference from Alias to Symbol.

bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override

Add the given Attribute to Symbol.

void emitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, Align ByteAlignment=Align(1), SMLoc Loc=SMLoc()) override

Emit the zerofill section and an optional symbol.

void emitAssemblerFlag(MCAssemblerFlag Flag) override

Note in the output the specified Flag.

Represents a location in source code.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

LLVM Value Representation.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ WASM_SYMBOL_TYPE_FUNCTION

This is an optimization pass for GlobalISel generic memory operations.

static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)

MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)

@ MCSA_WeakDefAutoPrivate

.weak_def_can_be_hidden (MachO)

@ MCSA_Protected

.protected (ELF)

@ MCSA_Exported

.globl _foo, exported (XCOFF)

@ MCSA_PrivateExtern

.private_extern (MachO)

@ MCSA_WeakReference

.weak_reference (MachO)

@ MCSA_LazyReference

.lazy_reference (MachO)

@ MCSA_Reference

.reference (MachO)

@ MCSA_SymbolResolver

.symbol_resolver (MachO)

@ MCSA_ELF_TypeTLS

.type _foo, STT_TLS # aka @tls_object

@ MCSA_IndirectSymbol

.indirect_symbol (MachO)

@ MCSA_WeakDefinition

.weak_definition (MachO)

@ MCSA_Global

.type _foo, @gnu_unique_object

@ MCSA_ELF_TypeObject

.type _foo, STT_OBJECT # aka @object

@ MCSA_ELF_TypeFunction

.type _foo, STT_FUNC # aka @function

@ MCSA_Hidden

.hidden (ELF)

@ MCSA_Invalid

Not a valid directive.

@ MCSA_NoDeadStrip

.no_dead_strip (MachO)

This struct is a compact representation of a valid (non-zero power of two) alignment.