Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
WAST::FunctionPrintContext Struct Reference
Collaboration diagram for WAST::FunctionPrintContext:

Public Types

typedef void Result
 

Public Member Functions

 FunctionPrintContext (ModulePrintContext &inModuleContext, Uptr functionDefIndex)
 
void printFunctionBody ()
 
void unknown (Opcode)
 
void block (ControlStructureImm imm)
 
void loop (ControlStructureImm imm)
 
void if_ (ControlStructureImm imm)
 
void else_ (NoImm imm)
 
void end (NoImm)
 
void return_ (NoImm)
 
void br (BranchImm imm)
 
void br_table (BranchTableImm imm)
 
void br_if (BranchImm imm)
 
void unreachable (NoImm)
 
void drop (NoImm)
 
void select (NoImm)
 
void get_local (GetOrSetVariableImm< false > imm)
 
void set_local (GetOrSetVariableImm< false > imm)
 
void tee_local (GetOrSetVariableImm< false > imm)
 
void get_global (GetOrSetVariableImm< true > imm)
 
void set_global (GetOrSetVariableImm< true > imm)
 
void call (CallImm imm)
 
void call_indirect (CallIndirectImm imm)
 
void printImm (NoImm)
 
void printImm (MemoryImm)
 
void printImm (LiteralImm< I32 > imm)
 
void printImm (LiteralImm< I64 > imm)
 
void printImm (LiteralImm< F32 > imm)
 
void printImm (LiteralImm< F64 > imm)
 
template<Uptr naturalAlignmentLog2>
void printImm (LoadOrStoreImm< naturalAlignmentLog2 > imm)
 

Public Attributes

ModulePrintContextmoduleContext
 
const Modulemodule
 
const FunctionDeffunctionDef
 
const FunctionTypefunctionType
 
std::string & string
 
const std::vector< std::string > & localNames
 
NameScope labelNameScope
 

Detailed Description

Definition at line 202 of file Print.cpp.

Member Typedef Documentation

◆ Result

Definition at line 204 of file Print.cpp.

Constructor & Destructor Documentation

◆ FunctionPrintContext()

WAST::FunctionPrintContext::FunctionPrintContext ( ModulePrintContext & inModuleContext,
Uptr functionDefIndex )
inline

Definition at line 215 of file Print.cpp.

216 : moduleContext(inModuleContext)
217 , module(inModuleContext.module)
218 , functionDef(inModuleContext.module.functions.defs[functionDefIndex])
219 , functionType(inModuleContext.module.types[functionDef.type.index])
220 , string(inModuleContext.string)
221 , localNames(inModuleContext.names.functions[module.functions.imports.size() + functionDefIndex].locals)
222 , labelNameScope('$')
223 {}
IndexedFunctionType type
Definition Module.h:43
IndexSpace< FunctionDef, IndexedFunctionType > functions
Definition Module.h:133
const Module & module
Definition Print.cpp:207
const std::vector< std::string > & localNames
Definition Print.cpp:212
ModulePrintContext & moduleContext
Definition Print.cpp:206
const FunctionType * functionType
Definition Print.cpp:209
const FunctionDef & functionDef
Definition Print.cpp:208

Member Function Documentation

◆ block()

void WAST::FunctionPrintContext::block ( ControlStructureImm imm)
inline

Definition at line 231 of file Print.cpp.

232 {
233 string += "\nblock";
234 pushControlStack(ControlContext::Type::block,"block");
236 }
void printControlSignature(std::string &string, ResultType resultType)
Definition Print.cpp:132
Here is the call graph for this function:

◆ br()

void WAST::FunctionPrintContext::br ( BranchImm imm)
inline

Definition at line 268 of file Print.cpp.

269 {
270 string += "\nbr " + getBranchTargetId(imm.targetDepth);
271 enterUnreachable();
272 }

◆ br_if()

void WAST::FunctionPrintContext::br_if ( BranchImm imm)
inline

Definition at line 291 of file Print.cpp.

292 {
293 string += "\nbr_if " + getBranchTargetId(imm.targetDepth);
294 }

◆ br_table()

void WAST::FunctionPrintContext::br_table ( BranchTableImm imm)
inline

Definition at line 273 of file Print.cpp.

274 {
275 string += "\nbr_table" INDENT_STRING;
276 enum { numTargetsPerLine = 16 };
278 const std::vector<U32>& targetDepths = functionDef.branchTables[imm.branchTableIndex];
279 for(Uptr targetIndex = 0;targetIndex < targetDepths.size();++targetIndex)
280 {
281 if(targetIndex % numTargetsPerLine == 0) { string += '\n'; }
282 else { string += ' '; }
283 string += getBranchTargetId(targetDepths[targetIndex]);
284 }
285 string += '\n';
286 string += getBranchTargetId(imm.defaultTargetDepth);
287 string += " ;; default" DEDENT_STRING;
288
289 enterUnreachable();
290 }
PointerIntHelper< sizeof(size_t)>::UnsignedIntType Uptr
Definition BasicTypes.h:22
#define WAVM_ASSERT_THROW(cond)
Definition Errors.h:29
#define INDENT_STRING
Definition Print.cpp:13
#define DEDENT_STRING
Definition Print.cpp:14
std::vector< std::vector< U32 > > branchTables
Definition Module.h:46

◆ call()

void WAST::FunctionPrintContext::call ( CallImm imm)
inline

Definition at line 326 of file Print.cpp.

327 {
328 string += "\ncall " + moduleContext.names.functions[imm.functionIndex].name;
329 }
U32 functionIndex
Definition Operators.h:45
std::vector< Function > functions
Definition Module.h:172
DisassemblyNames names
Definition Print.cpp:165

◆ call_indirect()

void WAST::FunctionPrintContext::call_indirect ( CallIndirectImm imm)
inline

Definition at line 330 of file Print.cpp.

331 {
332 string += "\ncall_indirect " + moduleContext.names.types[imm.type.index];
333 }
IndexedFunctionType type
Definition Operators.h:50
std::vector< std::string > types
Definition Module.h:171

◆ drop()

void WAST::FunctionPrintContext::drop ( NoImm )
inline

Definition at line 297 of file Print.cpp.

297{ string += "\ndrop"; }

◆ else_()

void WAST::FunctionPrintContext::else_ ( NoImm imm)
inline

Definition at line 249 of file Print.cpp.

250 {
251 string += DEDENT_STRING;
252 controlStack.back().type = ControlContext::Type::ifElse;
253 string += "\nelse" INDENT_STRING;
254 }

◆ end()

void WAST::FunctionPrintContext::end ( NoImm )
inline

Definition at line 255 of file Print.cpp.

256 {
257 string += DEDENT_STRING;
258 if(controlStack.back().type != ControlContext::Type::function) { string += "\nend ;; "; string += controlStack.back().labelId; }
259 controlStack.pop_back();
260 }

◆ get_global()

void WAST::FunctionPrintContext::get_global ( GetOrSetVariableImm< true > imm)
inline

Definition at line 317 of file Print.cpp.

318 {
319 string += "\nget_global " + moduleContext.names.globals[imm.variableIndex];
320 }
std::vector< std::string > globals
Definition Module.h:175

◆ get_local()

void WAST::FunctionPrintContext::get_local ( GetOrSetVariableImm< false > imm)
inline

Definition at line 304 of file Print.cpp.

305 {
306 string += "\nget_local " + localNames[imm.variableIndex];
307 }

◆ if_()

void WAST::FunctionPrintContext::if_ ( ControlStructureImm imm)
inline

Definition at line 243 of file Print.cpp.

244 {
245 string += "\nif";
246 pushControlStack(ControlContext::Type::ifThen,"if");
248 }
Here is the call graph for this function:

◆ loop()

void WAST::FunctionPrintContext::loop ( ControlStructureImm imm)
inline

Definition at line 237 of file Print.cpp.

238 {
239 string += "\nloop";
240 pushControlStack(ControlContext::Type::loop,"loop");
242 }
Here is the call graph for this function:

◆ printFunctionBody()

void WAST::FunctionPrintContext::printFunctionBody ( )

Definition at line 672 of file Print.cpp.

673 {
674 //string += "(";
675 pushControlStack(ControlContext::Type::function,nullptr);
676 string += DEDENT_STRING;
677
679 while(decoder && controlStack.size())
680 {
681 decoder.decodeOp(*this);
682 };
683
684 string += INDENT_STRING "\n";
685 }
std::vector< U8 > code
Definition Module.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printImm() [1/7]

void WAST::FunctionPrintContext::printImm ( LiteralImm< F32 > imm)
inline

Definition at line 340 of file Print.cpp.

340{ string += ' '; string += Floats::asString(imm.value); }
std::string asString(Float f)
Definition Floats.h:84
Here is the call graph for this function:

◆ printImm() [2/7]

void WAST::FunctionPrintContext::printImm ( LiteralImm< F64 > imm)
inline

Definition at line 341 of file Print.cpp.

341{ string += ' '; string += Floats::asString(imm.value); }
Here is the call graph for this function:

◆ printImm() [3/7]

void WAST::FunctionPrintContext::printImm ( LiteralImm< I32 > imm)
inline

Definition at line 338 of file Print.cpp.

338{ string += ' '; string += std::to_string(imm.value); }

◆ printImm() [4/7]

void WAST::FunctionPrintContext::printImm ( LiteralImm< I64 > imm)
inline

Definition at line 339 of file Print.cpp.

339{ string += ' '; string += std::to_string(imm.value); }

◆ printImm() [5/7]

template<Uptr naturalAlignmentLog2>
void WAST::FunctionPrintContext::printImm ( LoadOrStoreImm< naturalAlignmentLog2 > imm)
inline

Definition at line 344 of file Print.cpp.

345 {
346 if(imm.offset != 0)
347 {
348 string += " offset=";
349 string += std::to_string(imm.offset);
350 }
351 if(imm.alignmentLog2 != naturalAlignmentLog2)
352 {
353 string += " align=";
354 string += std::to_string(1 << imm.alignmentLog2);
355 }
356 }

◆ printImm() [6/7]

void WAST::FunctionPrintContext::printImm ( MemoryImm )
inline

Definition at line 336 of file Print.cpp.

336{}

◆ printImm() [7/7]

void WAST::FunctionPrintContext::printImm ( NoImm )
inline

Definition at line 335 of file Print.cpp.

335{}

◆ return_()

void WAST::FunctionPrintContext::return_ ( NoImm )
inline

Definition at line 262 of file Print.cpp.

263 {
264 string += "\nreturn";
265 enterUnreachable();
266 }

◆ select()

void WAST::FunctionPrintContext::select ( NoImm )
inline

Definition at line 299 of file Print.cpp.

300 {
301 string += "\nselect";
302 }

◆ set_global()

void WAST::FunctionPrintContext::set_global ( GetOrSetVariableImm< true > imm)
inline

Definition at line 321 of file Print.cpp.

322 {
323 string += "\nset_global " + moduleContext.names.globals[imm.variableIndex];
324 }

◆ set_local()

void WAST::FunctionPrintContext::set_local ( GetOrSetVariableImm< false > imm)
inline

Definition at line 308 of file Print.cpp.

309 {
310 string += "\nset_local " + localNames[imm.variableIndex];
311 }

◆ tee_local()

void WAST::FunctionPrintContext::tee_local ( GetOrSetVariableImm< false > imm)
inline

Definition at line 312 of file Print.cpp.

313 {
314 string += "\ntee_local " + localNames[imm.variableIndex];
315 }

◆ unknown()

void WAST::FunctionPrintContext::unknown ( Opcode )
inline

Definition at line 227 of file Print.cpp.

228 {
230 }
void unreachable()
Definition Errors.h:22
Here is the call graph for this function:

◆ unreachable()

void WAST::FunctionPrintContext::unreachable ( NoImm )
inline

Definition at line 296 of file Print.cpp.

296{ string += "\nunreachable"; enterUnreachable(); }

Member Data Documentation

◆ functionDef

const FunctionDef& WAST::FunctionPrintContext::functionDef

Definition at line 208 of file Print.cpp.

◆ functionType

const FunctionType* WAST::FunctionPrintContext::functionType

Definition at line 209 of file Print.cpp.

◆ labelNameScope

NameScope WAST::FunctionPrintContext::labelNameScope

Definition at line 213 of file Print.cpp.

◆ localNames

const std::vector<std::string>& WAST::FunctionPrintContext::localNames

Definition at line 212 of file Print.cpp.

◆ module

const Module& WAST::FunctionPrintContext::module

Definition at line 207 of file Print.cpp.

◆ moduleContext

ModulePrintContext& WAST::FunctionPrintContext::moduleContext

Definition at line 206 of file Print.cpp.

◆ string

std::string& WAST::FunctionPrintContext::string

Definition at line 210 of file Print.cpp.


The documentation for this struct was generated from the following file: