function ok = check_hdl_support(target, varargin) %CHECK_HDL_SUPPORT HDL Coder compatibility check for an RTL-bound subsystem. % % ok = CHECK_HDL_SUPPORT('model/HdlSubsystem') % ok = CHECK_HDL_SUPPORT(..., 'Out', 'hdl_support.txt') % % Wraps checkhdl: catches blocks that cannot become RTL at all -- the other % half of Task12-1 rule 1 ("must be built from blocks that generate RTL % directly"). The m-code policy audit is audit_hdl_blocks.m; run both. p = inputParser; p.addParameter('Out', ''); p.parse(varargin{:}); model = strtok(target, '/'); if ~bdIsLoaded(model) load_system(model); end txt = ''; threw = false; try txt = evalc('checkhdl(target)'); catch e threw = true; txt = sprintf('checkhdl threw: %s\n%s', e.identifier, e.message); end % The summary line is localised ("0 个错误、2 个警告" / "0 errors, 2 warnings"), % so count both spellings rather than grepping for the word "error". nErr = local_count(txt, {'(\d+)\s*个错误', '(\d+)\s+errors?'}); nWarn = local_count(txt, {'(\d+)\s*个警告', '(\d+)\s+warnings?'}); ok = ~threw && nErr == 0; rep = regexp(txt, '(?<=file:///)[^''"<>]*_report\.html', 'match', 'once'); fprintf('=== checkhdl %s : %s (%d error(s), %d warning(s)) ===\n', ... target, string(ok), nErr, nWarn); if ~isempty(rep) fprintf('report: %s\n', strrep(rep, '/', filesep)); end disp(txt); if nWarn > 0 fprintf(['NOTE: warnings are not a pass/fail gate here, but read them -- they are usually\n' ... ' "this block will cost you area/latency in RTL" hints.\n']); end if ~isempty(p.Results.Out) fid = fopen(p.Results.Out, 'w'); fwrite(fid, txt); fclose(fid); fprintf('checkhdl log -> %s\n', p.Results.Out); end end function n = local_count(txt, pats) n = 0; for i = 1:numel(pats) t = regexp(txt, pats{i}, 'tokens', 'once'); if ~isempty(t) n = str2double(t{1}); return end end end