mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-26 10:29:36 +00:00
Adding C and Ocaml bindings for ConstantExpr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42696 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
57db1734af
commit
4647569fe7
@ -209,6 +209,51 @@ external make_struct_constant : llvalue array -> bool -> llvalue
|
|||||||
external make_vector_constant : llvalue array -> llvalue
|
external make_vector_constant : llvalue array -> llvalue
|
||||||
= "llvm_make_vector_constant"
|
= "llvm_make_vector_constant"
|
||||||
|
|
||||||
|
(*--... Constant expressions ...............................................--*)
|
||||||
|
external sizeof : lltype -> llvalue = "LLVMSizeOf"
|
||||||
|
external const_neg : llvalue -> llvalue = "LLVMConstNeg"
|
||||||
|
external const_not : llvalue -> llvalue = "LLVMConstNot"
|
||||||
|
external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
|
||||||
|
external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
|
||||||
|
external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
|
||||||
|
external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
|
||||||
|
external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
|
||||||
|
external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
|
||||||
|
external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
|
||||||
|
external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
|
||||||
|
external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
|
||||||
|
external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
|
||||||
|
external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
|
||||||
|
external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
|
||||||
|
external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
|
||||||
|
= "llvm_const_icmp"
|
||||||
|
external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
|
||||||
|
= "llvm_const_fcmp"
|
||||||
|
external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
|
||||||
|
external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
|
||||||
|
external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
|
||||||
|
external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
|
||||||
|
external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
|
||||||
|
external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
|
||||||
|
external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
|
||||||
|
external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
|
||||||
|
external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
|
||||||
|
external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
|
||||||
|
external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
|
||||||
|
external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
|
||||||
|
external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
|
||||||
|
external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
|
||||||
|
external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
|
||||||
|
external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
|
||||||
|
external const_select : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstSelect"
|
||||||
|
external const_extractelement : llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstExtractElement"
|
||||||
|
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstInsertElement"
|
||||||
|
external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstShuffleVector"
|
||||||
|
|
||||||
(*--... Operations on global variables, functions, and aliases (globals) ...--*)
|
(*--... Operations on global variables, functions, and aliases (globals) ...--*)
|
||||||
external is_declaration : llvalue -> bool = "llvm_is_declaration"
|
external is_declaration : llvalue -> bool = "llvm_is_declaration"
|
||||||
external linkage : llvalue -> linkage = "llvm_linkage"
|
external linkage : llvalue -> linkage = "llvm_linkage"
|
||||||
|
@ -192,6 +192,51 @@ external make_struct_constant : llvalue array -> bool -> llvalue
|
|||||||
external make_vector_constant : llvalue array -> llvalue
|
external make_vector_constant : llvalue array -> llvalue
|
||||||
= "llvm_make_vector_constant"
|
= "llvm_make_vector_constant"
|
||||||
|
|
||||||
|
(*--... Constant expressions ...............................................--*)
|
||||||
|
external sizeof : lltype -> llvalue = "LLVMSizeOf"
|
||||||
|
external const_neg : llvalue -> llvalue = "LLVMConstNeg"
|
||||||
|
external const_not : llvalue -> llvalue = "LLVMConstNot"
|
||||||
|
external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd"
|
||||||
|
external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub"
|
||||||
|
external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul"
|
||||||
|
external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv"
|
||||||
|
external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv"
|
||||||
|
external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv"
|
||||||
|
external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem"
|
||||||
|
external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem"
|
||||||
|
external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem"
|
||||||
|
external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd"
|
||||||
|
external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr"
|
||||||
|
external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
|
||||||
|
external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
|
||||||
|
= "llvm_const_icmp"
|
||||||
|
external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
|
||||||
|
= "llvm_const_fcmp"
|
||||||
|
external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
|
||||||
|
external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
|
||||||
|
external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
|
||||||
|
external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
|
||||||
|
external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
|
||||||
|
external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
|
||||||
|
external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt"
|
||||||
|
external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc"
|
||||||
|
external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt"
|
||||||
|
external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP"
|
||||||
|
external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP"
|
||||||
|
external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI"
|
||||||
|
external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI"
|
||||||
|
external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt"
|
||||||
|
external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr"
|
||||||
|
external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast"
|
||||||
|
external const_select : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstSelect"
|
||||||
|
external const_extractelement : llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstExtractElement"
|
||||||
|
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstInsertElement"
|
||||||
|
external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
|
||||||
|
= "LLVMConstShuffleVector"
|
||||||
|
|
||||||
(*--... Operations on global variables, functions, and aliases (globals) ...--*)
|
(*--... Operations on global variables, functions, and aliases (globals) ...--*)
|
||||||
external is_declaration : llvalue -> bool = "llvm_is_declaration"
|
external is_declaration : llvalue -> bool = "llvm_is_declaration"
|
||||||
external linkage : llvalue -> linkage = "llvm_linkage"
|
external linkage : llvalue -> linkage = "llvm_linkage"
|
||||||
|
@ -139,8 +139,8 @@ CAMLprim value llvm_param_types(LLVMTypeRef FunTy) {
|
|||||||
/*--... Operations on struct types .........................................--*/
|
/*--... Operations on struct types .........................................--*/
|
||||||
|
|
||||||
/* lltype array -> bool -> lltype */
|
/* lltype array -> bool -> lltype */
|
||||||
CAMLprim value llvm_make_struct_type(value ElementTypes, value Packed) {
|
CAMLprim LLVMTypeRef llvm_make_struct_type(value ElementTypes, value Packed) {
|
||||||
return (value) LLVMCreateStructType((LLVMTypeRef *) ElementTypes,
|
return LLVMCreateStructType((LLVMTypeRef *) ElementTypes,
|
||||||
Wosize_val(ElementTypes),
|
Wosize_val(ElementTypes),
|
||||||
Bool_val(Packed));
|
Bool_val(Packed));
|
||||||
}
|
}
|
||||||
@ -160,8 +160,8 @@ CAMLprim value llvm_is_packed(LLVMTypeRef StructTy) {
|
|||||||
/*--... Operations on array, pointer, and vector types .....................--*/
|
/*--... Operations on array, pointer, and vector types .....................--*/
|
||||||
|
|
||||||
/* lltype -> int -> lltype */
|
/* lltype -> int -> lltype */
|
||||||
CAMLprim value llvm_make_array_type(LLVMTypeRef ElementTy, value Count) {
|
CAMLprim LLVMTypeRef llvm_make_array_type(LLVMTypeRef ElementTy, value Count) {
|
||||||
return (value) LLVMCreateArrayType(ElementTy, Int_val(Count));
|
return LLVMCreateArrayType(ElementTy, Int_val(Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lltype -> lltype */
|
/* lltype -> lltype */
|
||||||
@ -291,11 +291,33 @@ CAMLprim LLVMValueRef llvm_make_struct_constant(value ElementVals,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* llvalue array -> llvalue */
|
/* llvalue array -> llvalue */
|
||||||
CAMLprim value llvm_make_vector_constant(value ElementVals) {
|
CAMLprim LLVMValueRef llvm_make_vector_constant(value ElementVals) {
|
||||||
return (value) LLVMGetVectorConstant((LLVMValueRef*) Op_val(ElementVals),
|
return LLVMGetVectorConstant((LLVMValueRef*) Op_val(ElementVals),
|
||||||
Wosize_val(ElementVals));
|
Wosize_val(ElementVals));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*--... Constant expressions ...............................................--*/
|
||||||
|
|
||||||
|
/* int_predicate -> llvalue -> llvalue -> llvalue */
|
||||||
|
CAMLprim LLVMValueRef llvm_const_icmp(value Pred,
|
||||||
|
LLVMValueRef LHSConstant,
|
||||||
|
LLVMValueRef RHSConstant) {
|
||||||
|
return LLVMConstICmp(Int_val(Pred) + LLVMIntEQ, LHSConstant, RHSConstant);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* real_predicate -> llvalue -> llvalue -> llvalue */
|
||||||
|
CAMLprim LLVMValueRef llvm_const_fcmp(value Pred,
|
||||||
|
LLVMValueRef LHSConstant,
|
||||||
|
LLVMValueRef RHSConstant) {
|
||||||
|
return LLVMConstFCmp(Int_val(Pred), LHSConstant, RHSConstant);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* llvalue -> llvalue array -> llvalue */
|
||||||
|
CAMLprim LLVMValueRef llvm_const_gep(LLVMValueRef ConstantVal, value Indices) {
|
||||||
|
return LLVMConstGEP(ConstantVal, (LLVMValueRef*) Op_val(Indices),
|
||||||
|
Wosize_val(Indices));
|
||||||
|
}
|
||||||
|
|
||||||
/*--... Operations on global variables, functions, and aliases (globals) ...--*/
|
/*--... Operations on global variables, functions, and aliases (globals) ...--*/
|
||||||
|
|
||||||
/* llvalue -> bool */
|
/* llvalue -> bool */
|
||||||
|
@ -250,6 +250,55 @@ LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
|
|||||||
LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
|
LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
|
||||||
unsigned Size);
|
unsigned Size);
|
||||||
|
|
||||||
|
/* Constant expressions */
|
||||||
|
LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
|
||||||
|
LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
|
||||||
|
LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
|
||||||
|
LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
|
||||||
|
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
|
||||||
|
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
|
||||||
|
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
|
||||||
|
LLVMValueRef *ConstantIndices, unsigned NumIndices);
|
||||||
|
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
||||||
|
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
|
||||||
|
LLVMValueRef ConstantIfTrue,
|
||||||
|
LLVMValueRef ConstantIfFalse);
|
||||||
|
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
|
||||||
|
LLVMValueRef IndexConstant);
|
||||||
|
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
|
||||||
|
LLVMValueRef ElementValueConstant,
|
||||||
|
LLVMValueRef IndexConstant);
|
||||||
|
LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
|
||||||
|
LLVMValueRef VectorBConstant,
|
||||||
|
LLVMValueRef MaskConstant);
|
||||||
|
|
||||||
/* Operations on global variables, functions, and aliases (globals) */
|
/* Operations on global variables, functions, and aliases (globals) */
|
||||||
int LLVMIsDeclaration(LLVMValueRef Global);
|
int LLVMIsDeclaration(LLVMValueRef Global);
|
||||||
LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
|
LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
|
||||||
|
@ -599,7 +599,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// getSizeOf constant expr - computes the size of a type in a target
|
/// getSizeOf constant expr - computes the size of a type in a target
|
||||||
/// independent way (Note: the return type is a ULong).
|
/// independent way (Note: the return type is an i64).
|
||||||
///
|
///
|
||||||
static Constant *getSizeOf(const Type *Ty);
|
static Constant *getSizeOf(const Type *Ty);
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ Constant *ConstantExpr::getNeg(Constant *C) {
|
|||||||
C);
|
C);
|
||||||
}
|
}
|
||||||
Constant *ConstantExpr::getNot(Constant *C) {
|
Constant *ConstantExpr::getNot(Constant *C) {
|
||||||
assert(isa<ConstantInt>(C) && "Cannot NOT a nonintegral type!");
|
assert(isa<IntegerType>(C->getType()) && "Cannot NOT a nonintegral value!");
|
||||||
return get(Instruction::Xor, C,
|
return get(Instruction::Xor, C,
|
||||||
ConstantInt::getAllOnesValue(C->getType()));
|
ConstantInt::getAllOnesValue(C->getType()));
|
||||||
}
|
}
|
||||||
@ -1675,7 +1675,7 @@ Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Constant *ConstantExpr::getSizeOf(const Type *Ty) {
|
Constant *ConstantExpr::getSizeOf(const Type *Ty) {
|
||||||
// sizeof is implemented as: (ulong) gep (Ty*)null, 1
|
// sizeof is implemented as: (i64) gep (Ty*)null, 1
|
||||||
Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
|
Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
|
||||||
Constant *GEP =
|
Constant *GEP =
|
||||||
getGetElementPtr(getNullValue(PointerType::get(Ty)), &GEPIdx, 1);
|
getGetElementPtr(getNullValue(PointerType::get(Ty)), &GEPIdx, 1);
|
||||||
|
@ -266,6 +266,207 @@ LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
|
|||||||
Size));
|
Size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*--.. Constant expressions ................................................--*/
|
||||||
|
|
||||||
|
LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
|
||||||
|
return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
|
||||||
|
return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
|
||||||
|
return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
|
||||||
|
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getICmp(Predicate,
|
||||||
|
unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
|
||||||
|
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getFCmp(Predicate,
|
||||||
|
unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
|
||||||
|
unwrap<Constant>(RHSConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
|
||||||
|
LLVMValueRef *ConstantIndices, unsigned NumIndices) {
|
||||||
|
return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap<Constant>(ConstantIndices,
|
||||||
|
NumIndices),
|
||||||
|
NumIndices));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
|
||||||
|
unwrap(ToType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
|
||||||
|
LLVMValueRef ConstantIfTrue,
|
||||||
|
LLVMValueRef ConstantIfFalse) {
|
||||||
|
return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
|
||||||
|
unwrap<Constant>(ConstantIfTrue),
|
||||||
|
unwrap<Constant>(ConstantIfFalse)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
|
||||||
|
LLVMValueRef IndexConstant) {
|
||||||
|
return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
|
||||||
|
unwrap<Constant>(IndexConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
|
||||||
|
LLVMValueRef ElementValueConstant,
|
||||||
|
LLVMValueRef IndexConstant) {
|
||||||
|
return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
|
||||||
|
unwrap<Constant>(ElementValueConstant),
|
||||||
|
unwrap<Constant>(IndexConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
|
||||||
|
LLVMValueRef VectorBConstant,
|
||||||
|
LLVMValueRef MaskConstant) {
|
||||||
|
return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
|
||||||
|
unwrap<Constant>(VectorBConstant),
|
||||||
|
unwrap<Constant>(MaskConstant)));
|
||||||
|
}
|
||||||
|
|
||||||
/*--.. Operations on global variables, functions, and aliases (globals) ....--*/
|
/*--.. Operations on global variables, functions, and aliases (globals) ....--*/
|
||||||
|
|
||||||
int LLVMIsDeclaration(LLVMValueRef Global) {
|
int LLVMIsDeclaration(LLVMValueRef Global) {
|
||||||
|
@ -227,7 +227,108 @@ let test_constants () =
|
|||||||
let c = make_undef i1_type in
|
let c = make_undef i1_type in
|
||||||
ignore (define_global "Const12" c m);
|
ignore (define_global "Const12" c m);
|
||||||
insist (i1_type = type_of c);
|
insist (i1_type = type_of c);
|
||||||
insist (is_undef c)
|
insist (is_undef c);
|
||||||
|
|
||||||
|
group "constant arithmetic";
|
||||||
|
(* RUN: grep {ConstNeg.*sub} < %t.ll
|
||||||
|
* RUN: grep {ConstNot.*xor} < %t.ll
|
||||||
|
* RUN: grep {ConstAdd.*add} < %t.ll
|
||||||
|
* RUN: grep {ConstSub.*sub} < %t.ll
|
||||||
|
* RUN: grep {ConstMul.*mul} < %t.ll
|
||||||
|
* RUN: grep {ConstUDiv.*udiv} < %t.ll
|
||||||
|
* RUN: grep {ConstSDiv.*sdiv} < %t.ll
|
||||||
|
* RUN: grep {ConstFDiv.*fdiv} < %t.ll
|
||||||
|
* RUN: grep {ConstURem.*urem} < %t.ll
|
||||||
|
* RUN: grep {ConstSRem.*srem} < %t.ll
|
||||||
|
* RUN: grep {ConstFRem.*frem} < %t.ll
|
||||||
|
* RUN: grep {ConstAnd.*and} < %t.ll
|
||||||
|
* RUN: grep {ConstOr.*or} < %t.ll
|
||||||
|
* RUN: grep {ConstXor.*xor} < %t.ll
|
||||||
|
* RUN: grep {ConstICmp.*icmp} < %t.ll
|
||||||
|
* RUN: grep {ConstFCmp.*fcmp} < %t.ll
|
||||||
|
*)
|
||||||
|
let void_ptr = make_pointer_type i8_type in
|
||||||
|
let five = make_int_constant i64_type 5 false in
|
||||||
|
let ffive = const_uitofp five double_type in
|
||||||
|
let foldbomb_gv = define_global "FoldBomb" (make_null i8_type) m in
|
||||||
|
let foldbomb = const_ptrtoint foldbomb_gv i64_type in
|
||||||
|
let ffoldbomb = const_uitofp foldbomb double_type in
|
||||||
|
ignore (define_global "ConstNeg" (const_neg foldbomb) m);
|
||||||
|
ignore (define_global "ConstNot" (const_not foldbomb) m);
|
||||||
|
ignore (define_global "ConstAdd" (const_add foldbomb five) m);
|
||||||
|
ignore (define_global "ConstSub" (const_sub foldbomb five) m);
|
||||||
|
ignore (define_global "ConstMul" (const_mul foldbomb five) m);
|
||||||
|
ignore (define_global "ConstUDiv" (const_udiv foldbomb five) m);
|
||||||
|
ignore (define_global "ConstSDiv" (const_sdiv foldbomb five) m);
|
||||||
|
ignore (define_global "ConstFDiv" (const_fdiv ffoldbomb ffive) m);
|
||||||
|
ignore (define_global "ConstURem" (const_urem foldbomb five) m);
|
||||||
|
ignore (define_global "ConstSRem" (const_srem foldbomb five) m);
|
||||||
|
ignore (define_global "ConstFRem" (const_frem ffoldbomb ffive) m);
|
||||||
|
ignore (define_global "ConstAnd" (const_and foldbomb five) m);
|
||||||
|
ignore (define_global "ConstOr" (const_or foldbomb five) m);
|
||||||
|
ignore (define_global "ConstXor" (const_xor foldbomb five) m);
|
||||||
|
ignore (define_global "ConstICmp" (const_icmp Icmp_sle foldbomb five) m);
|
||||||
|
ignore (define_global "ConstFCmp" (const_fcmp Fcmp_ole ffoldbomb ffive) m);
|
||||||
|
|
||||||
|
group "constant casts";
|
||||||
|
(* RUN: grep {ConstTrunc.*trunc} < %t.ll
|
||||||
|
* RUN: grep {ConstSExt.*sext} < %t.ll
|
||||||
|
* RUN: grep {ConstZExt.*zext} < %t.ll
|
||||||
|
* RUN: grep {ConstFPTrunc.*fptrunc} < %t.ll
|
||||||
|
* RUN: grep {ConstFPExt.*fpext} < %t.ll
|
||||||
|
* RUN: grep {ConstUIToFP.*uitofp} < %t.ll
|
||||||
|
* RUN: grep {ConstSIToFP.*sitofp} < %t.ll
|
||||||
|
* RUN: grep {ConstFPToUI.*fptoui} < %t.ll
|
||||||
|
* RUN: grep {ConstFPToSI.*fptosi} < %t.ll
|
||||||
|
* RUN: grep {ConstPtrToInt.*ptrtoint} < %t.ll
|
||||||
|
* RUN: grep {ConstIntToPtr.*inttoptr} < %t.ll
|
||||||
|
* RUN: grep {ConstBitCast.*bitcast} < %t.ll
|
||||||
|
*)
|
||||||
|
let i128_type = make_integer_type 128 in
|
||||||
|
ignore (define_global "ConstTrunc" (const_trunc (const_add foldbomb five)
|
||||||
|
i8_type) m);
|
||||||
|
ignore (define_global "ConstSExt" (const_sext foldbomb i128_type) m);
|
||||||
|
ignore (define_global "ConstZExt" (const_zext foldbomb i128_type) m);
|
||||||
|
ignore (define_global "ConstFPTrunc" (const_fptrunc ffoldbomb float_type) m);
|
||||||
|
ignore (define_global "ConstFPExt" (const_fpext ffoldbomb fp128_type) m);
|
||||||
|
ignore (define_global "ConstUIToFP" (const_uitofp foldbomb double_type) m);
|
||||||
|
ignore (define_global "ConstSIToFP" (const_sitofp foldbomb double_type) m);
|
||||||
|
ignore (define_global "ConstFPToUI" (const_fptoui ffoldbomb i32_type) m);
|
||||||
|
ignore (define_global "ConstFPToSI" (const_fptosi ffoldbomb i32_type) m);
|
||||||
|
ignore (define_global "ConstPtrToInt" (const_ptrtoint
|
||||||
|
(const_gep (make_null (make_pointer_type i8_type))
|
||||||
|
[| make_int_constant i32_type 1 false |])
|
||||||
|
i32_type) m);
|
||||||
|
ignore (define_global "ConstIntToPtr" (const_inttoptr (const_add foldbomb five)
|
||||||
|
void_ptr) m);
|
||||||
|
ignore (define_global "ConstBitCast" (const_bitcast ffoldbomb i64_type) m);
|
||||||
|
|
||||||
|
group "misc constants";
|
||||||
|
(* RUN: grep {ConstSizeOf.*getelementptr.*null} < %t.ll
|
||||||
|
* RUN: grep {ConstGEP.*getelementptr} < %t.ll
|
||||||
|
* RUN: grep {ConstSelect.*select} < %t.ll
|
||||||
|
* RUN: grep {ConstExtractElement.*extractelement} < %t.ll
|
||||||
|
* RUN: grep {ConstInsertElement.*insertelement} < %t.ll
|
||||||
|
* RUN: grep {ConstShuffleVector.*shufflevector} < %t.ll
|
||||||
|
*)
|
||||||
|
ignore (define_global "ConstSizeOf" (sizeof (make_pointer_type i8_type)) m);
|
||||||
|
ignore (define_global "ConstGEP" (const_gep foldbomb_gv [| five |]) m);
|
||||||
|
ignore (define_global "ConstSelect" (const_select
|
||||||
|
(const_icmp Icmp_sle foldbomb five)
|
||||||
|
(make_int_constant i8_type (-1) true)
|
||||||
|
(make_int_constant i8_type 0 true)) m);
|
||||||
|
let zero = make_int_constant i32_type 0 false in
|
||||||
|
let one = make_int_constant i32_type 1 false in
|
||||||
|
ignore (define_global "ConstExtractElement" (const_extractelement
|
||||||
|
(make_vector_constant [| zero; one; zero; one |])
|
||||||
|
(const_trunc foldbomb i32_type)) m);
|
||||||
|
ignore (define_global "ConstInsertElement" (const_insertelement
|
||||||
|
(make_vector_constant [| zero; one; zero; one |])
|
||||||
|
zero (const_trunc foldbomb i32_type)) m);
|
||||||
|
ignore (define_global "ConstShuffleVector" (const_shufflevector
|
||||||
|
(make_vector_constant [| zero; one |])
|
||||||
|
(make_vector_constant [| one; zero |])
|
||||||
|
(const_bitcast foldbomb (make_vector_type i32_type 2))) m)
|
||||||
|
|
||||||
|
|
||||||
(*===-- Global Values -----------------------------------------------------===*)
|
(*===-- Global Values -----------------------------------------------------===*)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user