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
bool validKey = ValidateSerialNumber(validationKey, CHECKSUM_KEY, SERIAL_PREFIX);
#endif
Function<Void, Pointer<Byte>, Pointer<Byte> > function;
Function<Void(Pointer<Byte>, Pointer<Byte>)> function;
{
Pointer<Byte> dst(function.arg(0));
Pointer<Byte> src(function.arg(1));
......
......@@ -2475,8 +2475,13 @@ namespace sw
template<class T>
void Return(RValue<Pointer<T> > ret);
template<class R = Void, class A1 = Void, class A2 = Void, class A3 = Void, class A4 = Void>
class Function
// Generic template, leave undefined!
template<typename FunctionType>
class Function;
// Specialized for function types
template<typename Return, typename... Arguments>
class Function<Return(Arguments...)>
{
public:
Function();
......@@ -2917,34 +2922,35 @@ namespace sw
Nucleus::setInsertBlock(Nucleus::createBasicBlock());
}
template<class R, class A1, class A2, class A3, class A4>
Function<R, A1, A2, A3, A4>::Function()
template<typename Return, typename... Arguments>
Function<Return(Arguments...)>::Function()
{
core = new Nucleus();
if(!A1::isVoid()) arguments.push_back(A1::getType());
if(!A2::isVoid()) arguments.push_back(A2::getType());
if(!A3::isVoid()) arguments.push_back(A3::getType());
if(!A4::isVoid()) arguments.push_back(A4::getType());
llvm::Type *types[] = {Arguments::getType()...};
for(llvm::Type *type : types)
{
arguments.push_back(type);
}
function = Nucleus::createFunction(R::getType(), arguments);
function = Nucleus::createFunction(Return::getType(), arguments);
Nucleus::setFunction(function);
}
template<class R, class A1, class A2, class A3, class A4>
Function<R, A1, A2, A3, A4>::~Function()
template<typename Return, typename... Arguments>
Function<Return(Arguments...)>::~Function()
{
delete core;
}
template<class R, class A1, class A2, class A3, class A4>
llvm::Argument *Function<R, A1, A2, A3, A4>::arg(int index)
template<typename Return, typename... Arguments>
llvm::Argument *Function<Return(Arguments...)>::arg(int index)
{
return Nucleus::getArgument(function, index);
}
template<class R, class A1, class A2, class A3, class A4>
Routine *Function<R, A1, A2, A3, A4>::operator()(const wchar_t *name, ...)
template<typename Return, typename... Arguments>
Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...)
{
wchar_t fullName[1024 + 1];
......
......@@ -964,7 +964,7 @@ namespace sw
Routine *Blitter::generate(BlitState &state)
{
Function<Void, Pointer<Byte> > function;
Function<Void(Pointer<Byte>)> function;
{
Pointer<Byte> blit(function.arg(0));
......
......@@ -47,7 +47,7 @@ namespace sw
void QuadRasterizer::generate()
{
Function<Void, Pointer<Byte>, Int, Int, Pointer<Byte> > function;
Function<Void(Pointer<Byte>, Int, Int, Pointer<Byte>)> function;
{
#if PERF_PROFILE
Long pixelTime = Ticks();
......
......@@ -34,7 +34,7 @@ namespace sw
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> tri(function.arg(1));
......
......@@ -34,7 +34,7 @@ namespace sw
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> 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