/
/
set
swtich case
srand(time(
0
));
int
randNumCase
=
rand();
AllocaInst
*
swVarPtr
=
new AllocaInst(int32Type,
0
,
"swVar.ptr"
, entryBB);
new StoreInst(ConstantInt::get(int32Type,randNumCase),swVarPtr,entryBB);
/
/
creat loopEntry loopEnd swDefault
/
/
name loopEntry , belong to BasicBlock f , location entryBB (end)
BasicBlock
*
loopEntry
=
BasicBlock::Create(f
-
>getContext(),
"loopEntry"
, f, entryBB);
BasicBlock
*
loopEnd
=
BasicBlock::Create(f
-
>getContext(),
"loopEnd"
, f, entryBB);
BasicBlock
*
swDefault
=
BasicBlock::Create(f
-
>getContext(),
"swtichDefault"
,f,loopEnd);
entryBB
-
>moveBefore(loopEntry);
/
/
create swVar at loopEntry
LoadInst
*
swVar
=
new LoadInst(int32Type, swVarPtr,
"swVar"
, false, loopEntry);
/
/
entryBB
-
-
>loopEntry swDefault
-
-
>loopEnd
BranchInst::Create(loopEntry,entryBB);
BranchInst::Create(loopEnd,swDefault);
BranchInst::Create(loopEntry,loopEnd);
/
/
create switch at loopEntry
SwitchInst
*
switchI
=
SwitchInst::Create(swVar,swDefault,
0
,loopEntry);