-
Notifications
You must be signed in to change notification settings - Fork 9
/
sl_customization.m
299 lines (259 loc) · 8.44 KB
/
sl_customization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is part of CoCoSim.
% Copyright (C) 2014-2016 Carnegie Mellon University
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sl_customization(cm)
%% Register custom menu function.
cm.addCustomMenuFcn('Simulink:ToolsMenu', @getMyMenuItems);
end
%% Define the custom menu function.
function schemaFcns = getMyMenuItems
schemaFcns = {@getcocoSim};
end
%% Define the custom menu function.
function schema = getcocoSim(callbackInfo)
schema = sl_container_schema;
schema.label = 'CoCoSim';
schema.statustip = 'Automated Analysis Framework';
schema.autoDisableWhen = 'Busy';
schema.childrenFcns = {@getVerify,@getValidate,...
@getCheckBlocks, @viewContract, @getProps, ...
@getPP, @getCompiler};
end
function schema = getCheckBlocks(callbackInfo)
schema = sl_action_schema;
schema.label = 'Check unsupported blocks';
schema.callback = @checkBlocksCallBack;
end
function checkBlocksCallBack(callbackInfo)
try
model_full_path = get_file_name(gcs);
unsupported_blocks_gui( model_full_path );
catch ME
display_msg(ME.message,Constants.ERROR,'getCheckBlocks','');
display_msg(ME.getReport(),Constants.DEBUG,'getCheckBlocks','');
end
end
function schema = getValidate(callbackInfo)
schema = sl_action_schema;
schema.label = 'Compiler Validation (Experimental)';
schema.callback = @validateCallBack;
end
function validateCallBack(callbackInfo)
try
[cocoSim_path, ~, ~] = fileparts(mfilename('fullpath'));
model_full_path = get_file_name(gcs) ;
L = log4m.getLogger(fullfile(fileparts(model_full_path),'logfile.txt'));
validate_window(model_full_path,cocoSim_path,1,L);
catch ME
display_msg(ME.getReport(), Constants.DEBUG,'Validate_model','');
display_msg(ME.message, Constants.ERROR,'Validate_model','');
end
end
% Function to pre-process and simplify the Simulink model
function schema = getPP(callbackInfo)
schema = sl_action_schema;
schema.label = 'Simplifier';
schema.callback = @ppCallBack;
end
function ppCallBack(callbackInfo)
try
[prog_path, fname, ext] = fileparts(mfilename('fullpath'));
addpath(fullfile(prog_path, 'pp'));
simulink_name = get_file_name(gcs);%gcs;
pp_model = cocosim_pp(simulink_name);
load_system(char(pp_model));
catch ME
display_msg(ME.getReport(),Constants.DEBUG,'getPP','');
display_msg(ME.message,Constants.ERROR,'getPP','');
end
end
function cocoSimDialog(message)
msg= sprintf('CoCoSpec in: %s', message);
d = dialog('Position',[300 300 250 150],'Name','CoCoSim');
txt = uicontrol('Parent',d,...
'Style','text',...
'Position',[20 80 210 40],...
'String',msg);
btn = uicontrol('Parent',d,...
'Position',[85 20 70 25],...
'String','Close',...
'Callback','delete(gcf)');
end
function schema = viewContract(callbackInfo)
schema = sl_action_schema;
schema.label = 'View generated CoCoSpec (Experimental)';
schema.callback = @viewContractCallback;
end
function viewContractCallback(callbackInfo)
model_full_path = get_file_name(gcs);
simulink_name = gcs;
contract_name = [simulink_name '_COCOSPEC'];
emf_name = [simulink_name '_EMF'];
try
CONTRACT = evalin('base', contract_name);
EMF = evalin('base', emf_name);
disp(['CONTRACT LOCATION ' char(CONTRACT)])
catch ME
display_msg(ME.getReport(),Constants.DEBUG,'viewContract','');
msg = sprintf('No CoCoSpec Contract for %s \n Verify the model with Zustre', simulink_name);
warndlg(msg,'CoCoSim: Warning');
end
try
Output_url = view_cocospec(model_full_path, char(EMF));
open(Output_url);
catch ME
display_msg(ME.getReport(),Constants.DEBUG,'viewContract','');
end
end
function schema = getProps(callbackInfo)
schema = sl_action_schema;
schema.label = 'Create Property';
schema.callback = @synchObsCallback;
end
function synchObsCallback(callbackInfo)
try
[prog_path, fname, ext] = fileparts(mfilename('fullpath'));
simulink_name = get_file_name(gcs);
add_property(simulink_name);
catch ME
display_msg(ME.getReport(),Constants.DEBUG,'getProps','');
end
end
function schema = getCompiler(callbackInfo)
schema = sl_container_schema;
schema.label = 'Compile (Experimental)';
%schema.userdata = 'two';
schema.childrenFcns = {@getRust, @getC};
end
function schema = getRust(callbackInfo)
schema = sl_action_schema;
schema.label = 'to Rust';
schema.callback = @rustCallback;
end
function rustCallback(callbackInfo)
try
[prog_path, fname, ext] = fileparts(mfilename('fullpath'));
assignin('base', 'SOLVER', 'NONE');
assignin('base', 'RUST_GEN', 1);
assignin('base', 'C_GEN', 0);
simulink_name = get_file_name(gcs);%gcs;
cocoSim(simulink_name);
catch ME
display_msg(ME.getReport(),Constants.DEBUG,'getRust','');
disp('run the command in the top level of the model')
end
end
function schema = getC(callbackInfo)
schema = sl_action_schema;
schema.label = 'to C';
schema.callback = @cCallback;
end
function cCallback(callbackInfo)
clear;
assignin('base', 'SOLVER', 'NONE');
assignin('base', 'RUST_GEN', 0);
assignin('base', 'C_GEN', 1);
runCoCoSim;
end
%% Run cocoSim
function schema = getVerify(callbackInfo)
schema = sl_container_schema;
schema.label = 'Verify using ...';
schema.statustip = 'Verify the current model with CoCoSim';
schema.autoDisableWhen = 'Busy';
schema.childrenFcns = {@getZustre, @getKind, @getJKind};
end
function schema = getZustre(callbackInfo)
schema = sl_action_schema;
schema.label = 'Zustre';
schema.callback = @zustreCallback;
end
function zustreCallback(callbackInfo)
clear;
assignin('base', 'SOLVER', 'Z');
assignin('base', 'RUST_GEN', 0);
assignin('base', 'C_GEN', 0);
runCoCoSim;
end
function schema = getKind(callbackInfo)
schema = sl_action_schema;
schema.label = 'Kind2';
schema.callback = @kindCallback;
end
function kindCallback(callbackInfo)
clear;
[prog_path, fname, ext] = fileparts(mfilename('fullpath'));
assignin('base', 'SOLVER', 'K');
assignin('base', 'RUST_GEN', 0);
assignin('base', 'C_GEN', 0);
runCoCoSim;
end
function schema = getJKind(callbackInfo)
schema = sl_action_schema;
schema.label = 'JKind';
schema.callback = @jkindCallback;
end
function jkindCallback(callbackInfo)
clear;
[prog_path, fname, ext] = fileparts(mfilename('fullpath'));
assignin('base', 'SOLVER', 'J');
assignin('base', 'RUST_GEN', 0);
assignin('base', 'C_GEN', 0);
runCoCoSim;
end
function runCoCoSim
[path, name, ext] = fileparts(mfilename('fullpath'));
addpath(fullfile(path, 'utils'));
try
simulink_name = get_file_name(gcs);
cocosim_window(simulink_name);
% cocoSim(simulink_name); % run cocosim
catch ME
if strcmp(ME.identifier, 'MATLAB:badsubscript')
msg = ['Activate debug message by running cocosim_debug=true', ...
' to get more information where the model in failing'];
e_msg = sprintf('Error Msg: %s \n Action:\n\t %s', ME.message, msg);
display_msg(e_msg, Constants.ERROR, 'cocoSim', '');
display_msg(ME.getReport(),Constants.DEBUG,'cocoSim','');
elseif strcmp(ME.identifier,'MATLAB:MException:MultipleErrors')
msg = 'Make sure that the model can be run (i.e. most probably missing constants)';
d_msg = sprintf('Error Msg: %s', ME.getReport());
display_msg(d_msg, Constants.DEBUG, 'cocoSim', '');
display_msg(msg, Constants.ERROR, 'cocoSim', '');
elseif strcmp(ME.identifier, 'Simulink:Commands:ParamUnknown')
msg = 'Run CoCoSim on the most top block of the model';
e_msg = sprintf('Error Msg: %s \n Action:\n\t %s', ME.message, msg);
display_msg(e_msg, Constants.ERROR, 'cocoSim', '');
display_msg(ME.getReport(),Constants.DEBUG,'cocoSim','');
else
display_msg(ME.message,Constants.ERROR,'cocoSim','');
display_msg(ME.getReport(),Constants.DEBUG,'cocoSim','');
end
end
end
% function schema = getSeaHorn(callbackInfo)
% schema = sl_action_schema;
% schema.label = 'SeaHorn';
% end
% function schema = getEldarica(callbackInfo)
% schema = sl_action_schema;
% schema.label = 'Eldarica';
% schema.callback = @eldaricaCallback;
% end
% function eldaricaCallback(callbackInfo)
% try
% [prog_path, fname, ext] = fileparts(mfilename('fullpath'));
% fileID = fopen([prog_path filesep 'src' filesep 'config.m'],'a');
% fprintf(fileID, '\nSOLVER=''E'';\nRUST_GEN=0;\nC_GEN=0;');
% fclose(fileID);
% simulink_name = gcs;
% cocoSim(simulink_name);
% catch ME
% disp(ME.getReport())
% end
% end
function fname = get_file_name(gcs)
names = regexp(gcs,'/','split');
fname = get_param(names{1},'FileName');
end