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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [hdl_file.rb] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      hdl_file.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
#     A small classes, used to group information
39
#     and to verify, auto-correct and auto-complete
40
#     this information:
41
#     The class represents an high-level-description (HDL) file.
42
#     The two supported file-types are *.vhdl and *.v, whose information
43
#     is stored in @type ('verilog' or 'vhdl').
44
#     A @path is mandatory and defines, where the file is located.
45
#     In addition, is is used for auto-detecting the file-type (if not given).
46
#     There are three flags:
47
#           - use_syn      (use in synthesis)
48
#           - use_sys_sim  (use in system simulation)
49
#           - use_mod_sim  (use in module simulation)
50
#     These flags are not used at the moment and reserved for
51
#     future implementation.
52
#
53
#
54
###############################################################
55
 
56
module SOCMaker
57
class HDLFile
58
  include ERR
59
  attr_accessor :path
60
  attr_accessor :use_syn
61
  attr_accessor :use_sys_sim
62
  attr_accessor :use_mod_sim
63
  attr_accessor :type
64
 
65 9 feddischso
  def initialize( path, optional = {} )
66
    init_with( { 'path' => path }.merge( optional ) )
67 3 feddischso
  end
68
 
69
  def encode_with( coder )
70
    %w[ path use_syn use_sys_sim use_mod_sim type ].
71
      each { |v| coder[ v ] = instance_variable_get "@#{v}" }
72
  end
73
 
74
  def init_with( coder )
75
 
76
    serr_if( !( coder.is_a?( Hash         ) ||
77
                coder.is_a?( Psych::Coder ) ),
78
      'coder is not given as Hash neither as Psych::Coder' )
79
 
80
    # check path
81
    serr_if( coder[ 'path' ] == nil, 'no filepath specified' )
82
    @path = coder[ 'path' ]
83
    verr_if( !@path.is_a?( String ), 'path must be of type string' )
84
 
85
    # auto-complete to 'true'
86
    @use_syn      = coder[ 'use_syn'     ] || true
87
    @use_sys_sim  = coder[ 'use_sys_sim' ] || true
88
    @use_mod_sim  = coder[ 'use_mod_sim' ] || true
89
 
90
    # ensure, that the thee use... fields are boolean
91
    verr_if( !!@use_syn     != @use_syn,     'use_syn field must be true of false'      )
92
    verr_if( !!@use_sys_sim != @use_sys_sim, 'use_sys_sim field must be true of false'  )
93
    verr_if( !!@use_mod_sim != @use_mod_sim, 'use_mod_sim field must be true of false'  )
94
 
95
    # if the file-type is not given, we try to auto-detect it
96
    #   *.vhd  ->  vhdl
97
    #   *.v    ->  verilog
98
    #   (see conf[ :vhdl_file_regex ] and
99
    #        conf[ :verilog_file_regex ] )
100
    if  coder[ 'type' ] == nil
101
      if @path =~ SOCMaker::conf[ :vhdl_file_regex ]
102
        SOCMaker::logger.warn "Auto-detected vhdl file type for #{ @path }"
103
        @type = 'vhdl'
104
      elsif @path =~ SOCMaker::conf[ :verilog_file_regex ]
105
        SOCMaker::logger.warn "Auto-detected verilog file type for #{ @path }"
106
        @type = 'verilog'
107
      else
108
        verr_if( true, 'Cant auto-detect file type for "' + path + '"' )
109
      end
110
    else
111
      # if the file-type is given, ensure, that it is either 'vhdl' or 'verilog'
112
      verr_if( !SOCMaker::conf[ :hdl_type_regex ].match( coder[ 'type' ] ),
113
        "The type must be 'vhdl' or 'verilog'",
114
        instance: @path,
115
        field:    'type' )
116
      @type = coder[ 'type' ]
117
    end
118
 
119
  end
120
 
121
 
122
 
123
  def ==(o)
124
    o.class           == self.class         &&
125
    o.path            == self.path          &&
126
    o.use_syn         == self.use_syn       &&
127
    o.use_sys_sim     == self.use_sys_sim   &&
128
    o.use_mod_sim     == self.use_mod_sim   &&
129
    o.type            == self.type
130
  end
131
 
132
end
133
end
134
 
135
# vim: noai:ts=2:sw=2
136
 

powered by: WebSVN 2.1.0

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