1 ///////////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (c) 2019, The Regents of the University of California 4 // All rights reserved. 5 // 6 // BSD 3-Clause License 7 // 8 // Redistribution and use in source and binary forms, with or without 9 // modification, are permitted provided that the following conditions are met: 10 // 11 // * Redistributions of source code must retain the above copyright notice, this 12 // list of conditions and the following disclaimer. 13 // 14 // * Redistributions in binary form must reproduce the above copyright notice, 15 // this list of conditions and the following disclaimer in the documentation 16 // and/or other materials provided with the distribution. 17 // 18 // * Neither the name of the copyright holder nor the names of its 19 // contributors may be used to endorse or promote products derived from 20 // this software without specific prior written permission. 21 // 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 // POSSIBILITY OF SUCH DAMAGE. 33 // 34 /////////////////////////////////////////////////////////////////////////////// 35 36 #pragma once 37 38 #include <string> 39 #include <tuple> 40 #include <vector> 41 42 namespace utl { 43 class Logger; 44 } 45 46 namespace rmp { 47 48 enum class GateType 49 { 50 None, 51 Mlatch, 52 Gate 53 }; 54 55 struct Gate 56 { 57 GateType type_; 58 std::string master_; 59 std::vector<std::string> connections_; GateGate60 Gate(const GateType& type, 61 const std::string& master, 62 const std::vector<std::string>& connections) 63 : type_(type), master_(master), connections_(connections) 64 { 65 } 66 }; 67 68 class BlifParser 69 { 70 public: 71 BlifParser(); 72 bool parse(std::string& file_contents); 73 void addInput(const std::string& input); 74 void addOutput(const std::string& output); 75 void addClock(const std::string& clock); 76 void addNewInstanceType(const std::string& type); 77 void addNewGate(const std::string& cell_name); 78 void addConnection(const std::string& connection); 79 void endParser(); 80 81 const std::vector<std::string>& getInputs() const; 82 const std::vector<std::string>& getOutputs() const; 83 const std::vector<std::string>& getClocks() const; 84 const std::vector<Gate>& getGates() const; 85 int getCombGateCount() const; 86 int getFlopCount() const; 87 88 private: 89 std::vector<std::string> inputs_; 90 std::vector<std::string> outputs_; 91 std::vector<std::string> clocks_; 92 std::vector<Gate> gates_; 93 std::string currentGate_; 94 GateType currentInstanceType_; 95 std::vector<std::string> currentConnections_; 96 int combCount_; 97 int flopCount_; 98 }; 99 100 } // namespace rmp 101