| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8480280 commit 31db0b8
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -609,6 +609,14 @@ | |||
| 609 | 609 | default=None, | |
| 610 | 610 | help='Use Link Time Code Generation. This feature is only available on Windows.') | |
| 611 | 611 | ||
| 612 | + parser.add_argument('--write-snapshot-as-array-literals', | ||
| 613 | + action='store_true', | ||
| 614 | + dest='write_snapshot_as_array_literals', | ||
| 615 | + default=None, | ||
| 616 | + help='Write the snapshot data as array literals for readability.' | ||
| 617 | + 'By default the snapshot data may be written as string literals on some ' | ||
| 618 | + 'platforms to speed up compilation.') | ||
| 619 | + | ||
| 612 | 620 | parser.add_argument('--without-node-snapshot', | |
| 613 | 621 | action='store_true', | |
| 614 | 622 | dest='without_node_snapshot', | |
@@ -1290,6 +1298,11 @@ def configure_node(o): | |||
| 1290 | 1298 | o['variables']['node_use_node_code_cache'] = b( | |
| 1291 | 1299 | not cross_compiling and not options.shared) | |
| 1292 | 1300 | ||
| 1301 | + if options.write_snapshot_as_array_literals is not None: | ||
| 1302 | + o['variables']['node_write_snapshot_as_array_literals'] = b(options.write_snapshot_as_array_literals) | ||
| 1303 | + else: | ||
| 1304 | + o['variables']['node_write_snapshot_as_array_literals'] = b(flavor != 'mac' and flavor != 'linux') | ||
| 1305 | + | ||
| 1293 | 1306 | if target_arch == 'arm': | |
| 1294 | 1307 | configure_arm(o) | |
| 1295 | 1308 | elif target_arch in ('mips', 'mipsel', 'mips64el'): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | 'node_use_v8_platform%': 'true', | |
| 11 | 11 | 'node_use_bundled_v8%': 'true', | |
| 12 | 12 | 'node_shared%': 'false', | |
| 13 | + 'node_write_snapshot_as_string_literals': 'true', | ||
| 13 | 14 | 'force_dynamic_crt%': 0, | |
| 14 | 15 | 'ossfuzz' : 'false', | |
| 15 | 16 | 'node_module_version%': '', | |
@@ -1247,8 +1248,8 @@ | |||
| 1247 | 1248 | ], | |
| 1248 | 1249 | ||
| 1249 | 1250 | 'conditions': [ | |
| 1250 | - ['OS in "linux mac"', { | ||
| 1251 | - 'defines': [ 'NODE_MKSNAPSHOT_USE_STRING_LITERALS=1' ], | ||
| 1251 | + ['node_write_snapshot_as_array_literals=="true"', { | ||
| 1252 | + 'defines': [ 'NODE_MKSNAPSHOT_USE_ARRAY_LITERALS=1' ], | ||
| 1252 | 1253 | }], | |
| 1253 | 1254 | [ 'node_use_openssl=="true"', { | |
| 1254 | 1255 | 'defines': [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ class NODE_EXTERN_PRIVATE SnapshotBuilder { | |||
| 23 | 23 | const std::vector<std::string>& args, | |
| 24 | 24 | const std::vector<std::string>& exec_args, | |
| 25 | 25 | std::optional<std::string_view> main_script_path = std::nullopt, | |
| 26 | - bool use_string_literals = true); | ||
| 26 | + bool use_array_literals = false); | ||
| 27 | 27 | ||
| 28 | 28 | // Generate the snapshot into out. | |
| 29 | 29 | static ExitCode Generate(SnapshotData* out, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -773,11 +773,11 @@ void WriteByteVectorLiteral(std::ostream* ss, | |||
| 773 | 773 | const T* vec, | |
| 774 | 774 | size_t size, | |
| 775 | 775 | const char* var_name, | |
| 776 | - bool use_string_literals) { | ||
| 776 | + bool use_array_literals) { | ||
| 777 | 777 | constexpr bool is_uint8_t = std::is_same_v<T, uint8_t>; | |
| 778 | 778 | static_assert(is_uint8_t || std::is_same_v<T, char>); | |
| 779 | 779 | constexpr const char* type_name = is_uint8_t ? "uint8_t" : "char"; | |
| 780 | - if (use_string_literals) { | ||
| 780 | + if (!use_array_literals) { | ||
| 781 | 781 | const uint8_t* data = reinterpret_cast<const uint8_t*>(vec); | |
| 782 | 782 | *ss << "static const " << type_name << " *" << var_name << " = "; | |
| 783 | 783 | *ss << (is_uint8_t ? R"(reinterpret_cast<const uint8_t *>(")" : "\""); | |
@@ -818,7 +818,7 @@ static void WriteCodeCacheInitializer(std::ostream* ss, | |||
| 818 | 818 | ||
| 819 | 819 | void FormatBlob(std::ostream& ss, | |
| 820 | 820 | const SnapshotData* data, | |
| 821 | - bool use_string_literals) { | ||
| 821 | + bool use_array_literals) { | ||
| 822 | 822 | ss << R"(#include <cstddef> | |
| 823 | 823 | #include "env.h" | |
| 824 | 824 | #include "node_snapshot_builder.h" | |
@@ -833,7 +833,7 @@ namespace node { | |||
| 833 | 833 | data->v8_snapshot_blob_data.data, | |
| 834 | 834 | data->v8_snapshot_blob_data.raw_size, | |
| 835 | 835 | "v8_snapshot_blob_data", | |
| 836 | - use_string_literals); | ||
| 836 | + use_array_literals); | ||
| 837 | 837 | ||
| 838 | 838 | ss << R"(static const int v8_snapshot_blob_size = )" | |
| 839 | 839 | << data->v8_snapshot_blob_data.raw_size << ";\n"; | |
@@ -846,7 +846,7 @@ namespace node { | |||
| 846 | 846 | item.data.data, | |
| 847 | 847 | item.data.length, | |
| 848 | 848 | var_name.c_str(), | |
| 849 | - use_string_literals); | ||
| 849 | + use_array_literals); | ||
| 850 | 850 | } | |
| 851 | 851 | ||
| 852 | 852 | ss << R"(const SnapshotData snapshot_data { | |
@@ -1132,7 +1132,7 @@ ExitCode SnapshotBuilder::GenerateAsSource( | |||
| 1132 | 1132 | const std::vector<std::string>& args, | |
| 1133 | 1133 | const std::vector<std::string>& exec_args, | |
| 1134 | 1134 | std::optional<std::string_view> main_script_path, | |
| 1135 | - bool use_string_literals) { | ||
| 1135 | + bool use_array_literals) { | ||
| 1136 | 1136 | std::string main_script_content; | |
| 1137 | 1137 | std::optional<std::string_view> main_script_optional; | |
| 1138 | 1138 | if (main_script_path.has_value()) { | |
@@ -1159,7 +1159,7 @@ ExitCode SnapshotBuilder::GenerateAsSource( | |||
| 1159 | 1159 | if (exit_code != ExitCode::kNoFailure) { | |
| 1160 | 1160 | return exit_code; | |
| 1161 | 1161 | } | |
| 1162 | - FormatBlob(out, &data, use_string_literals); | ||
| 1162 | + FormatBlob(out, &data, use_array_literals); | ||
| 1163 | 1163 | ||
| 1164 | 1164 | if (!out) { | |
| 1165 | 1165 | std::cerr << "Failed to write to " << out_path << "\n"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,18 +79,18 @@ int BuildSnapshot(int argc, char* argv[]) { | |||
| 79 | 79 | out_path = result->args()[1]; | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - #ifdef NODE_MKSNAPSHOT_USE_STRING_LITERALS | ||
| 83 | - bool use_string_literals = true; | ||
| 82 | + #ifdef NODE_MKSNAPSHOT_USE_ARRAY_LITERALS | ||
| 83 | + bool use_array_literals = true; | ||
| 84 | 84 | #else | |
| 85 | - bool use_string_literals = false; | ||
| 85 | + bool use_array_literals = false; | ||
| 86 | 86 | #endif | |
| 87 | 87 | ||
| 88 | 88 | node::ExitCode exit_code = | |
| 89 | 89 | node::SnapshotBuilder::GenerateAsSource(out_path.c_str(), | |
| 90 | 90 | result->args(), | |
| 91 | 91 | result->exec_args(), | |
| 92 | 92 | main_script_path, | |
| 93 | - use_string_literals); | ||
| 93 | + use_array_literals); | ||
| 94 | 94 | ||
| 95 | 95 | node::TearDownOncePerProcess(); | |
| 96 | 96 | return static_cast<int>(exit_code); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments