function varargout = manageTargetInfo(h,action, varargin)
% TARGETINFO - internal use only

%   Copyright 2011-2022 The MathWorks, Inc.

    switch lower(action)
      case 'settargetwordsizes'
        targetType = varargin{1};
        locSetWordSizes(h,targetType);
      case 'settargetwordsizesforml'
        configInfo = varargin{1};
        locSetWordSizesForML(h,configInfo);   
      case 'gettargetwordsizes'
        varargout{1} = h.Settings.TargetInfo.wordSizes;
      otherwise
        error(message('coder_compile:CoderCompile:badMethodArguments',...
                       'RTW.BuildInfo.manageTargetInfo'));
    end
end

function locSetWordSizes(h,targetType)
    
    % load the binfo and get the word sizes from the saved configSet.  
    is = coder.internal.infoMATFileMgr('load', 'binfo', h.ModelName, targetType);
    wordSizes.charNumBits  = get_param(is.configSet,'TargetBitPerChar');
    wordSizes.shortNumBits = get_param(is.configSet,'TargetBitPerShort');
    wordSizes.intNumBits   = get_param(is.configSet,'TargetBitPerInt');
    wordSizes.longNumBits  = get_param(is.configSet,'TargetBitPerLong');
    wordSizes.wordSize     = get_param(is.configSet,'TargetWordSize');
        
    h.Settings.TargetInfo.wordSizes = wordSizes;
end

function locSetWordSizesForML(h,configInfo)
    % get the word sizes from the passed in config object. 
    if isprop(configInfo, 'HardwareImplementation')
        is = configInfo.HardwareImplementation;
    else
        is = coder.HardwareImplementation;
    end
    wordSizes.charNumBits  = is.TargetBitPerChar;
    wordSizes.shortNumBits = is.TargetBitPerShort;
    wordSizes.intNumBits   = is.TargetBitPerInt;
    wordSizes.longNumBits  = is.TargetBitPerLong;
    wordSizes.wordSize     = is.TargetWordSize;
        
    h.Settings.TargetInfo.wordSizes = wordSizes;
end
