Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadModule(type: string, filename: string): Instance {
const internalInstanceOptions = {
checkForI64InSignature: false,
returnStackLocal: true
};
const importObject = {
_internalInstanceOptions: internalInstanceOptions
};
if (type === "text") {
const content = readFileSync(join(WASM_TEST_DIR, filename), "utf8");
// we need a module in order to be compiled
const ast = parse("(module " + content + ")");
// TODO(sven): pass fakeCompiler here?
const module = createCompiledModule(ast);
return new Instance(module, importObject);
} else if (type === "binary") {
// $FlowIgnore
const buff = readFileSync(join(WASM_TEST_DIR, filename), null);
const ast = decode(buff, decoderOpts);
const module = createCompiledModule(ast);
return new Instance(module, importObject);
} else {
throw new Error("unsupported module type: " + type);
}
}
// @flow
const wastIdentifierToIndex = require("@webassemblyjs/ast/lib/transform/wast-identifier-to-index");
const denormalizeTypeReferences = require("@webassemblyjs/ast/lib/transform/denormalize-type-references");
const { parse } = require("@webassemblyjs/wast-parser");
const { print } = require("@webassemblyjs/wast-printer");
const { readFileSync } = require("fs");
const filename = process.argv[2];
if (typeof filename === "undefined") {
throw new Error("Missing file");
}
const content = readFileSync(filename, "utf8");
const ast = parse(content);
denormalizeTypeReferences.transform(ast);
wastIdentifierToIndex.transform(ast);
console.log(print(ast));
function replEval(input) {
if (isVerbose === true) {
console.log(input);
}
const ast = parse(input);
const [node] = ast.body;
// Empty input, skip this iteration
if (node === undefined) {
return;
}
if (node.type === "Instr") {
if (node.id === "assert_invalid") {
return assert_invalid(node);
}
if (node.id === "assert_return") {
return assert_return(node);
}
#!/usr/bin/env node
// @flow
const { parseSource } = require("@webassemblyjs/wast-parser");
const { readFileSync } = require("fs");
const filename = process.argv[2];
if (typeof filename === "undefined") {
throw new Error("Missing file");
}
const content = readFileSync(filename, "utf8");
const ast = parseSource(content);
console.log(JSON.stringify(ast, null, 2));
function replEval(input) {
if (isVerbose === true) {
onLog(input);
}
const ast = parse(input);
const [node] = ast.body;
// Empty input, skip this iteration
if (node === undefined) {
return;
}
if (node.type === "Instr") {
if (node.id === "assert_invalid") {
return assert_invalid(node);
}
if (node.id === "assert_return") {
return assert_return(node);
}
} else {
switch (instructionType) {
case "i32": {
return numberLiteral(parse32I(rawValue), String(original));
}
case "u32": {
return numberLiteral(parseU32(rawValue), String(original));
}
case "i64": {
return longNumberLiteral(parse64I(rawValue), String(original));
}
case "f32": {
return floatLiteral(
parse32F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
// f64
default: {
return floatLiteral(
parse64F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
}
}
}
return numberLiteral(parse32I(rawValue), String(original));
}
case "u32":
{
return numberLiteral(parseU32(rawValue), String(original));
}
case "i64":
{
return longNumberLiteral(parse64I(rawValue), String(original));
}
case "f32":
{
return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
}
// f64
default:
{
return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
}
}
}
}
export function instruction(id) {
return longNumberLiteral(parse64I(rawValue), String(original));
}
case "f32": {
return floatLiteral(
parse32F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
// f64
default: {
return floatLiteral(
parse64F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
}
}
}
}
case "i64":
{
return longNumberLiteral(parse64I(rawValue), String(original));
}
case "f32":
{
return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
}
// f64
default:
{
return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
}
}
}
}
export function instruction(id) {
return numberLiteral(rawValue, String(original));
} else {
switch (instructionType) {
case "i32": {
return numberLiteral(parse32I(rawValue), String(original));
}
case "u32": {
return numberLiteral(parseU32(rawValue), String(original));
}
case "i64": {
return longNumberLiteral(parse64I(rawValue), String(original));
}
case "f32": {
return floatLiteral(
parse32F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
// f64
default: {
return floatLiteral(
parse64F(rawValue),
isNanLiteral(rawValue),
isInfLiteral(rawValue),
String(original)
);
}
}
}
}