Change routine names to be strings of char

Routine names were passed as wide strings for the integration with
CodeAnalyst, which no longer exists.

- Rip out the remnants of the CodeAnalyst support
- Change Reactor interface to take routine names as const char *

Bug: b/123193048
Change-Id: I919ce3a55c59c3a08057f85cac994fbffad37614
Reviewed-on: https://swiftshader-review.googlesource.com/c/23908
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/docs/Reactor.md b/docs/Reactor.md
index 682052f..7085cc8 100644
--- a/docs/Reactor.md
+++ b/docs/Reactor.md
@@ -61,7 +61,7 @@
 The Routine is obtained and materialized by "calling" the ```Function<>``` object to give it a name:

 

 ```C++

-Routine *routine = function(L"one");

+Routine *routine = function("one");

 ```

 

 Finally, we can obtain the function pointer to the entry point of the routine, and call it:

diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index d8ee246..a082020 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -1625,7 +1625,7 @@
 			}
 		}
 
-		return function(L"BlitRoutine");
+		return function("BlitRoutine");
 	}
 
 	bool Blitter::blitReactor(Surface *source, const SliceRectF &sourceRect, Surface *dest, const SliceRect &destRect, const Blitter::Options &options)
diff --git a/src/Device/PixelProcessor.cpp b/src/Device/PixelProcessor.cpp
index 683eda2..b606a78 100644
--- a/src/Device/PixelProcessor.cpp
+++ b/src/Device/PixelProcessor.cpp
@@ -774,7 +774,7 @@
 			const bool integerPipeline = (context->pixelShaderModel() <= 0x0104);
 			QuadRasterizer *generator = new PixelProgram(state, context->pixelShader);
 			generator->generate();
-			routine = (*generator)(L"PixelRoutine_%0.8X", state.shaderID);
+			routine = (*generator)("PixelRoutine_%0.8X", state.shaderID);
 			delete generator;
 
 			routineCache->add(state, routine);
diff --git a/src/Device/VertexProcessor.cpp b/src/Device/VertexProcessor.cpp
index 7f7d265..c6cc68a 100644
--- a/src/Device/VertexProcessor.cpp
+++ b/src/Device/VertexProcessor.cpp
@@ -447,7 +447,7 @@
 		{
 			VertexRoutine *generator = new VertexProgram(state, context->vertexShader);
 			generator->generate();
-			routine = (*generator)(L"VertexRoutine_%0.8X", state.shaderID);
+			routine = (*generator)("VertexRoutine_%0.8X", state.shaderID);
 			delete generator;
 
 			routineCache->add(state, routine);
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp
index 7a8ddc1..7d2e6a0 100644
--- a/src/Main/FrameBuffer.cpp
+++ b/src/Main/FrameBuffer.cpp
@@ -531,7 +531,7 @@
 			}
 		}
 
-		return function(L"FrameBuffer");
+		return function("FrameBuffer");
 	}
 
 	void FrameBuffer::blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c)
diff --git a/src/Pipeline/SetupRoutine.cpp b/src/Pipeline/SetupRoutine.cpp
index b5b31cd..d3fd5c3 100644
--- a/src/Pipeline/SetupRoutine.cpp
+++ b/src/Pipeline/SetupRoutine.cpp
@@ -469,7 +469,7 @@
 			Return(true);
 		}
 
-		routine = function(L"SetupRoutine");
+		routine = function("SetupRoutine");
 	}
 
 	void SetupRoutine::setupGradient(Pointer<Byte> &primitive, Pointer<Byte> &triangle, Float4 &w012, Float4 (&m)[3], Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2, int attribute, int planeEquation, bool flat, bool sprite, bool perspective, bool wrap, int component)
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index c760081..8b4dcc0 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -95,15 +95,6 @@
 }
 #endif
 
-#if defined(_WIN32)
-extern "C"
-{
-	bool (*CodeAnalystInitialize)() = 0;
-	void (*CodeAnalystCompleteJITLog)() = 0;
-	bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0;
-}
-#endif
-
 #if REACTOR_LLVM_VERSION < 7
 namespace llvm
 {
@@ -887,18 +878,6 @@
 		if(!::builder)
 		{
 			::builder = new llvm::IRBuilder<>(*::context);
-
-			#if defined(_WIN32) && REACTOR_LLVM_VERSION < 7
-				HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll");
-				if(CodeAnalyst)
-				{
-					CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize");
-					CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog");
-					CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode");
-
-					CodeAnalystInitialize();
-				}
-			#endif
 		}
 	}
 
@@ -909,7 +888,7 @@
 		::codegenMutex.unlock();
 	}
 
-	Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
+	Routine *Nucleus::acquireRoutine(const char *name, bool runOptimizations)
 	{
 		if(::builder->GetInsertBlock()->empty() || !::builder->GetInsertBlock()->back().isTerminator())
 		{
@@ -954,13 +933,6 @@
 
 		LLVMRoutine *routine = ::reactorJIT->acquireRoutine(::function);
 
-#if defined(_WIN32) && REACTOR_LLVM_VERSION < 7
-		if(CodeAnalystLogJITCode)
-		{
-			CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name);
-		}
-#endif
-
 		return routine;
 	}
 
diff --git a/src/Reactor/Nucleus.hpp b/src/Reactor/Nucleus.hpp
index 7f63b96..ef695c5 100644
--- a/src/Reactor/Nucleus.hpp
+++ b/src/Reactor/Nucleus.hpp
@@ -53,7 +53,7 @@
 
 		virtual ~Nucleus();
 
-		Routine *acquireRoutine(const wchar_t *name, bool runOptimizations = true);
+		Routine *acquireRoutine(const char *name, bool runOptimizations = true);
 
 		static Value *allocateStackVariable(Type *type, int arraySize = 0);
 		static BasicBlock *createBasicBlock();
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index fe4cf1d..db4d5f8 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -20,7 +20,7 @@
 
 #include <cassert>
 #include <cstddef>
