diff options
author | Chris Lattner <sabre@nondot.org> | 2007-11-13 18:22:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-11-13 18:22:33 +0000 |
commit | 120119da1354e725da310fc3631162f18393d61b (patch) | |
tree | 96c994fa9bd6c6a76e83ed542686fc12e4908398 /tools/llvm2cpp | |
parent | e7c8754a521d90e1164f2db7a5f999f51b818f12 (diff) | |
download | external_llvm-120119da1354e725da310fc3631162f18393d61b.zip external_llvm-120119da1354e725da310fc3631162f18393d61b.tar.gz external_llvm-120119da1354e725da310fc3631162f18393d61b.tar.bz2 |
Make llvm2cpp better, patch for PR1794, contributed by Zack Rusin.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44051 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm2cpp')
-rw-r--r-- | tools/llvm2cpp/CppWriter.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp index 8fae51d..b7338cb 100644 --- a/tools/llvm2cpp/CppWriter.cpp +++ b/tools/llvm2cpp/CppWriter.cpp @@ -44,6 +44,7 @@ enum WhatToGenerate { GenModule, GenContents, GenFunction, + GenFunctions, GenInline, GenVariable, GenType @@ -53,13 +54,14 @@ static cl::opt<WhatToGenerate> GenerationType(cl::Optional, cl::desc("Choose what kind of output to generate"), cl::init(GenProgram), cl::values( - clEnumValN(GenProgram, "gen-program", "Generate a complete program"), - clEnumValN(GenModule, "gen-module", "Generate a module definition"), - clEnumValN(GenContents,"gen-contents", "Generate contents of a module"), - clEnumValN(GenFunction,"gen-function", "Generate a function definition"), - clEnumValN(GenInline, "gen-inline", "Generate an inline function"), - clEnumValN(GenVariable,"gen-variable", "Generate a variable definition"), - clEnumValN(GenType, "gen-type", "Generate a type definition"), + clEnumValN(GenProgram, "gen-program", "Generate a complete program"), + clEnumValN(GenModule, "gen-module", "Generate a module definition"), + clEnumValN(GenContents, "gen-contents", "Generate contents of a module"), + clEnumValN(GenFunction, "gen-function", "Generate a function definition"), + clEnumValN(GenFunctions,"gen-functions", "Generate all function definitions"), + clEnumValN(GenInline, "gen-inline", "Generate an inline function"), + clEnumValN(GenVariable, "gen-variable", "Generate a variable definition"), + clEnumValN(GenType, "gen-type", "Generate a type definition"), clEnumValEnd ) ); @@ -103,6 +105,7 @@ public: void printModule(const std::string& fname, const std::string& modName ); void printContents(const std::string& fname, const std::string& modName ); void printFunction(const std::string& fname, const std::string& funcName ); + void printFunctions(); void printInline(const std::string& fname, const std::string& funcName ); void printVariable(const std::string& fname, const std::string& varName ); void printType(const std::string& fname, const std::string& typeName ); @@ -1784,6 +1787,21 @@ void CppWriter::printFunction( Out << "}\n"; } +void CppWriter::printFunctions() { + const Module::FunctionListType &funcs = TheModule->getFunctionList(); + Module::const_iterator I = funcs.begin(); + Module::const_iterator IE = funcs.end(); + + for (; I != IE; ++I) { + const Function &func = *I; + if (!func.isDeclaration()) { + std::string name("define_"); + name += func.getName(); + printFunction(name, func.getName()); + } + } +} + void CppWriter::printVariable( const std::string& fname, /// Name of generated function const std::string& varName // Name of variable to generate @@ -1835,7 +1853,8 @@ void WriteModuleToCppFile(Module* mod, std::ostream& o) { std::string tgtname = NameToGenerate.getValue(); if (GenerationType == GenModule || GenerationType == GenContents || - GenerationType == GenProgram) { + GenerationType == GenProgram || + GenerationType == GenFunctions) { if (tgtname == "!bad!") { if (mod->getModuleIdentifier() == "-") tgtname = "<stdin>"; @@ -1867,6 +1886,9 @@ void WriteModuleToCppFile(Module* mod, std::ostream& o) { fname = "makeLLVMFunction"; W.printFunction(fname,tgtname); break; + case GenFunctions: + W.printFunctions(); + break; case GenInline: if (fname.empty()) fname = "makeLLVMInline"; |