1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 //   list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 //   this list of conditions and the following disclaimer in the documentation
15 //   and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 //   contributors may be used to endorse or promote products derived from
19 //   this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #pragma once
34 
35 #include <list>
36 #include <map>
37 #include <string>
38 
39 #include "db.h"
40 #include "dbMap.h"
41 #include "defout.h"
42 #include "odb.h"
43 namespace utl {
44 class Logger;
45 }
46 
47 namespace odb {
48 
49 class dbBlock;
50 class dbBTerm;
51 class dbInst;
52 class dbTechNonDefaultRule;
53 class dbTechLayerRule;
54 
55 class defout_impl
56 {
57   enum ObjType
58   {
59     COMPONENT,
60     COMPONENTPIN,
61     DESIGN,
62     GROUP,
63     NET,
64     NONDEFAULTRULE,
65     REGION,
66     ROW,
67     SPECIALNET
68   };
69 
70   double _dist_factor;
71   FILE* _out;
72   bool _use_net_inst_ids;
73   bool _use_master_ids;
74   bool _use_alias;
75   std::list<dbNet*> _select_net_list;
76   std::list<dbInst*> _select_inst_list;
77   dbMap<dbNet, char>* _select_net_map;
78   dbMap<dbInst, char>* _select_inst_map;
79   dbTechNonDefaultRule* _non_default_rule;
80   int _version;
81   std::map<std::string, bool> _prop_defs[9];
82   utl::Logger* _logger;
83 
defdist(int value)84   int defdist(int value) { return (int) (((double) value) * _dist_factor); }
85 
defdist(uint value)86   int defdist(uint value) { return (uint) (((double) value) * _dist_factor); }
87 
88   void writePropertyDefinitions(dbBlock* block);
89   void writeRows(dbBlock* block);
90   void writeTracks(dbBlock* block);
91   void writeGCells(dbBlock* block);
92   void writeVias(dbBlock* block);
93   void writeVia(dbVia* via);
94   void writeInsts(dbBlock* block);
95   void writeNonDefaultRules(dbBlock* block);
96   void writeNonDefaultRule(dbTechNonDefaultRule* rule);
97   void writeLayerRule(dbTechLayerRule* rule);
98   void writeInst(dbInst* inst);
99   void writeBTerms(dbBlock* block);
100   void writeBTerm(dbBTerm* bterm);
101   void writeBPin(dbBPin* bpin, int n);
102   void writeRegions(dbBlock* block);
103   void writeGroups(dbBlock* block);
104   void writeBlockages(dbBlock* block);
105   void writeFills(dbBlock* block);
106   void writeNets(dbBlock* block);
107   void writeNet(dbNet* net);
108   void writeSNet(dbNet* net);
109   void writeWire(dbWire* wire);
110   void writeSWire(dbSWire* wire);
111   void writeSpecialPath(dbSBox* box);
112   void writePropValue(dbProperty* prop);
113   void writeProperties(dbObject* object);
114   void writePinProperties(dbBlock* block);
115   bool hasProperties(dbObject* object, ObjType type);
116 
117  public:
defout_impl(utl::Logger * logger)118   defout_impl(utl::Logger* logger)
119   {
120     _use_net_inst_ids = false;
121     _use_master_ids = false;
122     _use_alias = false;
123     _select_net_map = NULL;
124     _select_inst_map = NULL;
125     _version = defout::DEF_5_8;
126     _logger = logger;
127   }
128 
~defout_impl()129   ~defout_impl() {}
130 
setUseLayerAlias(bool value)131   void setUseLayerAlias(bool value) { _use_alias = value; }
132 
setUseNetInstIds(bool value)133   void setUseNetInstIds(bool value) { _use_net_inst_ids = value; }
134 
setUseMasterIds(bool value)135   void setUseMasterIds(bool value) { _use_master_ids = value; }
136 
137   void selectNet(dbNet* net);
138 
139   void selectInst(dbInst* inst);
setVersion(int v)140   void setVersion(int v) { _version = v; }
141 
142   bool writeBlock(dbBlock* block, const char* def_file);
143 };
144 
145 }  // namespace odb
146