v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
platform-embedded-file-writer-base.h
Go to the documentation of this file.
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_BASE_H_
6#define V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_BASE_H_
7
8#include <cinttypes>
9#include <cstdio> // For FILE.
10#include <memory>
11
12#if V8_ENABLE_DRUMBRAKE
13#include <string>
14#endif // V8_ENABLE_DRUMBRAKE
15
16namespace v8 {
17namespace internal {
18
19class EmbeddedData;
20
27
29int DataDirectiveSize(DataDirective directive);
30
31enum class EmbeddedTargetOs {
32 kAIX,
35 kMac,
36 kWin,
38 kZOS,
39 kGeneric, // Everything not covered above falls in here.
40};
41
43 kArm,
44 kArm64,
45 kIA32,
46 kX64,
47 kGeneric, // Everything not covered above falls in here.
48};
49
50// The platform-dependent logic for emitting assembly code for the generated
51// embedded.S file.
53 public:
55
56 void SetFile(FILE* fp) { fp_ = fp; }
57 FILE* fp() const { return fp_; }
58
59 virtual void SectionText() = 0;
60 virtual void SectionRoData() = 0;
61
62 virtual void AlignToCodeAlignment() = 0;
63 virtual void AlignToPageSizeIfNeeded() {}
64 virtual void AlignToDataAlignment() = 0;
65
66 virtual void DeclareUint32(const char* name, uint32_t value) = 0;
67
68 virtual void DeclareSymbolGlobal(const char* name) = 0;
69 virtual void DeclareLabel(const char* name) = 0;
70 virtual void DeclareLabelProlog(const char* name) {}
71 virtual void DeclareLabelEpilogue() {}
72
73 virtual void SourceInfo(int fileid, const char* filename, int line) = 0;
74 virtual void DeclareFunctionBegin(const char* name, uint32_t size) = 0;
75 virtual void DeclareFunctionEnd(const char* name) = 0;
76
77 // Returns the number of printed characters.
78 virtual int HexLiteral(uint64_t value);
79
80 virtual void Comment(const char* string) = 0;
81 virtual void Newline() { fprintf(fp_, "\n"); }
82
83 virtual void FilePrologue() = 0;
84 virtual void DeclareExternalFilename(int fileid, const char* filename) = 0;
85 virtual void FileEpilogue() = 0;
86
87 virtual int IndentedDataDirective(DataDirective directive) = 0;
88
89 virtual DataDirective ByteChunkDataDirective() const { return kOcta; }
90 virtual int WriteByteChunk(const uint8_t* data);
91
92 // This awkward interface works around the fact that unwind data emission
93 // is both high-level and platform-dependent. The former implies it should
94 // live in EmbeddedFileWriter, but code there should be platform-independent.
95 //
96 // Emits unwinding data on x64 Windows, and does nothing otherwise.
97 virtual void MaybeEmitUnwindData(const char* unwind_info_symbol,
98 const char* embedded_blob_data_symbol,
99 const EmbeddedData* blob,
100 const void* unwind_infos) {}
101
102 protected:
103 FILE* fp_ = nullptr;
104};
105
106// The factory function. Returns the appropriate platform-specific instance.
107std::unique_ptr<PlatformEmbeddedFileWriterBase> NewPlatformEmbeddedFileWriter(
108 const char* target_arch, const char* target_os);
109
110#if V8_ENABLE_DRUMBRAKE
111inline bool IsDrumBrakeInstructionHandler(const char* name) {
112 std::string builtin_name(name);
113 return builtin_name.find("Builtins_r2r_") == 0 ||
114 builtin_name.find("Builtins_r2s_") == 0 ||
115 builtin_name.find("Builtins_s2r_") == 0 ||
116 builtin_name.find("Builtins_s2s_") == 0;
117}
118#endif // V8_ENABLE_DRUMBRAKE
119
120} // namespace internal
121} // namespace v8
122
123#endif // V8_SNAPSHOT_EMBEDDED_PLATFORM_EMBEDDED_FILE_WRITER_BASE_H_
virtual void Comment(const char *string)=0
virtual void DeclareFunctionEnd(const char *name)=0
virtual void DeclareUint32(const char *name, uint32_t value)=0
virtual void SourceInfo(int fileid, const char *filename, int line)=0
virtual void MaybeEmitUnwindData(const char *unwind_info_symbol, const char *embedded_blob_data_symbol, const EmbeddedData *blob, const void *unwind_infos)
virtual void DeclareExternalFilename(int fileid, const char *filename)=0
virtual void DeclareSymbolGlobal(const char *name)=0
virtual void DeclareLabel(const char *name)=0
virtual void DeclareFunctionBegin(const char *name, uint32_t size)=0
virtual int IndentedDataDirective(DataDirective directive)=0
std::string filename
int DataDirectiveSize(DataDirective directive)
std::unique_ptr< PlatformEmbeddedFileWriterBase > NewPlatformEmbeddedFileWriter(const char *target_arch, const char *target_os)