📄 oaverilogoutoptionstest.cpp
字号:
// *****************************************************************************// *****************************************************************************// oaVerilogOutOptionsTest.cpp//// This file contains the implementation of the oaVerilogOutOptionsTest class.//// *****************************************************************************// Except as specified in the OpenAccess terms of use of Cadence or Silicon// Integration Initiative, this material may not be copied, modified,// re-published, uploaded, executed, or istributed in any way, in any medium,// in whole or in part, without prior written permission from Cadence.//// Copyright 2003-2005 Cadence Design Systems, Inc.// All Rights Reserved.//// $Author: shaun $// $Revision: 1.22 $// $Date: 2005/07/09 17:35:33 $// $State: Exp $// *****************************************************************************// *****************************************************************************#include "oaVerilogOutTest.h"// *****************************************************************************// moduleWriter// *****************************************************************************class moduleWriter : public CallbacksOut { public: moduleWriter(OptionsOut &optIn); virtual void writeCell(oaModule &cell); static const oaString myVersion;};// *****************************************************************************// Initialize Static Data Members// *****************************************************************************const oaString moduleWriter::myVersion("custom");// *****************************************************************************// moduleWriter:: moduleWriter()//// This is the constructor for the moduleWriter class. The moduleWriter class// is a "user" defined callbacks class that slightly modifies the behavior // of the default callbacks.// ***************************************************************************** moduleWriter:: moduleWriter(OptionsOut &optIn): CallbacksOut(optIn, &myVersion){ setIndentShift(16);}// *****************************************************************************// moduleWriter::writeCell()//// This is the method produces the contents of the given module as a Verilog // netlist. This implementation writes a comment header before the module // definiton.// *****************************************************************************void moduleWriter::writeCell(oaModule &cell){ oaDesign *design = cell.getDesign(); oaString libName; oaString cellName; oaString viewName; design->getLibName(verNS, libName); design->getCellName(verNS, cellName); design->getViewName(verNS, viewName); oaScalarName moduleName; oaString moduleNameStr; cell.getName(moduleName); moduleName.get(verNS, moduleNameStr); write("\n"); write("%s **************************************************************\n", (const char*) commentPrefix); write("%s Module %s of %s.%s.%s\n", (const char*) commentPrefix, (const char*) moduleNameStr, (const char*) libName, (const char*) cellName, (const char*) viewName); write("%s **************************************************************", (const char*) commentPrefix); CallbacksOut::writeCell(cell);}// *****************************************************************************// leafWriter// *****************************************************************************class leafWriter : public moduleWriter { public: leafWriter(OptionsOut &optIn); virtual void writeHeader(oaModule &cell);};// *****************************************************************************// leafWriter:: leafWriter()//// This is the constructor for the leafWriter class. The leafWriter class// is a "user" defined callbacks class that slightly modifies the behavior // of the default callbacks.// ***************************************************************************** leafWriter:: leafWriter(OptionsOut &optIn): moduleWriter(optIn){}// *****************************************************************************// leafWriter:: writeHeader()//// This method produces the file header for the output file. In this// customization the header will identify the file as containing leaf cells.// *****************************************************************************void leafWriter:: writeHeader(oaModule &cell){ oaString libName; oaString cellName; oaString viewName; cell.getDesign()->getLibName(nameSpace, libName); cell.getDesign()->getCellName(nameSpace, cellName); cell.getDesign()->getViewName(nameSpace, viewName); write("%s This file contains the %s leaf cells for %s.%s.%s\n", getCommentPrefix(), getLanguageName(), (const char*) libName, (const char*) cellName, (const char*) viewName, getCommentSuffix()); write("%s Language Version: %s %s\n", getCommentPrefix(), getLanguageVersion(), getCommentSuffix());}// *****************************************************************************// oaVerilogOutOptionsTest::oaVerilogOutOptionsTest()//// This is the constructor for the oaVerilogOutOptionsTest class.// *****************************************************************************oaVerilogOutOptionsTest::oaVerilogOutOptionsTest(const oaString &name): oaVerilogOutTest(name){}// *****************************************************************************// oaVerilogOutOptionsTest::buildLeafLib()//// This function builds a library of leaf cells for Verilog files to reference.// It must be called after the database is initialized but before the first// Verilog file is read. The library will be created in the current working// directory. // *****************************************************************************voidoaVerilogOutOptionsTest::buildLeafLib(const oaString libPath, const oaString cellNameStr, const oaString viewNameStr){ oaScalarName leafLibName(ns, libPath); oaScalarName leafCellName(ns, cellNameStr); oaScalarName leafViewName(ns, viewNameStr); oaLib *lib = oaLib::find(leafLibName); if (!lib) { if (oaLib::exists(libPath)) { lib = oaLib::open(leafLibName, libPath); } else { lib = oaLib::create(leafLibName, libPath); } } if (oaDesign::find(leafLibName, leafCellName, leafViewName)) { return; } oaDesign *design = oaDesign::open(leafLibName, leafCellName, leafViewName, oaViewType::get(oacNetlist), 'w'); oaModule *module = oaModule::create(design, leafCellName); design->setTopModule(module); oaScalarName in(ns, "in"); oaModNet *net = oaModNet::create(module, in); oaModTerm *term = oaModTerm::create(net, in, oacInputTermType); term->setPosition(0); oaScalarName out(ns, "out"); net = oaModNet::create(module, out); term = oaModTerm::create(net, out, oacOutputTermType); term->setPosition(1); design->save();}// *****************************************************************************// oaVerilogOutOptionsTest::test()//// This method is the main entry point for the test.// *****************************************************************************oaBooleanoaVerilogOutOptionsTest::test(){ preTest(); openOutputFile(); oaString testcase = getPathToData() + ds + getName() + ".v"; oaString myLibName = getName() + "Lib"; MsgAdapter msgs; openLib(myLibName); try { buildLeafLib("leafLib", "leaf1", "abstract"); buildLeafLib("leafLib", "leaf2", "abstract"); msgs.setOutFile(NULL); VerilogIn reader(msgs); OptionsIn &readerOptions = reader.getOptions(); readerOptions.setLibName(myLibName); readerOptions.enableTolerate(); readerOptions.enableFileAndLine(true); readerOptions.addFile(testcase); readerOptions.addLeafLib("leafLib"); reader.parse(); } catch(Error &verr) { tout.print(verr.getMsg()); closeOutputFile(); throw; } catch(oaException &oaErr) { tout.print((const char*) oaErr.getMsg()); closeOutputFile(); throw; } catch(...) { tout.print("Caught an exception that was not handled by the reader.\n"); closeOutputFile(); throw; } const oaString outFile("temp.v"); const oaString leafFile("tmpLeaf.v"); try { VerilogOut writer(msgs); OptionsOut &writerOptions = writer.getOptions(); moduleWriter moduleCallbacks(writerOptions); leafWriter leafCallbacks(writerOptions); writerOptions.setFileName(outFile); writerOptions.setLeafFile(leafFile); writerOptions.setLibName(myLibName); writerOptions.setCellName("top"); writerOptions.setViewName("netlist"); writerOptions.enableRecursive(true); writerOptions.enableProduceLeaf(); writerOptions.enablePreserveInterface(); writer.setLeafCallbacks(&leafCallbacks); writer.setModuleCallbacks(&moduleCallbacks); writer.write(); } catch(Error &verr) { tout.print(verr.getMsg()); closeOutputFile(); throw; } catch(oaException &oaErr) { tout.print((const char*) oaErr.getMsg()); closeOutputFile(); throw; } catch(...) { tout.print("Caught an exception that was not handled by the writer.\n"); closeOutputFile(); throw; } FILE *moduleFP = fopen((const char*) outFile, "r"); if (moduleFP) { char buf[128]; while (fgets(buf, 127, moduleFP)) { tout.printLine(buf); } fclose(moduleFP); } else { tout.printLine("Unable to open test.v output file\n"); } FILE *leafFP = fopen((const char*) leafFile, "r"); if (leafFP) { char buf[128]; while (fgets(buf, 127, leafFP)) { tout.printLine(buf); } fclose(leafFP); } else { tout.printLine("Unable to open tmpLeaf.v output file\n"); } closeOutputFile(); cleanup(myLibName); cleanup("leafLib"); return compareOutputByName(getName());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -