function compute_machine_info

global gMachineInfo gTargetInfo %#ok<GVMIS>

if(isempty(sf('get',gMachineInfo.target,'target.id')))
construct_coder_error([],getString(message('Stateflow:sfprivate:SfcInvokedInvalidTarget',gMachineInfo.target)),1);
end

gMachineInfo.machineName = sf('get',gMachineInfo.machineId,'machine.name');
gMachineInfo.mainMachineName = sf('get',gMachineInfo.mainMachineId,'machine.name');
gMachineInfo.targetName = sf('get',gMachineInfo.target,'target.name');
if(~gTargetInfo.codingSFunction && ~gTargetInfo.codingRTW && ~gTargetInfo.codingHDL && ~gTargetInfo.codingPLC) % codingCustom
%% For custom target code generation, filter out charts which have
%% noCodegen flag set
gMachineInfo.charts = sf('find',gMachineInfo.charts,'chart.noCodegenForCustomTargets',0);
end

% Chart specializations
numCharts = length(gMachineInfo.charts);

% gMachineInfo.specializations is pre-populated for slhdlc target.
if ~isfield(gMachineInfo, 'specializations') || ...
isempty(gMachineInfo.specializations) || ...
length(gMachineInfo.specializations) ~= numCharts
gMachineInfo.specializations = cell(1, numCharts);
gMachineInfo.codingLLVM = cell(1, numCharts);
for i = 1:numCharts
gMachineInfo.specializations{i} = sf('Cg', 'get_module_specializations', gMachineInfo.charts(i));
gMachineInfo.codingLLVM{i} = zeros(1, numel(gMachineInfo.specializations{i}));
end
end

for i=1:numCharts
chart = gMachineInfo.charts(i);
if gTargetInfo.codingHDL
% do nothing. chart.unique.codegenName is already set by the HDL infrastructure
elseif gTargetInfo.codingCustom && gTargetInfo.codingExportChartNames
% custom target. if export chart names option is true, then just use the chart name.
chartUniqueName = get_param(sfprivate('chart2block',chart),'name');
chartUniqueName = matlab.lang.makeValidName(chartUniqueName); % make sure the name is cleaned up
sf('set', chart, 'chart.unique.codegenName', chartUniqueName);
else
% In all other cases, chart codegen name is calculated internally in "cdr_get_codegen_name()"
sf('set', chart, 'chart.unique.codegenName', '');
end
sf('set', chart, 'chart.number', i-1);
end

detect_chart_codegen_name_collisions;

sf('set',gMachineInfo.machineId,'machine.activeTarget',gMachineInfo.target);
sf('set',gMachineInfo.machineId,'machine.activeParentTarget',gMachineInfo.parentTarget);

function detect_chart_codegen_name_collisions
global gMachineInfo gTargetInfo %#ok<GVMIS>

if (gTargetInfo.codingCustom && sfprivate('target_code_flags','get',gMachineInfo.target,'exportcharts'))
numCharts = length(gMachineInfo.charts);
names = cell(1, numCharts);
for i=1:numCharts
names{i} = sf('get', gMachineInfo.charts(i), 'chart.unique.codegenName');
for j=1:i-1
if(strcmp(names{i},names{j}))
str = getString(message('Stateflow:sfprivate:GeneratedCodeSameFilename',...
gMachineInfo.charts(i),...
gMachineInfo.charts(j),...
names{i}));

construct_coder_error([gMachineInfo.charts(i),gMachineInfo.charts(j)],str,1);
end
end
end
end