00001
00002 #include "oaDesignDB.h"
00003 #include "oagFpga.h"
00004 #include "oagFpgaManager.h"
00005 #include "oagFpgaMapper.h"
00006
00007 #include "oagFpgaVerilogSynthesis.h"
00008
00009
00010 #include "oagFpgaModuleCompiler.h"
00011 #include <iostream>
00012
00013 #include "oagFpgaDebug.h"
00014
00015
00016
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
00030
00031
00033
00034 oa::oaVarDataAppDef<oa::oaDesign> *streamAppDef;
00035
00036 oa::oaVoidPointerAppDef<oa::oaDesign> *managerAppDef;
00037
00038 oa::oaIntAppDef<oa::oaModBitNet> *bbRefAppDef;
00039
00040 oa::oaIntAppDef<oa::oaModBitNet> *AiRefAppDef;
00041
00042 Observer *observer;
00043
00044 using namespace std;
00045
00046
00047
00048
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
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
00094 readVerilog(library, viewName, filename);
00095 }
00096
00097
00098
00099
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
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
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
00214
00215
00216
00217
00218
00219
00220
00221
00222 #ifdef YU_TEST
00223 YuTestCurLib = curLib;
00224 YuTestCurView = curView;
00225 #endif // #ifdef YU_TEST
00226
00227 const oa::oaVerilogNS verilogNS;
00228
00229
00230 FpgaMapper mapper(cutsPerNode);
00231 mapper.mapUtils.createSeq(curLib, curView);
00232 mapper.mapUtils.createLut(curLib, curView, lutSize);
00233
00234
00235
00236 if (flatten) {
00237 cerr << "Flattening is currently not implemented." << endl;
00238 QUIT_ON_INTERNAL_ERROR;
00239
00240
00241 }
00242
00243
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
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
00305
00306 mapper.mapUtils.removeDanglingNets(targetDesign->getTopModule());
00307
00308 }
00309
00310
00311
00312
00313
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 }