diff --git a/libgm/tools/gmpack.cpp b/libgm/tools/gmpack.cpp index 8ef9222..c237777 100644 --- a/libgm/tools/gmpack.cpp +++ b/libgm/tools/gmpack.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "wasmexcept.hpp" #include "Bitstream.hpp" #include "Chip.hpp" #include "ChipConfig.hpp" diff --git a/libgm/tools/gmunpack.cpp b/libgm/tools/gmunpack.cpp index d5549d6..b2f0349 100644 --- a/libgm/tools/gmunpack.cpp +++ b/libgm/tools/gmunpack.cpp @@ -23,6 +23,7 @@ #include #include #include +#include "wasmexcept.hpp" #include "Bitstream.hpp" #include "Chip.hpp" #include "ChipConfig.hpp" diff --git a/libgm/tools/wasmexcept.hpp b/libgm/tools/wasmexcept.hpp new file mode 100644 index 0000000..2da4693 --- /dev/null +++ b/libgm/tools/wasmexcept.hpp @@ -0,0 +1,25 @@ +#if defined(__wasm) + +#include +#include + +extern "C" { +// FIXME: WASI does not currently support exceptions. +void *__cxa_allocate_exception(size_t thrown_size) throw() { return malloc(thrown_size); } +bool __cxa_uncaught_exception() throw(); +void __cxa_throw(void *thrown_exception, struct std::type_info *tinfo, void (*dest)(void *)) { (void)thrown_exception; (void)tinfo; (void)dest; std::terminate(); } +} + +namespace boost { +struct source_location; +void throw_exception(std::exception const &e) { + std::cerr << "boost::exception(): " << e.what() << std::endl; + exit(1); +} +void throw_exception(std::exception const &e, boost::source_location const &) { + std::cerr << "boost::exception(): " << e.what() << std::endl; + exit(1); +} +} // namespace boost + +#endif