Reactor.hpp revision d946e0a3ab6030aad58a458e5a50b976364a01c1
1// SwiftShader Software Renderer
2//
3// Copyright(c) 2005-2011 TransGaming Inc.
4//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#include "Nucleus.hpp"
13#include "Routine.hpp"
14
15namespace sw
16{
17	#define For(init, cond, inc)                     \
18	init;                                            \
19	for(llvm::BasicBlock *loopBB__ = beginLoop(),    \
20		*bodyBB__ = Nucleus::createBasicBlock(),        \
21		*endBB__ = Nucleus::createBasicBlock(),         \
22		*onceBB__ = endBB__;                         \
23		onceBB__ && branch(cond, bodyBB__, endBB__); \
24		inc, onceBB__ = 0, Nucleus::createBr(loopBB__), Nucleus::setInsertBlock(endBB__))
25
26	#define While(cond) For(((void*)0), cond, ((void*)0))
27
28	#define Do \
29	{ \
30		llvm::BasicBlock *body = Nucleus::createBasicBlock(); \
31		Nucleus::createBr(body); \
32		Nucleus::setInsertBlock(body);
33
34	#define Until(cond) \
35		llvm::BasicBlock *end = Nucleus::createBasicBlock(); \
36		Nucleus::createCondBr((cond).value, end, body); \
37		Nucleus::setInsertBlock(end); \
38	}
39
40	#define If(cond)                                                              \
41	for(llvm::BasicBlock *trueBB__ = Nucleus::createBasicBlock(), \
42		*falseBB__ = Nucleus::createBasicBlock(),                 \
43		*endBB__ = Nucleus::createBasicBlock(),                   \
44		*onceBB__ = endBB__;                                   \
45		onceBB__ && branch(cond, trueBB__, falseBB__);         \
46		onceBB__ = 0, Nucleus::createBr(endBB__), Nucleus::setInsertBlock(falseBB__), Nucleus::createBr(endBB__), Nucleus::setInsertBlock(endBB__))
47
48	#define Else                                            \
49	for(llvm::BasicBlock *endBB__ = Nucleus::getInsertBlock(), \
50		*falseBB__ = Nucleus::getPredecessor(endBB__),         \
51		*onceBB__ = endBB__;                                \
52		onceBB__ && elseBlock(falseBB__);                   \
53		onceBB__ = 0, Nucleus::createBr(endBB__), Nucleus::setInsertBlock(endBB__))
54}