Class: SOCMaker::HDLParser

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

Direct Known Subclasses

VHDLParser, VerilogParser

Instance Method Summary collapse

Methods included from ERR

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

Constructor Details

#initializeHDLParser

Returns a new instance of HDLParser.



57
58
59
# File 'lib/soc_maker/hdl_parser.rb', line 57

def initialize

end

Instance Method Details

#get_all_hdl_files(files) ⇒ Object



71
72
73
74
75
# File 'lib/soc_maker/hdl_parser.rb', line 71

def get_all_hdl_files( files )
  hdl_files = []
  files.each { |f|   hdl_files += Dir[f] }
  return hdl_files
end

#get_content(file) ⇒ Object



62
63
64
# File 'lib/soc_maker/hdl_parser.rb', line 62

def get_content( file )
  return File.open( file, "r"){ |f| f.read }
end

#get_extension(file) ⇒ Object



67
68
69
# File 'lib/soc_maker/hdl_parser.rb', line 67

def get_extension( file )
  return File.extname( file )
end

#parse_core(top_file, files, package_file = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/soc_maker/hdl_parser.rb', line 80

def parse_core( top_file, files, package_file = nil )

  files = [ files ] if not files.kind_of?( Array )

  #
  # read and parse toplevel file
  #
  content = get_content( top_file )
  if get_extension( top_file ) == ".v" 
    toplevel = VerilogParser.instance.parse_toplevel( content )
    toplevel = VerilogParser.instance.extract_length( toplevel )
  elsif get_extension( top_file ) == ".vhd"
    toplevel = VHDLParser.instance.parse_toplevel( content )
    toplevel = VHDLParser.instance.extract_length( toplevel )
  end

  #
  # read and parse package file
  #
  #   -> not yet supported
  # 
  if package_file != nil
    content = get_content( package_file )
    if get_extension( package_file ) == ".v"
      package = VerilogParser.instance.parse_package( content )
    elsif get_extension( top_file ) == ".vhd"
      package = VerilogParser.instance.parse_package( content )
    end
  else
    package = {}
  end


  #
  # get all HDL files
  #
  hdl_files = get_all_hdl_files( files )



  #
  # Prepare options and ports hashes
  #
  options = { 'inst_parameters' => {},
              'hdlfiles'        => {},
              'interfaces'      => {} }

  if toplevel.has_key?( :generic )
    toplevel[ :generic ].values.each do | v |
      options[ 'inst_parameters' ][ v[:name] ] = Parameter.new( v[ :type ], default: v[ :default ] )
    end
  end

  ports = {}
  if toplevel.has_key?( :port )
    toplevel[ :port ].values.each do | v |
      ports[ v[ :name ] ] = IfcPort.new( v[:name], v[:length]  )
    end
  end

  ifc_name = toplevel[:name].to_s + '_ifc'
  ifc_id   = ifc_name + ",v1"
  options[ 'interfaces'][ ifc_name ] = IfcDef.new( ifc_name, ifc_id, 0, ports )

  hdl_files.each do | f |
    f_opts = {}
    name = Pathname.new( f ).basename( ".*" ).to_s
    if name.include? "sim"
      f_opts[ 'use_syn'     => false ]
      f_opts[ 'use_mod_sim' => true  ]
    else
      f_opts[ 'use_syn'     => true  ]
      f_opts[ 'use_mod_sim' => false ]
    end
    options[ 'hdlfiles' ][ name ] = HDLFile.new( f, f_opts )
  end

  #
  # create new core
  #
  d = CoreDef.new( toplevel[ :name ], 
                   toplevel[ :name ]+",v1",
                   toplevel[ :name ], options)



  # dump the result
  return SOCMaker::to_yaml_s( d )

end