Ophidian
 All Classes Namespaces Functions
verilog.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef OPHIDIAN_PARSING_VERILOG_H
22 #define OPHIDIAN_PARSING_VERILOG_H
23 
24 #include <string>
25 #include <vector>
26 #include <utility>
27 
28 namespace ophidian {
29 namespace parsing {
30 
31 class verilog
32 {
33 public:
34  struct module {
35  std::string type;
36  std::string name;
37  std::vector< std::pair<std::string, std::string> > pinnet_pairs;
38 
39  module(){
40  pinnet_pairs.reserve(5);
41  }
42 
43  bool operator==(const module & o) const {
44  bool result=pinnet_pairs.size()==o.pinnet_pairs.size();
45  if(!result) return false;
46  for(std::size_t i=0; i<pinnet_pairs.size();++i)
47  if(pinnet_pairs[i].first!=o.pinnet_pairs[i].first||pinnet_pairs[i].second!=o.pinnet_pairs[i].second)
48  return false;
49  return type==o.type&&name==o.name;
50  }
51  };
52 
53 private:
54  std::string m_design;
55  std::vector<std::string> m_inputs;
56  std::vector<std::string> m_outputs;
57  std::vector<std::string> m_wires;
58  std::vector<module> m_modules;
59 
60  std::size_t m_pin_count;
61  std::size_t m_net_count;
62 
63  std::vector<std::string> tokenize(std::string line);
64 
65  bool read_line_as_tokens(std::istream &in, std::vector<std::string> & tokens);
66  bool read_module(std::istream & in, std::string & token);
67  bool read_primary_input(std::istream & in, std::string & token);
68  bool read_primary_output(std::istream & in, std::string & token);
69  bool read_cell_inst(std::istream & in, std::string &cell_type, std::string &cell_inst, std::vector<std::pair<std::string, std::string> > &pin_net_pairs);
70 
71 
72  bool read_wire(std::istream & in, std::string & token);
73 
74  void read(const std::string & filename);
75 
76 
77 public:
78  verilog(const std::string & filename);
79  virtual ~verilog();
80 
81  const std::string & design() const {
82  return m_design;
83  }
84 
85  const std::vector<std::string> & inputs() const {
86  return m_inputs;
87  }
88 
89  const std::vector<std::string> & outputs() const {
90  return m_outputs;
91  }
92 
93  const std::vector<std::string> & wires() const {
94  return m_wires;
95  }
96 
97  const std::vector<module> & modules() const {
98  return m_modules;
99  }
100 
101  std::size_t cell_count() const {
102  return m_modules.size();
103  }
104 
105  std::size_t net_count() const {
106  return m_net_count;
107  }
108 
109  std::size_t pin_count() const {
110  return m_pin_count;
111  }
112 
113 };
114 
115 }
116 }
117 
118 #endif // OPHIDIAN_PARSING_VERILOG_H
Definition: verilog.h:34
Definition: verilog.h:31