#pragma once #include #include #include "WAVM/IR/FeatureSpec.h" #include "WAVM/IR/Module.h" #include "WAVM/IR/Value.h" #include "WAVM/Inline/BasicTypes.h" #include "WAVM/WASTParse/WASTParse.h" namespace WAVM { namespace WAST { struct Command { enum Type { _register, action, assert_return, assert_return_arithmetic_nan, assert_return_canonical_nan, assert_return_arithmetic_nan_f32x4, assert_return_canonical_nan_f32x4, assert_return_arithmetic_nan_f64x2, assert_return_canonical_nan_f64x2, assert_return_func, assert_trap, assert_throws, assert_invalid, assert_malformed, assert_unlinkable, benchmark, }; const Type type; const TextFileLocus locus; Command(Type inType, TextFileLocus&& inLocus) : type(inType), locus(inLocus) {} virtual ~Command() {} }; // Parse a test script from a string. Returns true if it succeeds, and writes the test commands // to outTestCommands. WAVM_API void parseTestCommands(const char* string, Uptr stringLength, const IR::FeatureSpec& featureSpec, std::vector>& outTestCommands, std::vector& outErrors); // Actions enum class ActionType { _module, invoke, get, }; enum class ExpectedTrapType { outOfBounds, outOfBoundsMemoryAccess, outOfBoundsTableAccess, outOfBoundsDataSegmentAccess, outOfBoundsElemSegmentAccess, stackOverflow, integerDivideByZeroOrIntegerOverflow, invalidFloatOperation, invokeSignatureMismatch, reachedUnreachable, indirectCallSignatureMismatch, uninitializedTableElement, outOfMemory, misalignedAtomicMemoryAccess, invalidArgument }; struct Action { const ActionType type; const TextFileLocus locus; Action(ActionType inType, TextFileLocus&& inLocus) : type(inType), locus(inLocus) {} virtual ~Action() {} }; struct ModuleAction : Action { std::string internalModuleName; std::unique_ptr module; ModuleAction(TextFileLocus&& inLocus, std::string&& inInternalModuleName, std::unique_ptr&& inModule) : Action(ActionType::_module, std::move(inLocus)) , internalModuleName(inInternalModuleName) , module(std::move(inModule)) { } }; struct InvokeAction : Action { std::string internalModuleName; std::string exportName; std::vector arguments; InvokeAction(TextFileLocus&& inLocus, std::string&& inInternalModuleName, std::string&& inExportName, std::vector&& inArguments) : Action(ActionType::invoke, std::move(inLocus)) , internalModuleName(inInternalModuleName) , exportName(inExportName) , arguments(inArguments) { } }; struct GetAction : Action { std::string internalModuleName; std::string exportName; GetAction(TextFileLocus&& inLocus, std::string&& inInternalModuleName, std::string&& inExportName) : Action(ActionType::get, std::move(inLocus)) , internalModuleName(inInternalModuleName) , exportName(inExportName) { } }; // Commands struct RegisterCommand : Command { std::string moduleName; std::string internalModuleName; RegisterCommand(TextFileLocus&& inLocus, std::string&& inModuleName, std::string&& inInternalModuleName) : Command(Command::_register, std::move(inLocus)) , moduleName(inModuleName) , internalModuleName(inInternalModuleName) { } }; struct ActionCommand : Command { std::unique_ptr action; ActionCommand(TextFileLocus&& inLocus, std::unique_ptr&& inAction) : Command(Command::action, std::move(inLocus)), action(std::move(inAction)) { } }; struct AssertReturnCommand : Command { std::unique_ptr action; std::vector expectedResults; AssertReturnCommand(TextFileLocus&& inLocus, std::unique_ptr&& inAction, std::vector inExpectedResults) : Command(Command::assert_return, std::move(inLocus)) , action(std::move(inAction)) , expectedResults(inExpectedResults) { } }; struct AssertReturnNaNCommand : Command { std::unique_ptr action; AssertReturnNaNCommand(Command::Type inType, TextFileLocus&& inLocus, std::unique_ptr&& inAction) : Command(inType, std::move(inLocus)), action(std::move(inAction)) { } }; struct AssertReturnFuncCommand : Command { std::unique_ptr action; AssertReturnFuncCommand(TextFileLocus&& inLocus, std::unique_ptr&& inAction) : Command(Command::assert_return_func, std::move(inLocus)), action(std::move(inAction)) { } }; struct AssertTrapCommand : Command { std::unique_ptr action; ExpectedTrapType expectedType; AssertTrapCommand(TextFileLocus&& inLocus, std::unique_ptr&& inAction, ExpectedTrapType inExpectedType) : Command(Command::assert_trap, std::move(inLocus)) , action(std::move(inAction)) , expectedType(inExpectedType) { } }; struct AssertThrowsCommand : Command { std::unique_ptr action; std::string exceptionTypeInternalModuleName; std::string exceptionTypeExportName; std::vector expectedArguments; AssertThrowsCommand(TextFileLocus&& inLocus, std::unique_ptr&& inAction, std::string&& inExceptionTypeInternalModuleName, std::string&& inExceptionTypeExportName, std::vector&& inExpectedArguments) : Command(Command::assert_throws, std::move(inLocus)) , action(std::move(inAction)) , exceptionTypeInternalModuleName(inExceptionTypeInternalModuleName) , exceptionTypeExportName(inExceptionTypeExportName) , expectedArguments(inExpectedArguments) { } }; enum class QuotedModuleType { none, text, binary }; enum class InvalidOrMalformed { wellFormedAndValid, invalid, malformed }; struct AssertInvalidOrMalformedCommand : Command { InvalidOrMalformed wasInvalidOrMalformed; QuotedModuleType quotedModuleType; std::string quotedModuleString; AssertInvalidOrMalformedCommand(Command::Type inType, TextFileLocus&& inLocus, InvalidOrMalformed inWasInvalidOrMalformed, QuotedModuleType inQuotedModuleType, std::string&& inQuotedModuleString) : Command(inType, std::move(inLocus)) , wasInvalidOrMalformed(inWasInvalidOrMalformed) , quotedModuleType(inQuotedModuleType) , quotedModuleString(inQuotedModuleString) { } }; struct AssertUnlinkableCommand : Command { std::unique_ptr moduleAction; AssertUnlinkableCommand(TextFileLocus&& inLocus, std::unique_ptr inModuleAction) : Command(Command::assert_unlinkable, std::move(inLocus)) , moduleAction(std::move(inModuleAction)) { } }; struct BenchmarkCommand : Command { std::string name; std::unique_ptr invokeAction; BenchmarkCommand(TextFileLocus&& inLocus, std::string&& inName, std::unique_ptr&& inInvokeAction) : Command(Command::benchmark, std::move(inLocus)) , name(std::move(inName)) , invokeAction(std::move(inInvokeAction)) { } }; }}