Skip to content

Commit

Permalink
Merge pull request #2052 from KhronosGroup/fix-processed-def-undef-1829
Browse files Browse the repository at this point in the history
Fix #1829: Allow "--" options for def/undef, for OpModuleProcessed.
  • Loading branch information
johnkslang committed Jan 8, 2020
2 parents 1642ca1 + 6f98892 commit e5dbc31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions StandAlone/StandAlone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class TPreamble {
text.append("#define ");
fixLine(def);

Processes.push_back("D");
Processes.push_back("define-macro ");
Processes.back().append(def);

// The first "=" needs to turn into a space
Expand All @@ -222,7 +222,7 @@ class TPreamble {
text.append("#undef ");
fixLine(undef);

Processes.push_back("U");
Processes.push_back("undef-macro ");
Processes.back().append(undef);

text.append(undef);
Expand Down Expand Up @@ -500,6 +500,13 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
} else
Error("expects vulkan100 or opengl100", lowerword.c_str());
bumpArg();
} else if (lowerword == "define-macro" ||
lowerword == "d") {
if (argc > 1)
UserPreamble.addDef(argv[1]);
else
Error("expects <name[=def]>", argv[0]);
bumpArg();
} else if (lowerword == "dump-builtin-symbols") {
DumpBuiltinSymbols = true;
} else if (lowerword == "entry-point") {
Expand Down Expand Up @@ -627,6 +634,13 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
"spirv1.0, spirv1.1, spirv1.2, spirv1.3, spirv1.4, or spirv1.5");
}
bumpArg();
} else if (lowerword == "undef-macro" ||
lowerword == "u") {
if (argc > 1)
UserPreamble.addUndef(argv[1]);
else
Error("expects <name>", argv[0]);
bumpArg();
} else if (lowerword == "variable-name" || // synonyms
lowerword == "vn") {
Options |= EOptionOutputHexadecimal;
Expand All @@ -649,7 +663,7 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
if (argv[0][2] == 0)
Options |= EOptionReadHlsl;
else
UserPreamble.addDef(getStringOperand("-D<macro> macro name"));
UserPreamble.addDef(getStringOperand("-D<name[=def]>"));
break;
case 'u':
uniformLocationOverrides.push_back(getUniformOverride());
Expand Down Expand Up @@ -692,7 +706,7 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
bumpArg();
break;
case 'U':
UserPreamble.addUndef(getStringOperand("-U<macro>: macro name"));
UserPreamble.addUndef(getStringOperand("-U<name>"));
break;
case 'V':
setVulkanSpv();
Expand Down Expand Up @@ -1502,8 +1516,8 @@ void usage()
"Options:\n"
" -C cascading errors; risk crash from accumulation of error recoveries\n"
" -D input is HLSL (this is the default when any suffix is .hlsl)\n"
" -D<macro=def>\n"
" -D<macro> define a pre-processor macro\n"
" -D<name[=def]> | --define-macro <name[=def]> | --D <name[=def]>\n"
" define a pre-processor macro\n"
" -E print pre-processed GLSL; cannot be used with -l;\n"
" errors will appear on stderr\n"
" -G[ver] create SPIR-V binary, under OpenGL semantics; turns on -l;\n"
Expand All @@ -1519,7 +1533,8 @@ void usage()
" -Os optimizes SPIR-V to minimize size\n"
" -S <stage> uses specified stage rather than parsing the file extension\n"
" choices for <stage> are vert, tesc, tese, geom, frag, or comp\n"
" -U<macro> undefine a pre-processor macro\n"
" -U<name> | --undef-macro <name> | --U <name>\n"
" undefine a pre-processor macro\n"
" -V[ver] create SPIR-V binary, under Vulkan semantics; turns on -l;\n"
" default file name is <stage>.spv (-o overrides this)\n"
" 'ver', when present, is the version of the input semantics,\n"
Expand Down
4 changes: 2 additions & 2 deletions Test/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ diff -b $BASEDIR/hlsl.pp.line3.frag.out $TARGETDIR/hlsl.pp.line3.frag.out || HAS
# Testing -D and -U
#
echo "Testing -D and -U"
$EXE -DUNDEFED -UIN_SHADER -DFOO=200 -i -l -UUNDEFED -DMUL=FOO*2 glsl.-D-U.frag > $TARGETDIR/glsl.-D-U.frag.out
$EXE -DUNDEFED -UIN_SHADER -DFOO=200 -i -l --U UNDEFED --define-macro MUL=FOO*2 glsl.-D-U.frag > $TARGETDIR/glsl.-D-U.frag.out
diff -b $BASEDIR/glsl.-D-U.frag.out $TARGETDIR/glsl.-D-U.frag.out || HASERROR=1
$EXE -D -Od -e main -V -i -DUNDEFED -UIN_SHADER -DFOO=200 -UUNDEFED -Od hlsl.-D-U.frag > $TARGETDIR/hlsl.-D-U.frag.out
$EXE -D -Od -e main -V -i -DUNDEFED -UIN_SHADER --D FOO=200 --undef-macro UNDEFED -Od hlsl.-D-U.frag > $TARGETDIR/hlsl.-D-U.frag.out
diff -b $BASEDIR/hlsl.-D-U.frag.out $TARGETDIR/hlsl.-D-U.frag.out || HASERROR=1

#
Expand Down

0 comments on commit e5dbc31

Please sign in to comment.