Method: SOCMaker::HDLFile#init_with
- Defined in:
- lib/soc_maker/hdl_file.rb
#init_with(coder) ⇒ Object
Initialization method (from yaml)
coder-
An instance of the Psych::Coder to init this class from a YAML file
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 |
# File 'lib/soc_maker/hdl_file.rb', line 103 def init_with( coder ) init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 'coder is not given as Hash neither as Psych::Coder' # check path init_error 'no filepath specified' if coder[ 'path' ] == nil @path = coder[ 'path' ] init_error 'path must be of type string' if !@path.is_a?( String ) # auto-complete to 'true' @use_syn = coder[ 'use_syn' ] || true @use_sys_sim = coder[ 'use_sys_sim' ] || true @use_mod_sim = coder[ 'use_mod_sim' ] || true # ensure, that the thee use... fields are boolean init_error 'use_syn field must be true of false' if !!@use_syn != @use_syn init_error 'use_sys_sim field must be true of false' if !!@use_sys_sim != @use_sys_sim init_error 'use_mod_sim field must be true of false' if !!@use_mod_sim != @use_mod_sim # if the file-type is not given, we try to auto-detect it # *.vhd -> vhdl # *.v -> verilog # (see conf[ :vhdl_file_regex ] and # conf[ :verilog_file_regex ] ) if coder[ 'type' ] == nil if @path =~ SOCMaker::conf[ :vhdl_file_regex ] SOCMaker::logger.warn "Auto-detected vhdl file type for #{ @path }" @type = 'vhdl' elsif @path =~ SOCMaker::conf[ :verilog_file_regex ] SOCMaker::logger.warn "Auto-detected verilog file type for #{ @path }" @type = 'verilog' else init_error "Cant auto-detect file type for #{path}" end else # if the file-type is given, ensure, that it is either 'vhdl' or 'verilog' init_error "The type must be 'vhdl' or 'verilog'", instance: @path, field: 'type' if !SOCMaker::conf[ :hdl_type_regex ].match( coder[ 'type' ] ) @type = coder[ 'type' ] end end |