Skip to content

Instantly share code, notes, and snippets.

@tomas789
Created December 28, 2013 19:39
Show Gist options
  • Save tomas789/8163282 to your computer and use it in GitHub Desktop.
Save tomas789/8163282 to your computer and use it in GitHub Desktop.
Dump functions from LLVM's bc file Compile: clang++-mp-3.3 `llvm-config-mp-3.3 --cxxflags --ldflags --libs core jit X86 bitreader` -std=c++0x -o llvmfcs llvmfcs.cpp Usage: llvmfcs filename.bc
#include <iostream>
#include <string>
#include <llvm/ADT/OwningPtr.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/system_error.h>
using namespace llvm;
int main(int argc, char * argv[]) {
if (2 != argc) {
std::cerr << "Invalid arguments\n";
return 1;
}
OwningPtr<MemoryBuffer> mbuff_ptr;
error_code ec = MemoryBuffer::getFile(argv[1], mbuff_ptr);
if (0 != ec.value()) {
std::cerr << "ERROR: " << argv[1] << ": " << ec.message() << std::endl;
return 1;
}
LLVMContext ctx;
std::string error_msg;
Module * module = ParseBitcodeFile(mbuff_ptr.get(), ctx, &error_msg);
if (!error_msg.empty()) {
std::cerr << "ERROR: " << argv[1] << ": " << error_msg << std::endl;
return 1;
}
Module::FunctionListType & fcs = module->getFunctionList();
std::size_t i = 0;
for (auto it = fcs.begin(); it != fcs.end(); ++it, ++i) {
FunctionType * type = it->getFunctionType();
(std::cout << i << ": ").flush();
type->dump();
std::cout << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment