diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-07 17:28:11 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-07 17:28:11 -0800 |
commit | 61e52f395a519f1811eab99911d513f6b5205f19 (patch) | |
tree | 96a6483f17173def93628c1d4f05ad0fcaf9cab9 /lib/Target | |
parent | a55ff5ad9716e37fbd4dbaf741de340966060637 (diff) |
refactor function printing into a function
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/JSBackend/JSBackend.cpp | 103 |
1 files changed, 50 insertions, 53 deletions
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index 1bee376b32..c5fa7018ca 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp @@ -135,11 +135,7 @@ namespace { void printProgram(const std::string& fname, const std::string& modName ); 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 printFunction(const Function *F); void error(const std::string& msg); @@ -1609,61 +1605,62 @@ void JSWriter::processConstants() { } } -void JSWriter::printModuleBody() { - processConstants(); +void JSWriter::printFunction(const Function *F) { + ValueNames.clear(); - // Emit function bodies. - nl(Out) << "// EMSCRIPTEN_START_FUNCTIONS"; nl(Out); - for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); - I != E; ++I) { - if (!I->isDeclaration()) { + // Ensure all arguments and locals are named (we assume used values need names, which might be false if the optimizer did not run) + unsigned Next = 1; + for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); + AI != AE; ++AI) { + if (!AI->hasName() && AI->hasNUsesOrMore(1)) { + ValueNames[AI] = "$" + utostr(Next++); + } + } + for (Function::const_iterator BI = F->begin(), BE = F->end(); + BI != BE; ++BI) { + for (BasicBlock::const_iterator II = BI->begin(), E = BI->end(); + II != E; ++II) { + if (!II->hasName() && II->hasNUsesOrMore(1)) { + ValueNames[II] = "$" + utostr(Next++); + } + } + } - ValueNames.clear(); + // Prepare and analyze function - // Ensure all arguments and locals are named (we assume used values need names, which might be false if the optimizer did not run) - unsigned Next = 1; - for (Function::const_arg_iterator AI = I->arg_begin(), AE = I->arg_end(); - AI != AE; ++AI) { - if (!AI->hasName() && AI->hasNUsesOrMore(1)) { - ValueNames[AI] = "$" + utostr(Next++); - } - } - for (Function::const_iterator BI = I->begin(), BE = I->end(); - BI != BE; ++BI) { - for (BasicBlock::const_iterator II = BI->begin(), E = BI->end(); - II != E; ++II) { - if (!II->hasName() && II->hasNUsesOrMore(1)) { - ValueNames[II] = "$" + utostr(Next++); - } - } - } + UsedVars.clear(); + UniqueNum = 0; + calculateNativizedVars(F); - // Prepare and analyze function + // Emit the function - UsedVars.clear(); - UniqueNum = 0; - calculateNativizedVars(I); + Out << "function _" << F->getName() << "("; + for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); + AI != AE; ++AI) { + if (AI != F->arg_begin()) Out << ","; + Out << getJSName(AI); + } + Out << ") {"; + nl(Out); + for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); + AI != AE; ++AI) { + std::string name = getJSName(AI); + Out << " " << name << " = " << getCast(name, AI->getType(), ASM_NONSPECIFIC) << ";"; + nl(Out); + } + printFunctionBody(F); + Out << "}"; + nl(Out); +} - // Emit the function +void JSWriter::printModuleBody() { + processConstants(); - Out << "function _" << I->getName() << "("; - for (Function::const_arg_iterator AI = I->arg_begin(), AE = I->arg_end(); - AI != AE; ++AI) { - if (AI != I->arg_begin()) Out << ","; - Out << getJSName(AI); - } - Out << ") {"; - nl(Out); - for (Function::const_arg_iterator AI = I->arg_begin(), AE = I->arg_end(); - AI != AE; ++AI) { - std::string name = getJSName(AI); - Out << " " << name << " = " << getCast(name, AI->getType(), ASM_NONSPECIFIC) << ";"; - nl(Out); - } - printFunctionBody(I); - Out << "}"; - nl(Out); - } + // Emit function bodies. + nl(Out) << "// EMSCRIPTEN_START_FUNCTIONS"; nl(Out); + for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); + I != E; ++I) { + if (!I->isDeclaration()) printFunction(I); } Out << "function runPostSets() {\n"; Out << " " << PostSets << "\n"; |