llvm.org GIT mirror llvm / 120119d
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 Chris Lattner 11 years ago
1 changed file(s) with 30 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
4343 GenModule,
4444 GenContents,
4545 GenFunction,
46 GenFunctions,
4647 GenInline,
4748 GenVariable,
4849 GenType
5253 cl::desc("Choose what kind of output to generate"),
5354 cl::init(GenProgram),
5455 cl::values(
55 clEnumValN(GenProgram, "gen-program", "Generate a complete program"),
56 clEnumValN(GenModule, "gen-module", "Generate a module definition"),
57 clEnumValN(GenContents,"gen-contents", "Generate contents of a module"),
58 clEnumValN(GenFunction,"gen-function", "Generate a function definition"),
59 clEnumValN(GenInline, "gen-inline", "Generate an inline function"),
60 clEnumValN(GenVariable,"gen-variable", "Generate a variable definition"),
61 clEnumValN(GenType, "gen-type", "Generate a type definition"),
56 clEnumValN(GenProgram, "gen-program", "Generate a complete program"),
57 clEnumValN(GenModule, "gen-module", "Generate a module definition"),
58 clEnumValN(GenContents, "gen-contents", "Generate contents of a module"),
59 clEnumValN(GenFunction, "gen-function", "Generate a function definition"),
60 clEnumValN(GenFunctions,"gen-functions", "Generate all function definitions"),
61 clEnumValN(GenInline, "gen-inline", "Generate an inline function"),
62 clEnumValN(GenVariable, "gen-variable", "Generate a variable definition"),
63 clEnumValN(GenType, "gen-type", "Generate a type definition"),
6264 clEnumValEnd
6365 )
6466 );
102104 void printModule(const std::string& fname, const std::string& modName );
103105 void printContents(const std::string& fname, const std::string& modName );
104106 void printFunction(const std::string& fname, const std::string& funcName );
107 void printFunctions();
105108 void printInline(const std::string& fname, const std::string& funcName );
106109 void printVariable(const std::string& fname, const std::string& varName );
107110 void printType(const std::string& fname, const std::string& typeName );
17831786 Out << "}\n";
17841787 }
17851788
1789 void CppWriter::printFunctions() {
1790 const Module::FunctionListType &funcs = TheModule->getFunctionList();
1791 Module::const_iterator I = funcs.begin();
1792 Module::const_iterator IE = funcs.end();
1793
1794 for (; I != IE; ++I) {
1795 const Function &func = *I;
1796 if (!func.isDeclaration()) {
1797 std::string name("define_");
1798 name += func.getName();
1799 printFunction(name, func.getName());
1800 }
1801 }
1802 }
1803
17861804 void CppWriter::printVariable(
17871805 const std::string& fname, /// Name of generated function
17881806 const std::string& varName // Name of variable to generate
18341852 std::string tgtname = NameToGenerate.getValue();
18351853 if (GenerationType == GenModule ||
18361854 GenerationType == GenContents ||
1837 GenerationType == GenProgram) {
1855 GenerationType == GenProgram ||
1856 GenerationType == GenFunctions) {
18381857 if (tgtname == "!bad!") {
18391858 if (mod->getModuleIdentifier() == "-")
18401859 tgtname = "";
18661885 fname = "makeLLVMFunction";
18671886 W.printFunction(fname,tgtname);
18681887 break;
1888 case GenFunctions:
1889 W.printFunctions();
1890 break;
18691891 case GenInline:
18701892 if (fname.empty())
18711893 fname = "makeLLVMInline";