Commit 3db0ec00 authored by Marius Wachtler's avatar Marius Wachtler

BST: remove the flattening visitor

we don't need it anymore now that we eliminated nearly all pointers to nodes.
parent 106533f9
......@@ -1344,7 +1344,6 @@ bool PrintVisitor::visit_unaryop(BST_UnaryOp* node) {
break;
}
stream << "(";
// node->operand->accept(this);
visit_vreg(&node->vreg_operand);
stream << ")";
return true;
......@@ -1394,242 +1393,4 @@ bool PrintVisitor::visit_makeclass(BST_MakeClass* node) {
stream << "make_";
return false;
}
namespace {
class FlattenVisitor : public BSTVisitor {
private:
std::vector<BST_stmt*>* output;
bool expand_scopes;
public:
FlattenVisitor(std::vector<BST_stmt*>* output, bool expand_scopes)
: BSTVisitor(false /* visit child CFG */), output(output), expand_scopes(expand_scopes) {
assert(expand_scopes && "not sure if this works properly");
}
virtual bool visit_vreg(int* vreg, bool is_dst = false) { return false; }
virtual bool visit_assert(BST_Assert* node) {
output->push_back(node);
return false;
}
virtual bool visit_copyvreg(BST_CopyVReg* node) {
output->push_back(node);
return false;
}
virtual bool visit_augbinop(BST_AugBinOp* node) {
output->push_back(node);
return false;
}
virtual bool visit_binop(BST_BinOp* node) {
output->push_back(node);
return false;
}
virtual bool visit_callfunc(BST_CallFunc* node) {
output->push_back(node);
return false;
}
virtual bool visit_callattr(BST_CallAttr* node) {
output->push_back(node);
return false;
}
virtual bool visit_callclsattr(BST_CallClsAttr* node) {
output->push_back(node);
return false;
}
virtual bool visit_classdef(BST_ClassDef* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_compare(BST_Compare* node) {
output->push_back(node);
return false;
}
virtual bool visit_deletesub(BST_DeleteSub* node) {
output->push_back(node);
return false;
}
virtual bool visit_deletesubslice(BST_DeleteSubSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_deleteattr(BST_DeleteAttr* node) {
output->push_back(node);
return false;
}
virtual bool visit_deletename(BST_DeleteName* node) {
output->push_back(node);
return false;
}
virtual bool visit_dict(BST_Dict* node) {
output->push_back(node);
return false;
}
virtual bool visit_exec(BST_Exec* node) {
output->push_back(node);
return false;
}
virtual bool visit_functiondef(BST_FunctionDef* node) {
output->push_back(node);
return !expand_scopes;
}
virtual bool visit_invoke(BST_Invoke* node) {
output->push_back(node);
return false;
}
virtual bool visit_list(BST_List* node) {
output->push_back(node);
return false;
}
virtual bool visit_print(BST_Print* node) {
output->push_back(node);
return false;
}
virtual bool visit_raise(BST_Raise* node) {
output->push_back(node);
return false;
}
virtual bool visit_repr(BST_Repr* node) {
output->push_back(node);
return false;
}
virtual bool visit_return(BST_Return* node) {
output->push_back(node);
return false;
}
virtual bool visit_set(BST_Set* node) {
output->push_back(node);
return false;
}
virtual bool visit_tuple(BST_Tuple* node) {
output->push_back(node);
return false;
}
virtual bool visit_unaryop(BST_UnaryOp* node) {
output->push_back(node);
return false;
}
virtual bool visit_unpackintoarray(BST_UnpackIntoArray* node) {
output->push_back(node);
return false;
}
virtual bool visit_yield(BST_Yield* node) {
output->push_back(node);
return false;
}
virtual bool visit_branch(BST_Branch* node) {
output->push_back(node);
return false;
}
virtual bool visit_jump(BST_Jump* node) {
output->push_back(node);
return false;
}
virtual bool visit_makeclass(BST_MakeClass* node) {
output->push_back(node);
return false;
}
virtual bool visit_makefunction(BST_MakeFunction* node) {
output->push_back(node);
return false;
}
virtual bool visit_makeslice(BST_MakeSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_landingpad(BST_Landingpad* node) {
output->push_back(node);
return false;
}
virtual bool visit_locals(BST_Locals* node) {
output->push_back(node);
return false;
}
virtual bool visit_getiter(BST_GetIter* node) {
output->push_back(node);
return false;
}
virtual bool visit_importfrom(BST_ImportFrom* node) {
output->push_back(node);
return false;
}
virtual bool visit_importname(BST_ImportName* node) {
output->push_back(node);
return false;
}
virtual bool visit_importstar(BST_ImportStar* node) {
output->push_back(node);
return false;
}
virtual bool visit_nonzero(BST_Nonzero* node) {
output->push_back(node);
return false;
}
virtual bool visit_checkexcmatch(BST_CheckExcMatch* node) {
output->push_back(node);
return false;
}
virtual bool visit_setexcinfo(BST_SetExcInfo* node) {
output->push_back(node);
return false;
}
virtual bool visit_uncacheexcinfo(BST_UncacheExcInfo* node) {
output->push_back(node);
return false;
}
virtual bool visit_hasnext(BST_HasNext* node) {
output->push_back(node);
return false;
}
virtual bool visit_printexpr(BST_PrintExpr* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadname(BST_LoadName* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadattr(BST_LoadAttr* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadsub(BST_LoadSub* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadsubslice(BST_LoadSubSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_storename(BST_StoreName* node) {
output->push_back(node);
return false;
}
virtual bool visit_storesub(BST_StoreSub* node) {
output->push_back(node);
return false;
}
virtual bool visit_storesubslice(BST_StoreSubSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_storeattr(BST_StoreAttr* node) {
output->push_back(node);
return false;
}
};
}
void flatten(llvm::ArrayRef<BST_stmt*> roots, std::vector<BST_stmt*>& output, bool expand_scopes) {
FlattenVisitor visitor(&output, expand_scopes);
for (int i = 0; i < roots.size(); i++) {
roots[i]->accept(&visitor);
}
}
}
......@@ -978,11 +978,6 @@ public:
virtual bool visit_unpackintoarray(BST_UnpackIntoArray* node);
virtual bool visit_yield(BST_Yield* node);
};
// Given an BST node, return a vector of the node plus all its descendents.
// This is useful for analyses that care more about the constituent nodes than the
// exact tree structure; ex, finding all "global" directives.
void flatten(llvm::ArrayRef<BST_stmt*> roots, std::vector<BST_stmt*>& output, bool expand_scopes);
};
}
#endif
......@@ -3252,25 +3252,6 @@ static std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body,
assert(rtn->getStartingBlock()->idx == 0);
std::vector<BST_stmt*> flattened;
for (auto b : rtn->blocks)
flatten(b->body, flattened, true);
std::unordered_map<BST_stmt*, int> deduped;
bool no_dups = true;
for (auto e : flattened) {
deduped[e]++;
if (deduped[e] == 2) {
printf("Duplicated: ");
print_bst(e, visitor.code_constants);
printf("\n");
no_dups = false;
}
}
if (!no_dups)
rtn->print(visitor.code_constants);
assert(no_dups);
// Uncomment this for some heavy checking to make sure that we don't forget
// to set lineno. It will catch a lot of things that don't necessarily
// need to be fixed.
......
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