parser.AddOption('v', "verbose", "Use multiple times for more info", []() {
s_verbose++;
s_log_stream = FileStream::CreateStderr();
});
parser.AddOption( 'o', "output", "FILENAME", "Output file for the generated C source file, by default use stdout",
[](constchar* argument) {
s_outfile = argument;
ConvertBackslashToSlash(&s_outfile);
});
parser.AddOption( '\0', "num-outputs", "NUM", "Number of output files to write",
[](constchar* argument) { s_num_outputs = atoi(argument); });
parser.AddOption( 'n', "module-name", "MODNAME", "Unique name for the module being generated. This name is prefixed to\n" "each of the generaed C symbols. By default, the module name from the\n" "names section is used. If that is not present the name of the input\n" "file is used as the default.\n",
[](constchar* argument) { s_write_c_options.module_name = argument; });
s_write_c_options.features.AddOptions(&parser);
parser.AddOption("no-debug-names", "Ignore debug names in the binary file",
[]() { s_read_debug_names = false; });
parser.AddArgument("filename", OptionParser::ArgumentCount::One,
[](constchar* argument) {
s_infile = argument;
ConvertBackslashToSlash(&s_infile);
});
parser.Parse(argc, argv);
Module module; constbool kStopOnFirstError = true; constbool kFailOnCustomSectionError = true;
ReadBinaryOptions options(s_write_c_options.features, s_log_stream.get(),
s_read_debug_names, kStopOnFirstError,
kFailOnCustomSectionError);
CHECK_RESULT(ReadBinaryIr(s_infile.c_str(), file_data.data(),
file_data.size(), options, &errors, &module));
CHECK_RESULT(ValidateModule(&module, &errors, s_write_c_options.features));
CHECK_RESULT(GenerateNames(&module)); /* TODO(binji): This shouldn't fail; if a name can't be applied
* (because the index is invalid, say) it should just be skipped. */
ApplyNames(&module);
if (!s_outfile.empty()) {
std::string header_name_full =
std::string(wabt::StripExtension(s_outfile)) + ".h";
std::vector<FileStream> c_streams; if (s_num_outputs == 1) {
c_streams.emplace_back(s_outfile.c_str());
} else {
std::string output_prefix{wabt::StripExtension(s_outfile)}; for (unsignedint i = 0; i < s_num_outputs; i++) {
c_streams.emplace_back(output_prefix + "_" + std::to_string(i) + ".c");
}
}
std::vector<Stream*> c_stream_ptrs; for (auto& s : c_streams) {
c_stream_ptrs.emplace_back(&s);
}
FileStream h_stream(header_name_full);
std::string_view header_name = GetBasename(header_name_full); if (s_write_c_options.module_name.empty()) {
s_write_c_options.module_name = module.name; if (s_write_c_options.module_name.empty()) { // In the absence of module name in the names section use the filename.
s_write_c_options.module_name = StripExtension(GetBasename(s_infile));
}
} if (s_num_outputs == 1) {
CHECK_RESULT(WriteC(std::move(c_stream_ptrs), &h_stream, c_stream_ptrs[0],
std::string(header_name).c_str(), "", &module,
s_write_c_options));
} else {
std::string header_impl_name_full =
std::string(wabt::StripExtension(s_outfile)) + "-impl.h";
FileStream h_impl_stream(header_impl_name_full);
std::string_view header_impl_name = GetBasename(header_impl_name_full);
CHECK_RESULT(WriteC(std::move(c_stream_ptrs), &h_stream, &h_impl_stream,
std::string(header_name).c_str(),
std::string(header_impl_name).c_str(), &module,
s_write_c_options));
}
} else {
FileStream stream(stdout);
CHECK_RESULT(WriteC({&stream}, &stream, &stream, "wasm.h", "", &module,
s_write_c_options));
}
return Result::Ok;
}
int ProgramMain(int argc, char** argv) {
Result result;
InitStdio();
ParseOptions(argc, argv);
Errors errors;
result = Wasm2cMain(errors);
FormatErrorsToFile(errors, Location::Type::Binary);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.