LLVM  4.0.0
WebAssemblyTargetStreamer.cpp
Go to the documentation of this file.
1 //==-- WebAssemblyTargetStreamer.cpp - WebAssembly Target Streamer Methods --=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file defines WebAssembly-specific target streamer classes.
12 /// These are for implementing support for target-specific assembly directives.
13 ///
14 //===----------------------------------------------------------------------===//
15 
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCSectionELF.h"
22 #include "llvm/MC/MCSymbolELF.h"
23 #include "llvm/Support/ELF.h"
26 using namespace llvm;
27 
29  : MCTargetStreamer(S) {}
30 
33  : WebAssemblyTargetStreamer(S), OS(OS) {}
34 
37 
39  bool First = true;
40  for (MVT Type : Types) {
41  if (First)
42  First = false;
43  else
44  OS << ", ";
46  }
47  OS << '\n';
48 }
49 
51  OS << "\t.param \t";
52  PrintTypes(OS, Types);
53 }
54 
56  OS << "\t.result \t";
57  PrintTypes(OS, Types);
58 }
59 
61  if (!Types.empty()) {
62  OS << "\t.local \t";
63  PrintTypes(OS, Types);
64  }
65 }
66 
67 void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; }
68 
71  OS << "\t.functype\t" << name;
72  if (Results.empty())
73  OS << ", void";
74  else {
75  assert(Results.size() == 1);
76  OS << ", " << WebAssembly::TypeToString(Results.front());
77  }
78  for (auto Ty : Params)
79  OS << ", " << WebAssembly::TypeToString(Ty);
80  OS << '\n';
81 }
82 
84  OS << "\t.import_global\t" << name << '\n';
85 }
86 
88  OS << "\t.indidx \t" << *Value << '\n';
89 }
90 
92  // Nothing to emit; params are declared as part of the function signature.
93 }
94 
96  // Nothing to emit; results are declared as part of the function signature.
97 }
98 
101  for (MVT Type : Types)
103 }
104 
107 }
108 
110  llvm_unreachable(".indidx encoding not yet implemented");
111 }
112 
115  // Nothing to emit here. TODO: Re-design how linking works and re-evaluate
116  // whether it's necessary for .o files to declare indirect function types.
117 }
118 
120 }
const char * TypeToString(MVT Ty)
void emitLocal(ArrayRef< MVT > Types) override
.local
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
void emitResult(ArrayRef< MVT > Types) override
.result
This class prints an WebAssembly MCInst to wasm file syntax.
Target specific streamer interface.
Definition: MCStreamer.h:73
Function Alias Analysis Results
void emitIndirectFunctionType(StringRef name, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results) override
.functype
void emitResult(ArrayRef< MVT > Types) override
.result
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
ValType toValType(const MVT &Ty)
void emitGlobalImport(StringRef name) override
.import_global
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:85
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
Streaming machine code generation interface.
Definition: MCStreamer.h:161
MVT - Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void emitIndIdx(const MCExpr *Value) override
.indidx
This file provides WebAssembly-specific target descriptions.
static void PrintTypes(formatted_raw_ostream &OS, ArrayRef< MVT > Types)
void emitIndIdx(const MCExpr *Value) override
.indidx
static const unsigned End
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:136
WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This file declares WebAssembly-specific target streamer classes.
MCStreamer & Streamer
Definition: MCStreamer.h:75
void emitIndirectFunctionType(StringRef name, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results) override
.functype
void emitParam(ArrayRef< MVT > Types) override
.param
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
void EmitULEB128IntValue(uint64_t Value, unsigned Padding=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:100
void emitLocal(ArrayRef< MVT > Types) override
.local
void emitGlobalImport(StringRef name) override
.import_global
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
static const char * name
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void emitParam(ArrayRef< MVT > Types) override
.param