Commit 2ab859f2 by Nicolas Capens

Make Function variadic and take a function signature.

Change-Id: If36ea6e74311f54bb4c2b0bc1b5b7ccd0e97d74b Reviewed-on: https://swiftshader-review.googlesource.com/4548Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 698633a8
...@@ -234,7 +234,7 @@ namespace sw ...@@ -234,7 +234,7 @@ namespace sw
bool validKey = ValidateSerialNumber(validationKey, CHECKSUM_KEY, SERIAL_PREFIX); bool validKey = ValidateSerialNumber(validationKey, CHECKSUM_KEY, SERIAL_PREFIX);
#endif #endif
Function<Void, Pointer<Byte>, Pointer<Byte> > function; Function<Void(Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> dst(function.arg(0)); Pointer<Byte> dst(function.arg(0));
Pointer<Byte> src(function.arg(1)); Pointer<Byte> src(function.arg(1));
......
...@@ -2475,8 +2475,13 @@ namespace sw ...@@ -2475,8 +2475,13 @@ namespace sw
template<class T> template<class T>
void Return(RValue<Pointer<T> > ret); void Return(RValue<Pointer<T> > ret);
template<class R = Void, class A1 = Void, class A2 = Void, class A3 = Void, class A4 = Void> // Generic template, leave undefined!
class Function template<typename FunctionType>
class Function;
// Specialized for function types
template<typename Return, typename... Arguments>
class Function<Return(Arguments...)>
{ {
public: public:
Function(); Function();
...@@ -2917,34 +2922,35 @@ namespace sw ...@@ -2917,34 +2922,35 @@ namespace sw
Nucleus::setInsertBlock(Nucleus::createBasicBlock()); Nucleus::setInsertBlock(Nucleus::createBasicBlock());
} }
template<class R, class A1, class A2, class A3, class A4> template<typename Return, typename... Arguments>
Function<R, A1, A2, A3, A4>::Function() Function<Return(Arguments...)>::Function()
{ {
core = new Nucleus(); core = new Nucleus();
if(!A1::isVoid()) arguments.push_back(A1::getType()); llvm::Type *types[] = {Arguments::getType()...};
if(!A2::isVoid()) arguments.push_back(A2::getType()); for(llvm::Type *type : types)
if(!A3::isVoid()) arguments.push_back(A3::getType()); {
if(!A4::isVoid()) arguments.push_back(A4::getType()); arguments.push_back(type);
}
function = Nucleus::createFunction(R::getType(), arguments); function = Nucleus::createFunction(Return::getType(), arguments);
Nucleus::setFunction(function); Nucleus::setFunction(function);
} }
template<class R, class A1, class A2, class A3, class A4> template<typename Return, typename... Arguments>
Function<R, A1, A2, A3, A4>::~Function() Function<Return(Arguments...)>::~Function()
{ {
delete core; delete core;
} }
template<class R, class A1, class A2, class A3, class A4> template<typename Return, typename... Arguments>
llvm::Argument *Function<R, A1, A2, A3, A4>::arg(int index) llvm::Argument *Function<Return(Arguments...)>::arg(int index)
{ {
return Nucleus::getArgument(function, index); return Nucleus::getArgument(function, index);
} }
template<class R, class A1, class A2, class A3, class A4> template<typename Return, typename... Arguments>
Routine *Function<R, A1, A2, A3, A4>::operator()(const wchar_t *name, ...) Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...)
{ {
wchar_t fullName[1024 + 1]; wchar_t fullName[1024 + 1];
......
...@@ -964,7 +964,7 @@ namespace sw ...@@ -964,7 +964,7 @@ namespace sw
Routine *Blitter::generate(BlitState &state) Routine *Blitter::generate(BlitState &state)
{ {
Function<Void, Pointer<Byte> > function; Function<Void(Pointer<Byte>)> function;
{ {
Pointer<Byte> blit(function.arg(0)); Pointer<Byte> blit(function.arg(0));
......
...@@ -47,7 +47,7 @@ namespace sw ...@@ -47,7 +47,7 @@ namespace sw
void QuadRasterizer::generate() void QuadRasterizer::generate()
{ {
Function<Void, Pointer<Byte>, Int, Int, Pointer<Byte> > function; Function<Void(Pointer<Byte>, Int, Int, Pointer<Byte>)> function;
{ {
#if PERF_PROFILE #if PERF_PROFILE
Long pixelTime = Ticks(); Long pixelTime = Ticks();
......
...@@ -34,7 +34,7 @@ namespace sw ...@@ -34,7 +34,7 @@ namespace sw
void SetupRoutine::generate() void SetupRoutine::generate()
{ {
Function<Bool, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte> > function; Function<Bool(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> primitive(function.arg(0)); Pointer<Byte> primitive(function.arg(0));
Pointer<Byte> tri(function.arg(1)); Pointer<Byte> tri(function.arg(1));
......
...@@ -34,7 +34,7 @@ namespace sw ...@@ -34,7 +34,7 @@ namespace sw
void VertexRoutine::generate() void VertexRoutine::generate()
{ {
Function<Void, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte> > function; Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> vertex(function.arg(0)); Pointer<Byte> vertex(function.arg(0));
Pointer<Byte> batch(function.arg(1)); Pointer<Byte> batch(function.arg(1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment