aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-size
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-04-23 16:57:46 -0700
committerStephen Hines <srhines@google.com>2014-04-24 15:53:16 -0700
commit36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch)
treee6cfb69fbbd937f450eeb83bfb83b9da3b01275a /tools/llvm-size
parent69a8640022b04415ae9fac62f8ab090601d8f889 (diff)
downloadexternal_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'tools/llvm-size')
-rw-r--r--tools/llvm-size/CMakeLists.txt5
-rw-r--r--tools/llvm-size/llvm-size.cpp73
2 files changed, 36 insertions, 42 deletions
diff --git a/tools/llvm-size/CMakeLists.txt b/tools/llvm-size/CMakeLists.txt
index 933cc75..6034573 100644
--- a/tools/llvm-size/CMakeLists.txt
+++ b/tools/llvm-size/CMakeLists.txt
@@ -1,4 +1,7 @@
-set(LLVM_LINK_COMPONENTS object)
+set(LLVM_LINK_COMPONENTS
+ Object
+ Support
+ )
add_llvm_tool(llvm-size
llvm-size.cpp
diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp
index 3de6605..d1bd45a 100644
--- a/tools/llvm-size/llvm-size.cpp
+++ b/tools/llvm-size/llvm-size.cpp
@@ -85,10 +85,10 @@ static size_t getNumLengthAsString(uint64_t num) {
return result.size();
}
-/// @brief Print the size of each section in @p o.
+/// @brief Print the size of each section in @p Obj.
///
/// The format used is determined by @c OutputFormat and @c Radix.
-static void PrintObjectSectionSizes(ObjectFile *o) {
+static void PrintObjectSectionSizes(ObjectFile *Obj) {
uint64_t total = 0;
std::string fmtbuf;
raw_string_ostream fmt(fmtbuf);
@@ -111,21 +111,18 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
std::size_t max_name_len = strlen("section");
std::size_t max_size_len = strlen("size");
std::size_t max_addr_len = strlen("addr");
- error_code ec;
- for (section_iterator i = o->begin_sections(),
- e = o->end_sections(); i != e;
- i.increment(ec)) {
- if (error(ec))
- return;
+ for (const SectionRef &Section : Obj->sections()) {
uint64_t size = 0;
- if (error(i->getSize(size)))
+ if (error(Section.getSize(size)))
return;
total += size;
StringRef name;
uint64_t addr = 0;
- if (error(i->getName(name))) return;
- if (error(i->getAddress(addr))) return;
+ if (error(Section.getName(name)))
+ return;
+ if (error(Section.getAddress(addr)))
+ return;
max_name_len = std::max(max_name_len, name.size());
max_size_len = std::max(max_size_len, getNumLengthAsString(size));
max_addr_len = std::max(max_addr_len, getNumLengthAsString(addr));
@@ -154,24 +151,19 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
<< "%#" << max_addr_len << radix_fmt << "\n";
// Print each section.
- for (section_iterator i = o->begin_sections(),
- e = o->end_sections(); i != e;
- i.increment(ec)) {
- if (error(ec))
- return;
-
+ for (const SectionRef &Section : Obj->sections()) {
StringRef name;
uint64_t size = 0;
uint64_t addr = 0;
- if (error(i->getName(name))) return;
- if (error(i->getSize(size))) return;
- if (error(i->getAddress(addr))) return;
+ if (error(Section.getName(name)))
+ return;
+ if (error(Section.getSize(size)))
+ return;
+ if (error(Section.getAddress(addr)))
+ return;
std::string namestr = name;
- outs() << format(fmt.str().c_str(),
- namestr.c_str(),
- size,
- addr);
+ outs() << format(fmt.str().c_str(), namestr.c_str(), size, addr);
}
// Print total.
@@ -189,21 +181,19 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
uint64_t total_bss = 0;
// Make one pass over the section table to calculate sizes.
- error_code ec;
- for (section_iterator i = o->begin_sections(),
- e = o->end_sections(); i != e;
- i.increment(ec)) {
- if (error(ec))
- return;
-
+ for (const SectionRef &Section : Obj->sections()) {
uint64_t size = 0;
bool isText = false;
bool isData = false;
bool isBSS = false;
- if (error(i->getSize(size))) return;
- if (error(i->isText(isText))) return;
- if (error(i->isData(isData))) return;
- if (error(i->isBSS(isBSS))) return;
+ if (error(Section.getSize(size)))
+ return;
+ if (error(Section.isText(isText)))
+ return;
+ if (error(Section.isData(isData)))
+ return;
+ if (error(Section.isBSS(isBSS)))
+ return;
if (isText)
total_text += size;
else if (isData)
@@ -244,17 +234,18 @@ static void PrintFileSectionSizes(StringRef file) {
}
// Attempt to open the binary.
- OwningPtr<Binary> binary;
- if (error_code ec = createBinary(file, binary)) {
- errs() << ToolName << ": " << file << ": " << ec.message() << ".\n";
+ ErrorOr<Binary *> BinaryOrErr = createBinary(file);
+ if (error_code EC = BinaryOrErr.getError()) {
+ errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
return;
}
+ std::unique_ptr<Binary> binary(BinaryOrErr.get());
if (Archive *a = dyn_cast<Archive>(binary.get())) {
// This is an archive. Iterate over each member and display its sizes.
- for (object::Archive::child_iterator i = a->begin_children(),
- e = a->end_children(); i != e; ++i) {
- OwningPtr<Binary> child;
+ for (object::Archive::child_iterator i = a->child_begin(),
+ e = a->child_end(); i != e; ++i) {
+ std::unique_ptr<Binary> child;
if (error_code ec = i->getAsBinary(child)) {
errs() << ToolName << ": " << file << ": " << ec.message() << ".\n";
continue;