Add upport for bitcast in the C API echo test

llvm-svn: 261177
This commit is contained in:
Amaury Sechet 2016-02-17 23:55:59 +00:00
parent 71434ff642
commit 40bbe519e5
1 changed files with 18 additions and 1 deletions

View File

@ -276,12 +276,24 @@ LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) {
if (LLVMIsUndef(Cst))
return LLVMGetUndef(TypeCloner(M).Clone(Cst));
// Try float literal
if (LLVMIsAConstantFP(Cst))
report_fatal_error("ConstantFP is not supported");
// This kind of constant is not supported
if (!LLVMIsAConstantExpr(Cst))
report_fatal_error("Expected a constant expression");
// At this point, it must be a constant expression
report_fatal_error("ConstantExpression are not supported");
LLVMOpcode Op = LLVMGetConstOpcode(Cst);
switch(Op) {
case LLVMBitCast:
return LLVMConstBitCast(clone_constant(LLVMGetOperand(Cst, 0), M),
TypeCloner(M).Clone(Cst));
default:
fprintf(stderr, "%d is not a supported opcode\n", Op);
exit(-1);
}
}
struct FunCloner {
@ -489,6 +501,11 @@ struct FunCloner {
Dst = LLVMBuildGEP(Builder, Ptr, Idx.data(), NumIdx, Name);
break;
}
case LLVMBitCast: {
LLVMValueRef V = CloneValue(LLVMGetOperand(Src, 0));
Dst = LLVMBuildBitCast(Builder, V, CloneType(Src), Name);
break;
}
case LLVMICmp: {
LLVMIntPredicate Pred = LLVMGetICmpPredicate(Src);
LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));