def reg(*args, &block)
      if block_given? || (args[1].is_a?(Integer) && !try(:_initialized?))
        @reg_define_file = define_file(caller[0])
        add_reg(*args, &block)
      else
        # Example use cases:
        # reg(:reg2)
        # reg(:name => :reg2)
        # reg('/reg2/')
        if !args.empty? && args.size == 1 && (args[0].class != Hash || (args[0].key?(:name) && args[0].size == 1))
          if args[0].class == Hash
            name = args[0][:name]
          else name = args.first
          end
          if has_reg(name)
            return _registers[name]
          elsif name =~ /\/(.+)\//
            regex = Regexp.last_match(1)
            return match_registers(regex)
          else
            if Origen.config.strict_errors
              puts ''
              if regs.empty?
                puts "#{self.class} does not have a register named #{name} or it is not enabled."
              else
                puts "#{self.class} does not have a register named #{name} or it is not enabled."
                puts 'You may need to add it. This could also be a typo, these are the valid register names:'
                puts regs.keys
              end
              puts ''
              fail 'Missing register error!'
            end
          end
        # Example use cases:
        # reg(:enabled_features => :all)
        # reg(:name => :reg2, enabled_features => :all)
        # reg(:name => :reg2, enabled_features => :fac)
        elsif !args.empty? && args.size == 1 && args[0].class == Hash
          params = args[0]

          # Example use case:
          # reg(:name => :reg2, :enabled_features => :all)
          if (params.key?(:enabled_features) || params.key?(:enabled_feature)) && params.key?(:name)
            name = params[:name]
            if has_reg(name, params)
              _registers[name]
            else
              reg_missing_error(params)
            end
          # Example use case:
          # reg(:enabled_features =>[:fac, fac2])
          elsif params.size == 1 && params.key?(:enabled_features)
            return get_registers(enabled_features: params[:enabled_features])
          end

        # Example use case:
        # reg(:reg2, :enabled_features => :all)
        # reg(:reg2, :enabled_features => :default)
        # reg(:reg2, :enabled_features => :fac)
        elsif !args.empty? && args.size == 2
          name = args[0]
          params = args[1]
          name, params = params, name if name.class == Hash
          if has_reg(name, params)
            _registers[name]
          else
            reg_missing_error(params)
          end
        elsif args.empty?
          if _registers.empty?
            return _registers
          else
            return get_registers(enabled_features: :default)
          end
        else
          if Origen.config.strict_errors
            fail 'Invalid call to reg method or invalid arguments specified'
          end
        end
      end
    end
def reg(*args, &block)
      if block_given? || (args[1].is_a?(Integer) && !try(:_initialized?))
        @reg_define_file = define_file(caller[0])
        add_reg(*args, &block)
      else
        # Example use cases:
        # reg(:reg2)
        # reg(:name => :reg2)
        # reg('/reg2/')
        if !args.empty? && args.size == 1 && (args[0].class != Hash || (args[0].key?(:name) && args[0].size == 1))
          if args[0].class == Hash
            name = args[0][:name]
          else name = args.first
          end
          if has_reg(name)
            return _registers[name]
          elsif name =~ /\/(.+)\//
            regex = Regexp.last_match(1)
            return match_registers(regex)
          else
            if Origen.config.strict_errors
              puts ''
              if regs.empty?
                puts "#{self.class} does not have a register named #{name} or it is not enabled."
              else
                puts "#{self.class} does not have a register named #{name} or it is not enabled."
                puts 'You may need to add it. This could also be a typo, these are the valid register names:'
                puts regs.keys
              end
              puts ''
              fail 'Missing register error!'
            end
          end
        # Example use cases:
        # reg(:enabled_features => :all)
        # reg(:name => :reg2, enabled_features => :all)
        # reg(:name => :reg2, enabled_features => :fac)
        elsif !args.empty? && args.size == 1 && args[0].class == Hash
          params = args[0]

          # Example use case:
          # reg(:name => :reg2, :enabled_features => :all)
          if (params.key?(:enabled_features) || params.key?(:enabled_feature)) && params.key?(:name)
            name = params[:name]
            if has_reg(name, params)
              _registers[name]
            else
              reg_missing_error(params)
            end
          # Example use case:
          # reg(:enabled_features =>[:fac, fac2])
          elsif params.size == 1 && params.key?(:enabled_features)
            return get_registers(enabled_features: params[:enabled_features])
          end

        # Example use case:
        # reg(:reg2, :enabled_features => :all)
        # reg(:reg2, :enabled_features => :default)
        # reg(:reg2, :enabled_features => :fac)
        elsif !args.empty? && args.size == 2
          name = args[0]
          params = args[1]
          name, params = params, name if name.class == Hash
          if has_reg(name, params)
            _registers[name]
          else
            reg_missing_error(params)
          end
        elsif args.empty?
          if _registers.empty?
            return _registers
          else
            return get_registers(enabled_features: :default)
          end
        else
          if Origen.config.strict_errors
            fail 'Invalid call to reg method or invalid arguments specified'
          end
        end
      end
    end
Returns
  -the register object matching the given name
  -or a hash of all registes matching a given regular expression
  -or a hash of all registers, associated with a feature, if no name is specified.

 Can also be used to define a new register if a block is supplied in which case
 it is equivalent to calling add_reg with a block.