class SOCMaker::VHDLParser
Public Class Methods
new()
click to toggle source
# File lib/soc_maker/hdl_parser.rb, line 293 def initialize end
Public Instance Methods
extract_length( content )
click to toggle source
# File lib/soc_maker/hdl_parser.rb, line 381 def extract_length( content ) content[ :port ].values.each do |v| v[:length ] = 'UNKNOWN' if v[:range] numeric_regex = /^\s*([0-9+\-\s]+)(to|downto+)([0-9+\-\s]+)/i parameter_regex = /^\s*(\D[\D\d]+)\s*-\s*1\s*(to|downto+)\s+0/i if m = numeric_regex.match( v[:range] ) if( m[2].downcase == "downto") tmp = "(" + m[1] + ") - ( " + m[3] + ") + 1" else tmp = "(" + m[3] + ") - ( " + m[1] + ") + 1" end begin v[ :length ] = eval( tmp ) rescue Exception v[:length] = 'UNKNOWN' end elsif m = parameter_regex.match( v[ :range ] ) v[:length] = m[1] end else v[ :length ] = 1 end end return content end
parse_package( data )
click to toggle source
# File lib/soc_maker/hdl_parser.rb, line 416 def parse_package( data ) result = {} #const_regex = /^\s*constant\s*(\S+)\s*:\s*(\w+)\s*(\(.*?\))?\s*:\s*=\s*"?([\d\w]+)"?/i #data.split("\n").each do |line| #end return result end
parse_toplevel( data )
click to toggle source
# File lib/soc_maker/hdl_parser.rb, line 299 def parse_toplevel( data ) # remove all newlines data = data.gsub( "\n", " " ) # empty result hash result = {} # thee expressions to parse the entity header entity_regex = / entity\s+(\S+)\s+is\s+ # entity <name> is (generic\s*\(\s*(.*?)\s*\)\s*;)?\s* # generic ( <generic-infos> ) ; --> optional (port\s*\(\s*(.*?)\s*\)\s*;)?\s* # port ( <port-info> ) ; --> optional end\s*(entity)?\s*(\S*)\s*; # end <entity-name --> optional> ; /x generic_regex = /\s*(\S+)\s*:\s*(\w+)\s*(\((.*?)\))?\s*(:\s*=\s([\d\w]+))?/ port_regex = /\s*(\S+)\s*:\s*(in|out)?\s*(\w+)\s*(\((.*?)\))?\s*/ # match the whole entity header, # -> extract name # -> extract generics # -> extract ports if m = entity_regex.match( data ) result[ :name ] = m[1] # if there are generics: # -> process each if m[3] result[ :generic ] = {} m[3].split(";").each do |x| if match = generic_regex.match( x ) result[ :generic ][ match[1] ] = { type: match[2], name: match[1] } if( match[3]) result[ :generic ][ match[1] ][ :range ] = match[4] end if( match[5]) result[ :generic ][ match[1] ][ :default ] = match[6] end end end end # if there are ports # -> process each # if m[5] result[ :port ] = {} m[5].split(";").each do |x| if port_match = port_regex.match( x ) result[ :port ][ port_match[ 1 ] ] = { name: port_match[1], type: port_match[3] } if( port_match[2]) result[ :port ][ port_match[1] ][ :direction] = port_match[2] else result[ :port ][ port_match[1] ][ :direction] = "in" end if( port_match[ 4 ]) result[ :port ][ port_match[1] ][ :range] = port_match[5] end end end end end return result; end