Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
IR Namespace Reference

Classes

struct  BranchImm
 
struct  BranchTableImm
 
struct  CallImm
 
struct  CallIndirectImm
 
struct  CodeValidationProxyStream
 
struct  CodeValidationStream
 
struct  CodeValidationStreamImpl
 
struct  ControlStructureImm
 
struct  DataSegment
 
struct  DisassemblyNames
 
struct  Export
 
struct  FromResultType
 
struct  FromResultType< ResultType::f32 >
 
struct  FromResultType< ResultType::f64 >
 
struct  FromResultType< ResultType::i32 >
 
struct  FromResultType< ResultType::i64 >
 
struct  FromResultType< ResultType::none >
 
struct  FromValueType
 
struct  FromValueType< ValueType::any >
 
struct  FromValueType< ValueType::f32 >
 
struct  FromValueType< ValueType::f64 >
 
struct  FromValueType< ValueType::i32 >
 
struct  FromValueType< ValueType::i64 >
 
struct  FunctionDef
 
struct  FunctionType
 
struct  FunctionTypeMap
 
struct  FunctionValidationContext
 
struct  GetOrSetVariableImm
 
struct  GlobalDef
 
struct  GlobalType
 
struct  Import
 
struct  IndexedFunctionType
 
struct  IndexSpace
 
struct  InitializerExpression
 
struct  LiteralImm
 
struct  LoadOrStoreImm
 
struct  MemoryDef
 
struct  MemoryImm
 
struct  MemoryType
 
struct  Module
 
struct  NoImm
 
struct  ObjectType
 
struct  OpcodeAndImm< MemoryImm >
 
struct  OpcodeAndImm< NoImm >
 
struct  OperatorDecoderStream
 
struct  OperatorEncoderStream
 
struct  OperatorPrinter
 
struct  SizeConstraints
 
struct  TableDef
 
struct  TableSegment
 
struct  TableType
 
struct  ToResultType
 
struct  ToResultType< 0 >
 
struct  ToResultType< 1 >
 
struct  ToResultType< 2 >
 
struct  ToResultType< 3 >
 
struct  ToResultType< 4 >
 
struct  ToValueType
 
struct  ToValueType< 0 >
 
struct  ToValueType< 1 >
 
struct  ToValueType< 2 >
 
struct  ToValueType< 3 >
 
struct  ToValueType< 4 >
 
struct  UserSection
 
struct  ValidationException
 
struct  ValueTypeInfo
 
struct  ValueTypeInfo< ValueType::f32 >
 
struct  ValueTypeInfo< ValueType::f64 >
 
struct  ValueTypeInfo< ValueType::i32 >
 
struct  ValueTypeInfo< ValueType::i64 >
 

Typedefs

typedef Import< UptrFunctionImport
 
typedef Import< TableTypeTableImport
 
typedef Import< MemoryTypeMemoryImport
 
typedef Import< GlobalTypeGlobalImport
 

Enumerations

enum  { maxMemoryPages = (Uptr)65536 }
 
enum  { numBytesPerPage = (Uptr)65536 }
 
enum  { numBytesPerPageLog2 = (Uptr)16 }
 
enum  { requireSharedFlagForAtomicOperators = false }
 
enum class  Opcode : U16 { VISIT_OPCODE , maxSingleByteOpcode = 0xcf }
 
enum class  ValueType : U8 {
  any = 0 , i32 = 1 , i64 = 2 , f32 = 3 ,
  f64 = 4 , num , max = num-1
}
 
enum class  ResultType : U8 {
  none = 0 , i32 = (U8)ValueType::i32 , i64 = (U8)ValueType::i64 , f32 = (U8)ValueType::f32 ,
  f64 = (U8)ValueType::f64 , num , max = num-1
}
 
enum class  TableElementType : U8 { anyfunc = 0x70 }
 
enum class  ObjectKind : U8 {
  function = 0 , table = 1 , memory = 2 , global = 3 ,
  module = 4 , max = 4 , invalid = 0xff
}
 

Functions

bool findUserSection (const Module &module, const char *userSectionName, Uptr &outUserSectionIndex)
 
IR_API void getDisassemblyNames (const Module &module, DisassemblyNames &outNames)
 
IR_API void setDisassemblyNames (Module &module, const DisassemblyNames &names)
 
 PACKED_STRUCT (template< typename Imm > struct OpcodeAndImm { Opcode opcode;Imm imm;})
 
IR_API const char * getOpcodeName (Opcode opcode)
 
std::string asString (I32 value)
 
std::string asString (I64 value)
 
std::string asString (F32 value)
 
std::string asString (F64 value)
 
U8 getTypeBitWidth (ValueType type)
 
const char * asString (ValueType type)
 
Uptr getArity (ResultType returnType)
 
const char * asString (ResultType type)
 
ValueType asValueType (ResultType type)
 
ResultType asResultType (ValueType type)
 
std::string asString (const std::vector< ValueType > &typeTuple)
 
std::string asString (const FunctionType *functionType)
 
std::string asString (const GlobalType &globalType)
 
std::string asString (const ObjectType &objectType)
 
IR_API void validateDefinitions (const IR::Module &module)
 
template<typename Key , typename Value , typename CreateValueThunk >
Value findExistingOrCreateNew (std::map< Key, Value > &map, Key &&key, CreateValueThunk createValueThunk)
 
void validate (ValueType valueType)
 
void validate (ResultType returnType)
 
void validate (ObjectKind kind)
 
void validate (SizeConstraints size, Uptr maxMax)
 
void validate (TableElementType type)
 
void validate (TableType type)
 
void validate (MemoryType type)
 
void validate (GlobalType type)
 
void validateImportKind (ObjectType importType, ObjectKind expectedKind)
 
template<typename Type >
void validateType (Type expectedType, Type actualType, const char *context)
 
void validateOperandType (ValueType expectedType, ValueType actualType, const char *context)
 
ValueType validateGlobalIndex (const Module &module, Uptr globalIndex, bool mustBeMutable, bool mustBeImmutable, bool mustBeImport, const char *context)
 
const FunctionTypevalidateFunctionIndex (const Module &module, Uptr functionIndex)
 
void validateInitializer (const Module &module, const InitializerExpression &expression, ValueType expectedType, const char *context)
 
template<typename Stream >
void serialize (Stream &stream, ValueType &type)
 
template<typename Stream >
void serialize (Stream &stream, SizeConstraints &sizeConstraints, bool hasMax)
 
template<typename Stream >
void serialize (Stream &stream, TableElementType &elementType)
 
template<typename Stream >
void serialize (Stream &stream, TableType &tableType)
 
template<typename Stream >
void serialize (Stream &stream, MemoryType &memoryType)
 
template<typename Stream >
void serialize (Stream &stream, GlobalType &globalType)
 
template<typename Stream >
void serialize (Stream &stream, ObjectKind &kind)
 
template<typename Stream >
void serialize (Stream &stream, Export &e)
 
template<typename Stream >
void serialize (Stream &stream, InitializerExpression &initializer)
 
template<typename Stream >
void serialize (Stream &stream, TableDef &tableDef)
 
template<typename Stream >
void serialize (Stream &stream, MemoryDef &memoryDef)
 
template<typename Stream >
void serialize (Stream &stream, GlobalDef &globalDef)
 
template<typename Stream >
void serialize (Stream &stream, DataSegment &dataSegment)
 
template<typename Stream >
void serialize (Stream &stream, TableSegment &tableSegment)
 

Typedef Documentation

◆ FunctionImport

Definition at line 77 of file Module.h.

◆ GlobalImport

Definition at line 80 of file Module.h.

◆ MemoryImport

Definition at line 79 of file Module.h.

◆ TableImport

Definition at line 78 of file Module.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
maxMemoryPages 

Definition at line 11 of file IR.h.

11{ maxMemoryPages = (Uptr)65536 };
PointerIntHelper< sizeof(size_t)>::UnsignedIntType Uptr
Definition BasicTypes.h:22
@ maxMemoryPages
Definition IR.h:11

◆ anonymous enum

anonymous enum
Enumerator
numBytesPerPage 

Definition at line 12 of file IR.h.

12{ numBytesPerPage = (Uptr)65536 };
@ numBytesPerPage
Definition IR.h:12

◆ anonymous enum

anonymous enum
Enumerator
numBytesPerPageLog2 

Definition at line 13 of file IR.h.

@ numBytesPerPageLog2
Definition IR.h:13

◆ anonymous enum

anonymous enum
Enumerator
requireSharedFlagForAtomicOperators 

Definition at line 15 of file IR.h.

@ requireSharedFlagForAtomicOperators
Definition IR.h:15

◆ ObjectKind

enum class IR::ObjectKind : U8
strong
Enumerator
function 
table 
memory 
global 
module 
max 
invalid 

Definition at line 306 of file Types.h.

307 {
308 function = 0,
309 table = 1,
310 memory = 2,
311 global = 3,
312 module = 4,
313 max = 4,
314 invalid = 0xff,
315 };

◆ Opcode

enum class IR::Opcode : U16
strong
Enumerator
VISIT_OPCODE 
maxSingleByteOpcode 

Definition at line 575 of file Operators.h.

576 {
577 #define VISIT_OPCODE(opcode,name,...) name = opcode,
579 #undef VISIT_OPCODE
580
581 maxSingleByteOpcode = 0xcf,
582 };
#define ENUM_OPERATORS(visitOp)
Definition Operators.h:571
#define VISIT_OPCODE(opcode, name,...)
Definition Operators.h:577
@ maxSingleByteOpcode

◆ ResultType

enum class IR::ResultType : U8
strong
Enumerator
none 
i32 
i64 
f32 
f64 
num 
max 

Definition at line 133 of file Types.h.

134 {
135 none = 0,
136 i32 = (U8)ValueType::i32,
137 i64 = (U8)ValueType::i64,
138 f32 = (U8)ValueType::f32,
139 f64 = (U8)ValueType::f64,
140 #if ENABLE_SIMD_PROTOTYPE
141 v128 = (U8)ValueType::v128,
142 #endif
143 num,
144 max = num-1,
145 };
uint8_t U8
Definition BasicTypes.h:5

◆ TableElementType

enum class IR::TableElementType : U8
strong
Enumerator
anyfunc 

Definition at line 246 of file Types.h.

247 {
248 anyfunc = 0x70
249 };

◆ ValueType

enum class IR::ValueType : U8
strong
Enumerator
any 
i32 
i64 
f32 
f64 
num 
max 

Definition at line 13 of file Types.h.

14 {
15 any = 0,
16 i32 = 1,
17 i64 = 2,
18 f32 = 3,
19 f64 = 4,
20
21 #if ENABLE_SIMD_PROTOTYPE
22 v128 = 5,
23 #endif
24
25 num,
26 max = num-1
27 };

Function Documentation

◆ asResultType()

ResultType IR::asResultType ( ValueType type)
inline

Definition at line 186 of file Types.h.

187 {
188 WAVM_ASSERT_THROW(type != ValueType::any);
189 return (ResultType)type;
190 }
#define WAVM_ASSERT_THROW(cond)
Definition Errors.h:29
ResultType
Definition Types.h:134
yh_object_type type
Definition yubihsm.h:672
Here is the caller graph for this function:

◆ asString() [1/10]

std::string IR::asString ( const FunctionType * functionType)
inline

Definition at line 225 of file Types.h.

226 {
227 return asString(functionType->parameters) + "->" + asString(functionType->ret);
228 }
ResultType ret
Definition Types.h:195
std::vector< ValueType > parameters
Definition Types.h:196
Here is the call graph for this function:

◆ asString() [2/10]

std::string IR::asString ( const GlobalType & globalType)
inline

Definition at line 299 of file Types.h.

300 {
301 if(globalType.isMutable) { return std::string("global ") + asString(globalType.valueType); }
302 else { return std::string("immutable ") + asString(globalType.valueType); }
303 }
ValueType valueType
Definition Types.h:287
bool isMutable
Definition Types.h:288
Here is the call graph for this function:

◆ asString() [3/10]

std::string IR::asString ( const ObjectType & objectType)
inline

Definition at line 358 of file Types.h.

359 {
360 switch(objectType.kind)
361 {
362 case ObjectKind::function: return "func " + asString(asFunctionType(objectType));
363 case ObjectKind::table: return "table";
364 case ObjectKind::memory: return "memory";
365 case ObjectKind::global: return asString(asGlobalType(objectType));
366 default: Errors::unreachable();
367 };
368 }
void unreachable()
Definition Errors.h:22
const ObjectKind kind
Definition Types.h:318
Here is the call graph for this function:

◆ asString() [4/10]

std::string IR::asString ( const std::vector< ValueType > & typeTuple)
inline

Definition at line 213 of file Types.h.

214 {
215 std::string result = "(";
216 for(Uptr parameterIndex = 0;parameterIndex < typeTuple.size();++parameterIndex)
217 {
218 if(parameterIndex != 0) { result += ','; }
219 result += asString(typeTuple[parameterIndex]);
220 }
221 result += ")";
222 return result;
223 }
Here is the call graph for this function:

◆ asString() [5/10]

std::string IR::asString ( F32 value)
inline

Definition at line 52 of file Types.h.

52{ return std::to_string(value); }
#define value
Definition pkcs11.h:157

◆ asString() [6/10]

std::string IR::asString ( F64 value)
inline

Definition at line 53 of file Types.h.

53{ return std::to_string(value); }

◆ asString() [7/10]

std::string IR::asString ( I32 value)
inline

Definition at line 50 of file Types.h.

50{ return std::to_string(value); }
Here is the caller graph for this function:

◆ asString() [8/10]

std::string IR::asString ( I64 value)
inline

Definition at line 51 of file Types.h.

51{ return std::to_string(value); }

◆ asString() [9/10]

const char * IR::asString ( ResultType type)
inline

Definition at line 163 of file Types.h.

164 {
165 switch(type)
166 {
167 case ResultType::i32: return "i32";
168 case ResultType::i64: return "i64";
169 case ResultType::f32: return "f32";
170 case ResultType::f64: return "f64";
171 #if ENABLE_SIMD_PROTOTYPE
172 case ResultType::v128: return "v128";
173 #endif
174 case ResultType::none: return "()";
175 default: Errors::unreachable();
176 };
177 }
Here is the call graph for this function:

◆ asString() [10/10]

const char * IR::asString ( ValueType type)
inline

Definition at line 116 of file Types.h.

117 {
118 switch(type)
119 {
120 case ValueType::any: return "any";
121 case ValueType::i32: return "i32";
122 case ValueType::i64: return "i64";
123 case ValueType::f32: return "f32";
124 case ValueType::f64: return "f64";
125 #if ENABLE_SIMD_PROTOTYPE
126 case ValueType::v128: return "v128";
127 #endif
128 default: Errors::unreachable();
129 };
130 }
Here is the call graph for this function:

◆ asValueType()

ValueType IR::asValueType ( ResultType type)
inline

Definition at line 180 of file Types.h.

181 {
182 WAVM_ASSERT_THROW(type != ResultType::none);
183 return (ValueType)type;
184 }
ValueType
Definition Types.h:14
Here is the caller graph for this function:

◆ findExistingOrCreateNew()

template<typename Key , typename Value , typename CreateValueThunk >
Value IR::findExistingOrCreateNew ( std::map< Key, Value > & map,
Key && key,
CreateValueThunk createValueThunk )

Definition at line 26 of file Types.cpp.

27 {
28 auto mapIt = map.find(key);
29 if(mapIt != map.end()) { return mapIt->second; }
30 else
31 {
32 Value value = createValueThunk();
33 map.insert({std::move(key),value});
34 return value;
35 }
36 }
Here is the caller graph for this function:

◆ findUserSection()

bool IR::findUserSection ( const Module & module,
const char * userSectionName,
Uptr & outUserSectionIndex )
inline

Definition at line 149 of file Module.h.

150 {
151 for(Uptr sectionIndex = 0;sectionIndex < module.userSections.size();++sectionIndex)
152 {
153 if(module.userSections[sectionIndex].name == userSectionName)
154 {
155 outUserSectionIndex = sectionIndex;
156 return true;
157 }
158 }
159 return false;
160 }
Here is the caller graph for this function:

◆ getArity()

Uptr IR::getArity ( ResultType returnType)
inline

Definition at line 161 of file Types.h.

161{ return returnType == ResultType::none ? 0 : 1; }

◆ getDisassemblyNames()

void IR::getDisassemblyNames ( const Module & module,
DisassemblyNames & outNames )

Definition at line 11 of file DisassemblyNames.cpp.

12 {
13 // Fill in the output with the correct number of blank names.
14 for(const auto& functionImport : module.functions.imports)
15 {
16 DisassemblyNames::Function functionNames;
17 functionNames.locals.resize(module.types[functionImport.type.index]->parameters.size());
18 outNames.functions.push_back(std::move(functionNames));
19 }
20 for(Uptr functionDefIndex = 0;functionDefIndex < module.functions.defs.size();++functionDefIndex)
21 {
22 const FunctionDef& functionDef = module.functions.defs[functionDefIndex];
23 DisassemblyNames::Function functionNames;
24 functionNames.locals.insert(functionNames.locals.begin(),module.types[functionDef.type.index]->parameters.size() + functionDef.nonParameterLocalTypes.size(),"");
25 outNames.functions.push_back(std::move(functionNames));
26 }
27
28 outNames.types.insert(outNames.types.end(),module.types.size(),"");
29 outNames.tables.insert(outNames.tables.end(),module.tables.defs.size() + module.tables.imports.size(),"");
30 outNames.memories.insert(outNames.memories.end(),module.memories.defs.size() + module.memories.imports.size(),"");
31 outNames.globals.insert(outNames.globals.end(),module.globals.defs.size() + module.globals.imports.size(),"");
32
33 // Deserialize the name section, if it is present.
34 Uptr userSectionIndex = 0;
35 if(findUserSection(module,"name",userSectionIndex))
36 {
37 try
38 {
39 const UserSection& nameSection = module.userSections[userSectionIndex];
40 MemoryInputStream stream(nameSection.data.data(),nameSection.data.size());
41
42 #if 0
43 while(stream.capacity())
44 {
45 U8 substreamType = 0;
46 serializeVarUInt7(stream,substreamType);
47
48 U32 numSubstreamBytes = 0;
49 serializeVarUInt32(stream,numSubstreamBytes);
50
51 MemoryInputStream substream(stream.advance(numSubstreamBytes),numSubstreamBytes);
52 switch(substreamType)
53 {
54 case 0: // function names
55 {
56 U32 numFunctionNames = 0;
57 serializeVarUInt32(substream,numFunctionNames);
58 for(Uptr functionNameIndex = 0;functionNameIndex < numFunctionNames;++functionNameIndex)
59 {
60 U32 functionIndex = 0;
61 serializeVarUInt32(substream,functionIndex);
62
63 std::string functionName;
64 serialize(substream,functionName);
65
66 if(functionIndex < outNames.functions.size()) { outNames.functions[functionIndex].name = std::move(functionName); }
67 }
68 break;
69 }
70 case 1: // local names
71 {
72 U32 numFunctionLocalNameMaps = 0;
73 serializeVarUInt32(substream,numFunctionLocalNameMaps);
74 for(Uptr functionNameIndex = 0;functionNameIndex < numFunctionLocalNameMaps;++functionNameIndex)
75 {
76 U32 functionIndex = 0;
77 serializeVarUInt32(substream,functionIndex);
78
79 U32 numLocalNames = 0;
80 serializeVarUInt32(substream,numLocalNames);
81
82 for(Uptr localNameIndex = 0;localNameIndex < numLocalNames;++numLocalNames)
83 {
84 U32 localIndex = 0;
85 serializeVarUInt32(substream,localIndex);
86
87 std::string localName;
88 serialize(substream,localName);
89
90 if(functionIndex < outNames.functions.size() && localIndex < outNames.functions[functionIndex].locals.size())
91 {
92 outNames.functions[functionIndex].locals[localIndex] = std::move(localName);
93 }
94 }
95 }
96
97 break;
98 }
99 };
100 };
101 #endif
102
103 Uptr numFunctionNames = 0;
104 serializeVarUInt32(stream,numFunctionNames);
105 numFunctionNames = std::min(numFunctionNames,(Uptr)outNames.functions.size());
106
107 for(Uptr functionIndex = 0;functionIndex < numFunctionNames;++functionIndex)
108 {
109 DisassemblyNames::Function& functionNames = outNames.functions[functionIndex];
110
111 serialize(stream,outNames.functions[functionIndex].name);
112
113 Uptr numLocalNames = 0;
114 serializeVarUInt32(stream,numLocalNames);
115
116 for(Uptr localIndex = 0;localIndex < numLocalNames;++localIndex)
117 {
118 std::string localName;
119 serialize(stream,localName);
120 if(localIndex < functionNames.locals.size()) { functionNames.locals[localIndex] = std::move(localName); }
121 }
122 }
123 }
124 catch(FatalSerializationException exception)
125 {
126 Log::printf(Log::Category::debug,"FatalSerializationException while deserializing WASM user name section: %s\n",exception.message.c_str());
127 }
128 }
129 }
uint32_t U32
Definition BasicTypes.h:9
bool findUserSection(const Module &module, const char *userSectionName, Uptr &outUserSectionIndex)
Definition Module.h:149
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
void serializeVarUInt32(Stream &stream, Value &value)
void serialize(Stream &stream, U8 &i)
void serializeVarUInt7(Stream &stream, Value &value)
std::vector< std::string > locals
Definition Module.h:168
std::vector< std::string > memories
Definition Module.h:174
std::vector< std::string > globals
Definition Module.h:175
std::vector< std::string > tables
Definition Module.h:173
std::vector< std::string > types
Definition Module.h:171
std::vector< Function > functions
Definition Module.h:172
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOpcodeName()

