[PATCH] D43855: [WebAssembly] Use toArrayRef. NFC.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 19:36:22 PST 2018


ruiu created this revision.
ruiu added a reviewer: sbc100.
Herald added subscribers: sunfish, aheejin, jgravelle-google, arichardson, emaste, dschuff, jfb.

[WebAssembly] Use toArrayRef. NFC.


https://reviews.llvm.org/D43855

Files:
  lld/ELF/InputFiles.cpp
  lld/ELF/Strings.h
  lld/include/lld/Common/Strings.h
  lld/wasm/Writer.cpp


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -17,6 +17,7 @@
 #include "WriterUtils.h"
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Memory.h"
+#include "lld/Common/Strings.h"
 #include "lld/Common/Threads.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/BinaryFormat/Wasm.h"
@@ -877,7 +878,6 @@
 
   // First write the body bytes to a string.
   std::string FunctionBody;
-  const WasmSignature *Signature = WasmSym::CallCtors->getFunctionType();
   {
     raw_string_ostream OS(FunctionBody);
     writeUleb128(OS, 0, "num locals");
@@ -893,11 +893,11 @@
   writeUleb128(OS, FunctionBody.size(), "function size");
   OS.flush();
   CtorFunctionBody += FunctionBody;
-  ArrayRef<uint8_t> BodyArray(
-      reinterpret_cast<const uint8_t *>(CtorFunctionBody.data()),
-      CtorFunctionBody.size());
-  SyntheticFunction *F = make<SyntheticFunction>(*Signature, BodyArray,
-                                                 WasmSym::CallCtors->getName());
+
+  const WasmSignature *Sig = WasmSym::CallCtors->getFunctionType();
+  SyntheticFunction *F = make<SyntheticFunction>(
+      *Sig, toArrayRef(CtorFunctionBody), WasmSym::CallCtors->getName());
+
   F->setOutputIndex(FunctionIndex);
   F->Live = true;
   WasmSym::CallCtors->Function = F;
Index: lld/include/lld/Common/Strings.h
===================================================================
--- lld/include/lld/Common/Strings.h
+++ lld/include/lld/Common/Strings.h
@@ -10,14 +10,19 @@
 #ifndef LLD_STRINGS_H
 #define LLD_STRINGS_H
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include <string>
 
 namespace lld {
 // Returns a demangled C++ symbol name. If Name is not a mangled
 // name, it returns Optional::None.
 llvm::Optional<std::string> demangleItanium(llvm::StringRef Name);
+
+inline llvm::ArrayRef<uint8_t> toArrayRef(llvm::StringRef S) {
+  return {reinterpret_cast<const uint8_t *>(S.data()), S.size()};
+}
 }
 
 #endif
Index: lld/ELF/Strings.h
===================================================================
--- lld/ELF/Strings.h
+++ lld/ELF/Strings.h
@@ -65,10 +65,6 @@
 private:
   std::vector<llvm::GlobPattern> Patterns;
 };
-
-inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
-  return {(const uint8_t *)S.data(), S.size()};
-}
 } // namespace elf
 } // namespace lld
 
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -15,6 +15,7 @@
 #include "SyntheticSections.h"
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Memory.h"
+#include "lld/Common/Strings.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43855.136220.patch
Type: text/x-patch
Size: 2852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180228/808fa6bf/attachment.bin>


More information about the llvm-commits mailing list