Class: SOCMaker::VHDLParser
- Includes:
- ERR, Singleton
- Defined in:
- lib/soc_maker/hdl_parser.rb
Instance Method Summary collapse
- #extract_length(content) ⇒ Object
-
#initialize ⇒ VHDLParser
constructor
A new instance of VHDLParser.
- #parse_package(data) ⇒ Object
- #parse_toplevel(data) ⇒ Object
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
#initialize ⇒ VHDLParser
Returns a new instance of VHDLParser.
293 294 295 |
# File 'lib/soc_maker/hdl_parser.rb', line 293 def initialize end |
Instance Method Details
#extract_length(content) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# 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) ⇒ Object
416 417 418 419 420 421 422 |
# 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) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# 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 |