Commit f96c49ab authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #904 from undingen/printvisitor

PrintVisitor: use raw_ostream
parents 1782dd56 fe6885a6
This diff is collapsed.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include "analysis/scoping_analysis.h" #include "analysis/scoping_analysis.h"
#include "core/common.h" #include "core/common.h"
...@@ -1329,11 +1330,13 @@ public: ...@@ -1329,11 +1330,13 @@ public:
void print_ast(AST* ast); void print_ast(AST* ast);
class PrintVisitor : public ASTVisitor { class PrintVisitor : public ASTVisitor {
private: private:
llvm::raw_ostream& stream;
int indent; int indent;
void printIndent(); void printIndent();
void printOp(AST_TYPE::AST_TYPE op_type);
public: public:
PrintVisitor(int indent = 0) : indent(indent) {} PrintVisitor(int indent = 0, llvm::raw_ostream& stream = llvm::outs()) : stream(stream), indent(indent) {}
virtual ~PrintVisitor() {} virtual ~PrintVisitor() {}
virtual bool visit_alias(AST_alias* node); virtual bool visit_alias(AST_alias* node);
......
...@@ -56,26 +56,26 @@ void CFGBlock::unconnectFrom(CFGBlock* successor) { ...@@ -56,26 +56,26 @@ void CFGBlock::unconnectFrom(CFGBlock* successor) {
successor->predecessors.end()); successor->predecessors.end());
} }
void CFGBlock::print() { void CFGBlock::print(llvm::raw_ostream& stream) {
printf("Block %d", idx); stream << "Block " << idx;
if (info) if (info)
printf(" '%s'", info); stream << " '" << info << "'";
printf("; Predecessors:"); stream << "; Predecessors:";
for (int j = 0; j < predecessors.size(); j++) { for (int j = 0; j < predecessors.size(); j++) {
printf(" %d", predecessors[j]->idx); stream << " " << predecessors[j]->idx;
} }
printf(" Successors:"); stream << " Successors:";
for (int j = 0; j < successors.size(); j++) { for (int j = 0; j < successors.size(); j++) {
printf(" %d", successors[j]->idx); stream << " " << successors[j]->idx;
} }
printf("\n"); stream << "\n";
PrintVisitor pv(4); PrintVisitor pv(4);
for (int j = 0; j < body.size(); j++) { for (int j = 0; j < body.size(); j++) {
printf(" "); stream << " ";
body[j]->accept(&pv); body[j]->accept(&pv);
printf("\n"); stream << "\n";
} }
} }
...@@ -2518,11 +2518,11 @@ public: ...@@ -2518,11 +2518,11 @@ public:
} }
}; };
void CFG::print() { void CFG::print(llvm::raw_ostream& stream) {
printf("CFG:\n"); stream << "CFG:\n";
printf("%ld blocks\n", blocks.size()); stream << blocks.size() << " blocks\n";
for (int i = 0; i < blocks.size(); i++) for (int i = 0; i < blocks.size(); i++)
blocks[i]->print(); blocks[i]->print(stream);
} }
class AssignVRegsVisitor : public NoopASTVisitor { class AssignVRegsVisitor : public NoopASTVisitor {
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
void unconnectFrom(CFGBlock* successor); void unconnectFrom(CFGBlock* successor);
void push_back(AST_stmt* node) { body.push_back(node); } void push_back(AST_stmt* node) { body.push_back(node); }
void print(); void print(llvm::raw_ostream& stream = llvm::outs());
}; };
// Control Flow Graph // Control Flow Graph
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
blocks.push_back(block); blocks.push_back(block);
} }
void print(); void print(llvm::raw_ostream& stream = llvm::outs());
bool hasVregsAssigned() { return has_vregs_assigned; } bool hasVregsAssigned() { return has_vregs_assigned; }
void assignVRegs(const ParamNames& param_names, ScopeInfo* scope_info); void assignVRegs(const ParamNames& param_names, ScopeInfo* scope_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment