#include "llvm/Support/MemoryBuffer.h"
#include <cassert>
#include <cstdlib>
+#include <cstring>
using namespace llvm;
return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
}
+static const fltSemantics &SemanticsForType(Type *Ty) {
+ assert(Ty->isFloatingPoint() && "Type is not floating point!");
+ if (Ty == Type::FloatTy)
+ return APFloat::IEEEsingle;
+ if (Ty == Type::DoubleTy)
+ return APFloat::IEEEdouble;
+ if (Ty == Type::X86_FP80Ty)
+ return APFloat::x87DoubleExtended;
+ if (Ty == Type::FP128Ty)
+ return APFloat::IEEEquad;
+ if (Ty == Type::PPC_FP128Ty)
+ return APFloat::PPCDoubleDouble;
+ return APFloat::Bogus;
+}
+
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
- return wrap(ConstantFP::get(unwrap(RealTy), APFloat(N)));
+ APFloat APN(N);
+ APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven);
+ return wrap(ConstantFP::get(unwrap(RealTy), APN));
+}
+
+LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
+ return wrap(ConstantFP::get(unwrap(RealTy),
+ APFloat(SemanticsForType(unwrap(RealTy)), Text)));
}
/*--.. Operations on composite constants ...................................--*/
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
return wrap(new GlobalVariable(unwrap(Ty), false,
- GlobalValue::ExternalLinkage, 0, Name, unwrap(M)));
+ GlobalValue::ExternalLinkage, 0, Name,
+ unwrap(M)));
}
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
return wrap(unwrap(B)->CreateUnreachable());
}
+void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
+ LLVMBasicBlockRef Dest) {
+ unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
+}
+
/*--.. Arithmetic ..........................................................--*/
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,