X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FCore.cpp;h=30d8a9b12f8c030728fa6112447bb3986c499d88;hb=1cce5bf8ef9ee3dc157ae5d8778f84a7a0d1d8b9;hp=644ee03b0beceea69bc258dbea2abc7090655771;hpb=45ca049f1f221f5fc1a118f6aab83ac290cb8211;p=oota-llvm.git diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 644ee03b0be..30d8a9b12f8 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm-c/Core.h" +#include "llvm/Attributes.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -114,6 +115,25 @@ void LLVMDumpModule(LLVMModuleRef M) { unwrap(M)->dump(); } +LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, + char **ErrorMessage) { + std::string error; + raw_fd_ostream dest(Filename, error); + if (!error.empty()) { + *ErrorMessage = strdup(error.c_str()); + return true; + } + + unwrap(M)->print(dest, NULL); + + if (!error.empty()) { + *ErrorMessage = strdup(error.c_str()); + return true; + } + dest.flush(); + return false; +} + /*--.. Operations on inline assembler ......................................--*/ void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) { unwrap(M)->setModuleInlineAsm(StringRef(Asm)); @@ -132,8 +152,7 @@ LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) { LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { switch (unwrap(Ty)->getTypeID()) { - default: - assert(false && "Unhandled TypeID."); + default: llvm_unreachable("Unhandled TypeID."); case Type::VoidTyID: return LLVMVoidTypeKind; case Type::HalfTyID: @@ -633,8 +652,8 @@ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, LLVMBool DontNullTerminate) { /* Inverted the sense of AddNull because ', 0)' is a better mnemonic for null termination than ', 1)'. */ - return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length), - DontNullTerminate == 0)); + return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), + DontNullTerminate == 0)); } LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, @@ -679,8 +698,7 @@ LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) { static LLVMOpcode map_to_llvmopcode(int opcode) { switch (opcode) { - default: - assert(0 && "Unhandled Opcode."); + default: llvm_unreachable("Unhandled Opcode."); #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc; #include "llvm/Instruction.def" #undef HANDLE_INST @@ -690,12 +708,11 @@ static LLVMOpcode map_to_llvmopcode(int opcode) static int map_from_llvmopcode(LLVMOpcode code) { switch (code) { - default: - assert(0 && "Unhandled Opcode."); #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num; #include "llvm/Instruction.def" #undef HANDLE_INST } + llvm_unreachable("Unhandled Opcode."); } /*--.. Constant expressions ................................................--*/ @@ -1059,8 +1076,6 @@ LLVMBool LLVMIsDeclaration(LLVMValueRef Global) { LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { switch (unwrap(Global)->getLinkage()) { - default: - assert(false && "Unhandled Linkage Type."); case GlobalValue::ExternalLinkage: return LLVMExternalLinkage; case GlobalValue::AvailableExternallyLinkage: @@ -1095,16 +1110,13 @@ LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { return LLVMCommonLinkage; } - // Should never get here. - return static_cast(0); + llvm_unreachable("Invalid GlobalValue linkage!"); } void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) { GlobalValue *GV = unwrap(Global); switch (Linkage) { - default: - assert(false && "Unhandled Linkage Type."); case LLVMExternalLinkage: GV->setLinkage(GlobalValue::ExternalLinkage); break; @@ -1356,14 +1368,14 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) { void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); - const AttrListPtr PALnew = PAL.addAttr(~0U, PA); + const AttrListPtr PALnew = PAL.addAttr(~0U, Attributes(PA)); Func->setAttributes(PALnew); } void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); - const AttrListPtr PALnew = PAL.removeAttr(~0U, PA); + const AttrListPtr PALnew = PAL.removeAttr(~0U, Attributes(PA)); Func->setAttributes(PALnew); } @@ -1371,7 +1383,7 @@ LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) { Function *Func = unwrap(Fn); const AttrListPtr PAL = Func->getAttributes(); Attributes attr = PAL.getFnAttributes(); - return (LLVMAttribute)attr; + return (LLVMAttribute)attr.Raw(); } /*--.. Operations on parameters ............................................--*/ @@ -1433,18 +1445,18 @@ LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) { } void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) { - unwrap(Arg)->addAttr(PA); + unwrap(Arg)->addAttr(Attributes(PA)); } void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) { - unwrap(Arg)->removeAttr(PA); + unwrap(Arg)->removeAttr(Attributes(PA)); } LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) { Argument *A = unwrap(Arg); Attributes attr = A->getParent()->getAttributes().getParamAttributes( A->getArgNo()+1); - return (LLVMAttribute)attr; + return (LLVMAttribute)attr.Raw(); } @@ -1622,10 +1634,9 @@ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { Value *V = unwrap(Instr); if (CallInst *CI = dyn_cast(V)) return CI->getCallingConv(); - else if (InvokeInst *II = dyn_cast(V)) + if (InvokeInst *II = dyn_cast(V)) return II->getCallingConv(); llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!"); - return 0; } void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { @@ -1641,14 +1652,14 @@ void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute PA) { CallSite Call = CallSite(unwrap(Instr)); Call.setAttributes( - Call.getAttributes().addAttr(index, PA)); + Call.getAttributes().addAttr(index, Attributes(PA))); } void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute PA) { CallSite Call = CallSite(unwrap(Instr)); Call.setAttributes( - Call.getAttributes().removeAttr(index, PA)); + Call.getAttributes().removeAttr(index, Attributes(PA))); } void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, @@ -2074,6 +2085,20 @@ LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name)); } +LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) { + Value *P = unwrap(MemAccessInst); + if (LoadInst *LI = dyn_cast(P)) + return LI->isVolatile(); + return cast(P)->isVolatile(); +} + +void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) { + Value *P = unwrap(MemAccessInst); + if (LoadInst *LI = dyn_cast(P)) + return LI->setVolatile(isVolatile); + return cast(P)->setVolatile(isVolatile); +} + /*--.. Casts ...............................................................--*/ LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,