Module: ParseHelper
- Defined in:
- lib/ParseHelper.rb
Overview
This module defines a number of helper methods that assist the Parser class in completing its task.
Class Method Summary collapse
-
.get_port_names(str, insts) ⇒ Object
Takes a string (str) that defines a netlist and a hash of all existing Inst objects (insts) as input and produces an array of unique port names that are defined as connections in that netlist.
-
.member_inst_names(numports, instname) ⇒ Object
Takes an integer (numports) and the name of an Inst (instname) and returns an array of Inst names properly formatted to take into account the fact that the Inst has multiple bits.
-
.parens_check(str) ⇒ Object
Takes a string (str) as input and returns true if the given string has matching sets of parentheses, otherwise it returns false.
-
.portname_split(str) ⇒ Object
Takes a string of a portname (str) as input and returns an array where the first element is the name of the Inst object to which the port belongs, and the second element is the port it represents on the given Inst.
Class Method Details
.get_port_names(str, insts) ⇒ Object
Takes a string (str) that defines a netlist and a hash of all existing Inst objects (insts) as input and produces an array of unique port names that are defined as connections in that netlist.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ParseHelper.rb', line 26 def self.get_port_names(str,insts) a = [] i = 0 s="" # while we are not at the end of the line while i < str.length # append current character to a new string s << str[i].chr # if the parens match append it to an array if parens_check(s) a << self.parse_port_names(s,insts) s = "" end # keep checking i+=1 end # return the array (use uniq to get rid of duplicate bufz ports) a.uniq end |
.member_inst_names(numports, instname) ⇒ Object
Takes an integer (numports) and the name of an Inst (instname) and returns an array of Inst names properly formatted to take into account the fact that the Inst has multiple bits.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ParseHelper.rb', line 10 def self.member_inst_names(numports,instname) p = 0 a = [] # while we have not reached the number of ports while p < numports # add a port name to the array addstr = "#{instname}m#{p}" a << addstr p+=1 end # return the array a end |
.parens_check(str) ⇒ Object
Takes a string (str) as input and returns true if the given string has matching sets of parentheses, otherwise it returns false.
4 5 6 |
# File 'lib/ParseHelper.rb', line 4 def self.parens_check(str) str.count("(") == str.count(")") end |
.portname_split(str) ⇒ Object
Takes a string of a portname (str) as input and returns an array where the first element is the name of the Inst object to which the port belongs, and the second element is the port it represents on the given Inst.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ParseHelper.rb', line 48 def self.portname_split(str) a = [] if str =~ /(\w+)((p\d+\z|out\z))/ a[0] = $1 a[1] = $2 else raise "Invalid EDF" end a end |