Commit cf5be24a by Nicolas Capens

Implement Reactor pointer subscript operator.

Change-Id: I8f4604a0cd81f004d46172d286286722b6198dd5 Reviewed-on: https://swiftshader-review.googlesource.com/5700Reviewed-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 05c32b9b
......@@ -216,9 +216,7 @@ Function<Int(Pointer<Int>, Int)> function;
For(Int i = 0, i < n, i++)
{
total += *p;
p = Pointer<Int>(Pointer<Byte>(p) + sizeof(int));
total += p[i];
}
Return(total);
......@@ -245,22 +243,20 @@ Function<Int(Pointer<Int>, Int)> function;
{
if(state.operation == ADD)
{
total += *p;
total += p[i];
}
else if(state.operation == SUBTRACT)
{
total -= *p;
total -= p[i];
}
else if(state.operation == AND)
{
total &= *p;
total &= p[i];
}
else if(...)
{
...
}
p = Pointer<Int>(Pointer<Byte>(p) + sizeof(int));
}
Return(total);
......
......@@ -2436,6 +2436,8 @@ namespace sw
RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs) const;
Reference<T> operator*();
Reference<T> operator[](int index);
Reference<T> operator[](RValue<Int> index);
static llvm::Type *getType();
......@@ -2465,7 +2467,6 @@ namespace sw
Reference<T> operator[](int index);
Reference<T> operator[](RValue<Int> index);
Reference<T> operator[](RValue<UInt> index);
};
// RValue<Array<T>> operator++(const Array<T> &val, int); // Post-increment
......@@ -2857,6 +2858,22 @@ namespace sw
}
template<class T>
Reference<T> Pointer<T>::operator[](int index)
{
llvm::Value *element = Nucleus::createGEP(LValue::loadValue(), (llvm::Value*)Nucleus::createConstantInt(index));
return Reference<T>(element, alignment);
}
template<class T>
Reference<T> Pointer<T>::operator[](RValue<Int> index)
{
llvm::Value *element = Nucleus::createGEP(LValue::loadValue(), index.value);
return Reference<T>(element, alignment);
}
template<class T>
llvm::Type *Pointer<T>::getType()
{
return Nucleus::getPointerType(T::getType());
......@@ -2883,14 +2900,6 @@ namespace sw
return Reference<T>(element);
}
template<class T, int S>
Reference<T> Array<T, S>::operator[](RValue<UInt> index)
{
llvm::Value *element = LValue::getAddress(index.value);
return Reference<T>(element);
}
// template<class T>
// RValue<Array<T>> operator++(const Array<T> &val, int)
// {
......
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