Rationalize command-line options: controlling memory leak testing, AST output, and info log output.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21141 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-04-14 19:23:50 +00:00
parent 4d5de020d8
commit 8df53cc057
2 changed files with 48 additions and 53 deletions

View File

@ -48,8 +48,6 @@ extern "C" {
SH_IMPORT_EXPORT void ShOutputHtml(); SH_IMPORT_EXPORT void ShOutputHtml();
} }
//#define MEASURE_MEMORY
// //
// Return codes from main. // Return codes from main.
// //
@ -81,7 +79,6 @@ void usage();
void FreeFileData(char **data); void FreeFileData(char **data);
char** ReadFileData(const char *fileName); char** ReadFileData(const char *fileName);
void InfoLogMsg(const char* msg, const char* name, const int num); void InfoLogMsg(const char* msg, const char* name, const int num);
int ShOutputMultipleStrings(const char *);
//Added to accomodate the multiple strings. //Added to accomodate the multiple strings.
int OutputMultipleStrings = 1; int OutputMultipleStrings = 1;
@ -134,21 +131,27 @@ int C_DECL main(int argc, char* argv[])
for (; argc >= 1; argc--, argv++) { for (; argc >= 1; argc--, argv++) {
if (argv[0][0] == '-') { if (argv[0][0] == '-') {
switch (argv[0][1]) { switch (argv[0][1]) {
case 'd': delay = true; break; case 'd':
delay = true;
#ifdef MEASURE_MEMORY break;
case 'i': break; case 'i':
case 'a': break; debugOptions |= EDebugOpIntermediate;
case 'h': break; break;
#else case 'a':
case 'i': debugOptions |= EDebugOpIntermediate; break; debugOptions |= EDebugOpAssembly;
case 'a': debugOptions |= EDebugOpAssembly; break; break;
#endif case 'l':
case 'c': if(!ShOutputMultipleStrings((++argv)[0])) debugOptions |= EDebugOpMemoryLeakMode;
return EFailUsage; break;
--argc; break; case 's':
case 'm': debugOptions |= EDebugOpLinkMaps; break; debugOptions |= EDebugOpSuppressInfolog;
default: usage(); return EFailUsage; break;
case 't':
debugOptions |= EDebugOpTexturePrototypes;
break;
default:
usage();
return EFailUsage;
} }
} else { } else {
compilers[numCompilers] = ShConstructCompiler(FindLanguage(argv[0]), debugOptions); compilers[numCompilers] = ShConstructCompiler(FindLanguage(argv[0]), debugOptions);
@ -182,15 +185,17 @@ int C_DECL main(int argc, char* argv[])
linkFailed = true; linkFailed = true;
} }
for (i = 0; i < numCompilers; ++i) { if (! (debugOptions & EDebugOpSuppressInfolog)) {
InfoLogMsg("BEGIN", "COMPILER", i); for (i = 0; i < numCompilers; ++i) {
puts(ShGetInfoLog(compilers[i])); InfoLogMsg("BEGIN", "COMPILER", i);
InfoLogMsg("END", "COMPILER", i); puts(ShGetInfoLog(compilers[i]));
} InfoLogMsg("END", "COMPILER", i);
}
InfoLogMsg("BEGIN", "LINKER", -1); InfoLogMsg("BEGIN", "LINKER", -1);
puts(ShGetInfoLog(linker)); puts(ShGetInfoLog(linker));
InfoLogMsg("END", "LINKER", -1); InfoLogMsg("END", "LINKER", -1);
}
#ifdef _WIN32 #ifdef _WIN32
} __finally { } __finally {
@ -248,25 +253,20 @@ bool CompileFile(const char *fileName, ShHandle compiler, int debugOptions, cons
{ {
int ret; int ret;
char **data = ReadFileData(fileName); char **data = ReadFileData(fileName);
PROCESS_MEMORY_COUNTERS counters; // just for memory leak testing
#ifdef MEASURE_MEMORY
PROCESS_MEMORY_COUNTERS counters;
#endif
if (!data) if (!data)
return false; return false;
#ifdef MEASURE_MEMORY for (int i = 0; i < ((debugOptions & EDebugOpMemoryLeakMode) ? 100 : 1); ++i) {
for (int i = 0; i < 10; ++i) { for (int j = 0; j < ((debugOptions & EDebugOpMemoryLeakMode) ? 100 : 1); ++j)
for (int j = 0; j < 1000; ++j)
#endif
ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, resources, debugOptions, 100, false, EShMsgDefault); ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, resources, debugOptions, 100, false, EShMsgDefault);
#ifdef MEASURE_MEMORY
GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters)); if (debugOptions & EDebugOpMemoryLeakMode) {
printf("Working set size: %d\n", counters.WorkingSetSize); GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters));
printf("Working set size: %d\n", counters.WorkingSetSize);
}
} }
#endif
FreeFileData(data); FreeFileData(data);
@ -279,11 +279,15 @@ bool CompileFile(const char *fileName, ShHandle compiler, int debugOptions, cons
// //
void usage() void usage()
{ {
printf("Usage: standalone [-i -a -c -m -d -h] file1 file2 ...\n" printf("Usage: standalone [ options ] filename\n"
"Where: filename = filename ending in .frag* or .vert*\n"); "Where: filename = filename ending in .frag* or .vert*\n"
"-i: intermediate (glslang AST)\n"
"-a: assembly dump (LLVM IR)\n"
"-d: delay end (keeps output up in debugger, WIN32)\n"
"-l: memory leak mode\n"
"-s: silent mode (no info log)\n");
} }
#ifndef _WIN32 #ifndef _WIN32
#include <errno.h> #include <errno.h>
@ -389,14 +393,3 @@ void InfoLogMsg(const char* msg, const char* name, const int num)
printf(num >= 0 ? "#### %s %s %d INFO LOG ####\n" : printf(num >= 0 ? "#### %s %s %d INFO LOG ####\n" :
"#### %s %s INFO LOG ####\n", msg, name, num); "#### %s %s INFO LOG ####\n", msg, name, num);
} }
int ShOutputMultipleStrings(const char *argv)
{
if(!(abs(OutputMultipleStrings = atoi(argv)))||((OutputMultipleStrings >5 || OutputMultipleStrings < 1)? 1:0)){
printf("Invalid Command Line Argument after -c option.\n"
"Usage: -c <integer> where integer =[1,5]\n"
"This option must be specified before the input file path\n");
return 0;
}
return 1;
}

View File

@ -227,7 +227,9 @@ enum TDebugOptions {
EDebugOpAssembly = 0x002, EDebugOpAssembly = 0x002,
EDebugOpObjectCode = 0x004, EDebugOpObjectCode = 0x004,
EDebugOpLinkMaps = 0x008, EDebugOpLinkMaps = 0x008,
EDebugSuppressInfolog = 0x010 EDebugOpSuppressInfolog = 0x010,
EDebugOpMemoryLeakMode = 0x020,
EDebugOpTexturePrototypes = 0x040
}; };
#ifdef __cplusplus #ifdef __cplusplus
} }