Add relocation iterators to the libObject C API.

llvm-svn: 143107
This commit is contained in:
Owen Anderson 2011-10-27 17:15:47 +00:00
parent 2aed4393b8
commit e245af65fa
2 changed files with 43 additions and 0 deletions

View File

@ -32,6 +32,7 @@ extern "C" {
typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
// ObjectFile creation // ObjectFile creation
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
@ -61,6 +62,14 @@ uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
LLVMSymbolIteratorRef Sym); LLVMSymbolIteratorRef Sym);
// Section Relocation iterators
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
LLVMRelocationIteratorRef RI);
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
// SymbolRef accessors // SymbolRef accessors
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
@ -99,6 +108,17 @@ namespace llvm {
return reinterpret_cast<LLVMSymbolIteratorRef> return reinterpret_cast<LLVMSymbolIteratorRef>
(const_cast<symbol_iterator*>(SI)); (const_cast<symbol_iterator*>(SI));
} }
inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
return reinterpret_cast<relocation_iterator*>(SI);
}
inline LLVMRelocationIteratorRef
wrap(const relocation_iterator *SI) {
return reinterpret_cast<LLVMRelocationIteratorRef>
(const_cast<relocation_iterator*>(SI));
}
} }
} }

View File

@ -112,6 +112,29 @@ LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
return ret; return ret;
} }
// Section Relocation iterators
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section) {
relocation_iterator SI = (*unwrap(Section))->begin_relocations();
return wrap(new relocation_iterator(SI));
}
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef SI) {
delete unwrap(SI);
}
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
LLVMRelocationIteratorRef SI) {
return (*unwrap(SI) == (*unwrap(Section))->end_relocations()) ? 1 : 0;
}
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
error_code ec;
unwrap(SI)->increment(ec);
if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " +
ec.message());
}
// SymbolRef accessors // SymbolRef accessors
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) { const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
StringRef ret; StringRef ret;