//========================================================================= // $Id$ // //This is the main program for the algorithm presented in WirthlinDAC05 // //TO-DO: // 1. Should be able to parse a .dot file as the algorithm input instead // of creating one by the program // 2. firGraph should not return a value //========================================================================= //--------------------------------------------------------------------- // Header files inclusion //--------------------------------------------------------------------- #include #include using namespace std; #include #include using namespace boost; #include "Operator.hpp" #include "helper.hpp" //--------------------------------------------------------------------- // Global data structures and variables //--------------------------------------------------------------------- static OperatorType* portType = new BasicOperatorType("Port"); static OperatorType* addType = new BasicOperatorType("+"); static OperatorType* subType = new BasicOperatorType("-"); static OperatorType* constantType = new BasicOperatorType("Const"); static OperatorType* constMultType= new BasicOperatorType("*c"); static OperatorType* multType = new BasicOperatorType("X"); static OperatorType* delayType = new BasicOperatorType("z^-1"); typedef adjacency_list< vecS, vecS, bidirectionalS, BasicOperator> Graph; //Class template of a property_writer template < typename Graph > class schedule_vertex_writer { public: schedule_vertex_writer(Graph _g) : g(_g) {} template void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << v << "(" << g[v].getOperatorType()->getMnemonic() << ")" << "\"]"; } private: Graph g; }; //Function template to return an object of the above class template inline schedule_vertex_writer make_schedule_vertex_writer(Graph g){ return schedule_vertex_writer(g); } //--------------------------------------------------------------------- // Function declarations //--------------------------------------------------------------------- Graph firGraph(int tapNumber); //--------------------------------------------------------------------- //Function description: // This is the main driver for the algorithm //Input: // None //Output: // A graph showing the scheduling result //--------------------------------------------------------------------- int main(void) { cout << "Algorithm starts..." << endl; //Step 1. Create an 8-tap FIR filter Graph firg = firGraph(8); // Print out the graph ofstream out("fir.dot"); write_graphviz(out, firg, make_schedule_vertex_writer(firg)); } //--------------------------------------------------------------------- //Function description: // This is a function that creates a FIR filter graph and returns it //Input: // int tap -> tap number //Output: // Graph -> The FIR filter graph //--------------------------------------------------------------------- Graph firGraph(int tapNumber) { Graph fg; //Declare all the nodes graph_traits::vertex_descriptor dataInNode, dataOutNode, tapsInNodes[tapNumber], multiplyNodes[tapNumber], addNodes[tapNumber - 1]; //Add nodes one by one dataInNode = add_vertex(fg); fg[dataInNode] = BasicOperator(portType, "dataIn"); for ( int i=0 ; i