Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

oagFpga.cpp

Go to the documentation of this file.
00001 
00002 #include "oaDesignDB.h"
00003 #include "oagFpga.h"
00004 #include "oagFpgaManager.h"
00005 #include "oagFpgaMapper.h"
00006 //#include "oagFpgaTimingLibrarySynthesis.h"
00007 #include "oagFpgaVerilogSynthesis.h"
00008 //#include "oagFpgaModGraph.h"
00009 //#include "oagFpgaOccGraph.h"
00010 #include "oagFpgaModuleCompiler.h"
00011 #include <iostream>
00012 
00013 #include "oagFpgaDebug.h"
00014 
00015 // *****************************************************************************
00016 // Global static variable definitions.
00017 // *****************************************************************************
00018 
00019 extern char                          *oagFpgaVerilog_yyfilename;
00020 extern FILE                          *oagFpgaVerilog_yyin;
00021 int                                   oagFpgaVerilog_yyparse();
00022 extern oagFpga::VerilogDesign        *oagFpgaVerilog_yydesign;
00023 extern FILE                          *oagFpgaLib_yyin;
00024 int                                   oagFpgaLib_yyparse();
00025 
00026 namespace oagFpga {
00027 
00028 // *****************************************************************************
00029 // Class static variable definitions.
00030 // *****************************************************************************
00031 
00033 //  application extension (for each design) for read/save the additional information
00034 oa::oaVarDataAppDef<oa::oaDesign>           *streamAppDef;
00035 //  application extension (for each design) for Manager class
00036 oa::oaVoidPointerAppDef<oa::oaDesign>       *managerAppDef;
00037 //  application extension (for each net) for connecting net and black box graph
00038 oa::oaIntAppDef<oa::oaModBitNet>            *bbRefAppDef;
00039 //  application extension (for each net) for connecting net and AIG
00040 oa::oaIntAppDef<oa::oaModBitNet>            *AiRefAppDef;
00041     
00042 Observer                                    *observer;
00043 
00044 using namespace std;
00045 
00046 
00047 // *****************************************************************************
00048 // initialize()
00049 //
00057 //
00058 // *****************************************************************************
00059 void            
00060 initialize() {
00061     streamAppDef = 
00062         oa::oaVarDataAppDef<oa::oaDesign>::get(oa::oaString("oagFpga_function_stream"));
00063     managerAppDef = 
00064         oa::oaVoidPointerAppDef<oa::oaDesign>::get(oa::oaString("oagFpga_manager"));
00065     bbRefAppDef =
00066         oa::oaIntAppDef<oa::oaModBitNet>::get(oa::oaString("oagFpga_RTLGraphRef"));
00067     AiRefAppDef =
00068         oa::oaIntAppDef<oa::oaModBitNet>::get(oa::oaString("oagAi_Graph"));
00069 
00070     observer = new Observer();
00071 }
00072 
00073 
00074 // *****************************************************************************
00075 // readVerilog()
00076 //
00083 //
00084 // *****************************************************************************
00085 void
00086 readVerilog(oa::oaLib *library, const char *filename) {
00087     assert(library);
00088     assert(filename);
00089 
00090     oa::oaNativeNS nativeNS;
00091     oa::oaScalarName viewName(nativeNS, "netlist");
00092 
00093     // read Verilog
00094     readVerilog(library, viewName, filename);
00095 }
00096 
00097 
00098 // *****************************************************************************
00099 // readVerilog()
00100 //
00106 //
00107 // *****************************************************************************
00108 void
00109 readVerilog(oa::oaLib *library, const oa::oaScalarName &viewName, 
00110         const char *filename) {
00111     assert(library);
00112     assert(filename);
00113 
00114     if(library->getAccess(oa::oaLibAccess(oa::oacWriteLibAccess))) {
00115         const oa::oaViewType *viewType = oa::oaViewType::get(oa::oacNetlist);
00116         oa::oaView *view = oa::oaView::get(library, viewName, viewType);
00117         assert(view);
00118 
00119         // parse verilog file
00120         VerilogSynthesis::setLibrary(library);
00121         VerilogSynthesis::setView(view);
00122         oagFpgaVerilog_yyfilename = const_cast<char *>(filename);
00123         oagFpgaVerilog_yyin = fopen(filename, "r");
00124         if (!oagFpgaVerilog_yyin) {
00125             cerr << "ERROR: Could not open Verilog file " << filename << endl;
00126             exit(0);
00127         }
00128 
00129         cerr << "Begin to parse Verilog file, please wait..." << endl;
00130 
00131         oagFpgaVerilog_yyparse();
00132 
00133         cerr << "Parsing is done!" << endl;
00134 
00135         cerr << "Begin to synthesize Verilog modules, please wait..." << endl;
00136 
00137         VerilogSynthesis::synthesize(oagFpgaVerilog_yydesign);
00138 
00139         cerr << "Begin to perform module compiler, please wait..." << endl;
00140 
00141         ModuleCompiler::compileModules(library, view);
00142 
00143         cerr << "Synthesis is done!" << endl;
00144 
00145         fclose(oagFpgaVerilog_yyin);
00146 
00147         library->releaseAccess();
00148     } else {
00149         cerr << "ERROR: Could not write into library " << endl;
00150         exit(0);
00151     }
00152 }
00153 
00154 #ifdef YU_TEST
00155 
00156 oa::oaLib* YuTestCurLib;
00157 oa::oaView* YuTestCurView;
00158 
00159 
00160 void YuTest(oa::oaLib* curLib, oa::oaView* curView, oa::oaModule* currentModule) {
00161     const oa::oaNativeNS nativeNS;
00162     const oa::oaScalarName cellName(nativeNS, "MYLUT");
00163     oa::oaScalarName    libName;
00164     curLib->getName(libName);
00165     oa::oaScalarName    viewName;
00166     curView->getName(viewName);
00167 
00168     oa::oaDesign* lutDesign = oa::oaDesign::open(libName, cellName, 
00169         viewName, oa::oaViewType::get(oa::oacNetlist), 'w');
00170     oa::oaModule* lutModule = oa::oaModule::create(lutDesign, cellName); 
00171     lutDesign->setTopModule(lutModule );
00172 
00173     oa::oaModScalarInst *inst = oa::oaModScalarInst::create(currentModule, lutDesign);
00174     cerr << "LUT instant is created!" << endl;
00175     exit(0);
00176 }
00177 
00178 
00179 
00180 #endif // ifdef YU_TEST
00181 
00182 
00183 // *****************************************************************************
00184 // lutMap()
00185 //
00198 //
00199 // *****************************************************************************
00200 void lutMap(oa::oaLib* curLib, oa::oaView* curView,
00201              oa::oaDesign *targetDesign,
00202              int lutSize = 4,
00203              int cutsPerNode = 200, 
00204              bool flatten = false, 
00205              char* clockNetName = NULL,
00206              char* clockTriggerName = NULL,
00207              char* resetNetName = NULL,
00208              char* resetTriggerName = NULL,
00209              char* objectiveName = "area"
00210              ) 
00211 {
00212 
00213 //    int lutSize = 4;
00214 //    int cutsPerNode = 200;
00215 //    bool flatten = false; 
00216 //    char* clockNetName = NULL;
00217 //    char* clockTriggerName = NULL;
00218 //    char* resetNetName = NULL;
00219 //    char* resetTriggerName = NULL;
00220 //    char* objectiveName = "delay";
00221 
00222 #ifdef YU_TEST
00223     YuTestCurLib = curLib;
00224     YuTestCurView = curView;
00225 #endif // #ifdef YU_TEST
00226 
00227     const oa::oaVerilogNS verilogNS;
00228 
00229     // initialize mapper
00230     FpgaMapper mapper(cutsPerNode);
00231     mapper.mapUtils.createSeq(curLib, curView);
00232     mapper.mapUtils.createLut(curLib, curView, lutSize);
00233     // TODO: mapper.useAlternateView(instanceViewName);
00234 
00235     // Flatten
00236     if (flatten) {
00237         cerr << "Flattening is currently not implemented." << endl;
00238         QUIT_ON_INTERNAL_ERROR;
00239         //cout << "Flattening \'" << cellString << "\' ... " << endl;
00240         //oagFunc::collapseAllInstancesAllLevels(targetDesign->getTopModule());
00241     }
00242 
00243     // Manually identify clocks/resets
00244     if (clockNetName) {
00245         oa::oaScalarName clockName(verilogNS, clockNetName);
00246         oa::oaModNet *clockNet = oa::oaModNet::find(targetDesign->getTopModule(), clockName);
00247         if (!clockNet) {
00248             cerr << "ERROR: Could not find clock net: " << clockNet << endl;
00249             exit(0);
00250         }
00251         if (clockNet->getNumBits() != 1) {
00252             cerr << "ERROR: Clock net not a single bit net: " << clockNet << endl;
00253             exit(0);                
00254         }
00255         MapperUtils::TriggerType clockTrigger = MapperUtils::POSEDGE;
00256         if (clockTrigger) {
00257             if (!strcmp(static_cast<const char*>(clockTriggerName), "pos")) {
00258                 clockTrigger = MapperUtils::POSEDGE;
00259             } else if (!strcmp(static_cast<const char*>(clockTriggerName), "neg")) {
00260                 clockTrigger = MapperUtils::NEGEDGE;
00261             } else {
00262                 cerr << "ERROR: Unknown trigger type.  Use \"pos\" or \"neg\"" << endl;
00263                 exit(0);
00264             }
00265         }
00266         mapper.mapUtils.addGlobalClock(oagFpga::toBitNet(clockNet), clockTrigger);
00267     }
00268     if (resetNetName) {
00269         oa::oaScalarName resetName(verilogNS, resetNetName);
00270         oa::oaModNet *resetNet = oa::oaModNet::find(targetDesign->getTopModule(), resetName);
00271         if (!resetNet) {
00272             cerr << "ERROR: Could not find reset net: " << resetNet << endl;
00273             exit(0);
00274         }
00275         if (resetNet->getNumBits() != 1) {
00276             cerr << "ERROR: Reset net not a single bit net: " << resetNet << endl;
00277             exit(0);
00278         }
00279         MapperUtils::TriggerType resetTrigger = MapperUtils::POSEDGE;
00280         if (resetTrigger) {
00281             if (!strcmp(static_cast<const char*>(resetTriggerName), "pos")) {
00282                 resetTrigger = MapperUtils::POSEDGE;
00283             } else if (!strcmp(static_cast<const char*>(resetTriggerName), "neg")) {
00284                 resetTrigger = MapperUtils::NEGEDGE;
00285             } else {
00286                 cerr << "ERROR: Unknown trigger type.  Use \"pos\" or \"neg\"" << endl;
00287                 exit(0);
00288             }
00289         }
00290         mapper.mapUtils.addGlobalReset(oagFpga::toBitNet(resetNet), resetTrigger);
00291     }
00292 
00293     // Map!
00294     if (!strcmp(static_cast<const char*>(objectiveName), "area")) {
00295         mapper.techmapArea(targetDesign->getTopModule());
00296     } else if (!strcmp(static_cast<const char*>(objectiveName), "delay")) {
00297         mapper.techmapDelay(targetDesign->getTopModule());
00298     } else {
00299         cerr << "ERROR: Can't understand mapping objective.  Try \"area\" or \"delay\"" << endl;
00300         exit(0);
00301     }
00302     mapper.mapUtils.printGateUsage(targetDesign->getTopModule());
00303 
00304     // Remove dangling nets
00305 
00306     mapper.mapUtils.removeDanglingNets(targetDesign->getTopModule());
00307 
00308 }
00309 
00310 /*
00311 // *****************************************************************************
00312 // readLiberty()
00313 //
00319 //
00320 // *****************************************************************************
00321 void
00322 readLiberty(oa::oaLib *library, const oa::oaScalarName &viewName, const char *filename) {
00323     assert(library);
00324     assert(filename);
00325 
00326     if(library->getAccess(oa::oaLibAccess(oa::oacWriteLibAccess))) {
00327         const oa::oaViewType *viewType = oa::oaViewType::get(oa::oacNetlist);
00328         oa::oaView *view = oa::oaView::get(library, viewName, viewType);
00329         assert(view);
00330 
00331         // parse Liberty file
00332         TimingLibrarySynthesis::initialize();
00333         TimingLibrarySynthesis::setLibrary(library);
00334         TimingLibrarySynthesis::setView(view);
00335         oagFpgaLib_yyin = fopen(filename, "r");
00336         if (!oagFpgaLib_yyin) {
00337             cerr << "ERROR: Could not open Liberty file " << filename << endl;
00338             exit(0);
00339         }
00340         cout << "Reading Liberty file " << filename << endl;
00341         oagFpgaLib_yyparse();
00342         fclose(oagFpgaLib_yyin);
00343         library->releaseAccess();
00344     } else {
00345         cerr << "ERROR: Could not write into library " << endl;
00346         exit(0);
00347     }
00348 }
00349 
00350 
00351 // *****************************************************************************
00352 // readLiberty()
00353 //
00360 //
00361 // *****************************************************************************
00362 void
00363 readLiberty(oa::oaLib *library, const char *filename) {
00364     assert(library);
00365     assert(filename);
00366 
00367     oa::oaNativeNS nativeNS;
00368     oa::oaScalarName viewName(nativeNS, "netlist");
00369 
00370     // read the Liberty file
00371     readLiberty(library, viewName, filename);
00372 }
00373 
00374 
00375 // *****************************************************************************
00376 // findBusTerm()
00377 //
00382 //
00383 // *****************************************************************************
00384 oa::oaOccBusTerm*
00385 findBusTerm(oa::oaOccBusTermBit *bitTerm) {
00386     assert(bitTerm);
00387 
00388     oa::oaName generalName;
00389     bitTerm->getName(generalName);
00390     if (generalName.getScalar()) {
00391       // ignore scalars
00392       return NULL;
00393     }
00394     assert(generalName.getVectorBit());
00395 
00396     oa::oaOccBusTermDef *busTermDef = static_cast<oa::oaOccBusTermBit*>(bitTerm)->getDef();
00397     if (busTermDef) {
00398       oa::oaIter<oa::oaOccBusTerm> busIter(busTermDef->getBusTerms());
00399       oa::oaOccBusTerm *busTerm = busIter.getNext();
00400       if (busTerm) {
00401         return busTerm;
00402       }
00403     }
00404     
00405     // should never reach this point
00406     QUIT_ON_INTERNAL_ERROR;
00407     return NULL;
00408 }
00409 
00410 
00411 // *****************************************************************************
00412 // findBusNet()
00413 //
00418 //
00419 // *****************************************************************************
00420 oa::oaModBusNet*
00421 findBusNet(oa::oaModBitNet *bitNet) {
00422     assert(bitNet);
00423 
00424     oa::oaName generalName;
00425     bitNet->getName(generalName);
00426     if (generalName.getScalar()) {
00427       // ignore scalars
00428       return NULL;
00429     }
00430     assert(generalName.getVectorBit());
00431 
00432     oa::oaModBusNetDef *busNetDef = static_cast<oa::oaModBusNetBit*>(bitNet)->getDef();
00433     if (busNetDef) {
00434       oa::oaIter<oa::oaModBusNet> busIter(busNetDef->getBusNets());
00435       oa::oaModBusNet *busNet = busIter.getNext();
00436       if (busNet) {
00437         return busNet;
00438       }
00439     }
00440     
00441     // should never reach this point
00442     QUIT_ON_INTERNAL_ERROR;
00443     return NULL;
00444 }
00445 */
00446 
00447 }

Generated on Mon Jul 9 14:17:19 2007 for OA Gear Fpga by  doxygen 1.3.9.1