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

Subversion Repositories soc_maker

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      if_spec.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
#
39
#
40
###############################################################
41
module SOCMaker
42
class IfcSpc
43
  include ERR
44
  include YAML_EXT
45
 
46
  attr_accessor :name
47 10 feddischso
  attr_accessor :id
48 3 feddischso
  attr_accessor :ports
49
 
50 10 feddischso
  def initialize( name, id, optional = {} )
51 3 feddischso
    init_with( { 'name' => name,
52 10 feddischso
                 'id' => id }.merge( optional ) )
53 3 feddischso
  end
54
  def encode_with( coder )
55 10 feddischso
    %w[ name id ports ].
56 3 feddischso
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
57
  end
58
  def init_with( coder )
59
 
60
    verr_if( coder[ 'name' ] == nil,
61
      "Name is not defined",
62
      field: "name" )
63
    @name = coder[ 'name' ]
64
    verr_if( !@name.is_a?( String ),
65
        "Name is not defined as string",
66
        field: "name" )
67
    verr_if( @name.size == 0,
68
        "Name has zero length",
69
        field: "name" )
70
 
71
 
72 10 feddischso
    verr_if( coder[ 'id' ] == nil,
73
      "Id is not defined",
74
      field: "id" )
75
    @id = coder[ 'id' ]
76
    verr_if( !@id.is_a?( String ),
77 3 feddischso
        "Version is not defined as string",
78
      instance: @name,
79 10 feddischso
      field:    "id" )
80
    verr_if( @id.size == 0,
81 3 feddischso
        "Version has zero length",
82
        field: "name" )
83
 
84
    @ports = coder[ 'ports' ] || {}
85 8 feddischso
    @ports.each do |pname, port|
86
 
87
      verr_if( !port.is_a?( Hash ),
88
        "Port field must be organized as a hash",
89
          instance: @name,
90
          field: "ports" )
91
 
92
      verr_if( !port.has_key?( :dir ),
93
          "No port direction specified for #{pname}",
94 3 feddischso
        instance: @name,
95 8 feddischso
        field: "ports" )
96
 
97
      verr_if( !port[ :dir ].is_a?( Fixnum ) ||
98
              ( port[ :dir ] != 0 && port[ :dir ] != 1 ),
99
               "Port direction value for #{pname} is neither 0 nor 1",
100
               instance: @name,
101
               field:    "ports" )
102
 
103
      port[ :mandatory ] = true if !port.has_key?( :mandatory )
104
      port[ :default ]   ||= '0'
105
 
106 3 feddischso
    end
107
 
108
  end
109
 
110
 
111
end
112
end
113
 
114
 
115
# 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.