Verified Commit cb4e06e2 authored by nagayama15's avatar nagayama15

add an extra parameter to import functions

parent 7f7ca746
#include <fmt/printf.h> #include <fmt/printf.h>
#include "cmdline.h" #include "cmdline.h"
#include "wasm-io.h" #include "wasm-io.h"
#include "wasm-validator.h"
namespace { namespace {
const std::string program_name = "kyuk"; const std::string program_name = "kyuk";
const std::string version = "0.1.0"; const std::string version = "0.1.0";
void add_parameter(wasm::Function& f) {
wasm::Type new_param{wasm::Type::i32};
switch (f.sig.params.getID()) {
case wasm::Type::none:
// No parameter
f.sig.params = new_param;
break;
case wasm::Type::i32:
case wasm::Type::i64:
case wasm::Type::f32:
case wasm::Type::f64:
case wasm::Type::v128:
// 1 primitive parameter
f.sig.params = wasm::Type{f.sig.params, new_param};
break;
default:
if (f.sig.params.isTuple()) {
// 2 or more parameters
wasm::Tuple tuple{};
for (const auto& t : f.sig.params) {
tuple.types.emplace_back(t);
}
tuple.types.emplace_back(new_param);
f.sig.params = wasm::Type{tuple};
} else {
// May not be reached
throw std::runtime_error{"unknown parameter type"};
}
break;
}
}
} // namespace } // namespace
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
...@@ -60,7 +96,26 @@ int main(int argc, char* argv[]) { ...@@ -60,7 +96,26 @@ int main(int argc, char* argv[]) {
wasm::Module module{}; wasm::Module module{};
wasm::ModuleReader{}.read(input, module); wasm::ModuleReader{}.read(input, module);
// TODO: Embedding // Embedding
// TODO: Add extra arguments to import function callings
// Add extra parameters to import functions
for (const auto& f : module.functions) {
if (f->body != nullptr) {
continue;
}
// `f` is an import function
fmt::print("f: {}, {}\n", f->name, f->sig.params.toString());
add_parameter(*f);
fmt::print("f: {}, {}\n", f->name, f->sig.params.toString());
}
// Validation
if (!wasm::WasmValidator{}.validate(module)) {
std::exit(EXIT_FAILURE);
}
wasm::ModuleWriter w{}; wasm::ModuleWriter w{};
w.setDebugInfo(preserve_debug); w.setDebugInfo(preserve_debug);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment