1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_WIN_H_
6#define V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_WIN_H_
7
8#include "src/base/macros.h"
9#include "src/snapshot/embedded/platform-embedded-file-writer-base.h"
10
11namespace v8 {
12namespace internal {
13
14class PlatformEmbeddedFileWriterWin : public PlatformEmbeddedFileWriterBase {
15 public:
16  PlatformEmbeddedFileWriterWin(EmbeddedTargetArch target_arch,
17                                EmbeddedTargetOs target_os)
18      : target_arch_(target_arch), target_os_(target_os) {
19    USE(target_os_);
20    DCHECK_EQ(target_os_, EmbeddedTargetOs::kWin);
21  }
22
23  void SectionText() override;
24  void SectionData() override;
25  void SectionRoData() override;
26
27  void AlignToCodeAlignment() override;
28  void AlignToDataAlignment() override;
29
30  void DeclareUint32(const char* name, uint32_t value) override;
31  void DeclarePointerToSymbol(const char* name, const char* target) override;
32
33  void DeclareSymbolGlobal(const char* name) override;
34  void DeclareLabel(const char* name) override;
35
36  void SourceInfo(int fileid, const char* filename, int line) override;
37  void DeclareFunctionBegin(const char* name, uint32_t size) override;
38  void DeclareFunctionEnd(const char* name) override;
39
40  int HexLiteral(uint64_t value) override;
41
42  void Comment(const char* string) override;
43
44  void FilePrologue() override;
45  void DeclareExternalFilename(int fileid, const char* filename) override;
46  void FileEpilogue() override;
47
48  int IndentedDataDirective(DataDirective directive) override;
49
50  DataDirective ByteChunkDataDirective() const override;
51  int WriteByteChunk(const uint8_t* data) override;
52
53  void StartPdataSection();
54  void EndPdataSection();
55  void StartXdataSection();
56  void EndXdataSection();
57  void DeclareExternalFunction(const char* name);
58
59  // Emits an RVA (address relative to the module load address) specified as an
60  // offset from a given symbol.
61  void DeclareRvaToSymbol(const char* name, uint64_t offset = 0);
62
63  void MaybeEmitUnwindData(const char* unwind_info_symbol,
64                           const char* embedded_blob_data_symbol,
65                           const EmbeddedData* blob,
66                           const void* unwind_infos) override;
67
68 private:
69  const char* DirectiveAsString(DataDirective directive);
70
71 private:
72  const EmbeddedTargetArch target_arch_;
73  const EmbeddedTargetOs target_os_;
74};
75
76}  // namespace internal
77}  // namespace v8
78
79#endif  // V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_WIN_H_
80