LLVM 인스트럭션 타입이랑 같이 출력

씨디팔공/팁 2016.06.10 14:29
크리에이티브 커먼즈 라이선스
Creative Commons License

도저히 인스트럭션이 llvm api상에서 무슨 타입인지 알수가 없어서 만들었습니다, 이 코드를 적용하면서 코드를 작성한 저도 제가 작업하는 LLVM버젼에 적용하면서 아주 약간 수정하면서 썼으니 필요에 따라 수정하면서 쓰시면됩니다

예를들어 LandingPadInst에서 and가 지워지고 LingPadInst 로 돼있습니다

이 글을 작성(6월 10일)하고 코드에 문제가 좀 있어서 공개를 안하고 있었는데 LLVM글 작성을 시작하면서 공개(7월 15일) 했습니다

inst_types = ['AddrSpaceCastInst', 'BitCastInst', 'PtrToIntInst', 'IntToPtrInst', 'FPToSIInst', 'FPToUIInst', 'SIToFPInst', 'UIToFPInst', 'FPExtInst', 'FPTruncInst', 'SExtInst', 'ZExtInst', 'TruncInst', 'UnreachableInst', 'CleanupReturnInst', 'CatchReturnInst', 'CatchPadInst', 'CleanupPadInst', 'CatchSwitchInst', 'ResumeInst', 'InvokeInst', 'IndirectBrInst', 'SwitchInst', 'BranchInst', 'ReturnInst', 'LingPadInst', 'PHINode', 'InsertValueInst', 'ExtractValueInst', 'ShuffleVectorInst', 'InsertElementInst', 'ExtractElementInst', 'VAArgInst', 'SelectInst', 'CallInst', 'FCmpInst', 'ICmpInst', 'FuncletPadInst', 'CmpInst', 'GetElementPtrInst', 'CastInst', 'AtomicRMWInst', 'AtomicCmpXchgInst', 'BinaryOperator', 'FenceInst', 'StoreInst', 'InstrProfValueProfileInst', 'InstrProfIncrementInst', 'VACopyInst', 'VAEndInst', 'GCRelocateInst', 'UnaryInstruction', 'VAStartInst', 'MemMoveInst', 'LoadInst', 'MemCpyInst', 'MemTransferInst', 'MemSetInst', 'MemIntrinsic', 'AllocaInst', 'DbgValueInst', 'DbgDeclareInst', 'TerminatorInst', 'DbgInfoIntrinsic', 'IntrinsicInst']
cpp_code = "void printInstWithType(Instruction inst){\n"
for inst_type in inst_types:
	cpp_code += ("""
	if(isa<%s>(inst)){
		errs() << "[%s] " << inst << "\\n";
	}
"""%(inst_type, inst_type))[1:]
cpp_code += "}"
print cpp_code
void printInstWithType(Instruction inst){
	if(isa<AddrSpaceCastInst>(inst)){
		errs() << "[AddrSpaceCastInst] " << inst << "\n";
	}
	if(isa<BitCastInst>(inst)){
		errs() << "[BitCastInst] " << inst << "\n";
	}
	if(isa<PtrToIntInst>(inst)){
		errs() << "[PtrToIntInst] " << inst << "\n";
	}
	if(isa<IntToPtrInst>(inst)){
		errs() << "[IntToPtrInst] " << inst << "\n";
	}
	if(isa<FPToSIInst>(inst)){
		errs() << "[FPToSIInst] " << inst << "\n";
	}
	if(isa<FPToUIInst>(inst)){
		errs() << "[FPToUIInst] " << inst << "\n";
	}
	if(isa<SIToFPInst>(inst)){
		errs() << "[SIToFPInst] " << inst << "\n";
	}
	if(isa<UIToFPInst>(inst)){
		errs() << "[UIToFPInst] " << inst << "\n";
	}
	if(isa<FPExtInst>(inst)){
		errs() << "[FPExtInst] " << inst << "\n";
	}
	if(isa<FPTruncInst>(inst)){
		errs() << "[FPTruncInst] " << inst << "\n";
	}
	if(isa<SExtInst>(inst)){
		errs() << "[SExtInst] " << inst << "\n";
	}
	if(isa<ZExtInst>(inst)){
		errs() << "[ZExtInst] " << inst << "\n";
	}
	if(isa<TruncInst>(inst)){
		errs() << "[TruncInst] " << inst << "\n";
	}
	if(isa<UnreachableInst>(inst)){
		errs() << "[UnreachableInst] " << inst << "\n";
	}
	if(isa<CleanupReturnInst>(inst)){
		errs() << "[CleanupReturnInst] " << inst << "\n";
	}
	if(isa<CatchReturnInst>(inst)){
		errs() << "[CatchReturnInst] " << inst << "\n";
	}
	if(isa<CatchPadInst>(inst)){
		errs() << "[CatchPadInst] " << inst << "\n";
	}
	if(isa<CleanupPadInst>(inst)){
		errs() << "[CleanupPadInst] " << inst << "\n";
	}
	if(isa<CatchSwitchInst>(inst)){
		errs() << "[CatchSwitchInst] " << inst << "\n";
	}
	if(isa<ResumeInst>(inst)){
		errs() << "[ResumeInst] " << inst << "\n";
	}
	if(isa<InvokeInst>(inst)){
		errs() << "[InvokeInst] " << inst << "\n";
	}
	if(isa<IndirectBrInst>(inst)){
		errs() << "[IndirectBrInst] " << inst << "\n";
	}
	if(isa<SwitchInst>(inst)){
		errs() << "[SwitchInst] " << inst << "\n";
	}
	if(isa<BranchInst>(inst)){
		errs() << "[BranchInst] " << inst << "\n";
	}
	if(isa<ReturnInst>(inst)){
		errs() << "[ReturnInst] " << inst << "\n";
	}
	if(isa<LingPadInst>(inst)){
		errs() << "[LingPadInst] " << inst << "\n";
	}
	if(isa<PHINode>(inst)){
		errs() << "[PHINode] " << inst << "\n";
	}
	if(isa<InsertValueInst>(inst)){
		errs() << "[InsertValueInst] " << inst << "\n";
	}
	if(isa<ExtractValueInst>(inst)){
		errs() << "[ExtractValueInst] " << inst << "\n";
	}
	if(isa<ShuffleVectorInst>(inst)){
		errs() << "[ShuffleVectorInst] " << inst << "\n";
	}
	if(isa<InsertElementInst>(inst)){
		errs() << "[InsertElementInst] " << inst << "\n";
	}
	if(isa<ExtractElementInst>(inst)){
		errs() << "[ExtractElementInst] " << inst << "\n";
	}
	if(isa<VAArgInst>(inst)){
		errs() << "[VAArgInst] " << inst << "\n";
	}
	if(isa<SelectInst>(inst)){
		errs() << "[SelectInst] " << inst << "\n";
	}
	if(isa<CallInst>(inst)){
		errs() << "[CallInst] " << inst << "\n";
	}
	if(isa<FCmpInst>(inst)){
		errs() << "[FCmpInst] " << inst << "\n";
	}
	if(isa<ICmpInst>(inst)){
		errs() << "[ICmpInst] " << inst << "\n";
	}
	if(isa<FuncletPadInst>(inst)){
		errs() << "[FuncletPadInst] " << inst << "\n";
	}
	if(isa<CmpInst>(inst)){
		errs() << "[CmpInst] " << inst << "\n";
	}
	if(isa<GetElementPtrInst>(inst)){
		errs() << "[GetElementPtrInst] " << inst << "\n";
	}
	if(isa<CastInst>(inst)){
		errs() << "[CastInst] " << inst << "\n";
	}
	if(isa<AtomicRMWInst>(inst)){
		errs() << "[AtomicRMWInst] " << inst << "\n";
	}
	if(isa<AtomicCmpXchgInst>(inst)){
		errs() << "[AtomicCmpXchgInst] " << inst << "\n";
	}
	if(isa<BinaryOperator>(inst)){
		errs() << "[BinaryOperator] " << inst << "\n";
	}
	if(isa<FenceInst>(inst)){
		errs() << "[FenceInst] " << inst << "\n";
	}
	if(isa<StoreInst>(inst)){
		errs() << "[StoreInst] " << inst << "\n";
	}
	if(isa<InstrProfValueProfileInst>(inst)){
		errs() << "[InstrProfValueProfileInst] " << inst << "\n";
	}
	if(isa<InstrProfIncrementInst>(inst)){
		errs() << "[InstrProfIncrementInst] " << inst << "\n";
	}
	if(isa<VACopyInst>(inst)){
		errs() << "[VACopyInst] " << inst << "\n";
	}
	if(isa<VAEndInst>(inst)){
		errs() << "[VAEndInst] " << inst << "\n";
	}
	if(isa<GCRelocateInst>(inst)){
		errs() << "[GCRelocateInst] " << inst << "\n";
	}
	if(isa<UnaryInstruction>(inst)){
		errs() << "[UnaryInstruction] " << inst << "\n";
	}
	if(isa<VAStartInst>(inst)){
		errs() << "[VAStartInst] " << inst << "\n";
	}
	if(isa<MemMoveInst>(inst)){
		errs() << "[MemMoveInst] " << inst << "\n";
	}
	if(isa<LoadInst>(inst)){
		errs() << "[LoadInst] " << inst << "\n";
	}
	if(isa<MemCpyInst>(inst)){
		errs() << "[MemCpyInst] " << inst << "\n";
	}
	if(isa<MemTransferInst>(inst)){
		errs() << "[MemTransferInst] " << inst << "\n";
	}
	if(isa<MemSetInst>(inst)){
		errs() << "[MemSetInst] " << inst << "\n";
	}
	if(isa<MemIntrinsic>(inst)){
		errs() << "[MemIntrinsic] " << inst << "\n";
	}
	if(isa<AllocaInst>(inst)){
		errs() << "[AllocaInst] " << inst << "\n";
	}
	if(isa<DbgValueInst>(inst)){
		errs() << "[DbgValueInst] " << inst << "\n";
	}
	if(isa<DbgDeclareInst>(inst)){
		errs() << "[DbgDeclareInst] " << inst << "\n";
	}
	if(isa<TerminatorInst>(inst)){
		errs() << "[TerminatorInst] " << inst << "\n";
	}
	if(isa<DbgInfoIntrinsic>(inst)){
		errs() << "[DbgInfoIntrinsic] " << inst << "\n";
	}
	if(isa<IntrinsicInst>(inst)){
		errs() << "[IntrinsicInst] " << inst << "\n";
	}
}


신고

'씨디팔공 > ' 카테고리의 다른 글

IT인들을 위한 건강챙기기 팁  (2) 2017.03.30
LLVM 인스트럭션 타입이랑 같이 출력  (0) 2016.06.10

설정

트랙백

댓글


티스토리 툴바