return function;
}
- llvm::Argument *Nucleus::getArgument(llvm::Function *function, unsigned int index)
+ llvm::Value *Nucleus::getArgument(llvm::Function *function, unsigned int index)
{
llvm::Function::arg_iterator args = function->arg_begin();
return Type::getX86_MMXTy(*Nucleus::getContext());
}
- Bool::Bool(Argument *argument)
+ Bool::Bool(Argument<Bool> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
Bool::Bool()
return Type::getInt1Ty(*Nucleus::getContext());
}
- Byte::Byte(Argument *argument)
+ Byte::Byte(Argument<Byte> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
Byte::Byte(RValue<Int> cast)
return Type::getInt8Ty(*Nucleus::getContext());
}
- SByte::SByte(Argument *argument)
+ SByte::SByte(Argument<SByte> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
SByte::SByte(RValue<Int> cast)
return Type::getInt8Ty(*Nucleus::getContext());
}
- Short::Short(Argument *argument)
+ Short::Short(Argument<Short> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
Short::Short(RValue<Int> cast)
return Type::getInt16Ty(*Nucleus::getContext());
}
- UShort::UShort(Argument *argument)
+ UShort::UShort(Argument<UShort> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
UShort::UShort(RValue<UInt> cast)
return VectorType::get(UShort::getType(), 8);
}
- Int::Int(Argument *argument)
+ Int::Int(Argument<Int> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
Int::Int(RValue<Byte> cast)
return VectorType::get(Long::getType(), 2);
}
- UInt::UInt(Argument *argument)
+ UInt::UInt(Argument<UInt> argument)
{
- storeValue(argument);
+ storeValue(argument.value);
}
UInt::UInt(RValue<UShort> cast)
return VectorType::get(Float::getType(), 4);
}
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset)
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
{
- return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
}
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{
- return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
}
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{
- return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value));
+ return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
}
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset)
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
{
return lhs = lhs + offset;
}
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
{
return lhs = lhs + offset;
}
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
{
return lhs = lhs + offset;
}
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset)
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
{
return lhs + -offset;
}
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset)
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{
return lhs + -offset;
}
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset)
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{
return lhs + -offset;
}
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset)
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset)
{
return lhs = lhs - offset;
}
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
{
return lhs = lhs - offset;
}
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
{
return lhs = lhs - offset;
}
return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
}
- //RValue<Int2> movd(RValue<Pointer<Int> > x)
+ //RValue<Int2> movd(RValue<Pointer<Int>> x)
//{
// Value *element = Nucleus::createLoad(x.value);
static llvm::BasicBlock *getPredecessor(llvm::BasicBlock *basicBlock);\r
\r
static llvm::Function *createFunction(llvm::Type *ReturnType, std::vector<llvm::Type*> &Params);\r
- static llvm::Argument *getArgument(llvm::Function *function, unsigned int index);\r
+ static llvm::Value *getArgument(llvm::Function *function, unsigned int index);\r
\r
// Terminators\r
static llvm::Value *createRetVoid();\r
public:\r
Variable(int arraySize = 0);\r
\r
- RValue<Pointer<T> > operator&();\r
+ RValue<Pointer<T>> operator&();\r
};\r
\r
template<class T>\r
llvm::Value *value; // FIXME: Make private\r
};\r
\r
+ template<typename T>\r
+ struct Argument\r
+ {\r
+ explicit Argument(llvm::Value *value) : value(value) {}\r
+\r
+ llvm::Value *value;\r
+ };\r
+\r
class MMX : public Variable<MMX>\r
{\r
public:\r
class Bool : public Variable<Bool>\r
{\r
public:\r
- explicit Bool(llvm::Argument *argument);\r
+ Bool(Argument<Bool> argument);\r
\r
Bool();\r
Bool(bool x);\r
class Byte : public Variable<Byte>\r
{\r
public:\r
- explicit Byte(llvm::Argument *argument);\r
+ Byte(Argument<Byte> argument);\r
\r
explicit Byte(RValue<Int> cast);\r
explicit Byte(RValue<UInt> cast);\r
class SByte : public Variable<SByte>\r
{\r
public:\r
- explicit SByte(llvm::Argument *argument);\r
+ SByte(Argument<SByte> argument);\r
\r
explicit SByte(RValue<Int> cast);\r
explicit SByte(RValue<Short> cast);\r
class Short : public Variable<Short>\r
{\r
public:\r
- explicit Short(llvm::Argument *argument);\r
+ Short(Argument<Short> argument);\r
\r
explicit Short(RValue<Int> cast);\r
\r
class UShort : public Variable<UShort>\r
{\r
public:\r
- explicit UShort(llvm::Argument *argument);\r
+ UShort(Argument<UShort> argument);\r
\r
explicit UShort(RValue<UInt> cast);\r
explicit UShort(RValue<Int> cast);\r
class Int : public Variable<Int>\r
{\r
public:\r
- explicit Int(llvm::Argument *argument);\r
+ Int(Argument<Int> argument);\r
\r
explicit Int(RValue<Byte> cast);\r
explicit Int(RValue<SByte> cast);\r
class Long : public Variable<Long>\r
{\r
public:\r
- // explicit Long(llvm::Argument *argument);\r
+ // Long(Argument<Long> argument);\r
\r
// explicit Long(RValue<Short> cast);\r
// explicit Long(RValue<UShort> cast);\r
// RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs);\r
\r
// RValue<Long> RoundLong(RValue<Float> cast);\r
- RValue<Long> AddAtomic( RValue<Pointer<Long> > x, RValue<Long> y);\r
+ RValue<Long> AddAtomic( RValue<Pointer<Long>> x, RValue<Long> y);\r
\r
class Long1 : public Variable<Long1>\r
{\r
public:\r
- // explicit Long1(llvm::Argument *argument);\r
+ // Long1(Argument<Long1> argument);\r
\r
// explicit Long1(RValue<Short> cast);\r
// explicit Long1(RValue<UShort> cast);\r
class UInt : public Variable<UInt>\r
{\r
public:\r
- explicit UInt(llvm::Argument *argument);\r
+ UInt(Argument<UInt> argument);\r
\r
explicit UInt(RValue<UShort> cast);\r
explicit UInt(RValue<Long> cast);\r
RValue<Float4> Ceil(RValue<Float4> x);\r
\r
template<class T>\r
- class Pointer : public Variable<Pointer<T> >\r
+ class Pointer : public Variable<Pointer<T>>\r
{\r
public:\r
template<class S>\r
- Pointer(RValue<Pointer<S> > pointerS, int alignment = 1) : alignment(alignment)\r
+ Pointer(RValue<Pointer<S>> pointerS, int alignment = 1) : alignment(alignment)\r
{\r
llvm::Value *pointerT = Nucleus::createBitCast(pointerS.value, Nucleus::getPointerType(T::getType()));\r
LValue::storeValue(pointerT);\r
LValue::storeValue(pointerT);\r
}\r
\r
- explicit Pointer(llvm::Argument *argument);\r
+ Pointer(Argument<Pointer<T>> argument);\r
explicit Pointer(const void *external);\r
\r
Pointer();\r
- Pointer(RValue<Pointer<T> > rhs);\r
+ Pointer(RValue<Pointer<T>> rhs);\r
Pointer(const Pointer<T> &rhs);\r
- Pointer(const Reference<Pointer<T> > &rhs);\r
+ Pointer(const Reference<Pointer<T>> &rhs);\r
\r
- RValue<Pointer<T> > operator=(RValue<Pointer<T> > rhs) const;\r
- RValue<Pointer<T> > operator=(const Pointer<T> &rhs) const;\r
- RValue<Pointer<T> > operator=(const Reference<Pointer<T> > &rhs) const;\r
+ RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs) const;\r
+ RValue<Pointer<T>> operator=(const Pointer<T> &rhs) const;\r
+ RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs) const;\r
\r
Reference<T> operator*();\r
\r
const int alignment;\r
};\r
\r
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset);\r
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset);\r
- RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset);\r
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset);\r
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset);\r
- RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset);\r
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);\r
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);\r
+ RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);\r
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset);\r
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset);\r
+ RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset);\r
\r
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset);\r
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset);\r
- RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset);\r
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset);\r
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset);\r
- RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset);\r
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);\r
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);\r
+ RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);\r
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset);\r
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset);\r
+ RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset);\r
\r
template<class T, int S = 1>\r
class Array : public Variable<T>\r
Reference<T> operator[](RValue<UInt> index);\r
};\r
\r
-// RValue<Array<T> > operator++(const Array<T> &val, int); // Post-increment\r
+// RValue<Array<T>> operator++(const Array<T> &val, int); // Post-increment\r
// const Array<T> &operator++(const Array<T> &val); // Pre-increment\r
-// RValue<Array<T> > operator--(const Array<T> &val, int); // Post-decrement\r
+// RValue<Array<T>> operator--(const Array<T> &val, int); // Post-decrement\r
// const Array<T> &operator--(const Array<T> &val); // Pre-decrement\r
\r
llvm::BasicBlock *beginLoop();\r
void Return(const Pointer<T> &ret);\r
\r
template<class T>\r
- void Return(RValue<Pointer<T> > ret);\r
+ void Return(RValue<Pointer<T>> ret);\r
+\r
+ template<unsigned int index, typename... Arguments>\r
+ struct ArgI;\r
+\r
+ template<typename Arg0, typename... Arguments>\r
+ struct ArgI<0, Arg0, Arguments...>\r
+ {\r
+ typedef Arg0 Type;\r
+ };\r
+\r
+ template<unsigned int index, typename Arg0, typename... Arguments>\r
+ struct ArgI<index, Arg0, Arguments...>\r
+ {\r
+ typedef typename ArgI<index - 1, Arguments...>::Type Type;\r
+ };\r
\r
// Generic template, leave undefined!\r
template<typename FunctionType>\r
\r
virtual ~Function();\r
\r
- llvm::Argument *arg(int index);\r
+ template<int index>\r
+ Argument<typename ArgI<index, Arguments...>::Type> Arg() const\r
+ {\r
+ llvm::Value *arg = Nucleus::getArgument(function, index);\r
+ return Argument<typename ArgI<index, Arguments...>::Type>(arg);\r
+ }\r
\r
Routine *operator()(const wchar_t *name, ...);\r
\r
std::vector<llvm::Type*> arguments;\r
};\r
\r
+ template<int index, typename Return, typename... Arguments>\r
+ Argument<typename ArgI<index, Arguments...>::Type> Arg(Function<Return(Arguments...)> &function)\r
+ {\r
+ return Argument<typename ArgI<index, Arguments...>::Type>(function.arg(index));\r
+ }\r
+\r
RValue<Long> Ticks();\r
}\r
\r
}\r
\r
template<class T>\r
- RValue<Pointer<T> > Variable<T>::operator&()\r
+ RValue<Pointer<T>> Variable<T>::operator&()\r
{\r
- return RValue<Pointer<T> >(LValue::address);\r
+ return RValue<Pointer<T>>(LValue::address);\r
}\r
\r
template<class T>\r
}\r
\r
template<class T>\r
- Pointer<T>::Pointer(llvm::Argument *argument) : alignment(1)\r
+ Pointer<T>::Pointer(Argument<Pointer<T>> argument) : alignment(1)\r
{\r
- LValue::storeValue((llvm::Value*)argument);\r
+ LValue::storeValue(argument.value);\r
}\r
\r
template<class T>\r
}\r
\r
template<class T>\r
- Pointer<T>::Pointer(RValue<Pointer<T> > rhs) : alignment(1)\r
+ Pointer<T>::Pointer(RValue<Pointer<T>> rhs) : alignment(1)\r
{\r
LValue::storeValue(rhs.value);\r
}\r
}\r
\r
template<class T>\r
- Pointer<T>::Pointer(const Reference<Pointer<T> > &rhs) : alignment(rhs.getAlignment())\r
+ Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs) : alignment(rhs.getAlignment())\r
{\r
llvm::Value *value = rhs.loadValue();\r
LValue::storeValue(value);\r
}\r
\r
template<class T>\r
- RValue<Pointer<T> > Pointer<T>::operator=(RValue<Pointer<T> > rhs) const\r
+ RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs) const\r
{\r
LValue::storeValue(rhs.value);\r
\r
}\r
\r
template<class T>\r
- RValue<Pointer<T> > Pointer<T>::operator=(const Pointer<T> &rhs) const\r
+ RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs) const\r
{\r
llvm::Value *value = rhs.loadValue();\r
LValue::storeValue(value);\r
\r
- return RValue<Pointer<T> >(value);\r
+ return RValue<Pointer<T>>(value);\r
}\r
\r
template<class T>\r
- RValue<Pointer<T> > Pointer<T>::operator=(const Reference<Pointer<T> > &rhs) const\r
+ RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs) const\r
{\r
llvm::Value *value = rhs.loadValue();\r
LValue::storeValue(value);\r
\r
- return RValue<Pointer<T> >(value);\r
+ return RValue<Pointer<T>>(value);\r
}\r
\r
template<class T>\r
}\r
\r
// template<class T>\r
-// RValue<Array<T> > operator++(const Array<T> &val, int)\r
+// RValue<Array<T>> operator++(const Array<T> &val, int)\r
// {\r
// // FIXME: Requires storing the address of the array\r
// }\r
// }\r
\r
// template<class T>\r
-// RValue<Array<T> > operator--(const Array<T> &val, int)\r
+// RValue<Array<T>> operator--(const Array<T> &val, int)\r
// {\r
// // FIXME: Requires storing the address of the array\r
// }\r
}\r
\r
template<class T>\r
- void Return(RValue<Pointer<T> > ret)\r
+ void Return(RValue<Pointer<T>> ret)\r
{\r
Nucleus::createRet(ret.value);\r
Nucleus::setInsertBlock(Nucleus::createBasicBlock());\r
for(llvm::Type *type : types)\r
{\r
arguments.push_back(type);\r
- } \r
+ }\r
\r
function = Nucleus::createFunction(Return::getType(), arguments);\r
Nucleus::setFunction(function);\r
}\r
\r
template<typename Return, typename... Arguments>\r
- llvm::Argument *Function<Return(Arguments...)>::arg(int index)\r
- {\r
- return Nucleus::getArgument(function, index);\r
- }\r
-\r
- template<typename Return, typename... Arguments>\r
Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...)\r
{\r
wchar_t fullName[1024 + 1];\r