diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.cc | 6 | ||||
-rw-r--r-- | src/common.h | 6 | ||||
-rw-r--r-- | src/error-handler.cc | 4 | ||||
-rw-r--r-- | src/lexer-source.cc | 4 | ||||
-rw-r--r-- | src/lexer-source.h | 2 | ||||
-rw-r--r-- | src/prebuilt/wast-lexer-gen.cc | 6 | ||||
-rw-r--r-- | src/tools/spectest-interp.cc | 39 | ||||
-rw-r--r-- | src/tools/wasm2wat.cc | 2 | ||||
-rw-r--r-- | src/wast-lexer.cc | 6 | ||||
-rw-r--r-- | src/wast-lexer.h | 8 |
10 files changed, 41 insertions, 42 deletions
diff --git a/src/common.cc b/src/common.cc index 65b2e15c..d26783a1 100644 --- a/src/common.cc +++ b/src/common.cc @@ -45,12 +45,12 @@ const char* g_reloc_type_name[] = { }; WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(g_reloc_type_name) == kRelocTypeCount); -Result ReadFile(const char* filename, std::vector<uint8_t>* out_data) { - FILE* infile = fopen(filename, "rb"); +Result ReadFile(string_view filename, std::vector<uint8_t>* out_data) { + FILE* infile = fopen(filename.to_string().c_str(), "rb"); if (!infile) { const char format[] = "unable to read file %s"; char msg[PATH_MAX + sizeof(format)]; - wabt_snprintf(msg, sizeof(msg), format, filename); + wabt_snprintf(msg, sizeof(msg), format, filename.to_string().c_str()); perror(msg); return Result::Error; } diff --git a/src/common.h b/src/common.h index 342316b2..4d94d688 100644 --- a/src/common.h +++ b/src/common.h @@ -161,14 +161,14 @@ struct Location { }; Location() : line(0), first_column(0), last_column(0) {} - Location(const char* filename, int line, int first_column, int last_column) + Location(string_view filename, int line, int first_column, int last_column) : filename(filename), line(line), first_column(first_column), last_column(last_column) {} explicit Location(size_t offset) : offset(offset) {} - const char* filename = nullptr; + string_view filename; union { // For text files. struct { @@ -263,7 +263,7 @@ enum class NameSectionSubsection { Local = 2, }; -Result ReadFile(const char* filename, std::vector<uint8_t>* out_data); +Result ReadFile(string_view filename, std::vector<uint8_t>* out_data); void InitStdio(); diff --git a/src/error-handler.cc b/src/error-handler.cc index 693c76d1..da61230e 100644 --- a/src/error-handler.cc +++ b/src/error-handler.cc @@ -34,8 +34,8 @@ std::string ErrorHandler::DefaultErrorMessage(const Color& color, result += color.MaybeBoldCode(); - if (loc.filename) { - result += loc.filename; + if (!loc.filename.empty()) { + result += loc.filename.to_string(); result += ":"; } diff --git a/src/lexer-source.cc b/src/lexer-source.cc index 8a455015..1d59dd9c 100644 --- a/src/lexer-source.cc +++ b/src/lexer-source.cc @@ -20,9 +20,9 @@ namespace wabt { -LexerSourceFile::LexerSourceFile(const std::string& filename) +LexerSourceFile::LexerSourceFile(string_view filename) : filename_(filename) { - file_ = fopen(filename.c_str(), "rb"); + file_ = fopen(filename_.c_str(), "rb"); } LexerSourceFile::~LexerSourceFile() { diff --git a/src/lexer-source.h b/src/lexer-source.h index e05b8be6..616913c0 100644 --- a/src/lexer-source.h +++ b/src/lexer-source.h @@ -41,7 +41,7 @@ class LexerSource { class LexerSourceFile : public LexerSource { public: - explicit LexerSourceFile(const std::string& filename); + explicit LexerSourceFile(string_view filename); ~LexerSourceFile(); bool IsOpen() const { return file_ != nullptr; } diff --git a/src/prebuilt/wast-lexer-gen.cc b/src/prebuilt/wast-lexer-gen.cc index 6467c068..c0951504 100644 --- a/src/prebuilt/wast-lexer-gen.cc +++ b/src/prebuilt/wast-lexer-gen.cc @@ -84,7 +84,7 @@ namespace wabt { -WastLexer::WastLexer(std::unique_ptr<LexerSource> source, const char* filename) +WastLexer::WastLexer(std::unique_ptr<LexerSource> source, string_view filename) : source_(std::move(source)), line_finder_(source_->Clone()), filename_(filename), @@ -105,13 +105,13 @@ WastLexer::~WastLexer() { } // static -std::unique_ptr<WastLexer> WastLexer::CreateFileLexer(const char* filename) { +std::unique_ptr<WastLexer> WastLexer::CreateFileLexer(string_view filename) { std::unique_ptr<LexerSource> source(new LexerSourceFile(filename)); return std::unique_ptr<WastLexer>(new WastLexer(std::move(source), filename)); } // static -std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(const char* filename, +std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(string_view filename, const void* data, size_t size) { std::unique_ptr<LexerSource> source(new LexerSourceBuffer(data, size)); diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc index c461b827..a1603198 100644 --- a/src/tools/spectest-interp.cc +++ b/src/tools/spectest-interp.cc @@ -200,7 +200,7 @@ class JSONParser { public: JSONParser() {} - wabt::Result ReadFile(const char* spec_json_filename); + wabt::Result ReadFile(string_view spec_json_filename); wabt::Result ParseScript(Script* out_script); private: @@ -241,7 +241,7 @@ class JSONParser { #define PARSE_KEY_STRING_VALUE(key, value) \ CHECK_RESULT(ParseKeyStringValue(key, value)) -wabt::Result JSONParser::ReadFile(const char* spec_json_filename) { +wabt::Result JSONParser::ReadFile(string_view spec_json_filename) { loc_.filename = spec_json_filename; loc_.line = 1; loc_.first_column = 1; @@ -251,8 +251,8 @@ wabt::Result JSONParser::ReadFile(const char* spec_json_filename) { void JSONParser::PrintError(const char* format, ...) { WABT_SNPRINTF_ALLOCA(buffer, length, format); - fprintf(stderr, "%s:%d:%d: %s\n", loc_.filename, loc_.line, loc_.first_column, - buffer); + fprintf(stderr, "%s:%d:%d: %s\n", loc_.filename.to_string().c_str(), + loc_.line, loc_.first_column, buffer); } void JSONParser::PutbackChar() { @@ -584,7 +584,7 @@ static string_view GetDirname(string_view path) { } std::string JSONParser::CreateModulePath(string_view filename) { - const char* spec_json_filename = loc_.filename; + string_view spec_json_filename = loc_.filename; string_view dirname = GetDirname(spec_json_filename); std::string path; @@ -785,11 +785,11 @@ class CommandRunner { void TallyCommand(wabt::Result); - wabt::Result ReadInvalidTextModule(const char* module_filename, + wabt::Result ReadInvalidTextModule(string_view module_filename, Environment* env, ErrorHandler* error_handler); wabt::Result ReadInvalidModule(int line_number, - const char* module_filename, + string_view module_filename, Environment* env, ModuleType module_type, const char* desc); @@ -1048,7 +1048,7 @@ ExecResult CommandRunner::RunAction(int line_number, return exec_result; } -wabt::Result CommandRunner::ReadInvalidTextModule(const char* module_filename, +wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename, Environment* env, ErrorHandler* error_handler) { std::unique_ptr<WastLexer> lexer = @@ -1066,7 +1066,7 @@ wabt::Result CommandRunner::ReadInvalidTextModule(const char* module_filename, return result; } -static wabt::Result ReadModule(const char* module_filename, +static wabt::Result ReadModule(string_view module_filename, Environment* env, ErrorHandler* error_handler, DefinedModule** out_module) { @@ -1093,7 +1093,7 @@ static wabt::Result ReadModule(const char* module_filename, } wabt::Result CommandRunner::ReadInvalidModule(int line_number, - const char* module_filename, + string_view module_filename, Environment* env, ModuleType module_type, const char* desc) { @@ -1121,7 +1121,7 @@ wabt::Result CommandRunner::ReadInvalidModule(int line_number, wabt::Result CommandRunner::OnModuleCommand(const ModuleCommand* command) { Environment::MarkPoint mark = env_.Mark(); ErrorHandlerFile error_handler(Location::Type::Binary); - wabt::Result result = ReadModule(command->filename.c_str(), &env_, + wabt::Result result = ReadModule(command->filename, &env_, &error_handler, &last_module_); if (Failed(result)) { @@ -1167,8 +1167,8 @@ wabt::Result CommandRunner::OnAssertMalformedCommand( InitEnvironment(&env); wabt::Result result = - ReadInvalidModule(command->line, command->filename.c_str(), &env, - command->type, "assert_malformed"); + ReadInvalidModule(command->line, command->filename, &env, command->type, + "assert_malformed"); if (Succeeded(result)) { PrintError(command->line, "expected module to be malformed: \"%s\"", command->filename.c_str()); @@ -1199,8 +1199,8 @@ wabt::Result CommandRunner::OnAssertUnlinkableCommand( const AssertUnlinkableCommand* command) { Environment::MarkPoint mark = env_.Mark(); wabt::Result result = - ReadInvalidModule(command->line, command->filename.c_str(), &env_, - command->type, "assert_unlinkable"); + ReadInvalidModule(command->line, command->filename, &env_, command->type, + "assert_unlinkable"); env_.ResetToMarkPoint(mark); if (Succeeded(result)) { @@ -1217,9 +1217,8 @@ wabt::Result CommandRunner::OnAssertInvalidCommand( Environment env; InitEnvironment(&env); - wabt::Result result = - ReadInvalidModule(command->line, command->filename.c_str(), &env, - command->type, "assert_invalid"); + wabt::Result result = ReadInvalidModule( + command->line, command->filename, &env, command->type, "assert_invalid"); if (Succeeded(result)) { PrintError(command->line, "expected module to be invalid: \"%s\"", command->filename.c_str()); @@ -1235,7 +1234,7 @@ wabt::Result CommandRunner::OnAssertUninstantiableCommand( DefinedModule* module; Environment::MarkPoint mark = env_.Mark(); wabt::Result result = - ReadModule(command->filename.c_str(), &env_, &error_handler, &module); + ReadModule(command->filename, &env_, &error_handler, &module); if (Succeeded(result)) { ExecResult exec_result = executor_.RunStartFunction(module); @@ -1395,7 +1394,7 @@ void CommandRunner::TallyCommand(wabt::Result result) { total_++; } -static wabt::Result ReadAndRunSpecJSON(const char* spec_json_filename) { +static wabt::Result ReadAndRunSpecJSON(string_view spec_json_filename) { JSONParser parser; CHECK_RESULT(parser.ReadFile(spec_json_filename)); diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc index 11f401c8..96fe5240 100644 --- a/src/tools/wasm2wat.cc +++ b/src/tools/wasm2wat.cc @@ -125,7 +125,7 @@ int ProgramMain(int argc, char** argv) { } if (Succeeded(result)) { - FileStream stream(!s_outfile.empty() ? FileStream(s_outfile.c_str()) + FileStream stream(!s_outfile.empty() ? FileStream(s_outfile) : FileStream(stdout)); result = WriteWat(&stream, &module, &s_write_wat_options); } diff --git a/src/wast-lexer.cc b/src/wast-lexer.cc index de47a0bc..008bc3c1 100644 --- a/src/wast-lexer.cc +++ b/src/wast-lexer.cc @@ -82,7 +82,7 @@ namespace wabt { -WastLexer::WastLexer(std::unique_ptr<LexerSource> source, const char* filename) +WastLexer::WastLexer(std::unique_ptr<LexerSource> source, string_view filename) : source_(std::move(source)), line_finder_(source_->Clone()), filename_(filename), @@ -103,13 +103,13 @@ WastLexer::~WastLexer() { } // static -std::unique_ptr<WastLexer> WastLexer::CreateFileLexer(const char* filename) { +std::unique_ptr<WastLexer> WastLexer::CreateFileLexer(string_view filename) { std::unique_ptr<LexerSource> source(new LexerSourceFile(filename)); return std::unique_ptr<WastLexer>(new WastLexer(std::move(source), filename)); } // static -std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(const char* filename, +std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(string_view filename, const void* data, size_t size) { std::unique_ptr<LexerSource> source(new LexerSourceBuffer(data, size)); diff --git a/src/wast-lexer.h b/src/wast-lexer.h index 284a73e7..f6bfcad8 100644 --- a/src/wast-lexer.h +++ b/src/wast-lexer.h @@ -37,12 +37,12 @@ class WastLexer { public: WABT_DISALLOW_COPY_AND_ASSIGN(WastLexer); - WastLexer(std::unique_ptr<LexerSource> source, const char* filename); + WastLexer(std::unique_ptr<LexerSource> source, string_view filename); ~WastLexer(); // Convenience functions. - static std::unique_ptr<WastLexer> CreateFileLexer(const char* filename); - static std::unique_ptr<WastLexer> CreateBufferLexer(const char* filename, + static std::unique_ptr<WastLexer> CreateFileLexer(string_view filename); + static std::unique_ptr<WastLexer> CreateBufferLexer(string_view filename, const void* data, size_t size); @@ -59,7 +59,7 @@ class WastLexer { std::unique_ptr<LexerSource> source_; LexerSourceLineFinder line_finder_; - const char* filename_; + std::string filename_; int line_; int comment_nesting_; size_t buffer_file_offset_; // File offset of the start of the buffer. |