-#include <cwchar>
+#include <cstdio>
 #undef Bool
 
 namespace rr
@@ -2257,7 +2257,7 @@
 			return Argument<typename ArgI<index, Arguments...>::Type>(arg);
 		}
 
-		Routine *operator()(const wchar_t *name, ...);
+		Routine *operator()(const char *name, ...);
 
 	protected:
 		Nucleus *core;
@@ -2757,13 +2757,13 @@
 	}
 
 	template<typename Return, typename... Arguments>
-	Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...)
+	Routine *Function<Return(Arguments...)>::operator()(const char *name, ...)
 	{
-		wchar_t fullName[1024 + 1];
+		char fullName[1024 + 1];
 
 		va_list vararg;
 		va_start(vararg, name);
-		vswprintf(fullName, 1024, name, vararg);
+		vsnprintf(fullName, 1024, name, vararg);
 		va_end(vararg);
 
 		return core->acquireRoutine(fullName, true);
diff --git a/src/Reactor/ReactorUnitTests.cpp b/src/Reactor/ReactorUnitTests.cpp
index f6484f4..7cbde5d 100644
--- a/src/Reactor/ReactorUnitTests.cpp
+++ b/src/Reactor/ReactorUnitTests.cpp
@@ -59,7 +59,7 @@
 			Return(sum);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -97,7 +97,7 @@
 			Return(a + z + q + c);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -129,7 +129,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -187,7 +187,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -234,7 +234,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -303,7 +303,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -440,7 +440,7 @@
 			Return(x);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -479,7 +479,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -569,7 +569,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -650,7 +650,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -747,7 +747,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -826,7 +826,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -880,7 +880,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -934,7 +934,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
@@ -973,7 +973,7 @@
 			Return(0);
 		}
 
-		routine = function(L"one");
+		routine = function("one");
 
 		if(routine)
 		{
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 083576e..7048640 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -578,16 +578,14 @@
 		::codegenMutex.unlock();
 	}
 
-	Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
+	Routine *Nucleus::acquireRoutine(const char *name, bool runOptimizations)
 	{
 		if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
 		{
 			createRetVoid();
 		}
 
-		std::wstring wideName(name);
-		std::string asciiName(wideName.begin(), wideName.end());
-		::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
+		::function->setFunctionName(Ice::GlobalString::createWithString(::context, name));
 
 		optimize();
 
diff --git a/src/Renderer/Blitter.cpp b/src/Renderer/Blitter.cpp
index f8ce48c..8f88d9d 100644
--- a/src/Renderer/Blitter.cpp
+++ b/src/Renderer/Blitter.cpp
@@ -1385,7 +1385,7 @@
 			}
 		}
 
-		return function(L"BlitRoutine");
+		return function("BlitRoutine");
 	}
 
 	bool Blitter::blitReactor(Surface *source, const SliceRectF &sourceRect, Surface *dest, const SliceRect &destRect, const Blitter::Options &options)
diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index a1cafde..1a158a7 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -1201,7 +1201,7 @@
 			}
 
 			generator->generate();
-			routine = (*generator)(L"PixelRoutine_%0.8X", state.shaderID);
+			routine = (*generator)("PixelRoutine_%0.8X", state.shaderID);
 			delete generator;
 
 			routineCache->add(state, routine);
diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 976ea2b..50c5a32 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -1107,7 +1107,7 @@
 			}
 
 			generator->generate();
-			routine = (*generator)(L"VertexRoutine_%0.8X", state.shaderID);
+			routine = (*generator)("VertexRoutine_%0.8X", state.shaderID);
 			delete generator;
 
 			routineCache->add(state, routine);
diff --git a/src/Shader/SetupRoutine.cpp b/src/Shader/SetupRoutine.cpp
index d733c2d..e5bd7fd 100644
--- a/src/Shader/SetupRoutine.cpp
+++ b/src/Shader/SetupRoutine.cpp
@@ -476,7 +476,7 @@
 			Return(true);
 		}
 
-		routine = function(L"SetupRoutine");
+		routine = function("SetupRoutine");
 	}
 
 	void SetupRoutine::setupGradient(Pointer<Byte> &primitive, Pointer<Byte> &triangle, Float4 &w012, Float4 (&m)[3], Pointer<Byte> &v0, Pointer<Byte> &v1, Pointer<Byte> &v2, int attribute, int planeEquation, bool flat, bool sprite, bool perspective, bool wrap, int component)
diff --git a/src/WSI/FrameBuffer.cpp b/src/WSI/FrameBuffer.cpp
index 4b408c1..04ab0fa 100644
--- a/src/WSI/FrameBuffer.cpp
+++ b/src/WSI/FrameBuffer.cpp
@@ -476,7 +476,7 @@
 			}
 		}
 
-		return function(L"FrameBuffer");
+		return function("FrameBuffer");
 	}
 
 	void FrameBuffer::blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c)
diff --git a/tests/fuzzers/VertexRoutineFuzzer.cpp b/tests/fuzzers/VertexRoutineFuzzer.cpp
index 8f005dc..dd82b65 100644
--- a/tests/fuzzers/VertexRoutineFuzzer.cpp
+++ b/tests/fuzzers/VertexRoutineFuzzer.cpp
@@ -203,7 +203,7 @@
 	sw::VertexProgram program(state, bytecodeShader.get());
 	program.generate();
 
-	sw::Routine *routine = program(L"VertexRoutine");
+	sw::Routine *routine = program("VertexRoutine");
 	assert(routine);
 	const void *entry = routine->getEntry();
 	assert(entry); (void)entry;