Class: SOCMaker::VerilogParser

Inherits:
HDLParser show all
Includes:
ERR, Singleton
Defined in:
lib/soc_maker/hdl_parser.rb

Instance Method Summary collapse

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Methods inherited from HDLParser

#get_all_hdl_files, #get_content, #get_extension, #parse_core

Constructor Details

#initializeVerilogParser

Returns a new instance of VerilogParser.



184
185
186
# File 'lib/soc_maker/hdl_parser.rb', line 184

def initialize

end

Instance Method Details

#extract_length(content) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/soc_maker/hdl_parser.rb', line 247

def extract_length( content )

  numeric_regex   = /^\s*([0-9+\-\s]+):([0-9+\-\s]+)/
  parameter_regex = /^\s*(\D[\D\d]+)\s*-\s*1\s*:\s*0/


  content[ :port ].values.each do |port|
    if port[ :range ]
      if m = numeric_regex.match( port[ :range ] )
        tmp = " ( #{ m[1] } ) - ( #{ m[ 2 ] }  ) + 1 "
        begin
          port[ :length ] =  eval( tmp )
        rescue Exception
          port[:length] = 'UNKNOWN'
        end

      elsif m = parameter_regex.match( port[ :range ] )
          port[:length] = m[1]
      end
    else
      port[ :length ] = 1
    end
  end
  return content
end

#parse_package(data) ⇒ Object



273
274
275
276
277
278
# File 'lib/soc_maker/hdl_parser.rb', line 273

def parse_package( data )
  result = {}
 #data.split("\n").each do |line|
 #end
  return result
end

#parse_toplevel(data) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/soc_maker/hdl_parser.rb', line 188

def parse_toplevel( data )
  # remove all newlines
  data = data.gsub( "\n", " " )

  # empty result hash
  result = {}

  module_regex    = /\s*module\s+(\w+)*\s*\(.*?\);/
  port_regex      = /(input|output)\s*(\[([\d\w\-\:\s]*)\s*\])?\s*(\w*);/
  parameter_regex = /parameter\s*(\w*)\s*=\s(.*?);/


  # extract module name
  if m = module_regex.match( data )
    result[ :name ] = m[1]
  else
    result[ :name ] = "unknown"
  end

  #
  # extract parameteters
  #
  parameters = data.scan( parameter_regex )
  result[ :generic ] = {}
  parameters.each do |port|

    result[ :generic ][ port[0] ] = { name: port[0], default: port[1], type: "integer" }

  end

  #
  # extract ports
  #
  ports = data.scan( port_regex )
  result[ :port ] = {}
  ports.each do |port|
    result[ :port ][ port[3] ] = { name: port[3] }


    if port[0] 
      if port[0] == "input"
        result[ :port ][ port[3] ][ :dir ] = "in"
      elsif port[0] == "output"
        result[ :port ][ port[3] ][ :dir ] = "out"
      else
        result[ :port ][ port[3] ][ :dir ] = "in"
      end
    end


    if port[ 2 ]
      result[ :port ][ port[ 3 ] ][ :range ] = port[ 2 ]
    end

  end

  return result
end