diff options
| author | Sam Clegg <sbc@chromium.org> | 2018-01-13 00:22:00 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2018-01-13 00:22:00 +0000 |
| commit | 4a379c3dd8caeb265d0cb7dae347a0456ce85d84 (patch) | |
| tree | d43aedc11258db5873a473e91ed17362a111fcf3 | |
| parent | 4463ae4f6dcb2a59e01e816e2ea0eb9ed8321c9a (diff) | |
| download | bcm5719-llvm-4a379c3dd8caeb265d0cb7dae347a0456ce85d84.tar.gz bcm5719-llvm-4a379c3dd8caeb265d0cb7dae347a0456ce85d84.zip | |
[WebAssembly] Use ArrayRef over raw pointers
Differential Revision: https://reviews.llvm.org/D42013
llvm-svn: 322423
| -rw-r--r-- | lld/wasm/InputChunks.cpp | 2 | ||||
| -rw-r--r-- | lld/wasm/InputChunks.h | 22 | ||||
| -rw-r--r-- | lld/wasm/Writer.cpp | 6 |
3 files changed, 15 insertions, 15 deletions
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp index 5f04eccc835..e87c97b47e9 100644 --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -86,7 +86,7 @@ static void applyRelocations(uint8_t *Buf, ArrayRef<OutputRelocation> Relocs) { } void InputChunk::writeTo(uint8_t *SectionStart) const { - memcpy(SectionStart + getOutputOffset(), getData(), getSize()); + memcpy(SectionStart + getOutputOffset(), data().data(), data().size()); applyRelocations(SectionStart, OutRelocations); } diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h index c02ebd6028e..990ca0bfb9a 100644 --- a/lld/wasm/InputChunks.h +++ b/lld/wasm/InputChunks.h @@ -56,7 +56,7 @@ protected: InputChunk(const ObjFile *F) : File(F) {} virtual ~InputChunk() = default; void calcRelocations(); - virtual const uint8_t *getData() const = 0; + virtual ArrayRef<uint8_t> data() const = 0; virtual uint32_t getInputSectionOffset() const = 0; std::vector<WasmRelocation> Relocations; @@ -88,9 +88,6 @@ public: OutputSegmentOffset = Offset; } - const uint8_t *getData() const override { - return Segment.Data.Content.data(); - } uint32_t getSize() const override { return Segment.Data.Content.size(); } uint32_t getAlignment() const { return Segment.Data.Alignment; } uint32_t startVA() const { return Segment.Data.Offset.Value.Int32; } @@ -101,6 +98,7 @@ public: int32_t OutputSegmentOffset = 0; protected: + ArrayRef<uint8_t> data() const override { return Segment.Data.Content; } uint32_t getInputSectionOffset() const override { return Segment.SectionOffset; } @@ -118,9 +116,6 @@ public: : InputChunk(F), Signature(S), WrittenToNameSec(false), Function(Func) {} uint32_t getSize() const override { return Function->Size; } - const uint8_t *getData() const override { - return File->CodeSection->Content.data() + getInputSectionOffset(); - } StringRef getComdat() const override { return Function->Comdat; } uint32_t getOutputIndex() const { return OutputIndex.getValue(); }; bool hasOutputIndex() const { return OutputIndex.hasValue(); }; @@ -131,25 +126,28 @@ public: unsigned WrittenToNameSec : 1; protected: + ArrayRef<uint8_t> data() const override { + return File->CodeSection->Content.slice(getInputSectionOffset(), getSize()); + } uint32_t getInputSectionOffset() const override { return Function->CodeSectionOffset; } + const WasmFunction *Function; llvm::Optional<uint32_t> OutputIndex; }; class SyntheticFunction : public InputFunction { public: - SyntheticFunction(const WasmSignature &S, StringRef Body) + SyntheticFunction(const WasmSignature &S, ArrayRef<uint8_t> Body) : InputFunction(S, nullptr, nullptr), Body(Body) {} uint32_t getSize() const override { return Body.size(); } - const uint8_t *getData() const override { - return reinterpret_cast<const uint8_t *>(Body.data()); - } protected: - StringRef Body; + ArrayRef<uint8_t> data() const override { return Body; } + + ArrayRef<uint8_t> Body; }; } // namespace wasm diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index eea5439c2b9..bb34f265d40 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -770,8 +770,10 @@ void Writer::createCtorFunction() { writeUleb128(OS, FunctionBody.size(), "function size"); OS.flush(); CtorFunctionBody += FunctionBody; - CtorFunction = - llvm::make_unique<SyntheticFunction>(Signature, CtorFunctionBody); + ArrayRef<uint8_t> BodyArray( + reinterpret_cast<const uint8_t *>(CtorFunctionBody.data()), + CtorFunctionBody.size()); + CtorFunction = llvm::make_unique<SyntheticFunction>(Signature, BodyArray); DefinedFunctions.emplace_back(CtorFunction.get()); } |