const char * IR::getOpcodeName ( Opcode opcode)

Definition at line 5 of file Operators.cpp.

6 {
7 switch(opcode)
8 {
9 #define VISIT_OPCODE(encoding,name,nameString,Imm,...) case Opcode::name: return nameString;
11 #undef VISIT_OPCODE
12 default: return "unknown";
13 };
14 }
#define VISIT_OPCODE(encoding, name, nameString, Imm,...)

◆ getTypeBitWidth()

U8 IR::getTypeBitWidth ( ValueType type)
inline

Definition at line 101 of file Types.h.

102 {
103 switch(type)
104 {
105 case ValueType::i32: return 32;
106 case ValueType::i64: return 64;
107 case ValueType::f32: return 32;
108 case ValueType::f64: return 64;
109 #if ENABLE_SIMD_PROTOTYPE
110 case ValueType::v128: return 128;
111 #endif
112 default: Errors::unreachable();
113 };
114 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PACKED_STRUCT()

IR::PACKED_STRUCT ( template< typename Imm > struct OpcodeAndImm { Opcode opcode;Imm imm;} )

◆ serialize() [1/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
DataSegment & dataSegment )

Definition at line 162 of file WASMSerialization.cpp.

163 {
164 serializeVarUInt32(stream,dataSegment.memoryIndex);
165 serialize(stream,dataSegment.baseOffset);
166 serialize(stream,dataSegment.data);
167 }
std::vector< U8 > data
Definition Module.h:95
InitializerExpression baseOffset
Definition Module.h:94
Uptr memoryIndex
Definition Module.h:93
Here is the call graph for this function:

◆ serialize() [2/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
Export & e )

Definition at line 118 of file WASMSerialization.cpp.

119 {
120 serialize(stream,e.name);
121 throwIfNotValidUTF8(e.name);
122 serialize(stream,e.kind);
123 serializeVarUInt32(stream,e.index);
124 }
ObjectKind kind
Definition Module.h:86
std::string name
Definition Module.h:85
Uptr index
Definition Module.h:87
Here is the call graph for this function:

◆ serialize() [3/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
GlobalDef & globalDef )

Definition at line 155 of file WASMSerialization.cpp.

156 {
157 serialize(stream,globalDef.type);
158 serialize(stream,globalDef.initializer);
159 }
GlobalType type
Definition Module.h:64
InitializerExpression initializer
Definition Module.h:65
Here is the call graph for this function:

◆ serialize() [4/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
GlobalType & globalType )

Definition at line 103 of file WASMSerialization.cpp.

104 {
105 serialize(stream,globalType.valueType);
106 U8 isMutable = globalType.isMutable ? 1 : 0;
107 serializeVarUInt1(stream,isMutable);
108 if(Stream::isInput) { globalType.isMutable = isMutable != 0; }
109 }
void serializeVarUInt1(Stream &stream, Value &value)
Here is the call graph for this function:

◆ serialize() [5/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
InitializerExpression & initializer )

Definition at line 127 of file WASMSerialization.cpp.

128 {
129 serializeNativeValue(stream,*(U8*)&initializer.type);
130 switch(initializer.type)
131 {
132 case InitializerExpression::Type::i32_const: serializeVarInt32(stream,initializer.i32); break;
133 case InitializerExpression::Type::i64_const: serializeVarInt64(stream,initializer.i64); break;
134 case InitializerExpression::Type::f32_const: serialize(stream,initializer.f32); break;
135 case InitializerExpression::Type::f64_const: serialize(stream,initializer.f64); break;
136 case InitializerExpression::Type::get_global: serializeVarUInt32(stream,initializer.globalIndex); break;
137 default: throw FatalSerializationException("invalid initializer expression opcode");
138 }
139 serializeConstant(stream,"expected end opcode",(U8)Opcode::end);
140 }
void serializeConstant(InputStream &stream, const char *constantMismatchMessage, Constant constant)
void serializeVarInt64(Stream &stream, Value &value)
FORCEINLINE void serializeNativeValue(Stream &stream, Value &value)
void serializeVarInt32(Stream &stream, Value &value)
Here is the call graph for this function:

◆ serialize() [6/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
MemoryDef & memoryDef )

Definition at line 149 of file WASMSerialization.cpp.

150 {
151 serialize(stream,memoryDef.type);
152 }
MemoryType type
Definition Module.h:58
Here is the call graph for this function:

◆ serialize() [7/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
MemoryType & memoryType )

Definition at line 88 of file WASMSerialization.cpp.

89 {
90 Uptr flags = 0;
91 if(!Stream::isInput && memoryType.size.max != UINT64_MAX) { flags |= 0x01; }
92 #if ENABLE_THREADING_PROTOTYPE
93 if(!Stream::isInput && memoryType.isShared) { flags |= 0x10; }
95 if(Stream::isInput) { memoryType.isShared = (flags & 0x10) != 0; }
96 #else
98 #endif
99 serialize(stream,memoryType.size,flags & 0x01);
100 }
#define UINT64_MAX
Definition stdint.h:189
SizeConstraints size
Definition Types.h:274
bool isShared
Definition Types.h:273
pInfo flags
Here is the call graph for this function:

◆ serialize() [8/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
ObjectKind & kind )

Definition at line 112 of file WASMSerialization.cpp.

113 {
114 serializeNativeValue(stream,*(U8*)&kind);
115 }
Here is the call graph for this function:

◆ serialize() [9/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
SizeConstraints & sizeConstraints,
bool hasMax )

Definition at line 57 of file WASMSerialization.cpp.

58 {
59 serializeVarUInt32(stream,sizeConstraints.min);
60 if(hasMax) { serializeVarUInt32(stream,sizeConstraints.max); }
61 else if(Stream::isInput) { sizeConstraints.max = UINT64_MAX; }
62 }
Here is the call graph for this function:

◆ serialize() [10/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
TableDef & tableDef )

Definition at line 143 of file WASMSerialization.cpp.

144 {
145 serialize(stream,tableDef.type);
146 }
TableType type
Definition Module.h:52
Here is the call graph for this function:

◆ serialize() [11/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
TableElementType & elementType )

Definition at line 65 of file WASMSerialization.cpp.

66 {
67 serializeNativeValue(stream,elementType);
68 }
Here is the call graph for this function:

◆ serialize() [12/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
TableSegment & tableSegment )

Definition at line 170 of file WASMSerialization.cpp.

171 {
172 serializeVarUInt32(stream,tableSegment.tableIndex);
173 serialize(stream,tableSegment.baseOffset);
174 serializeArray(stream,tableSegment.indices,[](Stream& stream,Uptr& functionIndex){serializeVarUInt32(stream,functionIndex);});
175 }
Concept for reading and writing characters.
void serializeArray(Stream &stream, std::vector< Element, Allocator > &vector, SerializeElement serializeElement)
std::vector< Uptr > indices
Definition Module.h:103
InitializerExpression baseOffset
Definition Module.h:102
Here is the call graph for this function:

◆ serialize() [13/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
TableType & tableType )

Definition at line 71 of file WASMSerialization.cpp.

72 {
73 serialize(stream,tableType.elementType);
74
75 Uptr flags = 0;
76 if(!Stream::isInput && tableType.size.max != UINT64_MAX) { flags |= 0x01; }
77 #if ENABLE_THREADING_PROTOTYPE
78 if(!Stream::isInput && tableType.isShared) { flags |= 0x10; }
80 if(Stream::isInput) { tableType.isShared = (flags & 0x10) != 0; }
81 #else
83 #endif
84 serialize(stream,tableType.size,flags & 0x01);
85 }
TableElementType elementType
Definition Types.h:254
SizeConstraints size
Definition Types.h:256
bool isShared
Definition Types.h:255
Here is the call graph for this function:

◆ serialize() [14/14]

template<typename Stream >
void IR::serialize ( Stream & stream,
ValueType & type )

Definition at line 26 of file WASMSerialization.cpp.

27 {
28 I8 encodedValueType = -(I8)type;
29 serializeVarInt7(stream,encodedValueType);
30 if(Stream::isInput) { type = (ValueType)-encodedValueType; }
31 }
int8_t I8
Definition BasicTypes.h:6
void serializeVarInt7(Stream &stream, Value &value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDisassemblyNames()

void IR::setDisassemblyNames ( Module & module,
const DisassemblyNames & names )

Definition at line 131 of file DisassemblyNames.cpp.

132 {
133 // Replace an existing name section if one is present, or create a new section.
134 Uptr userSectionIndex = 0;
135 if(!findUserSection(module,"name",userSectionIndex))
136 {
137 userSectionIndex = module.userSections.size();
138 module.userSections.push_back({"name",{}});
139 }
140
141 ArrayOutputStream stream;
142
143 Uptr numFunctionNames = names.functions.size();
144 serializeVarUInt32(stream,numFunctionNames);
145
146 for(Uptr functionIndex = 0;functionIndex < names.functions.size();++functionIndex)
147 {
148 std::string functionName = names.functions[functionIndex].name;
149 serialize(stream,functionName);
150
151 Uptr numLocalNames = names.functions[functionIndex].locals.size();
152 serializeVarUInt32(stream,numLocalNames);
153 for(Uptr localIndex = 0;localIndex < numLocalNames;++localIndex)
154 {
155 std::string localName = names.functions[functionIndex].locals[localIndex];
156 serialize(stream,localName);
157 }
158 }
159
160 module.userSections[userSectionIndex].data = stream.getBytes();
161 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate() [1/8]

void IR::validate ( GlobalType type)

Definition at line 77 of file Validate.cpp.

78 {
79 validate(type.valueType);
80 }
bool validate(server *, websocketpp::connection_hdl)
Here is the call graph for this function:

◆ validate() [2/8]

void IR::validate ( MemoryType type)

Definition at line 68 of file Validate.cpp.

69 {
71 if(ENABLE_THREADING_PROTOTYPE)
72 {
73 VALIDATE_UNLESS("shared tables must have a maximum size: ",type.isShared && type.size.max == UINT64_MAX);
74 }
75 }
#define VALIDATE_UNLESS(reason, comparison)
Definition Validate.cpp:14
Here is the call graph for this function:

◆ validate() [3/8]

void IR::validate ( ObjectKind kind)

Definition at line 38 of file Validate.cpp.

39 {
40 if(kind > ObjectKind::max)
41 {
42 throw ValidationException("invalid external kind (" + std::to_string((Uptr)kind) + ")");
43 }
44 }

◆ validate() [4/8]

void IR::validate ( ResultType returnType)

Definition at line 30 of file Validate.cpp.

31 {
32 if(returnType > ResultType::max)
33 {
34 throw ValidationException("invalid return type (" + std::to_string((Uptr)returnType) + ")");
35 }
36 }

◆ validate() [5/8]

void IR::validate ( SizeConstraints size,
Uptr maxMax )

Definition at line 46 of file Validate.cpp.

47 {
48 U64 max = size.max == UINT64_MAX ? maxMax : size.max;
49 VALIDATE_UNLESS("disjoint size bounds: ",size.min>max);
50 VALIDATE_UNLESS("maximum size exceeds limit: ",max>maxMax);
51 }
uint64_t U64
Definition BasicTypes.h:11

◆ validate() [6/8]

void IR::validate ( TableElementType type)

Definition at line 53 of file Validate.cpp.

54 {
55 if(type != TableElementType::anyfunc) { throw ValidationException("invalid table element type (" + std::to_string((Uptr)type) + ")"); }
56 }

◆ validate() [7/8]

void IR::validate ( TableType type)

Definition at line 58 of file Validate.cpp.

59 {
60 validate(type.elementType);
61 validate(type.size,UINT32_MAX);
62 if(ENABLE_THREADING_PROTOTYPE)
63 {
64 VALIDATE_UNLESS("shared tables must have a maximum size: ",type.isShared && type.size.max == UINT64_MAX);
65 }
66 }
#define UINT32_MAX
Definition stdint.h:188
Here is the call graph for this function:

◆ validate() [8/8]

void IR::validate ( ValueType valueType)

Definition at line 22 of file Validate.cpp.

23 {
24 if(valueType == ValueType::any || valueType > ValueType::max)
25 {
26 throw ValidationException("invalid value type (" + std::to_string((Uptr)valueType) + ")");
27 }
28 }
Here is the caller graph for this function:

◆ validateDefinitions()

void IR::validateDefinitions ( const IR::Module & module)

Definition at line 556 of file Validate.cpp.

559 {
560 if(type != ResultType::none) { pushOperand(asValueType(type)); }
561 }
562 };
563
564 void validateDefinitions(const Module& module)
565 {
566 Timing::Timer timer;
567
568 for(Uptr typeIndex = 0;typeIndex < module.types.size();++typeIndex)
569 {
570 const FunctionType* functionType = module.types[typeIndex];
571 for(auto parameterType : functionType->parameters) { validate(parameterType); }
572 validate(functionType->ret);
573 }
574
575 for(auto& functionImport : module.functions.imports)
576 {
577 VALIDATE_INDEX(functionImport.type.index,module.types.size());
578 }
579 for(auto& tableImport : module.tables.imports) { validate(tableImport.type); }
580 for(auto& memoryImport : module.memories.imports) { validate(memoryImport.type); }
581 for(auto& globalImport : module.globals.imports)
582 {
583 validate(globalImport.type);
584 VALIDATE_UNLESS("mutable globals cannot be imported: ",globalImport.type.isMutable);
585 }
586
587 for(Uptr functionDefIndex = 0;functionDefIndex < module.functions.defs.size();++functionDefIndex)
588 {
589 const FunctionDef& functionDef = module.functions.defs[functionDefIndex];
590 VALIDATE_INDEX(functionDef.type.index,module.types.size());
591 for(auto localType : functionDef.nonParameterLocalTypes) { validate(localType); }
592 }
593
594 for(auto& globalDef : module.globals.defs)
595 {
596 validate(globalDef.type);
597 validateInitializer(module,globalDef.initializer,globalDef.type.valueType,"global initializer expression");
598 }
599
600 for(auto& tableDef : module.tables.defs) { validate(tableDef.type); }
601 VALIDATE_UNLESS("too many tables: ",module.tables.size()>1);
602
603 for(auto& memoryDef : module.memories.defs) { validate(memoryDef.type); }
604 VALIDATE_UNLESS("too many memories: ",module.memories.size()>1);
605
606 std::set<std::string> exportNameMap;
607 for(auto& exportIt : module.exports)
608 {
609 switch(exportIt.kind)
610 {
611 case ObjectKind::function:
612 VALIDATE_INDEX(exportIt.index,module.functions.size());
613 break;
614 case ObjectKind::table:
615 VALIDATE_INDEX(exportIt.index,module.tables.size());
616 break;
617 case ObjectKind::memory:
618 VALIDATE_INDEX(exportIt.index,module.memories.size());
619 break;
620 case ObjectKind::global:
621 validateGlobalIndex(module,exportIt.index,false,true,false,"exported global index");
622 break;
623 default: throw ValidationException("unknown export kind");
624 };
625
626 VALIDATE_UNLESS("duplicate export: ",exportNameMap.count(exportIt.name));
627 exportNameMap.emplace(exportIt.name);
628 }
629
630 if(module.startFunctionIndex != UINTPTR_MAX)
631 {
632 VALIDATE_INDEX(module.startFunctionIndex,module.functions.size());
633 const FunctionType* startFunctionType = module.types[module.functions.getType(module.startFunctionIndex).index];
634 VALIDATE_UNLESS("start function must not have any parameters or results: ",startFunctionType != FunctionType::get());
635 }
636
637 for(auto& dataSegment : module.dataSegments)
638 {
639 VALIDATE_INDEX(dataSegment.memoryIndex,module.memories.size());
640 validateInitializer(module,dataSegment.baseOffset,ValueType::i32,"data segment base initializer");
641 }
642
643 for(auto& tableSegment : module.tableSegments)
#define VALIDATE_INDEX(index, arraySize)
Definition Validate.cpp:20
IR_API void validateDefinitions(const IR::Module &module)
Definition Validate.cpp:556
ValueType asValueType(ResultType type)
Definition Types.h:180
void validateInitializer(const Module &module, const InitializerExpression &expression, ValueType expectedType, const char *context)
Definition Validate.cpp:125
ValueType validateGlobalIndex(const Module &module, Uptr globalIndex, bool mustBeMutable, bool mustBeImmutable, bool mustBeImport, const char *context)
Definition Validate.cpp:109
#define UINTPTR_MAX
Definition stdint.h:227
Here is the caller graph for this function:

◆ validateFunctionIndex()

const FunctionType * IR::validateFunctionIndex ( const Module & module,
Uptr functionIndex )

Definition at line 119 of file Validate.cpp.

120 {
121 VALIDATE_INDEX(functionIndex,module.functions.size());
122 return module.types[module.functions.getType(functionIndex).index];
123 }
Here is the caller graph for this function:

◆ validateGlobalIndex()

ValueType IR::validateGlobalIndex ( const Module & module,
Uptr globalIndex,
bool mustBeMutable,
bool mustBeImmutable,
bool mustBeImport,
const char * context )

Definition at line 109 of file Validate.cpp.

110 {
111 VALIDATE_INDEX(globalIndex,module.globals.size());
112 const GlobalType& globalType = module.globals.getType(globalIndex);
113 if(mustBeMutable && !globalType.isMutable) { throw ValidationException("attempting to mutate immutable global"); }
114 else if(mustBeImport && globalIndex >= module.globals.imports.size()) { throw ValidationException("global variable initializer expression may only access imported globals"); }
115 else if(mustBeImmutable && globalType.isMutable) { throw ValidationException("global variable initializer expression may only access immutable globals"); }
116 return globalType.valueType;
117 }
Here is the caller graph for this function:

◆ validateImportKind()

void IR::validateImportKind ( ObjectType importType,
ObjectKind expectedKind )

Definition at line 82 of file Validate.cpp.

83 {
84 if(importType.kind != expectedKind)
85 {
86 throw ValidationException("incorrect kind");
87 }
88 }

◆ validateInitializer()

void IR::validateInitializer ( const Module & module,
const InitializerExpression & expression,
ValueType expectedType,
const char * context )

Definition at line 125 of file Validate.cpp.

126 {
127 switch(expression.type)
128 {
129 case InitializerExpression::Type::i32_const: validateType(expectedType,ValueType::i32,context); break;
130 case InitializerExpression::Type::i64_const: validateType(expectedType,ValueType::i64,context); break;
131 case InitializerExpression::Type::f32_const: validateType(expectedType,ValueType::f32,context); break;
132 case InitializerExpression::Type::f64_const: validateType(expectedType,ValueType::f64,context); break;
133 case InitializerExpression::Type::get_global:
134 {
135 const ValueType globalValueType = validateGlobalIndex(module,expression.globalIndex,false,true,true,"initializer expression global index");
136 validateType(expectedType,globalValueType,context);
137 break;
138 }
139 default:
140 throw ValidationException("invalid initializer expression");
141 };
142 }
void validateType(Type expectedType, Type actualType, const char *context)
Definition Validate.cpp:91
Here is the call graph for this function:

◆ validateOperandType()

void IR::validateOperandType ( ValueType expectedType,
ValueType actualType,
const char * context )

Definition at line 100 of file Validate.cpp.

101 {
102 // Handle polymorphic values popped off the operand stack after unconditional branches.
103 if(expectedType != actualType && expectedType != ValueType::any && actualType != ValueType::any)
104 {
105 throw ValidationException( "type mismatch" );
106 }
107 }
Here is the caller graph for this function:

◆ validateType()

template<typename Type >
void IR::validateType ( Type expectedType,
Type actualType,
const char * context )

Definition at line 91 of file Validate.cpp.

92 {
93 if(expectedType != actualType)
94 {
96 std::string("type mismatch: expected in ") + context);
97 }
98 }
Here is the caller graph for this function: