//---------------------------------------------------------------------- // USAGE [-Time-only | -Memory-only] [-RESET] //---------------------------------------------------------------------- V3CmdExecStatus V3UsageCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); bool timeOnly = false, memoryOnly = false, reset = false; size_t n = options.size(); for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-Time-only", token, 2) == 0) { if (timeOnly || memoryOnly) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else timeOnly = true; } else if (v3StrNCmp("-Memory-only", token, 2) == 0) { if (timeOnly || memoryOnly) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else memoryOnly = true; } else if (v3StrNCmp("-RESET", token, 6) == 0) { if (reset) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else reset = true; } else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); } v3Usage.report(!memoryOnly, !timeOnly); if (reset) v3Usage.reset(); return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // BLAst NTk [-Primary] //---------------------------------------------------------------------- V3CmdExecStatus V3BlastNtkCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); bool primary = false; size_t n = options.size(); for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-Primary", token, 2) == 0) { if (primary) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else primary = true; } else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); } V3NtkHandler* const handler = v3Handler.getCurHandler(); if (handler) { if (dynamic_cast<V3BvNtk*>(handler->getNtk())) { if (primary) { V3BvBlastBv* const blastHandler = new V3BvBlastBv(handler); assert (blastHandler); v3Handler.pushAndSetCurHandler(blastHandler); } else { V3BvBlastAig* const blastHandler = new V3BvBlastAig(handler); assert (blastHandler); v3Handler.pushAndSetCurHandler(blastHandler); } } else Msg(MSG_ERR) << "Current Network is Already an AIG Network !!" << endl; } else Msg(MSG_ERR) << "Empty Ntk !!" << endl; return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // HELp [<(string cmd) [-Verbose]> | -Revealed] //---------------------------------------------------------------------- V3CmdExecStatus V3HelpCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); bool verbose = false, revealed = false; string cmd = ""; size_t n = options.size(); for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-Verbose", token, 2) == 0) { if (revealed) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); else if (verbose) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else verbose = true; } else if (v3StrNCmp("-Revealed", token, 2) == 0) { if (verbose || cmd.size()) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); else if (revealed) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else revealed = true; } else { if (revealed) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); if (cmd.size()) cmd.append(" "); cmd.append(token); } } if (revealed) v3CmdMgr->printHelps(true); // Print All Commands else if (!cmd.size()) v3CmdMgr->printHelps(); // Print Commands else { V3CmdExec* e = v3CmdMgr->getCmd(cmd); if (e) { e->usage(verbose); return CMD_EXEC_DONE; } // if exact match V3CmdExecSubSet list = v3CmdMgr->getCmdListFromPart(cmd); if (list.size()) { // if partial match V3CmdExecSubSet::iterator it = list.begin(); if (verbose) for (; it != list.end(); ++it) (*it)->usage(); else for (; it != list.end(); ++it) (*it)->help(); return CMD_EXEC_DONE; } else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, cmd); } return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // Quit [-Force] //---------------------------------------------------------------------- V3CmdExecStatus V3QuitCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); if (options.size() > 1) return V3CmdExec::errorOption(CMD_OPT_EXTRA, options[1]); else if (options.size()) { if (v3StrNCmp("-Forced", options[0], 2) == 0) return CMD_EXEC_QUIT; else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, options[0]); } Msg(MSG_IFO) << "Are you sure to quit (Yes/No)? [No] "; char str[1024]; cin.getline(str, 1024); string ss = string(str); if (ss.size()) { size_t s = ss.find_first_not_of(' ', 0); if (s != string::npos) ss = ss.substr(s); } if (v3StrNCmp("Yes", ss, 1) == 0) return CMD_EXEC_QUIT; else return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // EXPand NTk <(unsigned cycle)> [-Initial] //---------------------------------------------------------------------- V3CmdExecStatus V3ExpandNtkCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); bool init = false; uint32_t cycle = 0; size_t n = options.size(); for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-Initial", token, 2) == 0) { if (init) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else init = true; } else if (!cycle) { int temp; if (!v3Str2Int(token, temp)) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); if (temp <= 0) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); cycle = uint32_t(temp); } else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); } if (!cycle) return V3CmdExec::errorOption(CMD_OPT_MISSING, "<(unsigned cycle)>"); V3NtkHandler* const handler = v3Handler.getCurHandler(); if (handler) { if (!handler->getNtk()->getModuleSize()) { V3NtkExpand* const expandHandler = new V3NtkExpand(handler, cycle, init); assert (expandHandler); v3Handler.pushAndSetCurHandler(expandHandler); } else Msg(MSG_ERR) << "Currently Networks with Module Instances Cannot be Expanded !!" << endl; } else Msg(MSG_ERR) << "Empty Ntk !!" << endl; return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // SET LOgfile [| -All | -Cmd | -Error | -Warning | -Info | -Debug] // <(string fileName)> [| -File-only | -Both] [-APPend] //---------------------------------------------------------------------- V3CmdExecStatus V3LogFileCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); bool all = false, cmd = false, error = false, warning = false, info = false, debug = false; bool fileonly = false, both = false; bool append = false; string fileName = ""; size_t n = options.size(); if (n == 0) all = true; else { for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-APPend", token, 4) == 0) { if (append) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); append = true; } else if (v3StrNCmp("-All", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else all = true; } else if (v3StrNCmp("-Cmd", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else cmd = true; } else if (v3StrNCmp("-Error", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else error = true; } else if (v3StrNCmp("-Warning", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else warning = true; } else if (v3StrNCmp("-Info", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else info = true; } else if (v3StrNCmp("-Debug", token, 2) == 0) { if (all || cmd || error || warning || info || debug) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else debug = true; } else if (v3StrNCmp("-File-only", token, 2) == 0) { if (fileonly || both) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); fileonly = true; } else if (v3StrNCmp("-Both", token, 2) == 0) { if (fileonly || both) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); both = true; } else { if (fileName == "") fileName = token; else return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); } } } if (fileName == "") return V3CmdExec::errorOption(CMD_OPT_MISSING, "<(string fileName)>"); if (!(all || cmd || error || warning || info || debug)) all = true; if (!(fileonly || both)) fileonly = true; if (all) { Msg.setAllOutFile(fileName); Msg.startAllOutFile(append); if (fileonly) Msg.stopAllDefault(); else Msg.startAllDefault(); } else { V3MsgType type = (cmd) ? MSG_LOG : (error) ? MSG_ERR : (warning) ? MSG_WAR : (info) ? MSG_IFO : MSG_DBG; Msg.setOutFile(fileName, type); Msg.startOutFile(type, append); if (fileonly) Msg.stopDefault(type); else if (type != MSG_LOG) Msg.startDefault(type); } return CMD_EXEC_DONE; }
//---------------------------------------------------------------------- // MITer NTk <(unsigned ntkId1)> <(unsigned ntkId2)> // [-Name <(string miterNtkName)>] [| -SEC | -CEC] [-Merge] //---------------------------------------------------------------------- V3CmdExecStatus V3MiterNtkCmd::exec(const string& option) { vector<string> options; V3CmdExec::lexOptions(option, options); uint32_t id1 = V3NtkUD, id2 = V3NtkUD; bool miterName = false, miterNameON = false; bool sec = false, cec = false, merge = false; string miterNtkName = ""; int temp; size_t n = options.size(); for (size_t i = 0; i < n; ++i) { const string& token = options[i]; if (v3StrNCmp("-Name", token, 2) == 0) { if (miterName) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else miterName = miterNameON = true; } else if (v3StrNCmp("-SEC", token, 4) == 0) { if (sec || cec) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else sec = true; } else if (v3StrNCmp("-CEC", token, 4) == 0) { if (sec || cec) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else cec = true; } else if (v3StrNCmp("-Merge", token, 2) == 0) { if (merge) return V3CmdExec::errorOption(CMD_OPT_EXTRA, token); else merge = true; } else if (miterNameON) { miterNameON = false; miterNtkName = token; } else if (V3NtkUD == id1) { if (!v3Str2Int(token, temp)) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, "(unsigned ntkId1)"); else if (temp < 0) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, "(unsigned ntkId1)"); id1 = (uint32_t)temp; } else if (V3NtkUD == id2) { if (!v3Str2Int(token, temp)) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, "(unsigned ntkId2)"); else if (temp < 0) return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, "(unsigned ntkId2)"); id2 = (uint32_t)temp; } else return V3CmdExec::errorOption(CMD_OPT_ILLEGAL, token); } if (V3NtkUD == id1) return V3CmdExec::errorOption(CMD_OPT_MISSING, "(unsigned ntkId1)"); if (V3NtkUD == id2) return V3CmdExec::errorOption(CMD_OPT_MISSING, "(unsigned ntkId2)"); if (miterNameON) return V3CmdExec::errorOption(CMD_OPT_MISSING, "(string miterNtkName)"); V3NtkHandler* const handler = v3Handler.getCurHandler(); if (handler) { if (id1 >= v3Handler.getHandlerCount()) Msg(MSG_ERR) << "Network with id = " << id1 << " Does NOT Exist !!" << endl; else if (id2 >= v3Handler.getHandlerCount()) Msg(MSG_ERR) << "Network with id = " << id2 << " Does NOT Exist !!" << endl; else { V3NtkHandler* const handler1 = v3Handler.getHandler(id1); assert (handler); V3NtkHandler* const handler2 = v3Handler.getHandler(id2); assert (handler); if (!(reportIncompatibleModule(handler1, handler2) || reportIncompatibleModule(handler1, handler2))) { if (!cec) { V3NtkMiter* const miterHandler = new V3NtkMiter(handler1, handler2, merge, miterNtkName); assert (miterHandler); v3Handler.pushAndSetCurHandler(miterHandler); } else { // Compute Name Mapping for Latches Between Two Networks if (handler1->getNtk()->getLatchSize() == handler2->getNtk()->getLatchSize()) { V3Map<string, uint32_t>::Map nameMap; nameMap.clear(); for (uint32_t i = 0; i < handler2->getNtk()->getLatchSize(); ++i) nameMap.insert(make_pair(handler2->getNetName(handler2->getNtk()->getLatch(i)), i)); if (handler2->getNtk()->getLatchSize() == nameMap.size()) { V3Map<string, uint32_t>::Map::const_iterator it; V3UI32Vec latchMap; latchMap.clear(); latchMap.reserve(handler1->getNtk()->getLatchSize()); for (uint32_t i = 0; i < nameMap.size(); ++i) { it = nameMap.find(handler1->getNetName(handler1->getNtk()->getLatch(i))); if ((nameMap.end() == it) || (handler1->getNtk()->getNetWidth(handler1->getNtk()->getLatch(i)) != handler2->getNtk()->getNetWidth(handler2->getNtk()->getLatch(it->second)))) break; else latchMap.push_back(it->second); } if (handler1->getNtk()->getLatchSize() == latchMap.size()) { V3NtkMiter* const miterHandler = new V3NtkMiter(handler1, handler2, latchMap, merge, miterNtkName); assert (miterHandler); v3Handler.pushAndSetCurHandler(miterHandler); } else Msg(MSG_ERR) << "Unmapped Latch " << latchMap.size() << " Found in Network " << id1 << " !!" << endl; } else Msg(MSG_ERR) << "Repeated or Missing Latch Names Exist !!" << endl; } else Msg(MSG_ERR) << "Number of Latches in Networks NOT Matched : " << id1 << "(" << handler1->getNtk()->getLatchSize() << ") != " << id2 << "(" << handler2->getNtk()->getLatchSize() << ") !!" << endl; } } } } else Msg(MSG_ERR) << "Empty Ntk !!" << endl; return CMD_EXEC_DONE; }