MCPcopy Create free account
hub / github.com/alecazam/kram / PruneTree

Function PruneTree

hlslparser/src/HLSLTree.cpp:1081–1145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1079};
1080
1081void PruneTree(HLSLTree *tree, const char *entryName0, const char *entryName1 /*=NULL*/)
1082{
1083 HLSLRoot *root = tree->GetRoot();
1084
1085 // Reset all flags.
1086 ResetHiddenFlagVisitor reset;
1087 reset.VisitRoot(root);
1088
1089 // Mark all the statements necessary for these entrypoints.
1090 HLSLFunction *entry = tree->FindFunction(entryName0);
1091 if (entry != NULL) {
1092 MarkVisibleStatementsVisitor mark(tree);
1093 mark.VisitFunction(entry);
1094 }
1095
1096 if (entryName1 != NULL) {
1097 entry = tree->FindFunction(entryName1);
1098 if (entry != NULL) {
1099 MarkVisibleStatementsVisitor mark(tree);
1100 mark.VisitFunction(entry);
1101 }
1102 }
1103
1104 // Mark buffers visible, if any of their fields is visible.
1105 HLSLStatement *statement = root->statement;
1106 while (statement != NULL) {
1107 if (statement->nodeType == HLSLNodeType_Buffer) {
1108 HLSLBuffer *buffer = (HLSLBuffer *)statement;
1109
1110 if (buffer->IsGlobalFields()) {
1111 // mark buffer visible if any of its fields are used
1112 HLSLDeclaration *field = buffer->field;
1113 while (field != NULL) {
1114 ASSERT(field->nodeType == HLSLNodeType_Declaration);
1115 if (!field->hidden) {
1116 buffer->hidden = false;
1117 break;
1118 }
1119 field = (HLSLDeclaration *)field->nextStatement;
1120 }
1121 }
1122 else {
1123 // TODO: these load from a struct so may just need
1124 // to somehow mark this if present.
1125
1126 /* all struct fields are hidden = false, so this doesn't work
1127 // mark buffer visible if any struct fields are used
1128 HLSLStructField* field = buffer->bufferStruct->field;
1129 while (field != NULL)
1130 {
1131 ASSERT(field->nodeType == HLSLNodeType_StructField);
1132 if (!field->hidden)
1133 {
1134 buffer->hidden = false;
1135 break;
1136 }
1137 field = (HLSLStructField*)field->nextField;
1138 }

Callers 2

GenerateMethod · 0.85
PrepassMethod · 0.85

Calls 5

GetRootMethod · 0.80
VisitRootMethod · 0.80
IsGlobalFieldsMethod · 0.80
FindFunctionMethod · 0.45
VisitFunctionMethod · 0.45

Tested by

no test coverage detected