| 1026 | } |
| 1027 | |
| 1028 | void MSLGenerator::OutputFunction(int indent, HLSLFunction* function) |
| 1029 | { |
| 1030 | const char* functionName = function->name; |
| 1031 | const char* returnTypeName = GetTypeName(function->returnType, /*exactType=*/false); |
| 1032 | |
| 1033 | // Declare output tuple. |
| 1034 | if (function->numOutputArguments > 0) { |
| 1035 | returnTypeName = m_tree->AddStringFormat("%s_out%d", functionName, function->line); // @@ Find a better way to generate unique name. |
| 1036 | |
| 1037 | m_writer.BeginLine(indent, function->fileName, function->line); |
| 1038 | m_writer.Write("struct %s { ", returnTypeName); |
| 1039 | m_writer.EndLine(); |
| 1040 | |
| 1041 | if (function->returnType.baseType != HLSLBaseType_Void) { |
| 1042 | m_writer.BeginLine(indent + 1, function->fileName, function->line); |
| 1043 | OutputDeclaration(function->returnType, "__result", /*defaultValue=*/NULL, /*isRef=*/false, /*isConst=*/false); |
| 1044 | m_writer.EndLine(";"); |
| 1045 | } |
| 1046 | |
| 1047 | HLSLArgument* argument = function->argument; |
| 1048 | while (argument != NULL) { |
| 1049 | if (argument->modifier == HLSLArgumentModifier_Out || argument->modifier == HLSLArgumentModifier_Inout) { |
| 1050 | m_writer.BeginLine(indent + 1, function->fileName, function->line); |
| 1051 | OutputDeclaration(argument->type, argument->name, /*defaultValue=*/NULL, /*isRef=*/false, /*isConst=*/false); |
| 1052 | m_writer.EndLine(";"); |
| 1053 | } |
| 1054 | argument = argument->nextArgument; |
| 1055 | } |
| 1056 | |
| 1057 | m_writer.WriteLine(indent, "};"); |
| 1058 | |
| 1059 | // Create unique function name to avoid collision with overloads and different return types. |
| 1060 | m_writer.BeginLine(indent, function->fileName, function->line); |
| 1061 | m_writer.Write("%s %s_%d(", returnTypeName, functionName, function->line); |
| 1062 | } |
| 1063 | else { |
| 1064 | m_writer.BeginLine(indent, function->fileName, function->line); |
| 1065 | m_writer.Write("%s %s(", returnTypeName, functionName); |
| 1066 | } |
| 1067 | |
| 1068 | OutputArguments(function->argument); |
| 1069 | |
| 1070 | m_writer.EndLine(") {"); |
| 1071 | m_currentFunction = function; |
| 1072 | |
| 1073 | // Local declarations for output arguments. |
| 1074 | HLSLArgument* argument = function->argument; |
| 1075 | while (argument != NULL) { |
| 1076 | if (argument->modifier == HLSLArgumentModifier_Out) { |
| 1077 | m_writer.BeginLine(indent + 1, function->fileName, function->line); |
| 1078 | OutputDeclaration(argument->type, argument->name, /*defaultValue=*/NULL, /*isRef=*/false, /*isConst=*/false); |
| 1079 | m_writer.EndLine(";"); |
| 1080 | } |
| 1081 | argument = argument->nextArgument; |
| 1082 | } |
| 1083 | |
| 1084 | OutputStatements(indent + 1, function->statement); // @@ Modify return statements if function has multiple output arguments! |
| 1085 |
nothing calls this directly
no test coverage detected