X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FIR%2FCore.cpp;h=8bc0bb92e60272f9893d78731d025babeac681ec;hp=40c1c70257e140462a53929199ed2527b9d43f78;hb=5f3f0620f6bb3627fc0fd906bc89ada0cc1cdb7b;hpb=ab67b30df6b14e8e90f4778215ed4e1d5939638e diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 40c1c70257e..8bc0bb92e60 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -17,9 +17,9 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" -#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/IRBuilder.h" @@ -35,10 +35,10 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" #include #include #include +#include using namespace llvm; @@ -281,7 +281,11 @@ char *LLVMPrintTypeToString(LLVMTypeRef Ty) { std::string buf; raw_string_ostream os(buf); - unwrap(Ty)->print(os); + if (unwrap(Ty)) + unwrap(Ty)->print(os); + else + os << "Printing Type"; + os.flush(); return strdup(buf.c_str()); @@ -531,7 +535,11 @@ char* LLVMPrintValueToString(LLVMValueRef Val) { std::string buf; raw_string_ostream os(buf); - unwrap(Val)->print(os); + if (unwrap(Val)) + unwrap(Val)->print(os); + else + os << "Printing Value"; + os.flush(); return strdup(buf.c_str()); @@ -782,11 +790,27 @@ LLVMValueRef LLVMConstString(const char *Str, unsigned Length, return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length, DontNullTerminate); } + +LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx) { + return wrap(static_cast(unwrap(c))->getElementAsConstant(idx)); +} + +LLVMBool LLVMIsConstantString(LLVMValueRef c) { + return static_cast(unwrap(c))->isString(); +} + +const char *LLVMGetAsString(LLVMValueRef c, size_t* Length) { + StringRef str = static_cast(unwrap(c))->getAsString(); + *Length = str.size(); + return str.data(); +} + LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, unsigned Length) { ArrayRef V(unwrap(ConstantVals, Length), Length); return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V)); } + LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed) { return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count, @@ -1286,7 +1310,7 @@ void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) { } const char *LLVMGetSection(LLVMValueRef Global) { - return unwrap(Global)->getSection().c_str(); + return unwrap(Global)->getSection(); } void LLVMSetSection(LLVMValueRef Global, const char *Section) { @@ -1489,9 +1513,9 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) { LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name) { auto *PTy = cast(unwrap(Ty)); - return wrap(new GlobalAlias( - PTy->getElementType(), GlobalValue::ExternalLinkage, Name, - unwrap(Aliasee), unwrap(M), PTy->getAddressSpace())); + return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(), + GlobalValue::ExternalLinkage, Name, + unwrap(Aliasee), unwrap(M))); } /*--.. Operations on functions .............................................--*/ @@ -2598,28 +2622,24 @@ LLVMBool LLVMCreateMemoryBufferWithContentsOfFile( LLVMMemoryBufferRef *OutMemBuf, char **OutMessage) { - std::unique_ptr MB; - error_code ec; - if (!(ec = MemoryBuffer::getFile(Path, MB))) { - *OutMemBuf = wrap(MB.release()); - return 0; + ErrorOr> MBOrErr = MemoryBuffer::getFile(Path); + if (std::error_code EC = MBOrErr.getError()) { + *OutMessage = strdup(EC.message().c_str()); + return 1; } - - *OutMessage = strdup(ec.message().c_str()); - return 1; + *OutMemBuf = wrap(MBOrErr.get().release()); + return 0; } LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, char **OutMessage) { - std::unique_ptr MB; - error_code ec; - if (!(ec = MemoryBuffer::getSTDIN(MB))) { - *OutMemBuf = wrap(MB.release()); - return 0; + ErrorOr> MBOrErr = MemoryBuffer::getSTDIN(); + if (std::error_code EC = MBOrErr.getError()) { + *OutMessage = strdup(EC.message().c_str()); + return 1; } - - *OutMessage = strdup(ec.message().c_str()); - return 1; + *OutMemBuf = wrap(MBOrErr.get().release()); + return 0; } LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange( @@ -2700,11 +2720,10 @@ void LLVMDisposePassManager(LLVMPassManagerRef PM) { /*===-- Threading ------------------------------------------------------===*/ LLVMBool LLVMStartMultithreaded() { - return llvm_start_multithreaded(); + return LLVMIsMultithreaded(); } void LLVMStopMultithreaded() { - llvm_stop_multithreaded(); } LLVMBool LLVMIsMultithreaded() {