1 /*
2 * Copyright (c) 2019, The Regents of the University of California
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <functional>
29 #include <string>
30
31 #include "boostParser.h"
32 #include "db.h"
33 #include "lefLayerPropParser.h"
34 #include "lefin.h"
35
36 namespace odb {
37
lefTechLayerEolExtensionRuleParser(lefin * l)38 lefTechLayerEolExtensionRuleParser::lefTechLayerEolExtensionRuleParser(lefin* l)
39 {
40 lefin_ = l;
41 }
42
parse(std::string s,odb::dbTechLayer * layer)43 void lefTechLayerEolExtensionRuleParser::parse(std::string s,
44 odb::dbTechLayer* layer)
45 {
46 std::vector<std::string> rules;
47 boost::split(rules, s, boost::is_any_of(";"));
48 for (auto rule : rules) {
49 boost::algorithm::trim(rule);
50 if (rule.empty())
51 continue;
52 rule += " ; ";
53 if (!parseSubRule(rule, layer))
54 lefin_->warning(260,
55 "parse mismatch in layer propery "
56 "LEF58_EOLEXTENSIONSPACING for layer {} :\"{}\"",
57 layer->getName(),
58 rule);
59 }
60 }
61
setInt(double val,odb::dbTechLayerEolExtensionRule * rule,void (odb::dbTechLayerEolExtensionRule::* func)(int))62 void lefTechLayerEolExtensionRuleParser::setInt(
63 double val,
64 odb::dbTechLayerEolExtensionRule* rule,
65 void (odb::dbTechLayerEolExtensionRule::*func)(int))
66 {
67 (rule->*func)(lefin_->dbdist(val));
68 }
addEntry(boost::fusion::vector<double,double> & params,odb::dbTechLayerEolExtensionRule * rule)69 void lefTechLayerEolExtensionRuleParser::addEntry(
70 boost::fusion::vector<double, double>& params,
71 odb::dbTechLayerEolExtensionRule* rule)
72 {
73 double eol = at_c<0>(params);
74 double ext = at_c<1>(params);
75 rule->addEntry(lefin_->dbdist(eol), lefin_->dbdist(ext));
76 }
parseSubRule(std::string s,odb::dbTechLayer * layer)77 bool lefTechLayerEolExtensionRuleParser::parseSubRule(std::string s,
78 odb::dbTechLayer* layer)
79 {
80 odb::dbTechLayerEolExtensionRule* rule
81 = odb::dbTechLayerEolExtensionRule::create(layer);
82
83 qi::rule<std::string::iterator, space_type> EXTENSION_ENTRY
84 = (lit("ENDOFLINE") >> double_ >> lit("EXTENSION")
85 >> double_)[boost::bind(
86 &lefTechLayerEolExtensionRuleParser::addEntry, this, _1, rule)];
87
88 qi::rule<std::string::iterator, space_type> EOLEXTENSIONSPACING
89 = (lit("EOLEXTENSIONSPACING")
90 >> double_[boost::bind(&lefTechLayerEolExtensionRuleParser::setInt,
91 this,
92 _1,
93 rule,
94 &odb::dbTechLayerEolExtensionRule::setSpacing)]
95 >> -lit("PARALLELONLY")[boost::bind(
96 &odb::dbTechLayerEolExtensionRule::setParallelOnly, rule, true)]
97 >> +EXTENSION_ENTRY >> lit(";"));
98 auto first = s.begin();
99 auto last = s.end();
100 bool valid = qi::phrase_parse(first, last, EOLEXTENSIONSPACING, space)
101 && first == last;
102 if (!valid)
103 odb::dbTechLayerEolExtensionRule::destroy(rule);
104 return valid;
105 }
106
107 } // namespace odb
108