summaryrefslogtreecommitdiff
path: root/src/support/file.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Do not add an extra null character when reading files (#6538)Thomas Lively2024-04-241-3/+3
| | | | | | | | The new wat parser currently considers itself to be at the end of the file whenever it cannot lex another token. This is not quite right, but fixing it causes parser errors because of the extra null character we were appending to files when we read them. This null character is not useful since we can already read files as `std::string`, which always has an implicit null character, so remove it. Clean up some users of `read_file` while we're at it.
* Encode command line to UTF8 on Windows (#5671)Derek Schuff2023-09-141-7/+11
| | | | | | | | | | | | | | | | This PR changes how file paths and the command line are handled. On startup on Windows, we process the wstring version of the command line (including the file paths) and re-encode it to UTF8 before handing it off to the rest of the command line handling logic. This means that all paths are stored in UTF8-encoded std::strings as they go through the program, right up until they are used to open files. At that time, they are converted to the appropriate native format with the new to_path function before passing to the stdlib open functions. This has the advantage that all of the non-file-opening code can use a single type to hold paths (which is good since std::filesystem::path has proved problematic in some cases), but has the disadvantage that someone could add new code that forgets to convert to_path before opening. That's somewhat mitigated by the fact that most of the code uses the ModuleIOBase classes for opening files. Fixes #4995
* Change `exit()` to `Fatal()`; make it possible to throw on `Fatal()`. (#5087)Brian Anderson2022-10-011-8/+6
| | | | | | | | | | | | | | | | This patch makes binaryen easier to call from other applications by making more errors recoverable instead of early-exiting. The main thing it does is change three calls to exit on I/O errors into calls to Fatal(), which is an existing custom abstraction for handling unrecoverable errors. Currently Fatal's destructor calls _Exit(1). My intent is to make it possible for Fatal to not exit, but to throw, allowing an embedding application to catch the exception. Because the previous early exits were exiting with error code EXIT_FAILURE, I also changed Fatal to exit with EXIT_FAILURE. The test suite continues to pass so I assume this is ok. Next I changed Fatal to buffer its error message until the destructor instead of immediately printing it to stderr. This is for ease of patching Fatal to throw instead. Finally, I also included the patch I need to make Fatal throw when THROW_ON_FATAL is defined at compile time. I can carry this patch out of tree, but it is a small patch, so perhaps you will be willing to take it. I am happy to remove it. Fixes #4938
* Read from stdin when the input file is `-` (#4106)Thomas Lively2021-08-271-0/+14
| | | | We already supported `-` as meaning stdout for output and this is useful in similar situations. Fixes #4105.
* Support --symbolmap and --symbolmap=FOO in wasm-opt (#3885)Alon Zakai2021-05-141-6/+5
| | | | | | | | | | wasm-as supports --symbolmap=FOO as an argument. We got a request to support the same in wasm-opt. wasm-opt does have --print-function-map which does the same, but as a pass. To unify them, use the new pass arg sugar from #3882 which allows us to add a --symbolmap pass whose argument can be set as --symbolmap=FOO. That perfectly matches the wasm-as notation. For now, keep the old --print-function-map notation as well, to not break emscripten. After we remove it there we can remove it here.
* Convert to using DEBUG macros (#2497)Sam Clegg2019-12-041-23/+14
| | | | | | This means that debugging/tracing can now be enabled and controlled centrally without managing and passing state around the codebase.
* Support response files, and use that in Asyncify (#2319)Alon Zakai2019-08-301-0/+8
| | | See emscripten-core/emscripten#9206, the asyncify names can need complex escaping, so this provides an escape hatch.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-6/+12
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-33/+50
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Move features from passOptions to Module (#2001)Thomas Lively2019-04-121-0/+3
| | | | | This allows us to emit a (potentially modified) target features section and conditionally emit other sections such as the DataCount section based on the presence of features.
* Allow tools to read from stdin (#1950)Thomas Lively2019-03-181-1/+11
| | | | This is necessary to write tests that don't require temporary files, such as in #1948, and is generally useful.
* standardize on 'template<' over 'template <' (i.e., remove a space) (#1782)Alon Zakai2018-11-291-1/+1
|
* 'std::string &' => 'std::string& ' (#1403)Alon Zakai2018-02-051-4/+4
| | | The & on the type is the proper convention.
* wasm-reduce tool (#1139)Alon Zakai2017-09-011-0/+12
| | | Reduce an interesting wasm to a smaller still interesting wasm. This takes an arbitrary command to run, and reduces the wasm as much as it can while keeping the behavior of that command fixed. This can be used to reduce compiler bugs in an arbitrary VM, etc.
* Fix wasm::read_file() to read correctly sized input strings in text mode. ↵juj2017-07-181-0/+6
| | | | (#1088)
* Wrap description (#839)Loo Rong Jie2016-11-281-0/+1
|
* add support for symbol assignments, closes #4422 (#615)Dominic Chen2016-07-111-1/+1
| | | Adds support for aliases to objects, to go along with the existing support for aliases to functions.
* Build fixes/workarounds to support Visual Studio 2013 build, which has ↵juj2016-06-211-0/+1
| | | | trouble with some new C++11 constructs. (#581)
* Changed type of flags to fix Visual Studio 2015 error (#418)BSalita2016-04-301-1/+1
| | | Changed type of flags (line 26) in read_file() from auto to std::ios_base::openmode to fix Visual Studio 2015 error.
* fix file size for binary files readAlon Zakai2016-04-211-1/+1
|
* refactor file flags into enumsAlon Zakai2016-03-311-8/+8
|
* set the binary bit on files we need to open in binary modeAlon Zakai2016-03-311-7/+12
|
* Repair broken file-size checkpjuftring2016-03-311-1/+1
|
* streampos may be signed on some platformsAlon Zakai2016-03-281-2/+2
|
* Use std::numeric_limits<uint32_t>::max() instead of 0xFFFFFFFF.Jukka Jylänki2016-03-281-2/+3
|
* Fix wasm::read_file() to abort if input file is too big to read in when ↵Jukka Jylänki2016-03-281-2/+7
| | | | building a 32-bit executable and size_t is not 64-bit.
* asm2wasm: use support's command-lineJF Bastien2016-01-111-2/+7
|
* Move file input / output to support.JF Bastien2016-01-041-0/+51