OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [core_def.rb] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      core_def.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#
37
########
38
module SOCMaker
39 9 feddischso
 
40
 
41
#########
42
#
43
# This class represents a core definition.
44
# It is one of the central classes and holds data,
45
# which is used to describe and instanciate this core.
46
# In general, instances of this class desribe a core,
47
# it's interface and parameters as well as the files,
48
# which are required for synthesis/simulation.
49
#
50
# In addition to this core, there exist SOCMaker::CoreInst,
51
# which represents a concret instanciation of a definition.
52
#
53 3 feddischso
class CoreDef  < Component
54
  include ERR
55
  include YAML_EXT
56
 
57
  attr_accessor :hdlfiles
58 9 feddischso
 
59
 
60 10 feddischso
  #
61
  # Constructor
62
  # The four attributes are required, and all other attributes
63
  # can be given as a optinal hash
64
  #
65
  # *name*:: Name of this component
66
  # *id*:: Id of this component
67
  # *hdl_files*:: Hash of HDL files
68
  # *toplevel*:: Toplevel name
69
  # *optional*:: Non-mandatory values, which can be set during initialization.
70
  #
71
  #
72
  def initialize( name, id, hdl_files, toplevel, optional = {} )
73 3 feddischso
    init_with( { 'name'      => name,
74 10 feddischso
                 'id'        => id,
75 3 feddischso
                 'hdlfiles'  => hdl_files,
76 9 feddischso
                 'toplevel'  => toplevel }.merge( optional ) )
77 3 feddischso
  end
78 10 feddischso
 
79
  #
80
  # Encoder function (to yaml)
81
  #
82
  # +coder+:: An instance of the Psych::Coder to encode this class to a YAML file
83
  #
84 3 feddischso
  def encode_with( coder )
85
    super coder
86
    coder[ 'hdlfiles' ] = @hdlfiles
87
  end
88 10 feddischso
 
89
  #
90
  # Initialization function (from yaml)
91
  #
92
  # +coder+:: An instance of the Psych::Coder to init this class from a YAML file
93
  #
94
  #
95 3 feddischso
  def init_with( coder )
96
    super( coder )
97
 
98 8 feddischso
    @hdlfiles = coder[ 'hdlfiles' ] || {}
99 3 feddischso
    serr_if( !@hdlfiles.is_a?( Hash ),
100
      'HDL file def. != Hash',
101
      instance: @name,
102
      field:    'hdlfiles' )
103
 
104
    @hdlfiles.each do |file_name, defn |
105
      serr_if( defn == nil,
106
            'HDL file not defined',
107
            instance:   @name+":"+file_name.to_s )
108
 
109
      serr_if( !defn.is_a?( SOCMaker::HDLFile ),
110
            'HDL file not SOCMaker::HDLFile (use SOCM_HDL_FILE)',
111
            instance: @name+":"+file_name.to_s )
112
    end
113
 
114
  end
115
 
116
 
117
 
118 10 feddischso
  #
119
  # Loop over all generic values of the core
120
  # and yield the block with the
121
  # - generic name
122
  # - generic type
123
  # - the default value
124
  # - is-last value
125
  #
126
  #
127 3 feddischso
  def generics
128
    @inst_parameters.each_with_index do |(name, val), i|
129
      yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
130
    end
131
  end
132
 
133
 
134 10 feddischso
  #
135 6 feddischso
  # this is a core_def and doesn't have
136
  # sub-cores
137
  def get_core_def( inst )
138 10 feddischso
    perr_if( nil, "We don't have sub-cores" )
139 6 feddischso
    return nil
140
  end
141 3 feddischso
 
142 10 feddischso
 
143
  #
144
  # Nothing implemented, yet.
145
  #
146 7 feddischso
  def consistency_check
147 8 feddischso
    super
148 7 feddischso
  end
149 6 feddischso
 
150 7 feddischso
 
151 10 feddischso
  #
152
  # Equality operator
153
  #
154 3 feddischso
  def ==(o)
155
    o.class         == self.class       &&
156
    o.hdlfiles      == self.hdlfiles    &&
157
    super( o )
158
  end
159
 
160 10 feddischso
  #
161
  # Returns a string describing this instance
162
  #
163
  def to_s
164
    super
165
  end
166 3 feddischso
 
167 10 feddischso
 
168 3 feddischso
end # class CoreDef
169
end # module SOCMaker
170
 
171
 
172
# vim: noai:ts=2:sw=2

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.