00001 /* Call Graph Nodes */ 00002 00003 /* Copyright (c) 1995, 1997 Stanford University 00004 00005 All rights reserved. 00006 00007 This software is provided under the terms described in 00008 the "suif_copyright.h" include file. */ 00009 00010 #include "common/suif_copyright.h" 00011 00012 #include <stdio.h> 00013 #include "common/suif_list.h" 00014 #include "basicnodes/basic_forwarders.h" 00015 #include "cgraph.h" 00016 00017 #ifndef CG_NODE_H 00018 #define CG_NODE_H 00019 00020 /* 00021 * Each call graph node contains only an ID number and information 00022 * related to the call graph. Other information can be associated with 00023 * a node by storing it in a separate array where the node ID number 00024 * is used to index the array. 00025 */ 00026 00027 class cg_node; 00028 00029 class cg_node_list : public list<cg_node*> 00030 { 00031 public: 00032 void toposort_helper( cg_node_list *l, bit_vector *mark, bool reverse = false ); 00033 00034 void remove_node( cg_node *n ); 00035 void print( FILE *fp = stdout ); 00036 }; 00037 00038 00039 class cg_node { 00040 private: 00041 unsigned nnum; // node number 00042 cg *par; // parent call graph 00043 cg_node_list prs; // predecessors 00044 cg_node_list scs; // successors 00045 ProcedureSymbol *psym; // procedure_symbol this node represents 00046 int unknown; // number of calls to unknown procs 00047 00048 public: 00049 void toposort_helper( cg_node_list *l, bit_vector *mark, bool reverse = false ); 00050 00051 cg_node(ProcedureSymbol *ps); 00052 ~cg_node(); 00053 00054 unsigned number() { return nnum; } 00055 cg *parent() { return par; } 00056 ProcedureSymbol *get_procedure_symbol() { return psym; } 00057 int unknown_callees() { return unknown; } 00058 00059 cg_node_list *preds() { return &prs; } 00060 cg_node_list *succs() { return &scs; } 00061 void inc_unknowns(int val = 1) { unknown += val; } 00062 00063 void add_pred(cg_node *n); 00064 void add_succ(cg_node *n); 00065 void remove_pred(cg_node *n); 00066 void remove_succ(cg_node *n); 00067 00068 void toposort(cg_node_list *l, bool reverse = false); 00069 00070 void print(FILE *fp=stdout); 00071 00072 void set_number(unsigned n) { nnum = n; } 00073 void set_parent(cg *p) { par = p; } 00074 00075 }; 00076 00077 #endif /* CG_NODE_H */