summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2016-06-03 18:34:36 +0000
committerDerek Schuff <dschuff@google.com>2016-06-03 18:34:36 +0000
commit5859a9ed80829bf3eee5f8e9946b0ab0d2142600 (patch)
tree0cb6a628d9d33ce3eebbaf07026d3f3462039f86 /llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
parent96938d67b601dc7a9b9f1b4f70c1371ea406d08b (diff)
downloadbcm5719-llvm-5859a9ed80829bf3eee5f8e9946b0ab0d2142600.tar.gz
bcm5719-llvm-5859a9ed80829bf3eee5f8e9946b0ab0d2142600.zip
[WebAssembly] Emit type signatures for declared functions
Under emscripten, C code can take the address of a function implemented in Javascript (which is exposed via an import in wasm). Because imports do not have linear memory address in wasm, we need to generate a thunk to be the target of the indirect call; it call the import directly. To make this possible, LLVM needs to emit the type signatures for these functions, because they may not be called directly or referred to other than where the address is taken. This uses s new .s directive (.functype) which specifies the signature. Differential Revision: http://reviews.llvm.org/D20891 Re-apply r271599 but instead of bailing with an error when a declared function has multiple returns, replace it with a pointer argument. Also add the test case I forgot to 'git add' last time around. llvm-svn: 271703
Diffstat (limited to 'llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
index 789a176155b..3d61c15717b 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
@@ -64,6 +64,16 @@ void WebAssemblyTargetAsmStreamer::emitLocal(ArrayRef<MVT> Types) {
void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; }
+void WebAssemblyTargetAsmStreamer::emitIndirectFunctionType(
+ StringRef name, SmallVectorImpl<MVT> &SignatureVTs, size_t NumResults) {
+ OS << "\t.functype\t" << name;
+ if (NumResults == 0) OS << ", void";
+ for (auto Ty : SignatureVTs) {
+ OS << ", " << WebAssembly::TypeToString(Ty);
+ }
+ OS << "\n";
+}
+
// FIXME: What follows is not the real binary encoding.
static void EncodeTypes(MCStreamer &Streamer, ArrayRef<MVT> Types) {
OpenPOWER on IntegriCloud