Skip to content

Commit

Permalink
Trigger JIT in parsing phase
Browse files Browse the repository at this point in the history
Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 authored and ksh8281 committed Nov 23, 2023
1 parent b6cbdb1 commit 1d852c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ void WASMParsingResult::clear()
}
}

std::pair<Optional<Module*>, std::string> WASMParser::parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len)
std::pair<Optional<Module*>, std::string> WASMParser::parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const bool useJIT, const int jitVerbose)
{
wabt::WASMBinaryReader delegate;

Expand All @@ -2508,6 +2508,10 @@ std::pair<Optional<Module*>, std::string> WASMParser::parseBinary(Store* store,
}

Module* module = new Module(store, delegate.parsingResult());
if (useJIT) {
module->jitCompile(nullptr, 0, jitVerbose);
}

return std::make_pair(module, std::string());
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/WASMParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct WASMParsingResult {
class WASMParser {
public:
// returns <result, error>
static std::pair<Optional<Module*>, std::string> parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len);
static std::pair<Optional<Module*>, std::string> parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const bool useJIT = false, const int jitVerbose = 0);
};

} // namespace Walrus
Expand Down
14 changes: 2 additions & 12 deletions src/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,14 @@ static void printF64(double v)
static Trap::TrapResult executeWASM(Store* store, const std::string& filename, const std::vector<uint8_t>& src, SpecTestFunctionTypes& functionTypes,
std::map<std::string, Instance*>* registeredInstanceMap = nullptr)
{
auto parseResult = WASMParser::parseBinary(store, filename, src.data(), src.size());
auto parseResult = WASMParser::parseBinary(store, filename, src.data(), src.size(), useJIT, jitVerbose);
if (!parseResult.second.empty()) {
Trap::TrapResult tr;
tr.exception = Exception::create(parseResult.second);
return tr;
}

auto module = parseResult.first;
if (useJIT) {
module->jitCompile(nullptr, 0, jitVerbose);
}

const auto& importTypes = module->imports();

ExternVector importValues;
Expand Down Expand Up @@ -874,19 +870,13 @@ static void executeWAST(Store* store, const std::string& filename, const std::ve

static void runExports(Store* store, const std::string& filename, const std::vector<uint8_t>& src, std::string& exportToRun)
{
auto parseResult = WASMParser::parseBinary(store, filename, src.data(), src.size());

auto parseResult = WASMParser::parseBinary(store, filename, src.data(), src.size(), useJIT, jitVerbose);
if (!parseResult.second.empty()) {
fprintf(stderr, "parse error: %s\n", parseResult.second.c_str());
return;
}

auto module = parseResult.first;

if (useJIT) {
module->jitCompile(nullptr, 0, jitVerbose);
}

const auto& importTypes = module->imports();

if (importTypes.size() != 0) {
Expand Down

0 comments on commit 1d852c6

Please sign in to comment.