478 {
479 ScopedTagPrinter moduleTag(string,"module");
480
481
483 {
484 string += '\n';
485 ScopedTagPrinter typeTag(string,"type");
486 string += ' ';
488 string += " (func ";
490 string += ')';
491 }
492
493
495 {
497 }
498 for(
Uptr importIndex = 0;importIndex <
module.
tables.imports.size();++importIndex)
499 {
501 }
503 {
505 }
506 for(
Uptr importIndex = 0;importIndex <
module.
globals.imports.size();++importIndex)
507 {
509 }
510
512 {
513 string += '\n';
514 ScopedTagPrinter exportTag(string,"export");
515 string += " \"";
517 string += "\" (";
519 {
525 };
526 string += ')';
527 }
528
529
530 for(
Uptr memoryDefIndex = 0;memoryDefIndex <
module.
memories.defs.size();++memoryDefIndex)
531 {
532 const MemoryDef& memoryDef =
module.memories.defs[memoryDefIndex];
533 string += '\n';
534 ScopedTagPrinter memoryTag(string,"memory");
535 string += ' ';
536 string +=
names.
memories[
module.memories.imports.size() + memoryDefIndex];
537 string += ' ';
539 }
540
541
542 for(
Uptr tableDefIndex = 0;tableDefIndex <
module.
tables.defs.size();++tableDefIndex)
543 {
544 const TableDef& tableDef =
module.tables.defs[tableDefIndex];
545 string += '\n';
546 ScopedTagPrinter memoryTag(string,"table");
547 string += ' ';
548 string +=
names.
tables[
module.tables.imports.size() + tableDefIndex];
549 string += ' ';
551 }
552
553
554 for(
Uptr globalDefIndex = 0;globalDefIndex <
module.
globals.defs.size();++globalDefIndex)
555 {
556 const GlobalDef& globalDef =
module.globals.defs[globalDefIndex];
557 string += '\n';
558 ScopedTagPrinter memoryTag(string,"global");
559 string += ' ';
560 string +=
names.
globals[
module.globals.imports.size() + globalDefIndex];
561 string += ' ';
563 string += ' ';
565 }
566
567
569 {
570 string += '\n';
571 ScopedTagPrinter dataTag(string,"elem");
572 string += ' ';
574 string += ' ';
576 enum { numElemsPerLine = 8 };
577 for(
Uptr elementIndex = 0;elementIndex < tableSegment.indices.size();++elementIndex)
578 {
579 if(elementIndex % numElemsPerLine == 0) { string += '\n'; }
580 else { string += ' '; }
581 string +=
names.
functions[tableSegment.indices[elementIndex]].name;
582 }
583 }
585 {
586 string += '\n';
587 ScopedTagPrinter dataTag(string,"data");
588 string += ' ';
590 string += ' ';
592 enum { numBytesPerLine = 64 };
593 for(
Uptr offset = 0;offset < dataSegment.data.size();offset += numBytesPerLine)
594 {
595 string += "\n\"";
596 string +=
escapeString((
const char*)dataSegment.data.data() + offset,std::min(dataSegment.data.size() - offset,(
Uptr)numBytesPerLine));
597 string += "\"";
598 }
599 }
600
601 for(
Uptr functionDefIndex = 0;functionDefIndex <
module.
functions.defs.size();++functionDefIndex)
602 {
603 const Uptr functionIndex =
module.functions.imports.size() + functionDefIndex;
604 const FunctionDef& functionDef =
module.functions.defs[functionDefIndex];
605 const FunctionType* functionType =
module.types[functionDef.type.index];
606 FunctionPrintContext functionContext(*this,functionDefIndex);
607
608 string += "\n\n";
609 ScopedTagPrinter funcTag(string,"func");
610
611 string += ' ';
613
614
616 {
617 for(
Uptr parameterIndex = 0;parameterIndex < functionType->
parameters.size();++parameterIndex)
618 {
619 string += '\n';
620 ScopedTagPrinter paramTag(string,"param");
621 string += ' ';
622 string += functionContext.localNames[parameterIndex];
623 string += ' ';
625 }
626 }
627
628
629 if(functionType->
ret != ResultType::none)
630 {
631 string += '\n';
632 ScopedTagPrinter resultTag(string,"result");
633 string += ' ';
635 }
636
637
639 {
640 string += '\n';
641 ScopedTagPrinter localTag(string,"local");
642 string += ' ';
643 string += functionContext.localNames[functionType->
parameters.size() + localIndex];
644 string += ' ';
646 }
647
648 functionContext.printFunctionBody();
649 }
650
651
653 {
654 if(userSection.name != "name")
655 {
656 string += '\n';
657 ScopedTagPrinter dataTag(string,"user_section");
658 string += " \"";
659 string +=
escapeString(userSection.name.c_str(),userSection.name.length());
660 string += "\" ";
661 enum { numBytesPerLine = 64 };
662 for(
Uptr offset = 0;offset < userSection.data.size();offset += numBytesPerLine)
663 {
664 string += "\n\"";
665 string +=
escapeString((
const char*)userSection.data.data() + offset,std::min(userSection.data.size() - offset,(
Uptr)numBytesPerLine));
666 string += "\"";
667 }
668 }
669 }
670 }
PointerIntHelper< sizeof(size_t)>::UnsignedIntType Uptr
std::string escapeString(const char *string, Uptr numChars)
WAST_API std::string print(const IR::Module &module)
void printImport(std::string &string, const Module &module, const Import< Type > &import, Uptr importIndex, const char *name, const char *typeTag)
std::vector< ValueType > nonParameterLocalTypes
std::vector< ValueType > parameters
InitializerExpression initializer
std::vector< UserSection > userSections
IndexSpace< MemoryDef, MemoryType > memories
IndexSpace< TableDef, TableType > tables
IndexSpace< FunctionDef, IndexedFunctionType > functions
std::vector< const FunctionType * > types
std::vector< TableSegment > tableSegments
IndexSpace< GlobalDef, GlobalType > globals
std::vector< DataSegment > dataSegments
std::vector< Export > exports
void printInitializerExpression(const InitializerExpression &expression)