MCPcopy Create free account
hub / github.com/dfranx/ShaderDebugger / translateFunction

Method translateFunction

src/HLSLCompiler.cpp:1112–1201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1110 }
1111 }
1112 void HLSLCompiler::translateFunction(M4::HLSLFunction* func)
1113 {
1114 m_func.push_back(Function());
1115 m_curFuncData = &m_func[m_func.size() - 1];
1116 m_curFuncData->Arguments.clear();
1117
1118 // add arguments
1119 translateArguments(func->argument);
1120
1121 // build list for internal workings
1122 M4::HLSLArgument* arg = func->argument;
1123 int index = 0;
1124 std::vector<ag::Type> argTypes;
1125 std::vector<std::string> argNames;
1126 while (arg != NULL) {
1127 HLSLCompiler::ExpressionType btype = m_convertType(arg->type);
1128 argTypes.push_back(btype.Type);
1129 argNames.push_back(btype.Name);
1130 arg = arg->nextArgument;
1131 }
1132
1133 m_curFuncData->ID = m_gen.Function.Create(func->name, func->numArguments, argTypes, argNames);
1134 m_curFuncData->Name = m_currentFunction = func->name;
1135
1136 m_curFuncData->ReturnType = m_convertType(func->returnType).Name;
1137
1138 m_gen.Function.SetCurrent(m_curFuncData->ID);
1139
1140 // initialize global variables at the start of main()
1141 if (m_curFuncData->Name == m_entryFunction) {
1142 // create global objects (vec3, etc..)
1143 for (auto& gInitClass : m_initObjsInMain) {
1144
1145 // skip textures and sampler states (TODO: should actually check if register is set, i guess..)
1146 if (sd::IsBasicTexture(gInitClass.second.c_str()) || gInitClass.second == "SamplerState")
1147 continue;
1148
1149 size_t varID = 0;
1150 for (auto& gVar : m_globals)
1151 if (gVar.Name == gInitClass.first)
1152 varID = gVar.ID;
1153 m_gen.Function.GetGlobal(varID);
1154 m_gen.Function.PushNull();
1155 m_gen.Function.Equal();
1156 size_t ifPos = m_gen.Function.If(); // if global == null then initialize
1157 m_gen.Function.NewObjectByName(gInitClass.second, 0);
1158 m_gen.Function.SetGlobal(varID);
1159 m_gen.Function.SetAddress(ifPos, m_gen.Function.GetCurrentAddress());
1160 }
1161
1162 // init array
1163 for (auto& gArray : m_initArraysInMain) {
1164 M4::HLSLExpression* sizeExpr = gArray.second;
1165 int arrDepth = 0;
1166 while (sizeExpr) {
1167 translateExpression(gArray.second);
1168 arrDepth++;
1169 sizeExpr = sizeExpr->nextExpression;

Callers

nothing calls this directly

Calls 3

FunctionClass · 0.85
IsBasicTextureFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected