Moved or removed unused variables

Some variables were either unused or only used in certain contexts,
like debug or tracing, so these were either removed (when unused)
or moved to the right scope (when used conditionally).
Also fixed a string format warning and a missing case warning.

Change-Id: I2d130faa992b5dc06fb332d7404a8aebc7c121ef
Reviewed-on: https://swiftshader-review.googlesource.com/5462
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Common/Configurator.cpp b/src/Common/Configurator.cpp
index 994d105..445305c 100644
--- a/src/Common/Configurator.cpp
+++ b/src/Common/Configurator.cpp
@@ -184,7 +184,6 @@
 	void Configurator::addValue(string const keyName, string const valueName, string const value)
 	{
 		int keyID = findKey(keyName);
-		bool create = true;
 
 		if(keyID == -1)
 		{
diff --git a/src/Main/SwiftConfig.cpp b/src/Main/SwiftConfig.cpp
index c3eb19c..b1cc2e9 100644
--- a/src/Main/SwiftConfig.cpp
+++ b/src/Main/SwiftConfig.cpp
@@ -522,7 +522,7 @@
 		}
 
 		sprintf(header, "Content-Type: text/html; charset=UTF-8\r\n"
-						"Content-Length: %d\r\n"
+						"Content-Length: %zd\r\n"
 						"Host: localhost\r\n"
 						"\r\n", body.size());
 
diff --git a/src/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index 511b91e..9c467ab 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -496,7 +496,6 @@
 		TIntermTyped *right = node->getRight();
 		const TType &leftType = left->getType();
 		const TType &rightType = right->getType();
-		const TType &resultType = node->getType();
 
 		if(isSamplerRegister(result))
 		{
@@ -1270,8 +1269,8 @@
 
 							if(argumentCount == 2 || (textureFunction.offset && argumentCount == 3))
 							{
-								Instruction *tex = emit(textureFunction.offset ? sw::Shader::OPCODE_TEXOFFSET : sw::Shader::OPCODE_TEX,
-								                        result, &coord, arg[0], offset);
+								emit(textureFunction.offset ? sw::Shader::OPCODE_TEXOFFSET : sw::Shader::OPCODE_TEX,
+								     result, &coord, arg[0], offset);
 							}
 							else if(argumentCount == 3 || (textureFunction.offset && argumentCount == 4))   // bias
 							{
@@ -1398,7 +1397,7 @@
 				{
 					for(int i = 0; i < outCols; i++)
 					{
-						Instruction *init = emit(sw::Shader::OPCODE_MOV, result, i, &zero);
+						emit(sw::Shader::OPCODE_MOV, result, i, &zero);
 						Instruction *mov = emitCast(result, i, arg0, 0);
 						mov->dst.mask = 1 << i;
 						ASSERT(mov->src[0].swizzle == 0x00);
@@ -1415,7 +1414,7 @@
 						{
 							// Initialize to identity matrix
 							Constant col((i == 0 ? 1.0f : 0.0f), (i == 1 ? 1.0f : 0.0f), (i == 2 ? 1.0f : 0.0f), (i == 3 ? 1.0f : 0.0f));
-							Instruction *mov = emitCast(result, i, &col, 0);
+							emitCast(result, i, &col, 0);
 						}
 
 						if(i < inCols)
diff --git a/src/OpenGL/compiler/ParseHelper.cpp b/src/OpenGL/compiler/ParseHelper.cpp
index 9d8d6a2..1201edc 100644
--- a/src/OpenGL/compiler/ParseHelper.cpp
+++ b/src/OpenGL/compiler/ParseHelper.cpp
@@ -655,8 +655,6 @@
 		return true;
 
 	// check for layout qualifier issues
-	const TLayoutQualifier layoutQualifier = pType.layoutQualifier;
-
 	if (pType.qualifier != EvqVertexIn && pType.qualifier != EvqFragmentOut &&
 		layoutLocationErrorCheck(line, pType.layoutQualifier))
 	{
diff --git a/src/OpenGL/compiler/debug.cpp b/src/OpenGL/compiler/debug.cpp
index b30632d..61943a3 100644
--- a/src/OpenGL/compiler/debug.cpp
+++ b/src/OpenGL/compiler/debug.cpp
@@ -22,8 +22,6 @@
 #include "InitializeParseContext.h"
 #include "ParseHelper.h"
 
-static const int kTraceBufferLen = 1024;
-
 #ifdef TRACE_ENABLED
 extern "C" {
 void Trace(const char *format, ...) {
@@ -31,6 +29,7 @@
 
 	TParseContext* parseContext = GetGlobalParseContext();
 	if (parseContext) {
+		const int kTraceBufferLen = 1024;
 		char buf[kTraceBufferLen];
 		va_list args;
 		va_start(args, format);
diff --git a/src/OpenGL/libGLESv2/Program.cpp b/src/OpenGL/libGLESv2/Program.cpp
index f32ef70..2a3bb68 100644
--- a/src/OpenGL/libGLESv2/Program.cpp
+++ b/src/OpenGL/libGLESv2/Program.cpp
@@ -42,8 +42,6 @@
 
 	Uniform::BlockInfo::BlockInfo(const glsl::Uniform& uniform, int blockIndex)
 	{
-		static unsigned int registerSizeStd140 = 4; // std140 packing requires dword alignment
-
 		if(blockIndex >= 0)
 		{
 			index = blockIndex;
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index df6a2c7..7e7ec40 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -1523,7 +1523,6 @@
 
 		DrawCall &draw = *drawList[primitiveProgress[unit].drawCall % DRAW_COUNT];
 		SetupProcessor::State &state = draw.setupState;
-		SetupProcessor::RoutinePointer setupRoutine = draw.setupPointer;
 
 		const Vertex &v0 = triangle[0].v0;
 		const Vertex &v1 = triangle[0].v1;
diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp
index 4d84cf0..c758b98 100644
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -3687,7 +3687,6 @@
 
 		void *source = internal.lockRect(0, 0, 0, LOCK_READWRITE);
 
-		int quality = internal.depth;
 		int width = internal.width;
 		int height = internal.height;
 		int pitch = internal.pitchB;
diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index 36560fe..24dd7ed 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -1407,7 +1407,6 @@
 
 		int rgbaWriteMask = state.colorWriteActive(index);
 		int bgraWriteMask = (rgbaWriteMask & 0x0000000A) | (rgbaWriteMask & 0x00000001) << 2 | (rgbaWriteMask & 0x00000004) >> 2;
-		int brgaWriteMask = (rgbaWriteMask & 0x00000008) | (rgbaWriteMask & 0x00000001) << 1 | (rgbaWriteMask & 0x00000002) << 1 | (rgbaWriteMask & 0x00000004) >> 2;
 
 		switch(state.targetFormat[index])
 		{
@@ -1978,20 +1977,13 @@
 		Short4 c23;
 
 		Float4 one;
-		switch(state.targetFormat[index])
+		if(Surface::isFloatFormat(state.targetFormat[index]))
 		{
-		case FORMAT_R32I:
-		case FORMAT_G32R32I:
-			one = As<Float4>(Int4(0x7FFFFFFF));
-			break;
-		case FORMAT_R32UI:
-		case FORMAT_G32R32UI:
-			one = As<Float4>(Int4(0xFFFFFFFF));
-			break;
-		case FORMAT_R32F:
-		case FORMAT_G32R32F:
 			one = Float4(1.0f);
-			break;
+		}
+		else if(Surface::isNonNormalizedInteger(state.targetFormat[index]))
+		{
+			one = As<Float4>(Surface::isUnsignedComponent(state.targetFormat[index], 0) ? Int4(0xFFFFFFFF) : Int4(0x7FFFFFFF));
 		}
 
 		switch(state.targetFormat[index])
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp
index d321fce..806b6e8 100644
--- a/src/Shader/PixelShader.cpp
+++ b/src/Shader/PixelShader.cpp
@@ -68,7 +68,7 @@
 		}
 
 		unsigned short version = (unsigned short)(token[0] & 0x0000FFFF);
-		unsigned char minorVersion = (unsigned char)(token[0] & 0x000000FF);
+		// unsigned char minorVersion = (unsigned char)(token[0] & 0x000000FF);
 		unsigned char majorVersion = (unsigned char)((token[0] & 0x0000FF00) >> 8);
 		ShaderType shaderType = (ShaderType)((token[0] & 0xFFFF0000) >> 16);
 
@@ -230,7 +230,6 @@
 				if(instruction[i]->dst.type == Shader::PARAMETER_TEXTURE)
 				{
 					int index = instruction[i]->dst.index + 2;
-					int mask = instruction[i]->dst.mask;
 
 					switch(instruction[i]->opcode)
 					{
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index cc29156..7db625c 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -251,12 +251,12 @@
 
 				if(state.multiSample == 1)
 				{
-					For(yMin, yMin < yMax && *Pointer<Short>(leftEdge + yMin * sizeof(Primitive::Span)) == *Pointer<Short>(rightEdge + yMin * sizeof(Primitive::Span)), yMin++)
+					For(, yMin < yMax && *Pointer<Short>(leftEdge + yMin * sizeof(Primitive::Span)) == *Pointer<Short>(rightEdge + yMin * sizeof(Primitive::Span)), yMin++)
 					{
 						// Increments yMin
 					}
 
-					For(yMax, yMax > yMin && *Pointer<Short>(leftEdge + (yMax - 1) * sizeof(Primitive::Span)) == *Pointer<Short>(rightEdge + (yMax - 1) * sizeof(Primitive::Span)), yMax--)
+					For(, yMax > yMin && *Pointer<Short>(leftEdge + (yMax - 1) * sizeof(Primitive::Span)) == *Pointer<Short>(rightEdge + (yMax - 1) * sizeof(Primitive::Span)), yMax--)
 					{
 						// Decrements yMax
 					}