├── .gitignore ├── .travis.yml ├── AUTHORS ├── CocosimMenu.m ├── Guidelines.md ├── LICENSE ├── PreContextMenu.m ├── README.md ├── doc ├── compositionalAnalysis.md ├── images │ ├── 2_contracts_simulink.png │ ├── compositionalAnalysis.png │ ├── contextMenuVerificationResults.png │ ├── counterExampleOptions.png │ ├── generalArchitecture.png │ ├── kindLibrary.png │ ├── menu.png │ ├── preferences.png │ ├── propertyColors.png │ ├── subsystemColors.png │ └── validatorMask.png ├── installation.md ├── kind2 installation.md ├── menu.md ├── pp_doc │ └── pp_doc.tex ├── specificationLibrary.md ├── verificationVisualization.md └── videos │ ├── compositionalAbstract.mp4 │ ├── compositionalAbstract.png │ ├── docker.PNG │ ├── docker.html │ ├── docker.mp4 │ ├── htmlVerificationResults.mp4 │ ├── htmlVerificationResults.png │ ├── installation.mp4 │ ├── installation.png │ ├── kind2WebService.PNG │ ├── kind2WebService.html │ └── kind2WebService.mp4 ├── examples ├── StateFlow │ ├── Arrays1V2.mdl │ ├── MicrowaveCex.slx │ ├── MicrowaveV2.mdl │ └── set_up_parameters.m ├── contract │ ├── Days.m │ ├── DaysEnum.slx │ ├── DaysEnumInvalid.slx │ ├── DoorLock.slx │ ├── DoorLockCompositional.slx │ ├── DoorLockCompositionalHtml.slx │ ├── DoorLockInvalid.slx │ ├── StopwatchSpec.slx │ ├── absolute.slx │ ├── bacteriaPopulation.lus │ ├── bacteriaPopulation.slx │ ├── bacteriaPopulationDemo.slx │ ├── bacteriaPopulationStateflow.slx │ └── bacteriaPopulationTruthTable.slx └── properties │ ├── AltitudeControl_Demo.slx │ ├── assertion.mdl │ ├── assumption.slx │ ├── safe_1.mdl │ ├── safe_math_functions.slx │ ├── two_property.mdl │ └── unsafe_1.mdl ├── libs └── contract │ ├── CoCoSimSpecification.slx │ ├── CoCoSimSpecification_r2015a.slx │ ├── Kind.slx │ ├── contract.m │ ├── contractAfterSimulation.m │ ├── contractBeforeSimulation.m │ ├── contract_callback.m │ ├── saveValidatorParameters.m │ └── slblocks.m ├── pre-commit.cmd ├── pre-commit.sh ├── sanity ├── README ├── pre_release_script.m └── sanity_check.py ├── sl_customization.m ├── src ├── backEnd │ ├── common │ │ ├── Kind2Utils.m │ │ └── plotting.m │ ├── generate_code │ │ ├── lustrec.m │ │ └── rust.m │ ├── generate_invariants │ │ ├── ViewContractMenu.m │ │ └── zustre_invariants │ │ │ ├── utils │ │ │ ├── get_block_name_from_variable_using_xRoot.m │ │ │ └── parse_json.m │ │ │ └── view_cocospec.m │ ├── templates │ │ ├── ann.html │ │ ├── annot.html │ │ ├── footer.html │ │ ├── header.html │ │ ├── list_item.html │ │ ├── list_item_mat_code.html │ │ ├── list_title.html │ │ ├── materialize.css │ │ ├── title.html │ │ └── title2.html │ ├── unsupported_blocks │ │ ├── UnsupportedBlocksMenu.m │ │ └── unsupported_blocks.m │ ├── validation │ │ ├── ValidationMenu.m │ │ ├── cocoSpecValidate │ │ │ └── cocoSpecValidate.m │ │ ├── common │ │ │ └── ValidateUtils.m │ │ └── lustreValidate │ │ │ └── validate_lustre.m │ └── verification │ │ ├── VerificationMenu.m │ │ ├── cocoSpecVerify │ │ ├── cocoSpecVerify.m │ │ └── utils │ │ │ ├── CocoSim_IR_Compiler-0.1-jar-with-dependencies.jar │ │ │ ├── cocoSpecKind2.m │ │ │ ├── displayCexHtmlTables.m │ │ │ ├── displayCexSignals.m │ │ │ ├── displayCexTables.m │ │ │ ├── displayVerificationResults.m │ │ │ ├── generateModelWithSignalBuilders.m │ │ │ └── html │ │ │ ├── cexTemplate.html │ │ │ ├── css │ │ │ ├── bootstrap.min.css │ │ │ ├── fa-svg-with-js.css │ │ │ └── jquery.dataTables.min.css │ │ │ ├── js │ │ │ ├── bootstrap.min.js │ │ │ ├── fontawesome-all.js │ │ │ ├── jquery.dataTables.min.js │ │ │ ├── jquery.min.js │ │ │ └── popper.min.js │ │ │ ├── test │ │ │ ├── bootstrap.min.css │ │ │ ├── bootstrap.min.js │ │ │ ├── fa-svg-with-js.css │ │ │ ├── fontawesome-all.js │ │ │ ├── jquery.min.js │ │ │ ├── popper.min.js │ │ │ └── verificationResultsTest.html │ │ │ └── verificationResultsTemplate.html │ │ └── lustreVerify │ │ ├── lustre_verify.m │ │ └── utils │ │ ├── jkind.m │ │ ├── kind2.m │ │ ├── seahorn.m │ │ ├── solver_result.m │ │ └── zustre.m ├── cocosim_config.m ├── frontEnd │ ├── IR │ │ ├── IR_config.m │ │ ├── README.md │ │ ├── blocks │ │ │ ├── chart_struct.m │ │ │ ├── common_struct.m │ │ │ ├── specific_parameters_struct.m │ │ │ └── subsystems_struct.m │ │ ├── cocosim_IR.m │ │ ├── example │ │ │ ├── Model_example.json │ │ │ ├── Model_example.slx │ │ │ └── Model_example_IR.json │ │ ├── meta │ │ │ └── buildDeclarationsStruct.m │ │ └── utils │ │ │ ├── ChartParser.jar │ │ │ ├── ChartParser │ │ │ ├── README.md │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ ├── Main.java │ │ │ │ │ └── edu │ │ │ │ │ └── uiowa │ │ │ │ │ └── chart │ │ │ │ │ ├── state │ │ │ │ │ ├── StateAction.java │ │ │ │ │ ├── StateParser.java │ │ │ │ │ ├── StateVisitor.java │ │ │ │ │ └── antlr │ │ │ │ │ │ ├── StateLabel.g4 │ │ │ │ │ │ ├── StateLabelBaseListener.java │ │ │ │ │ │ ├── StateLabelBaseVisitor.java │ │ │ │ │ │ ├── StateLabelLexer.java │ │ │ │ │ │ ├── StateLabelListener.java │ │ │ │ │ │ ├── StateLabelParser.java │ │ │ │ │ │ ├── StateLabelVisitor.java │ │ │ │ │ │ ├── antlr-4.7.1-complete.jar │ │ │ │ │ │ ├── antlr.bat │ │ │ │ │ │ ├── antlrForGui.bat │ │ │ │ │ │ ├── compile.bat │ │ │ │ │ │ ├── grun.bat │ │ │ │ │ │ └── test.txt │ │ │ │ │ └── transition │ │ │ │ │ ├── Transition.java │ │ │ │ │ ├── TransitionParser.java │ │ │ │ │ ├── TransitionVisitor.java │ │ │ │ │ └── antlr │ │ │ │ │ ├── TransitionLabel.g4 │ │ │ │ │ ├── TransitionLabelBaseListener.java │ │ │ │ │ ├── TransitionLabelBaseVisitor.java │ │ │ │ │ ├── TransitionLabelLexer.java │ │ │ │ │ ├── TransitionLabelListener.java │ │ │ │ │ ├── TransitionLabelParser.java │ │ │ │ │ ├── TransitionLabelVisitor.java │ │ │ │ │ ├── antlr-4.7.1-complete.jar │ │ │ │ │ ├── antlr.bat │ │ │ │ │ ├── compile.bat │ │ │ │ │ ├── grun.bat │ │ │ │ │ └── test.txt │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── edu │ │ │ │ └── uiowa │ │ │ │ └── chart │ │ │ │ ├── state │ │ │ │ └── StateActionParserTest.java │ │ │ │ └── transition │ │ │ │ └── TransitionParserTest.java │ │ │ ├── IRUtils.m │ │ │ ├── catstruct.m │ │ │ ├── cocoget_param.m │ │ │ ├── get_struct.m │ │ │ ├── jsmn.c │ │ │ ├── jsmn.h │ │ │ ├── json_decode.c │ │ │ ├── json_decode.m │ │ │ ├── json_decode.mexa64 │ │ │ ├── json_decode.mexmaci64 │ │ │ ├── json_decode.mexw64 │ │ │ ├── json_encode.c │ │ │ ├── json_encode.m │ │ │ ├── json_encode.mexa64 │ │ │ ├── json_encode.mexmaci64 │ │ │ ├── json_encode.mexw64 │ │ │ ├── license.txt │ │ │ └── make.m │ └── pp │ │ ├── PreprocessingMenu.m │ │ ├── README │ │ ├── blocks │ │ ├── chart_process.m │ │ ├── clock_process.m │ │ ├── constant_process.m │ │ ├── deadzone_dynamic_process.m │ │ ├── deadzone_process.m │ │ ├── discrete_integrator_process.m │ │ ├── discrete_state_space_process.m │ │ ├── from_workspace_process.m │ │ ├── function_process.m │ │ ├── gain_process.m │ │ ├── goto_process.m │ │ ├── integrator_process.m │ │ ├── link_process.m │ │ ├── lookuptable_nD_process.m │ │ ├── lookuptable_process.m │ │ ├── math_process.m │ │ ├── product_process.m │ │ ├── pulsegenerator_process.m │ │ ├── rate_transition_process.m │ │ ├── rename_numerical_prefix.m │ │ ├── replace_variables.m │ │ ├── saturation_dynamic_process.m │ │ ├── saturation_process.m │ │ ├── selector_process.m │ │ ├── signalbuilder_process.m │ │ ├── to_workspace_process.m │ │ ├── transfer_function_process.m │ │ └── zero_pole_process.m │ │ ├── cocosim_pp.m │ │ ├── common │ │ ├── datatable_process.m │ │ ├── gal_lib.slx │ │ ├── goto_block_process.m │ │ ├── pos.m │ │ ├── remove_line_tags.m │ │ ├── replace_one_block.m │ │ ├── state_matrix_process.m │ │ └── verification_template.slx │ │ ├── default_constants.m │ │ └── math │ │ ├── expr_parser.py │ │ ├── expr_parser.pyc │ │ ├── expression_process.m │ │ └── parse_math.m ├── gui │ ├── CocosimWindow │ │ ├── CocosimWindowMenu.m │ │ └── cocosim_window.m │ ├── PropertyGeneration │ │ ├── PropertyGenerationMenu.m │ │ └── add_property.m │ ├── cocosim_window.m │ ├── unsupported_blocks_gui.m │ ├── utils │ │ └── add_cocospec.m │ └── validate_window.m ├── middleEnd │ ├── cocoSpecCompiler │ │ ├── IR_pp │ │ │ └── cocoSpecIRPP.m │ │ └── cocoSpecCompiler.m │ └── lustre_compiler │ │ ├── IR_pp │ │ ├── README │ │ ├── fields │ │ │ ├── conversion.m │ │ │ └── lustre_pp.m │ │ └── ir_pp.m │ │ ├── blocks │ │ ├── Stateflow │ │ │ ├── common │ │ │ │ ├── Parallel_states_call.m │ │ │ │ ├── add_node_param.m │ │ │ │ ├── add_unchanged_variables.m │ │ │ │ ├── add_variables.m │ │ │ │ ├── chart_and_function_code.m │ │ │ │ ├── construct_node_header.m │ │ │ │ ├── extern_nodes_header.m │ │ │ │ ├── get_full_name.m │ │ │ │ ├── sT2fT.m │ │ │ │ ├── temporal_operators.m │ │ │ │ ├── transition_code.m │ │ │ │ ├── update_variables.m │ │ │ │ ├── write_Transition_actions.m │ │ │ │ ├── write_action.m │ │ │ │ ├── write_global_node.m │ │ │ │ ├── write_sf_Matlab_function_node.m │ │ │ │ ├── write_state_actions.m │ │ │ │ └── write_state_node.m │ │ │ └── write_Chart.m │ │ ├── write_Abs.m │ │ ├── write_ActionPort.m │ │ ├── write_Assignment.m │ │ ├── write_Bias.m │ │ ├── write_BitwiseOperator.m │ │ ├── write_BusAssignment.m │ │ ├── write_BusCreator.m │ │ ├── write_BusSelector.m │ │ ├── write_CoCoSimImplies.m │ │ ├── write_CompareTo.m │ │ ├── write_Concatenate.m │ │ ├── write_Constant.m │ │ ├── write_Create3x3Matrix.m │ │ ├── write_CrossProduct.m │ │ ├── write_DataTypeConversion.m │ │ ├── write_Delay.m │ │ ├── write_Demux.m │ │ ├── write_Detect.m │ │ ├── write_DiscreteIntegrator.m │ │ ├── write_DiscreteStateSpace.m │ │ ├── write_DiscreteZeroPole.m │ │ ├── write_DiscretizedZeroPole.m │ │ ├── write_DotProduct.m │ │ ├── write_EnablePort.m │ │ ├── write_Fcn.m │ │ ├── write_ForIterator.m │ │ ├── write_From.m │ │ ├── write_FromWorkspace.m │ │ ├── write_Gain.m │ │ ├── write_Goto.m │ │ ├── write_If.m │ │ ├── write_Inport.m │ │ ├── write_Logic.m │ │ ├── write_LookupNDDirect.m │ │ ├── write_Math.m │ │ ├── write_Memory.m │ │ ├── write_Merge.m │ │ ├── write_MinMax.m │ │ ├── write_Multiportswitch.m │ │ ├── write_Mux.m │ │ ├── write_Observer.m │ │ ├── write_Outport.m │ │ ├── write_Polyval.m │ │ ├── write_Product.m │ │ ├── write_RelationalOperator.m │ │ ├── write_Reshape.m │ │ ├── write_SFunction.m │ │ ├── write_Saturate.m │ │ ├── write_SaturationDynamic.m │ │ ├── write_Scope.m │ │ ├── write_Selector.m │ │ ├── write_SignalConversion.m │ │ ├── write_SignalSpecification.m │ │ ├── write_Signum.m │ │ ├── write_Sqrt.m │ │ ├── write_SubSystem.m │ │ ├── write_Sum.m │ │ ├── write_Switch.m │ │ ├── write_SwitchCase.m │ │ ├── write_Terminator.m │ │ ├── write_ToWorkspace.m │ │ ├── write_TriggerPort.m │ │ ├── write_Trigonometry.m │ │ ├── write_UnitDelay.m │ │ └── write_matlab_function_node.m │ │ ├── common │ │ ├── BlockUtils.m │ │ ├── BusUtils.m │ │ ├── CoCoSpec.m │ │ ├── LusUtils.m │ │ ├── XML_Trace.m │ │ ├── blockType_format.m │ │ ├── complex_arith_int.lus │ │ ├── complex_arith_real.lus │ │ ├── compute_complex_structs.m │ │ ├── convert_cocospec.m │ │ ├── func2node.py │ │ ├── generate-tables.py │ │ ├── get_subsystem_struct.m │ │ ├── list_var_action.m │ │ ├── list_var_entree.m │ │ ├── list_var_input.m │ │ ├── list_var_outport.m │ │ ├── list_var_sortie.m │ │ ├── math_functions.m │ │ ├── name_block.m │ │ ├── setdiff_struct.m │ │ ├── sort_by_order.m │ │ ├── split_transition.m │ │ ├── traceability_annotation.m │ │ ├── write_buses.m │ │ ├── write_extern_SFunction.m │ │ └── write_extern_functions.m │ │ ├── frontEnd │ │ ├── blocks2lustre.m │ │ ├── write_code.m │ │ └── write_config.m │ │ └── lustre_compiler.m ├── miscellaneous │ └── MiscellaneousMenu.m ├── preferences │ ├── PreferencesMenu.m │ └── loadCoCoSimPreferences.m └── utils │ ├── Constants.m │ ├── Utils.m │ ├── app_sprintf.m │ ├── cprintf.m │ ├── display_msg.m │ └── log4m.m └── start_cocosim.m /.gitignore: -------------------------------------------------------------------------------- 1 | src/config.m 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Project leaders: 3 | Temesghen Kahsai : teme DOT kahsai AT sv DOT cmu DOT com (NASA AMES / CMU) 4 | Cesare Tinelli : cesare DASH tinelli AT uiowa DOT edu (UIOWA) 5 | Corina Pasareanu : corina DOT pasareanu AT west DOT cmu DOT edu (NASA AMES / CMU) 6 | 7 | Developers/Contributors: 8 | Hamza Bourbouh : hamza DOT bourbouh AT nasa DOT gov (NASA AMES) 9 | Pierre-Loic Garoche : pierre DASH loic DOT garoche AT onera DOT fr (ONERA) 10 | Mudathir Mohamed : mudathir DASH mahgoubyahia AT uiowa DOT edu (UIOWA) 11 | Baoluo Meng : baoluo DASH meng AT uiowa DOT edu (UIOWA) 12 | Daniel Larraz : daniel DASH larraz AT uiowa DOT edu (UIOWA) 13 | Christelle Dambreville : christelledambreville AT hotmail DOT fr (ENSEEIHTENSEEIHT) 14 | Claire Pagetti : claire DOT pagetti AT onera DOT fr (ONERA) 15 | Eric Noulard : eric DOT noulard AT onera DOT fr (ONERA) 16 | Thomas Loquen : thomas DOT loquen AT onera DOT fr (ONERA) 17 | Xavier Thirioux : xavier DOT thirioux AT enseeiht DOT fr (ENSEEIHT) 18 | Arnaud Dieumegard : arnaud DOT dieumegard AT gmail DOT com (IRIT) 19 | 20 | -------------------------------------------------------------------------------- /CocosimMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef CocosimMenu 9 | methods(Static) 10 | %% Define the custom menu function. 11 | function schemaFcns = cocosimMenu 12 | schemaFcns = {@CocosimMenu.getcocoSim}; 13 | end 14 | 15 | %% Define the custom menu function. 16 | function schema = getcocoSim(callbackInfo) 17 | schema = sl_container_schema; 18 | schema.label = 'CoCoSim'; 19 | schema.statustip = 'Automated Analysis Framework'; 20 | schema.autoDisableWhen = 'Busy'; 21 | 22 | % modelWorkspace = get_param(callbackInfo.studio.App.blockDiagramHandle,'modelworkspace'); 23 | % if modelWorkspace.hasVariable('isPreprocessedModel') && ... 24 | % modelWorkspace.getVariable('isPreprocessedModel') == 1 25 | % schema.state = 'Disabled'; 26 | % end 27 | 28 | schema.childrenFcns = {... 29 | @VerificationMenu.verify, ... 30 | @VerificationMenu.verifyUsing,... 31 | @ValidationMenu.validate, ... 32 | @UnsupportedBlocksMenu.checkUnsupportedBlocks, ... 33 | %@ViewContractMenu.viewContract, ... 34 | @PropertyGenerationMenu.generateProperty, ... 35 | @PreprocessingMenu.preprocess,... 36 | @CocosimWindowMenu.getCompiler, ... 37 | @PreferencesMenu.getMenu ... 38 | }; 39 | end 40 | end 41 | end -------------------------------------------------------------------------------- /Guidelines.md: -------------------------------------------------------------------------------- 1 | How to be sure your model is well supported by our tool: 2 | 3 | * Make sure all Simulink blocks has the same `Sample Time` 4 | * Blocks names should start with a character or underscore 5 | 6 | 7 | 8 | 9 | Some constraints for some specific blocks: 10 | 11 | ### Discrete-Time Integrator 12 | 13 | * We support only `Forward Euler method` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CoCoSim Automated Analysis Framework 2 | Copyright (c) 2015-2018 Carnegie Mellon University 3 | Copyright (c) 2015-2018 The University of Iowa 4 | All Rights Reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following acknowledgments and 12 | disclaimers. 13 | 14 | 2. Redistributions in binary form must reproduce the 15 | above copyright notice, this list of conditions and the following 16 | acknowledgments and disclaimers in the documentation and/or other 17 | materials provided with the distribution. 18 | 19 | 3. Products derived from this software may not include “Carnegie Mellon 20 | University” or “The University of Iowa” in the name of such derived product, 21 | nor shall “Carnegie Mellon University” or “The University of Iowa” 22 | be used to endorse or promote products derived from this software without 23 | prior written permission. 24 | 25 | 26 | ACKNOWLEDGMENTS AND DISCLAIMERS: 27 | 28 | Copyright 2015-2018 Carnegie Mellon University 29 | Copyright 2015-2018 The University of Iowa 30 | 31 | This material is based upon work funded and supported by 32 | NASA NRA Contract No. NNX14AI09G and NSF Award No. 1422705. 33 | 34 | Any opinions, findings and conclusions or recommendations expressed in 35 | this material are those of the author(s) and do not necessarily 36 | reflect the views of NASA nor NSF. 37 | 38 | 39 | NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON 40 | UNIVERSITY AND THE UNIVERSITY OF IOWA MAKE NO WARRANTIES OF ANY KIND, 41 | EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, 42 | WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS 43 | OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY AND 44 | THE UNIVERSITY OF IOWA DO NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO 45 | FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. 46 | 47 | 48 | -------------------------------------------------------------------------------- /PreContextMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | classdef PreContextMenu 8 | methods(Static) 9 | function schemaFcns = preContextMenu 10 | schemaFcns = {@PreContextMenu.cocoSimActions}; 11 | end 12 | 13 | function schema = cocoSimActions(callbackInfo) 14 | schema = sl_container_schema; 15 | schema.label = 'CoCoSim'; 16 | schema.statustip = 'CoCoSim'; 17 | schema.autoDisableWhen = 'Busy'; 18 | 19 | modelWorkspace = get_param(callbackInfo.studio.App.blockDiagramHandle,'modelworkspace'); 20 | if ~isempty(modelWorkspace) && modelWorkspace.hasVariable('compositionalMap') 21 | schema.childrenFcns = {... 22 | @VerificationMenu.displayHtmlVerificationResults,... 23 | @VerificationMenu.compositionalOptions,... 24 | @MiscellaneousMenu.replaceInportsWithSignalBuilders... 25 | }; 26 | else 27 | schema.childrenFcns = {@MiscellaneousMenu.replaceInportsWithSignalBuilders}; 28 | end 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /doc/images/2_contracts_simulink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/2_contracts_simulink.png -------------------------------------------------------------------------------- /doc/images/compositionalAnalysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/compositionalAnalysis.png -------------------------------------------------------------------------------- /doc/images/contextMenuVerificationResults.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/contextMenuVerificationResults.png -------------------------------------------------------------------------------- /doc/images/counterExampleOptions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/counterExampleOptions.png -------------------------------------------------------------------------------- /doc/images/generalArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/generalArchitecture.png -------------------------------------------------------------------------------- /doc/images/kindLibrary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/kindLibrary.png -------------------------------------------------------------------------------- /doc/images/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/menu.png -------------------------------------------------------------------------------- /doc/images/preferences.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/preferences.png -------------------------------------------------------------------------------- /doc/images/propertyColors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/propertyColors.png -------------------------------------------------------------------------------- /doc/images/subsystemColors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/subsystemColors.png -------------------------------------------------------------------------------- /doc/images/validatorMask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/images/validatorMask.png -------------------------------------------------------------------------------- /doc/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | There are two ways to use CoCoSim on your computer. You can install it as a MATLAB toolbox, or you can get a local copy of the source code. CoCoSim requires MATLAB version **R2015a** or newer. CoCoSim works better with recent versions of MATLAB. 4 | 5 | ## Installation using MATLAB toolbox 6 | 7 | The CoCoSim toolbox (CoCoSim.mltbx) contains Linux and macOS binaries for the backend solvers. You can download the latest release for CoCoSim toolbox from [here](https://github.com/coco-team/cocoSim2/releases). 8 | 9 | The following video explains how to install and start CoCoSim: 10 | 11 | [![Installation](https://github.com/coco-team/cocoSim2/blob/master/doc/videos/installation.png)](http://milner.cs.uiowa.edu/cocosim/installation.mp4) 12 | 13 | The latest version of CoCoSim depends on the [Kind 2](https://github.com/kind2-mc/kind2) model checker. Kind 2 binaries for Linux and macOS are provided in the toolbox. Alternatively, CoCoSim can run Kind 2 remotely as a [web service](#kind2-web-service) or locally as a [Docker](#docker) image. Please note that Kind 2 binaries are not available for Windows. 14 | 15 | ## Installation using source code 16 | 17 | 1. Clone the CoCoSim repository: ```git clone https://github.com/coco-team/cocoSim2``` 18 | 2. For Linux and macOS users: download and extract the tools zip file ```https://github.com/coco-team/cocoSim2/releases/download/v.0.4/tools.zip``` into the ```cocoSim2``` folder. For Windows, configure CoCoSim to use the [Kind 2 web service](#kind2-web-service) or a [Docker](#docker) image of Kind 2. 19 | 20 | ### Kind2 web service 21 | 22 | The following video explains how to configure CoCoSim to use the Kind 2 web service: 23 | 24 | [![Kind2 web service](https://github.com/coco-team/cocoSim2/blob/master/doc/videos/kind2WebService.PNG)](http://milner.cs.uiowa.edu/cocosim/kind2WebService.mp4) 25 | 26 | ### Docker 27 | 28 | The following video explains how to install and configure CoCoSim to use a Docker image of Kind 2: 29 | 30 | [![Docker](https://github.com/coco-team/cocoSim2/blob/master/doc/videos/docker.PNG)](http://milner.cs.uiowa.edu/cocosim/docker.mp4) 31 | 32 | ## Launching 33 | 34 | + Launch MATLAB 35 | + Run the command ```start_cocosim``` 36 | + You can now open and verify your Simulink model 37 | 38 | -------------------------------------------------------------------------------- /doc/kind2 installation.md: -------------------------------------------------------------------------------- 1 | 1. Install Automake 2 | 3 | ```sudo apt-get install automake``` 4 | 5 | 2. Install opam for ocaml: 6 | 7 | ``` 8 | wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin 9 | 10 | opam init 11 | 12 | opam switch 4.06.1 13 | 14 | eval `opam config env` 15 | 16 | opam install ocamlbuild 17 | 18 | opam install menhir 19 | 20 | opam install num 21 | ``` 22 | 23 | 3. Install z3 24 | 25 | ``` 26 | git clone https://github.com/Z3Prover/z3 27 | 28 | cd z3 29 | 30 | python scripts/mk_make.py 31 | 32 | cd build 33 | 34 | make 35 | 36 | sudo make install 37 | 38 | ``` 39 | 40 | 4. Install kind2 41 | 42 | ``` 43 | git clone https://github.com/kind2-mc/kind2 44 | 45 | cd kind2 46 | 47 | ./autogen.sh 48 | 49 | ./build.sh 50 | 51 | make install 52 | 53 | ``` 54 | -------------------------------------------------------------------------------- /doc/menu.md: -------------------------------------------------------------------------------- 1 | # CoCoSim menu 2 | 3 | ![Kind Library](https://github.com/coco-team/cocoSim2/blob/master/doc/images/menu.png) 4 | 5 | CoCoSim Menu can be accessed after [launching CoCoSim](https://github.com/coco-team/cocoSim2/blob/master/doc/installation.md#launching) through the Tools menu in Simulink models. CoCoSim menu contains many items: 6 | 7 | + Verify: this option starts the verification process for the current model using the current user's preferences 8 | + Create Property (deprecated): This option adds an observer property to the model. Observers are subsumed by the new [CoCoSim Specification Library](https://github.com/coco-team/cocoSim2/blob/master/doc/specificationLibrary.md) 9 | + Verify using: this option starts the verification process for the current model using the selected back-end solver 10 | + Simplifier: [to be completed] 11 | + Compiler Validation (experimental): [to be completed] 12 | + Check unsupported blocks: check whether all blocks used in the model are supported by the plugin 13 | + Preferences: user's preferences are updated using this menu item: 14 | ![Preferences](https://github.com/coco-team/cocoSim2/blob/master/doc/images/preferences.png) 15 | + Use IR to lustre Compiler (enabled by default): CoCoSim uses the latest [translator](https://github.com/coco-team/ir2lustre) from CoCoSim IR to Lustre (written in Java) which supports [contract specification](https://github.com/coco-team/cocoSim2/blob/master/doc/specificationLibrary.md). If this option is disabled, CoCoSim will use the old translator (written in MATLAB) which only supports the observer block. 16 | + Compositional Analysis (enabled by default): CoCoSim will verify the model specification using a [compositional analysis](https://github.com/coco-team/cocoSim2/blob/master/doc/compositionalAnalysis.md). If it is disabled, CoCoSim will perform only a modular analysis. 17 | + Kind 2 binary: This option specifies which Kind 2 binary is used in the backend: 18 | + Local: The default option in Linux and macOS which tells CoCoSim to use the local binary located inside the tools folder. 19 | + Docker: This option tells CoCoSim to use Kind 2 image installed in docker container platform. See [here](https://github.com/coco-team/cocoSim2/blob/master/doc/installation.md#docker) on how to install docker and Kind 2 in Windows 20 | + Kind2 web service: This is the default option in Windows. This option tells CoCoSim to use [Kind2 web service](https://github.com/kind2-mc/kind2-webservices/wiki) which supports verification and simulation requests. 21 | + Verification timeout: the timeout argument for Kind 2 22 | -------------------------------------------------------------------------------- /doc/videos/compositionalAbstract.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/compositionalAbstract.mp4 -------------------------------------------------------------------------------- /doc/videos/compositionalAbstract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/compositionalAbstract.png -------------------------------------------------------------------------------- /doc/videos/docker.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/docker.PNG -------------------------------------------------------------------------------- /doc/videos/docker.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc/videos/docker.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/docker.mp4 -------------------------------------------------------------------------------- /doc/videos/htmlVerificationResults.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/htmlVerificationResults.mp4 -------------------------------------------------------------------------------- /doc/videos/htmlVerificationResults.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/htmlVerificationResults.png -------------------------------------------------------------------------------- /doc/videos/installation.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/installation.mp4 -------------------------------------------------------------------------------- /doc/videos/installation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/installation.png -------------------------------------------------------------------------------- /doc/videos/kind2WebService.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/kind2WebService.PNG -------------------------------------------------------------------------------- /doc/videos/kind2WebService.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc/videos/kind2WebService.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/doc/videos/kind2WebService.mp4 -------------------------------------------------------------------------------- /examples/StateFlow/MicrowaveCex.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/StateFlow/MicrowaveCex.slx -------------------------------------------------------------------------------- /examples/StateFlow/set_up_parameters.m: -------------------------------------------------------------------------------- 1 | 2 | step_size = Simulink.Parameter; 3 | step_size.Value = 1.0; 4 | step_size.DataType = 'double'; 5 | 6 | dt = 0.01; 7 | 8 | Primary_Side = Simulink.Parameter; 9 | Primary_Side.Value = 0; 10 | Primary_Side.DataType = 'boolean'; 11 | 12 | MANUAL = Simulink.Parameter; 13 | MANUAL.Value = 1; 14 | MANUAL.DataType = 'uint8'; 15 | 16 | LO = Simulink.Parameter; 17 | LO.Value = 2; 18 | LO.DataType = 'uint8'; 19 | 20 | MED = Simulink.Parameter; 21 | MED.Value = 3; 22 | MED.DataType = 'uint8'; 23 | 24 | MAX = Simulink.Parameter; 25 | MAX.Value = 4; 26 | MAX.DataType = 'uint8'; 27 | 28 | BRAKE_PRESSURE_LO = Simulink.Parameter; 29 | BRAKE_PRESSURE_LO.Value = 170; 30 | BRAKE_PRESSURE_LO.DataType = 'int32'; 31 | 32 | BRAKE_PRESSURE_MED = Simulink.Parameter; 33 | BRAKE_PRESSURE_MED.Value = 340; 34 | BRAKE_PRESSURE_MED.DataType = 'int32'; 35 | 36 | BRAKE_PRESSURE_MAX = Simulink.Parameter; 37 | BRAKE_PRESSURE_MAX.Value = 510; 38 | BRAKE_PRESSURE_MAX.DataType = 'int32'; -------------------------------------------------------------------------------- /examples/contract/Days.m: -------------------------------------------------------------------------------- 1 | classdef Days < Simulink.IntEnumType 2 | enumeration 3 | Sunday(1) 4 | Monday(2) 5 | Tuesday(3) 6 | Wednesday(4) 7 | Thursday(5) 8 | Friday(6) 9 | Saturday(7) 10 | end 11 | % methods(Static) 12 | % function retVal = getDefaultValue() 13 | % % GETDEFAULTVALUE Specifies the default enumeration member. 14 | % % Return a valid member of this enumeration class to specify the default. 15 | % % If you do not define this method, Simulink uses the first member. 16 | % retVal = Days.Monday; 17 | % end 18 | % end 19 | end -------------------------------------------------------------------------------- /examples/contract/DaysEnum.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DaysEnum.slx -------------------------------------------------------------------------------- /examples/contract/DaysEnumInvalid.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DaysEnumInvalid.slx -------------------------------------------------------------------------------- /examples/contract/DoorLock.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DoorLock.slx -------------------------------------------------------------------------------- /examples/contract/DoorLockCompositional.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DoorLockCompositional.slx -------------------------------------------------------------------------------- /examples/contract/DoorLockCompositionalHtml.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DoorLockCompositionalHtml.slx -------------------------------------------------------------------------------- /examples/contract/DoorLockInvalid.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/DoorLockInvalid.slx -------------------------------------------------------------------------------- /examples/contract/StopwatchSpec.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/StopwatchSpec.slx -------------------------------------------------------------------------------- /examples/contract/absolute.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/absolute.slx -------------------------------------------------------------------------------- /examples/contract/bacteriaPopulation.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/bacteriaPopulation.slx -------------------------------------------------------------------------------- /examples/contract/bacteriaPopulationDemo.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/bacteriaPopulationDemo.slx -------------------------------------------------------------------------------- /examples/contract/bacteriaPopulationStateflow.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/bacteriaPopulationStateflow.slx -------------------------------------------------------------------------------- /examples/contract/bacteriaPopulationTruthTable.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/contract/bacteriaPopulationTruthTable.slx -------------------------------------------------------------------------------- /examples/properties/AltitudeControl_Demo.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/properties/AltitudeControl_Demo.slx -------------------------------------------------------------------------------- /examples/properties/assertion.mdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/properties/assertion.mdl -------------------------------------------------------------------------------- /examples/properties/assumption.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/properties/assumption.slx -------------------------------------------------------------------------------- /examples/properties/safe_math_functions.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/examples/properties/safe_math_functions.slx -------------------------------------------------------------------------------- /libs/contract/CoCoSimSpecification.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/libs/contract/CoCoSimSpecification.slx -------------------------------------------------------------------------------- /libs/contract/CoCoSimSpecification_r2015a.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/libs/contract/CoCoSimSpecification_r2015a.slx -------------------------------------------------------------------------------- /libs/contract/Kind.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/libs/contract/Kind.slx -------------------------------------------------------------------------------- /libs/contract/contractAfterSimulation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | function contractAfterSimulation() 8 | assignin('base','ContractValidatorReady', 0); 9 | end 10 | 11 | -------------------------------------------------------------------------------- /libs/contract/contractBeforeSimulation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | function contractBeforeSimulation() 8 | assignin('base','ContractValidatorReady', 1); 9 | end 10 | 11 | -------------------------------------------------------------------------------- /libs/contract/saveValidatorParameters.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | 8 | function saveValidatorParameters(blockPath) 9 | values = get_param(blockPath,'MaskValues'); 10 | 11 | ContractValidatorBlock.block = blockPath; 12 | 13 | ContractValidatorBlock.assumePorts = str2num(char(values(1))); 14 | ContractValidatorBlock.guaranteePorts = str2num(char(values(2))); 15 | ContractValidatorBlock.modeBlocksPorts = str2num(char(values(3))); 16 | 17 | ContractValidatorBlock.portHandles = get_param(ContractValidatorBlock.block, 'PortHandles'); 18 | ContractValidatorBlock.portConnectivity =get_param(ContractValidatorBlock.block, 'PortConnectivity'); 19 | 20 | % store ContractValidatorBlock in ContractValidatorBlocksMap 21 | modelWorkspace = get_param(bdroot,'ModelWorkspace'); 22 | if modelWorkspace.hasVariable('ContractValidatorBlocksMap') 23 | ContractValidatorBlocksMap = modelWorkspace.getVariable('ContractValidatorBlocksMap'); 24 | else 25 | ContractValidatorBlocksMap = containers.Map; 26 | end 27 | 28 | ContractValidatorBlocksMap(ContractValidatorBlock.block) = ContractValidatorBlock; 29 | assignin(modelWorkspace,'ContractValidatorBlocksMap',ContractValidatorBlocksMap); 30 | 31 | end 32 | 33 | -------------------------------------------------------------------------------- /libs/contract/slblocks.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | function blkStruct = slblocks 8 | % This function specifies that the library should appear 9 | % in the Library Browser 10 | % and be cached in the browser repository 11 | version_year = regexp(version('-release'), '^\d+', 'match', 'once'); 12 | version_year = str2double(version_year); 13 | if version_year >= 2017 14 | Browser.Library = 'CoCoSimSpecification'; 15 | else 16 | Browser.Library = 'CoCoSimSpecification_r2015a'; 17 | end 18 | % 'CoCoSimSpecification' is the name of the library 19 | 20 | Browser.Name = 'CoCoSim Specification'; 21 | % 'CoCoSim Specification' is the library name that appears 22 | % in the Library Browser 23 | blkStruct.Browser = Browser; 24 | end -------------------------------------------------------------------------------- /pre-commit.cmd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this hook is in SCM so that it can be shared 3 | # to install it, create a symbolic link in the projects .git/hooks folder 4 | # 5 | # i.e. - from the .git/hooks directory, run 6 | # $ ln -s ../../git-hooks/pre-commit.sh pre-commit 7 | # 8 | # to skip the tests, run with the --no-verify argument 9 | # i.e. - $ 'git commit --no-verify' 10 | 11 | echo "CoCoSim Pre Commit checks ... (you better have run the regression tests)" 12 | # stash any unstaged changes 13 | git stash -q --keep-index 14 | 15 | # check for results of regression te 16 | python sanity/sanity_check.py 17 | 18 | # store the last exit code in a variable 19 | RESULT=$? 20 | 21 | echo $RESULT 22 | 23 | # unstash the unstashed changes 24 | git stash pop -q 25 | 26 | # return the './gradlew test' exit code 27 | exit $RESULT 28 | -------------------------------------------------------------------------------- /pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this hook is in SCM so that it can be shared 3 | # to install it, create a symbolic link in the projects .git/hooks folder 4 | # 5 | # i.e. - from the .git/hooks directory, run 6 | # $ ln -s ../../pre-commit.sh pre-commit 7 | # 8 | # to skip the tests, run with the --no-verify argument 9 | # i.e. - $ 'git commit --no-verify' 10 | 11 | echo "CoCoSim Pre Commit checks ..." 12 | # stash any unstaged changes 13 | git stash -q --keep-index 14 | 15 | # check for results of regression te 16 | python sanity/sanity_check.py 17 | 18 | # store the last exit code in a variable 19 | RESULT=$? 20 | 21 | 22 | # unstash the unstashed changes 23 | git stash pop -q 24 | 25 | # return the './gradlew test' exit code 26 | exit $RESULT 27 | -------------------------------------------------------------------------------- /sanity/README: -------------------------------------------------------------------------------- 1 | This directory will contain one file reporting the result of regression testing 2 | -------------------------------------------------------------------------------- /sanity/pre_release_script.m: -------------------------------------------------------------------------------- 1 | function pre_release_script(folder_Path, version) 2 | 3 | if nargin==0 4 | [file_path, ~, ~] = fileparts(mfilename('fullpath')); 5 | folder_Path = fileparts(file_path); 6 | end 7 | if nargin < 2 8 | version = 'R2014a'; 9 | end 10 | mdl_models = dir(fullfile(folder_Path,'**/*.mdl')); 11 | slx_models = dir(fullfile(folder_Path,'**/*.slx')); 12 | models = [mdl_models; slx_models]; 13 | 14 | 15 | for i=1:numel(models) 16 | m = models(i); 17 | 18 | full_path = fullfile(folder_Path, m.name); 19 | try 20 | info = Simulink.MDLInfo(full_path); 21 | if str2double(info.SimulinkVersion) > 8.3 22 | fprintf('saving model %s in %s format\n', m.name, version); 23 | load_system(full_path); 24 | [path, base_name, ext] = fileparts(full_path); 25 | get_param(base_name,'Modelversionformat') 26 | target_filename = fullfile(path, strcat(base_name, '_tmp',ext)); 27 | 28 | Simulink.exportToVersion(base_name,target_filename,version); 29 | close_system(full_path,1); 30 | delete(full_path); 31 | copyfile(target_filename, full_path); 32 | delete(target_filename); 33 | delete(strcat(full_path,'.r20*')); 34 | display('Done'); 35 | end 36 | catch ME 37 | display(ME.getReport()) 38 | continue; 39 | end 40 | 41 | end 42 | bdclose('all') 43 | end -------------------------------------------------------------------------------- /sanity/sanity_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import glob 5 | #import time 6 | from os import path 7 | #from datetime import datetime, timedelta 8 | 9 | current_path = os.path.dirname(os.path.abspath(__file__)) 10 | 11 | print("Runing regression testing....") 12 | cocosim_path = os.path.abspath(os.path.join(current_path, os.pardir)) 13 | cocoTeam_path = os.path.abspath(os.path.join(cocosim_path, os.pardir)) 14 | regression_runner_path = os.path.abspath(os.path.join(cocoTeam_path, "regression-test/scripts")) 15 | add_path = "addpath('"+regression_runner_path+"')" 16 | bashCommand = "matlab -nodisplay -r \"try, "+add_path+"; test_all; bdclose('all'); catch e, disp(getReport(e)), exit(7); end, exit()\"" 17 | return_val = os.system(bashCommand) 18 | 19 | if return_val == 0: 20 | 21 | print("Checking for regression testing result ....") 22 | 23 | all_reg = glob.glob(current_path + os.sep + 'not_valid_models*') 24 | 25 | if len(all_reg) > 0: 26 | for reg in all_reg: 27 | print(":( You need to fix these models") 28 | with open(reg, 'r') as fin: 29 | print fin.read() 30 | exit(1) 31 | else: 32 | print(":) Good Job!!! All models are valid") 33 | exit(0) 34 | 35 | else: 36 | print(":( You need to check your regression tests:") 37 | print("1. Checkout https://github.com/coco-team/regression-test in the same folder as cocoSim") 38 | print("2. Configure scripts/test_all.m") 39 | exit(1) 40 | -------------------------------------------------------------------------------- /sl_customization.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | function sl_customization(cm) 9 | cm.addCustomMenuFcn('Simulink:ToolsMenu', @CocosimMenu.cocosimMenu); 10 | cm.addCustomMenuFcn('Simulink:PreContextMenu', @PreContextMenu.preContextMenu); 11 | end 12 | -------------------------------------------------------------------------------- /src/backEnd/common/plotting.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function plotting(name, in ) 7 | %PLOTTING Summary of this function goes here 8 | % Detailed explanation goes here 9 | 10 | fig = findobj('Type', 'Figure', 'name', name); 11 | n_prev = 0; 12 | if numel(fig) == 0 13 | fig = figure('name', name, 'NumberTitle', 'off'); 14 | else 15 | figure(fig); 16 | axes = findall(fig, 'type', 'axes'); 17 | prev_stairs = findall(axes(1), 'type', 'stair'); 18 | n_prev = numel(prev_stairs); 19 | end 20 | 21 | cm = jet(500); 22 | step = .083; 23 | 24 | nb_io = 0; 25 | for idx_in=1:numel(in) 26 | nb_io = nb_io + numel(in{idx_in}.signals); 27 | end 28 | 29 | last_time = in{1}.time(end) + 1; 30 | time_values = [in{1}.time last_time]; 31 | 32 | cpt = 1; 33 | for idx_in=1:numel(in) 34 | for idx_sig=1:numel(in{idx_in}.signals) 35 | subplot(nb_io, 1, cpt); 36 | color_f = ((cpt -1)/nb_io) + (n_prev * step); 37 | if color_f > 1 38 | integ = floor(color_f); 39 | color_f = color_f - integ; 40 | end 41 | colorID = max(1, sum(color_f > [0:1/length(cm(:,1)):1])); 42 | color = cm(colorID, :); 43 | if numel(in{idx_in}.signals(idx_sig).values) ~= numel(time_values) 44 | last_value = in{idx_in}.signals(idx_sig).values(end); 45 | signal_values = [in{idx_in}.signals(idx_sig).values ; last_value]; 46 | else 47 | signal_values = in{idx_in}.signals(idx_sig).values; 48 | end 49 | if n_prev == 0 50 | leg = in{idx_in}.signals(idx_sig).var_name; 51 | else 52 | leg = [in{idx_in}.signals(idx_sig).var_name '_' num2str(n_prev + 1)]; 53 | end 54 | stairs(time_values, signal_values, 'LineStyle', '-', 'LineWidth', 2, 'Color', color, 'DisplayName', leg); 55 | legend('off'); 56 | l = legend('show'); 57 | set(l, 'Interpreter', 'none'); 58 | xbounds = xlim(); 59 | ylabel(in{idx_in}.signals(idx_sig).var_name, 'FontSize', 8); 60 | set(gca, 'xtick', xbounds(1):1:xbounds(2)); 61 | hold on; 62 | cpt = cpt + 1; 63 | end 64 | end 65 | xlabel('time', 'FontSize', 8); 66 | end 67 | 68 | -------------------------------------------------------------------------------- /src/backEnd/generate_code/lustrec.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function lustrec(lustre_file_name) 8 | 9 | [path file ext] = fileparts(lustre_file_name); 10 | cocosim_config; 11 | new_dir = [path '/' file '_cgen']; 12 | if ~exist(new_dir, 'dir') 13 | mkdir(new_dir); 14 | end 15 | if exist(LUSTREC,'file') 16 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 17 | command = sprintf('%s -I %s -d %s %s', LUSTREC, include_dir, new_dir, lustre_file_name); 18 | [status, lustrec_out] = system(command); 19 | if isempty(strfind(lustrec_out, '.. done')) 20 | display_msg('Error Generating C code', Constants.ERROR, 'C Generation', ''); 21 | else 22 | msg = ['C code is generated in : ' new_dir] ; 23 | display_msg(msg, Constants.RESULT, 'C Generation', ''); 24 | end 25 | else 26 | msg = 'Running C: Impossible to find LustreC'; 27 | display_msg(msg, Constants.ERROR, 'C Generation', ''); 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /src/backEnd/generate_code/rust.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function rust(lustre_file_name) 8 | 9 | [path file ext] = fileparts(lustre_file_name); 10 | cocosim_config; 11 | new_dir = [path '_rust']; 12 | if ~exist(new_dir, 'dir') 13 | mkdir(new_dir); 14 | end 15 | if exist(KIND2,'file') 16 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 17 | command = sprintf('%s --compile true --z3_bin %s --output_dir %s --check_implem false %s', KIND2, Z3, new_dir, lustre_file_name); 18 | display_msg(['KIND2_COMMAND ' command], Constants.DEBUG, 'write_code', ''); 19 | [status, rust_out] = system(command); 20 | if isempty(strfind(rust_out, 'Success')) 21 | display_msg('Error Generating Rust code', Constants.ERROR, 'Rust Generation', ''); 22 | display_msg(rust_out, Constants.ERROR, 'Rust Generation', ''); 23 | else 24 | msg = ['Rust code is generated in : ' new_dir] ; 25 | display_msg(msg, Constants.INFO, 'Rust', ''); 26 | end 27 | else 28 | msg = 'Running Kind2: Impossible to find Kind2'; 29 | display_msg(msg, Constants.ERROR, 'Rust', ''); 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /src/backEnd/generate_invariants/ViewContractMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef ViewContractMenu 9 | methods(Static) 10 | 11 | function schema = viewContract(callbackInfo) 12 | schema = sl_action_schema; 13 | schema.label = 'View generated CoCoSpec (Experimental)'; 14 | schema.callback = @ViewContractMenu.viewContractCallback; 15 | end 16 | 17 | function viewContractCallback(callbackInfo) 18 | model_full_path = ViewContractMenu.get_file_name(gcs); 19 | simulink_name = gcs; 20 | contract_name = [simulink_name '_COCOSPEC']; 21 | emf_name = [simulink_name '_EMF']; 22 | try 23 | CONTRACT = evalin('base', contract_name); 24 | EMF = evalin('base', emf_name); 25 | disp(['CONTRACT LOCATION ' char(CONTRACT)]); 26 | 27 | catch ME 28 | display_msg(ME.getReport(),Constants.DEBUG,'viewContract',''); 29 | msg = sprintf('No CoCoSpec Contract for %s \n Verify the model with Zustre', simulink_name); 30 | warndlg(msg,'CoCoSim: Warning'); 31 | end 32 | try 33 | Output_url = view_cocospec(model_full_path, char(EMF)); 34 | open(Output_url); 35 | catch ME 36 | display_msg(ME.getReport(),Constants.DEBUG,'viewContract',''); 37 | end 38 | end 39 | 40 | 41 | function fname = get_file_name(gcs) 42 | names = regexp(gcs,'/','split'); 43 | fname = get_param(names{1},'FileName'); 44 | end % get_file_name 45 | 46 | end 47 | end -------------------------------------------------------------------------------- /src/backEnd/generate_invariants/zustre_invariants/utils/get_block_name_from_variable_using_xRoot.m: -------------------------------------------------------------------------------- 1 | function block_name = get_block_name_from_variable_using_xRoot(xRoot, node_name, var_name) 2 | %GET_BLOCK_NAME_FROM_VARIABLE_USING_XROOT 3 | %this function help to get the name of Simulink block from lustre 4 | %variable name, using the generated tracability by Cocosim. 5 | 6 | block_name = ''; 7 | nodes = xRoot.getElementsByTagName('Node'); 8 | for idx_node=0:nodes.getLength-1 9 | block_name_node = nodes.item(idx_node).getAttribute('node_name'); 10 | if strcmp(block_name_node, node_name) 11 | inputs = nodes.item(idx_node).getElementsByTagName('Input'); 12 | for idx_input=0:inputs.getLength-1 13 | input = inputs.item(idx_input); 14 | if strcmp(input.getAttribute('variable'), var_name) 15 | block = input.getElementsByTagName('block_name'); 16 | block_name = char(block.item(0).getFirstChild.getData); 17 | return; 18 | end 19 | end 20 | outputs = nodes.item(idx_node).getElementsByTagName('Output'); 21 | for idx_output=0:outputs.getLength-1 22 | output = outputs.item(idx_output); 23 | if strcmp(output.getAttribute('variable'), var_name) 24 | block = output.getElementsByTagName('block_name'); 25 | block_name = char(block.item(0).getFirstChild.getData); 26 | return; 27 | end 28 | end 29 | end 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /src/backEnd/templates/ann.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 |

8 | Counter example for property_assert_test/observer

9 | 10 |

11 | Inputs:

12 |
  • 13 | In1 = [[0; 0; 0]];
  • 14 |
  • 15 | In2 = [[0; 0; 0]];
  • 16 |
  • 17 | In3 = [[0; 1/2; -1]];
  • 18 |
  • 19 | In4 = [[15 16 17;18 19 20]];
  • 20 |

    21 | Outputs:

    22 | 23 |
  • 24 | Out1 = [[1; 1/2; 2]];
  • 25 |
  • 26 | Out2 = [[0 0 0;0 0 0]];
  • 27 | 28 | -------------------------------------------------------------------------------- /src/backEnd/templates/annot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    5 | Counter example for [observer_full_name]

    6 |

    7 |

    8 | Inputs:

    9 |
  • 10 | [inport_name] = [[inport_values]];
  • 11 |

    12 |

    13 | Outputs:

    14 |
  • 15 | [outport_name] = [[outport_value]];
  • 16 | 17 | -------------------------------------------------------------------------------- /src/backEnd/templates/footer.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/backEnd/templates/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/backEnd/templates/list_item.html: -------------------------------------------------------------------------------- 1 |
    [Item]
    2 | -------------------------------------------------------------------------------- /src/backEnd/templates/list_item_mat_code.html: -------------------------------------------------------------------------------- 1 |
    [Item]
    2 | -------------------------------------------------------------------------------- /src/backEnd/templates/list_title.html: -------------------------------------------------------------------------------- 1 |
    2 |
    3 |
    4 |

    [Title]:

    5 | [List_Content] 6 |
    7 |
    8 |
    9 | -------------------------------------------------------------------------------- /src/backEnd/templates/title.html: -------------------------------------------------------------------------------- 1 |
    2 | 7 |
    8 | -------------------------------------------------------------------------------- /src/backEnd/templates/title2.html: -------------------------------------------------------------------------------- 1 |
    2 | 7 |
    8 | -------------------------------------------------------------------------------- /src/backEnd/unsupported_blocks/UnsupportedBlocksMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef UnsupportedBlocksMenu 9 | methods(Static) 10 | function schema = checkUnsupportedBlocks(callbackInfo) 11 | schema = sl_action_schema; 12 | schema.label = 'Check unsupported blocks'; 13 | schema.callback = @UnsupportedBlocksMenu.checkBlocksCallBack; 14 | end % checkUnsupportedBlocks 15 | 16 | function checkBlocksCallBack(callbackInfo) 17 | try 18 | model_full_path = UnsupportedBlocksMenu.get_file_name(gcs); 19 | unsupported_blocks_gui( model_full_path ); 20 | catch ME 21 | display_msg(ME.message,Constants.ERROR,'getCheckBlocks',''); 22 | display_msg(ME.getReport(),Constants.DEBUG,'getCheckBlocks',''); 23 | end 24 | end % checkBlocksCallBack 25 | 26 | function fname = get_file_name(gcs) 27 | names = regexp(gcs,'/','split'); 28 | fname = get_param(names{1},'FileName'); 29 | end % get_file_name 30 | 31 | end 32 | end -------------------------------------------------------------------------------- /src/backEnd/validation/ValidationMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef ValidationMenu 9 | 10 | methods(Static) 11 | function schema = validate(callbackInfo) 12 | schema = sl_action_schema; 13 | schema.label = 'Compiler Validation (Experimental)'; 14 | schema.callback = @ValidationMenu.validateCallBack; 15 | end % validate 16 | 17 | function validateCallBack(callbackInfo) 18 | try 19 | [cocoSim_path, ~, ~] = fileparts(mfilename('fullpath')); 20 | model_full_path = ValidationMenu.get_file_name(gcs) ; 21 | L = log4m.getLogger(fullfile(fileparts(model_full_path),'logfile.txt')); 22 | validate_window(model_full_path,cocoSim_path,1,L); 23 | catch ME 24 | display_msg(ME.getReport(), Constants.DEBUG,'Validate_model',''); 25 | display_msg(ME.message, Constants.ERROR,'Validate_model',''); 26 | end 27 | end % validateCallBack 28 | 29 | function fname = get_file_name(gcs) 30 | names = regexp(gcs,'/','split'); 31 | fname = get_param(names{1},'FileName'); 32 | end % get_file_name 33 | 34 | end 35 | end -------------------------------------------------------------------------------- /src/backEnd/validation/common/ValidateUtils.m: -------------------------------------------------------------------------------- 1 | classdef ValidateUtils 2 | methods (Static = true) 3 | 4 | function vector = construct_random_integers(nb_iterations, IMIN, IMAX, dt, dim) 5 | if numel(dim)==1 6 | vector = randi([IMIN, IMAX], [nb_iterations,dim],dt); 7 | else 8 | vector = randi([IMIN, IMAX], [dim,nb_iterations],dt); 9 | end 10 | end 11 | 12 | function vector = construct_random_booleans(nb_iterations, IMIN, IMAX, dim) 13 | vector = boolean(ValidateUtils.construct_random_integers(nb_iterations, IMIN, IMAX, 'uint8',dim)); 14 | end 15 | 16 | function vector = construct_random_doubles(nb_iterations, IMIN, IMAX,dim) 17 | if numel(dim)==1 18 | vector = double(IMIN + (IMAX-IMIN).*rand([nb_iterations,dim])); 19 | else 20 | vector = double(IMIN + (IMAX-IMIN).*rand([dim, nb_iterations])); 21 | end 22 | end 23 | end 24 | end 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/backEnd/verification/cocoSpecVerify/cocoSpecVerify.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Christelle Dambreville, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | function [ ] = cocoSpecVerify(model_full_path) 9 | if nargin==1 10 | [nom_lustre_file, ~, ir_struct]=cocoSpecCompiler(model_full_path); 11 | end 12 | 13 | Utils.update_status('Verification'); 14 | 15 | [output_dir, file_name, ~] = fileparts(nom_lustre_file); 16 | [models, ~] = find_mdlrefs(file_name); 17 | 18 | try 19 | SOLVER = evalin('base','SOLVER'); 20 | catch 21 | SOLVER = 'NONE'; 22 | end 23 | 24 | % Get start time 25 | t_start = now; 26 | 27 | mapping_file = strcat(output_dir,'/', file_name,'_mapping.json'); 28 | 29 | if (exist(mapping_file,'file') == 2) 30 | if not (strcmp(SOLVER, 'Z') || strcmp(SOLVER,'K') || strcmp(SOLVER, 'J')) 31 | display_msg('Available solver is K for Kind2', Constants.WARNING, 'cocoSim', ''); 32 | return 33 | end 34 | open(models{end}); 35 | if strcmp(SOLVER, 'K') 36 | display_msg('Running Kind2', Constants.INFO, 'Verification', ''); 37 | try 38 | cocoSpecKind2(nom_lustre_file, mapping_file); 39 | catch ME 40 | display_msg(ME.message, Constants.ERROR, 'Verification', ''); 41 | display_msg(ME.getReport(), Constants.DEBUG, 'Verification', ''); 42 | end 43 | end 44 | else 45 | display_msg('No property to prove', Constants.RESULT, 'Verification', ''); 46 | end 47 | 48 | t_end = now; 49 | t_compute = t_end - t_start; 50 | display_msg(['Total verification time: ' datestr(t_compute, 'HH:MM:SS.FFF')], Constants.RESULT, 'Time', ''); 51 | end 52 | -------------------------------------------------------------------------------- /src/backEnd/verification/cocoSpecVerify/utils/CocoSim_IR_Compiler-0.1-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/backEnd/verification/cocoSpecVerify/utils/CocoSim_IR_Compiler-0.1-jar-with-dependencies.jar -------------------------------------------------------------------------------- /src/backEnd/verification/lustreVerify/utils/seahorn.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function [smt_out_file] = seahorn(c_file_name) 8 | 9 | [path file ext] = fileparts(c_file_name); 10 | config; 11 | entry_function = file; 12 | display_msg(['Entry Function: ' entry_function], Constants.INFO, 'SEAHORN', ''); 13 | smt_out_file = fullfile(path, strcat(entry_function,'.smt2')); 14 | if exist(SEAHORN,'file') 15 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 16 | command = sprintf('%s smt -O0 --horn-no-verif --horn-stats --entry=%s -o %s %s', SEAHORN, entry_function, smt_out_file, c_file_name); 17 | 18 | [status, seahorn_out] = system(command); 19 | if isempty(strfind(seahorn_out, 'BRUNCH STATS END')) 20 | display_msg('Error Generating HORN Clause', Constants.ERROR, 'SEAHORN', ''); 21 | display_msg(seahorn_out, Constants.ERROR, 'SEAHORN', ''); 22 | else 23 | if exist(smt_out_file, 'file') 24 | msg = ['HORN Clauses are generated in : ' smt_out_file] ; 25 | display_msg(msg, Constants.RESULT, 'SEAHORN', ''); 26 | else 27 | display_msg('Error Generating HORN Clause', Constants.ERROR, 'SEAHORN', ''); 28 | display_msg(seahorn_out, Constants.ERROR, 'SEAHORN', ''); 29 | end 30 | end 31 | else 32 | msg = 'Running SEAHORN: Impossible to find SEAHORN'; 33 | display_msg(msg, Constants.ERROR, 'SeaHorn', ''); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /src/backEnd/verification/lustreVerify/utils/solver_result.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % Parse the XML output of Solver and return the status of the result (SAFE, CEX, UNKNOWN) 7 | function [answer, cex] = solver_result(solver, xml_result, property_node_name, property_file_base_name) 8 | answer = ''; 9 | cex = ''; 10 | prop_file_name = [property_file_base_name '_' property_node_name '.xml']; 11 | fid = fopen(prop_file_name, 'w'); 12 | fprintf(fid, xml_result); 13 | fclose(fid); 14 | s = dir(prop_file_name); 15 | if s.bytes ~= 0 16 | xml_doc = xmlread(prop_file_name); 17 | xml_properties = xml_doc.getElementsByTagName('Property'); 18 | % logs = xml_doc.getElementsByTagName('Log'); 19 | % for idx=0:(logs.getLength-1) 20 | % log = logs.item(idx); 21 | % end 22 | for idx=0:(xml_properties.getLength-1) 23 | prop = xml_properties.item(idx); 24 | answer = prop.getElementsByTagName('Answer').item(0).getTextContent; 25 | 26 | if strcmp(solver, 'KIND2') || strcmp(solver, 'JKIND') 27 | if strcmp(answer, 'valid') 28 | answer = 'SAFE'; 29 | elseif strcmp(answer, 'falsifiable') 30 | answer = 'CEX'; 31 | else 32 | answer = 'UNKNOWN'; 33 | end 34 | end 35 | 36 | msg = [solver ' result for property node [' property_node_name ']: ' char(answer)]; 37 | display_msg(msg, Constants.RESULT, 'Property checking', ''); 38 | if strcmp(answer, 'CEX') || strcmp(answer, 'falsifiable') 39 | if strcmp(solver, 'JKIND') 40 | xml_cex = xml_doc.getElementsByTagName('Counterexample'); 41 | else 42 | xml_cex = xml_doc.getElementsByTagName('CounterExample'); 43 | end 44 | if xml_cex.getLength > 0 45 | cex = xml_cex; 46 | else 47 | msg = [solver ': FAILURE to get counter example: ']; 48 | msg = [msg property_node_name '\n']; 49 | display_msg(msg, Constants.WARNING, 'Property Checking', ''); 50 | end 51 | end 52 | end 53 | end 54 | end 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/cocosim_config.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | % Configuration file for the backend solvers 8 | if ~exist('solvers_path', 'var') 9 | [file_path, ~, ~] = fileparts(mfilename('fullpath')); 10 | cocosim_path = fileparts(file_path); 11 | if ismac 12 | solvers_path = fullfile(cocosim_path, 'tools/verifiers/osx/bin/'); 13 | JKIND =fullfile(cocosim_path,'tools/verifiers/jkind/jkind'); 14 | Z3Library_path = fullfile(cocosim_path, 'tools/verifiers/osx/lib/libz3.so'); 15 | include_dir = fullfile(cocosim_path, 'tools/verifiers/osx/include/lustrec'); 16 | elseif isunix 17 | solvers_path = fullfile(cocosim_path, 'tools/verifiers/linux/bin/'); 18 | JKIND =fullfile(cocosim_path,'tools/verifiers/jkind/jkind'); 19 | Z3Library_path = fullfile(cocosim_path, 'tools/verifiers/linux/lib/libz3.so'); 20 | include_dir = fullfile(cocosim_path, 'tools/verifiers/linux/include/lustrec'); 21 | elseif ispc 22 | % warndlg('Only JKind can be used', 'CoCoSim backend configuration') 23 | solvers_path = fullfile(cocosim_path, 'tools\verifiers\'); 24 | JKIND =fullfile(solvers_path,'jkind\jkind.bat'); 25 | Z3Library_path = fullfile(cocosim_path, 'tools\verifiers\Z3\bin\libz3.dll'); 26 | else 27 | errordlg('OS not supported yet','CoCoSim backend configuration'); 28 | end 29 | OldLibPath = getenv('LD_LIBRARY_PATH'); 30 | if isempty(strfind(OldLibPath,'libz3.so')) || ~isempty(strfind(OldLibPath,'::')) 31 | setenv('LD_LIBRARY_PATH',Z3Library_path); 32 | %to keep the old LD_LIBRARY_PATH use the following (it does not work) 33 | %setenv('LD_LIBRARY_PATH',[getenv('LD_LIBRARY_PATH') Z3Library_path ':']); 34 | end 35 | end 36 | if ~ispc 37 | LUSTREC = fullfile(solvers_path,'lustrec'); 38 | LUCTREC_INCLUDE_DIR = include_dir; 39 | else 40 | %ToDo: review in windows 41 | LUSTREC = ''; 42 | LUCTREC_INCLUDE_DIR = ''; 43 | end 44 | ZUSTRE = fullfile(solvers_path,'zustre'); 45 | Z3 = fullfile(solvers_path,'z3'); 46 | KIND2 = fullfile(solvers_path,'kind2'); 47 | SEAHORN = 'PATH'; 48 | cocosim_version = 'v0.1'; 49 | -------------------------------------------------------------------------------- /src/frontEnd/IR/README.md: -------------------------------------------------------------------------------- 1 | # IR 2 | 3 | IR build an internal representation of Simulink models using matlab's struct. 4 | Here is a description of the structure of the IR : 5 | 6 | IR = {”meta” : META 7 | ”model_name” : {SUBS_IR} 8 | } 9 | 10 | META = {”date” : date 11 | ”file_path” : model_path 12 | } 13 | 14 | SUBS_IR = ”Content” : {BLOCKS_IR} 15 | 16 | BLOCKS_IR = ”block_formated_name” : {PROPERTIES} 17 | BLOCKS_IR 18 | 19 | BLOCKS_IR = ”block_formated_name” : {PROPERTIES, SUBS_IR} 20 | BLOCKS_IR 21 | 22 | BLOCKS_IR = Λ 23 | 24 | PROPERTIES = "PropertyName" : value, PROPERTIES 25 | 26 | PROPERTIES = Λ 27 | 28 | There is one particular field for each block called "Origin_path". It contains the path to the block 29 | with its original name (with space and/or line breaks). 30 | 31 | ## Configuration 32 | You can set some configuration for existing (in the doc) parameters you want in your IR in 33 | IR_config.m. 34 | For more information look at the description in IR_config. 35 | *It is possible to pre-process the IR to adapt it at your convenience and add non-existing 36 | parameters or modified values of existing parameters. 37 | 38 | ## Example 39 | You can call cocosim_IR on the example exemple/Model_example.slx file. 40 | ir_struct = cocosim_IR('exemple/Model_example', true). Add true if you want 41 | to save the struct in a json file (Model_example.json). 42 | -------------------------------------------------------------------------------- /src/frontEnd/IR/blocks/common_struct.m: -------------------------------------------------------------------------------- 1 | function [ S ] = common_struct( block_path, model_ref_parent ) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % This file is part of CoCoSim. 4 | % Copyright (C) 2014-2016 Carnegie Mellon University 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | % COMMON_STRUCT - common internal representation for all blocks 7 | % 8 | % This function create the structure for the internal representation's 9 | % parameters common to all blocks 10 | % 11 | % S = COMMON_STRUCT(file_name) 12 | 13 | % load config 14 | global block_param_map; 15 | if nargin < 2 16 | model_ref_parent = ''; 17 | end 18 | unwanted_params = block_param_map('UnwantedParameters'); 19 | 20 | %% Construction of the internal representation 21 | S = struct(); 22 | 23 | if ~isempty(model_ref_parent) 24 | full_path_model_ref = regexp(block_path, '/', 'split'); 25 | full_path_model_ref{1} = model_ref_parent; 26 | S.Path = IRUtils.name_format(fullfile(full_path_model_ref{1}, full_path_model_ref{2:end})); 27 | else 28 | S.Path = IRUtils.name_format(block_path); %modified path of the block to be a valid name 29 | end 30 | S.BlockType = get_param(block_path, 'BlockType'); 31 | S.Name = get_param(block_path, 'Name'); 32 | S.Origin_path = block_path; %origin_path of the block 33 | index = find(strcmp(unwanted_params, 'Handle'), 1); 34 | if isempty(index) 35 | S.Handle = get_param(block_path, 'Handle'); 36 | end 37 | index = find(strcmp(unwanted_params, 'LineHandles'), 1); 38 | if isempty(index) 39 | S.LineHandles = get_param(block_path, 'LineHandles'); 40 | end 41 | 42 | %% Common properties added 43 | if isKey(block_param_map, 'CommonParameters') 44 | values = block_param_map('CommonParameters'); 45 | for i=1:numel(values) 46 | index = find(strcmp(unwanted_params, values{i}), 1); 47 | if isempty(index) 48 | S.(values{i}) = get_param(block_path, values{i}); 49 | end 50 | end 51 | end 52 | 53 | end 54 | 55 | -------------------------------------------------------------------------------- /src/frontEnd/IR/blocks/specific_parameters_struct.m: -------------------------------------------------------------------------------- 1 | function [ S ] = specific_parameters_struct( block_path, block_type ) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % This file is part of CoCoSim. 4 | % Copyright (C) 2014-2016 Carnegie Mellon University 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | % SPECIFIC_PARAMETERS_STRUCT - create the internal representation of 7 | % specific parameters' blocks 8 | % 9 | % This function create the structure for the internal representation of the 10 | % specific parameters of a block_type 11 | % 12 | % S = SPECIFIC_PARAMETERS_STRUCT(file_name, block_type) 13 | 14 | % load config to filter blocks' params 15 | global block_param_map; 16 | unwanted_params = block_param_map('UnwantedParameters'); 17 | S = struct(); 18 | 19 | if isKey(block_param_map, block_type) 20 | value = block_param_map(block_type); 21 | for i=1:numel(value) 22 | index = find(strcmp(unwanted_params, value{i}), 1); 23 | if isempty(index) 24 | S.(value{i}) = get_param(block_path, value{i}); 25 | end 26 | end 27 | else 28 | % no filter, print all dialog parameters 29 | dialog_param = get_param(block_path, 'DialogParameters'); 30 | if ~isempty(dialog_param) 31 | fields = fieldnames(dialog_param); 32 | for i=1:numel(fields) 33 | index = find(strcmp(unwanted_params, fields{i}), 1); 34 | if isempty(index) 35 | S.(fields{i}) = get_param(block_path, fields{i}); 36 | end 37 | end 38 | end 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /src/frontEnd/IR/example/Model_example.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/example/Model_example.slx -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/ChartParser.jar -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/README.md: -------------------------------------------------------------------------------- 1 | # ChartParser 2 | 3 | To build the project use the command 4 | ``` 5 | mvn install 6 | ``` 7 | 8 | This will generate the file ```target/ChartParser.jar```. 9 | To deploy the jar file in CoCoSim, just replace ```CoCoSim/src/frontEnd/IR/utils/ChartParser.jar``` with the new jar file. 10 | 11 | ## State labels 12 | 13 | The parser class for state labels is [`StateParser`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/StateParser.java). It has a static function `StateParser.parse` which receives a string representing the state label and returns an object of [`StateAction`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/StateAction.java). StateParser relies on the following ANTRL grammar for state labels [`StateLabel.g4`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/StateLabel.g4). The corresponding visitor code is available in [`StateVisitor`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/StateVisitor.java). 14 | 15 | ## Transition labels 16 | 17 | The parser class for transition labels is [`TransitionParser`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/TransitionParser.java). It has a static function `TransitionParser.parse` which receives a string representing the transition label and returns an object of [`Transition`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/Transition.java). TransitionParser relies on the following ANTRL grammar for transition labels [`TransitionLabel.g4`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/TransitionLabel.g4). The corresponding visitor code is available in [`TransitionVisitor`](https://github.com/coco-team/cocoSim2/blob/master/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/TransitionVisitor.java). 18 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | import edu.uiowa.chart.state.StateAction; 11 | import edu.uiowa.chart.state.StateVisitor; 12 | import edu.uiowa.chart.state.antlr.*; 13 | import org.antlr.v4.runtime.CharStream; 14 | import org.antlr.v4.runtime.CharStreams; 15 | import org.antlr.v4.runtime.CommonTokenStream; 16 | import org.antlr.v4.runtime.tree.ParseTree; 17 | 18 | public class Main { 19 | 20 | public static void main(String[] args) 21 | { 22 | String stateLabel = "increasing\n" + 23 | "entry:\n" + 24 | "prePopulation = population;\n" + 25 | "population = prePopulation * 2.0;"; 26 | CharStream charStream = CharStreams.fromString(stateLabel); 27 | StateLabelLexer lexer = new StateLabelLexer(charStream); 28 | CommonTokenStream tokenStream = new CommonTokenStream(lexer); 29 | StateLabelParser parser = new StateLabelParser(tokenStream); 30 | 31 | ParseTree tree = parser.stateLabel(); 32 | System.out.println(tree.toStringTree(parser)); 33 | StateVisitor visitor = new StateVisitor(); 34 | StateAction stateAction = visitor.visit(tree); 35 | System.out.println(stateAction); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/StateAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | package edu.uiowa.chart.state; 11 | 12 | class OnAction 13 | { 14 | // matlab accepts double for n 15 | public double n; 16 | public String eventName=""; 17 | public String actions = ""; 18 | 19 | public OnAction(double n, String eventName, String actions) 20 | { 21 | this.n = n; 22 | this.eventName = eventName; 23 | this.actions = actions; 24 | } 25 | } 26 | 27 | public class StateAction 28 | { 29 | public String [] entry = new String[0]; 30 | public String [] during = new String[0]; 31 | public String [] exit = new String[0]; 32 | public String [] bind = new String[0]; 33 | public OnAction [] on = new OnAction[0]; 34 | public OnAction [] onAfter = new OnAction[0]; 35 | public OnAction [] onBefore = new OnAction[0]; 36 | public OnAction [] onAt = new OnAction[0]; 37 | public OnAction [] onEvery = new OnAction[0]; 38 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/StateParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | package edu.uiowa.chart.state; 11 | 12 | import edu.uiowa.chart.state.antlr.*; 13 | import org.antlr.v4.runtime.CharStream; 14 | import org.antlr.v4.runtime.CharStreams; 15 | import org.antlr.v4.runtime.CommonTokenStream; 16 | import org.antlr.v4.runtime.tree.ParseTree; 17 | 18 | public class StateParser 19 | { 20 | public static StateAction parse(String stateLabel) 21 | { 22 | CharStream charStream = CharStreams.fromString(stateLabel); 23 | StateLabelLexer lexer = new StateLabelLexer(charStream); 24 | CommonTokenStream tokenStream = new CommonTokenStream(lexer); 25 | StateLabelParser parser = new StateLabelParser(tokenStream); 26 | 27 | ParseTree tree = parser.stateLabel(); 28 | StateVisitor visitor = new StateVisitor(); 29 | StateAction stateAction = visitor.visit(tree); 30 | 31 | return stateAction; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/StateLabel.g4: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | grammar StateLabel; 11 | 12 | // parser rules 13 | 14 | stateLabel : stateName '\r'? '\n'* actions?; 15 | 16 | stateName : Identifier '/'?; 17 | 18 | actions : (action)+ ; 19 | 20 | action : actionType (',' actionType)* ':' actionBody; 21 | 22 | actionType: Entry 23 | | During 24 | | Exit 25 | | Bind 26 | | On Identifier 27 | | On After '(' Number ',' Identifier ')' 28 | | On Before '(' Number ',' Identifier ')' 29 | | On At '(' Number ',' Identifier ')' 30 | | On Every '(' Number ',' Identifier ')' 31 | ; 32 | 33 | actionBody: (.| '\r'? '\n')*? ; 34 | 35 | // lexer rules 36 | 37 | Entry : 'entry' | 'en' ; 38 | 39 | During : 'during' | 'du' ; 40 | 41 | Exit : 'exit' | 'ex' ; 42 | 43 | Bind : 'bind' ; 44 | 45 | On : 'on' ; 46 | 47 | After : 'after' ; 48 | 49 | Before : 'before' ; 50 | 51 | At : 'at' ; 52 | 53 | Every : 'every' ; 54 | 55 | Identifier : IdentifierLetter (IdentifierLetter | Digit)* ; 56 | 57 | IdentifierLetter : 'a'..'z'|'A'..'Z'|'_' ; 58 | 59 | Number : Integer | Float ; 60 | 61 | Integer : Digit+ ; 62 | 63 | Float : Digit+ '.' Digit* 64 | | '.' Digit+ ; 65 | 66 | Digit : '0'..'9' ; 67 | 68 | LineComment : '%' .*? '\n' -> skip ; 69 | 70 | WhiteSpace : [ \t\r]+ -> skip ; 71 | 72 | AnyCharacter : . ; -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/StateLabelBaseVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from StateLabel.g4 by ANTLR 4.7.1 2 | package edu.uiowa.chart.state.antlr; 3 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; 4 | 5 | /** 6 | * This class provides an empty implementation of {@link StateLabelVisitor}, 7 | * which can be extended to create a visitor which only needs to handle a subset 8 | * of the available methods. 9 | * 10 | * @param The return type of the visit operation. Use {@link Void} for 11 | * operations with no return type. 12 | */ 13 | public class StateLabelBaseVisitor extends AbstractParseTreeVisitor implements StateLabelVisitor { 14 | /** 15 | * {@inheritDoc} 16 | * 17 | *

    The default implementation returns the result of calling 18 | * {@link #visitChildren} on {@code ctx}.

    19 | */ 20 | @Override public T visitStateLabel(StateLabelParser.StateLabelContext ctx) { return visitChildren(ctx); } 21 | /** 22 | * {@inheritDoc} 23 | * 24 | *

    The default implementation returns the result of calling 25 | * {@link #visitChildren} on {@code ctx}.

    26 | */ 27 | @Override public T visitStateName(StateLabelParser.StateNameContext ctx) { return visitChildren(ctx); } 28 | /** 29 | * {@inheritDoc} 30 | * 31 | *

    The default implementation returns the result of calling 32 | * {@link #visitChildren} on {@code ctx}.

    33 | */ 34 | @Override public T visitActions(StateLabelParser.ActionsContext ctx) { return visitChildren(ctx); } 35 | /** 36 | * {@inheritDoc} 37 | * 38 | *

    The default implementation returns the result of calling 39 | * {@link #visitChildren} on {@code ctx}.

    40 | */ 41 | @Override public T visitAction(StateLabelParser.ActionContext ctx) { return visitChildren(ctx); } 42 | /** 43 | * {@inheritDoc} 44 | * 45 | *

    The default implementation returns the result of calling 46 | * {@link #visitChildren} on {@code ctx}.

    47 | */ 48 | @Override public T visitActionType(StateLabelParser.ActionTypeContext ctx) { return visitChildren(ctx); } 49 | /** 50 | * {@inheritDoc} 51 | * 52 | *

    The default implementation returns the result of calling 53 | * {@link #visitChildren} on {@code ctx}.

    54 | */ 55 | @Override public T visitActionBody(StateLabelParser.ActionBodyContext ctx) { return visitChildren(ctx); } 56 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/StateLabelVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from StateLabel.g4 by ANTLR 4.7.1 2 | package edu.uiowa.chart.state.antlr; 3 | import org.antlr.v4.runtime.tree.ParseTreeVisitor; 4 | 5 | /** 6 | * This interface defines a complete generic visitor for a parse tree produced 7 | * by {@link StateLabelParser}. 8 | * 9 | * @param The return type of the visit operation. Use {@link Void} for 10 | * operations with no return type. 11 | */ 12 | public interface StateLabelVisitor extends ParseTreeVisitor { 13 | /** 14 | * Visit a parse tree produced by {@link StateLabelParser#stateLabel}. 15 | * @param ctx the parse tree 16 | * @return the visitor result 17 | */ 18 | T visitStateLabel(StateLabelParser.StateLabelContext ctx); 19 | /** 20 | * Visit a parse tree produced by {@link StateLabelParser#stateName}. 21 | * @param ctx the parse tree 22 | * @return the visitor result 23 | */ 24 | T visitStateName(StateLabelParser.StateNameContext ctx); 25 | /** 26 | * Visit a parse tree produced by {@link StateLabelParser#actions}. 27 | * @param ctx the parse tree 28 | * @return the visitor result 29 | */ 30 | T visitActions(StateLabelParser.ActionsContext ctx); 31 | /** 32 | * Visit a parse tree produced by {@link StateLabelParser#action}. 33 | * @param ctx the parse tree 34 | * @return the visitor result 35 | */ 36 | T visitAction(StateLabelParser.ActionContext ctx); 37 | /** 38 | * Visit a parse tree produced by {@link StateLabelParser#actionType}. 39 | * @param ctx the parse tree 40 | * @return the visitor result 41 | */ 42 | T visitActionType(StateLabelParser.ActionTypeContext ctx); 43 | /** 44 | * Visit a parse tree produced by {@link StateLabelParser#actionBody}. 45 | * @param ctx the parse tree 46 | * @return the visitor result 47 | */ 48 | T visitActionBody(StateLabelParser.ActionBodyContext ctx); 49 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/antlr-4.7.1-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/antlr-4.7.1-complete.jar -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/antlr.bat: -------------------------------------------------------------------------------- 1 | java -jar antlr-4.7.1-complete.jar StateLabel.g4 -visitor -package edu.uiowa.chart.state.antlr -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/antlrForGui.bat: -------------------------------------------------------------------------------- 1 | java -jar antlr-4.7.1-complete.jar StateLabel.g4 -visitor -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/compile.bat: -------------------------------------------------------------------------------- 1 | javac *.java -cp antlr-4.7.1-complete.jar -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/grun.bat: -------------------------------------------------------------------------------- 1 | java -cp ".;antlr-4.7.1-complete.jar" org.antlr.v4.gui.TestRig StateLabel stateLabel test.txt -gui 2 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/state/antlr/test.txt: -------------------------------------------------------------------------------- 1 | increasing/ 2 | entry: 3 | prePopulation = population; 4 | population = prePopulation * 2.0; -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/Transition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | package edu.uiowa.chart.transition; 10 | 11 | public class Transition 12 | { 13 | public String eventOrMessage = ""; 14 | public String condition = ""; 15 | public String conditionAction = ""; 16 | public String transitionAction = ""; 17 | } 18 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/TransitionParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | package edu.uiowa.chart.transition; 11 | 12 | import edu.uiowa.chart.transition.antlr.TransitionLabelLexer; 13 | import edu.uiowa.chart.transition.antlr.TransitionLabelParser; 14 | import org.antlr.v4.runtime.CharStream; 15 | import org.antlr.v4.runtime.CharStreams; 16 | import org.antlr.v4.runtime.CommonTokenStream; 17 | import org.antlr.v4.runtime.tree.ParseTree; 18 | 19 | 20 | public class TransitionParser 21 | { 22 | public static Transition parse(String TransitionLabel) 23 | { 24 | CharStream charStream = CharStreams.fromString(TransitionLabel); 25 | TransitionLabelLexer lexer = new TransitionLabelLexer(charStream); 26 | CommonTokenStream tokenStream = new CommonTokenStream(lexer); 27 | TransitionLabelParser parser = new TransitionLabelParser(tokenStream); 28 | 29 | ParseTree tree = parser.transitionLabel(); 30 | TransitionVisitor visitor = new TransitionVisitor(); 31 | Transition transition = visitor.visit(tree); 32 | 33 | return transition; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/TransitionVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | package edu.uiowa.chart.transition; 11 | import edu.uiowa.chart.transition.antlr.TransitionLabelBaseVisitor; 12 | import edu.uiowa.chart.transition.antlr.TransitionLabelParser; 13 | 14 | public class TransitionVisitor extends TransitionLabelBaseVisitor 15 | { 16 | Transition transition = new Transition(); 17 | 18 | @Override 19 | public Transition visitTransitionLabel(TransitionLabelParser.TransitionLabelContext ctx) 20 | { 21 | super.visitTransitionLabel(ctx); 22 | return this.transition; 23 | } 24 | 25 | @Override 26 | public Transition visitEventOrMessage(TransitionLabelParser.EventOrMessageContext ctx) 27 | { 28 | this.transition.eventOrMessage = ctx.getText(); 29 | return this.transition; 30 | } 31 | 32 | @Override 33 | public Transition visitCondition(TransitionLabelParser.ConditionContext ctx) { 34 | this.transition.condition = ctx.getText(); 35 | return this.transition; 36 | } 37 | 38 | @Override 39 | public Transition visitConditionAction(TransitionLabelParser.ConditionActionContext ctx) 40 | { 41 | this.transition.conditionAction = ctx.getText(); 42 | return this.transition; 43 | } 44 | 45 | @Override 46 | public Transition visitTransitionAction(TransitionLabelParser.TransitionActionContext ctx) 47 | { 48 | this.transition.transitionAction = ctx.getText(); 49 | return this.transition; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/TransitionLabel.g4: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | grammar TransitionLabel; 11 | 12 | // parser rules 13 | 14 | transitionLabel : eventOrMessage? 15 | (LeftSquareBracket condition RightSquareBracket)? 16 | (LeftCurlyBracket conditionAction RightCurlyBracket)? 17 | (Slash LeftCurlyBracket transitionAction RightCurlyBracket)? ; 18 | 19 | eventOrMessage : Identifier; 20 | 21 | condition: (.)*? ; 22 | 23 | conditionAction: (.)*? ; 24 | 25 | transitionAction: (.)*? ; 26 | 27 | // lexer rules 28 | 29 | LeftSquareBracket : '[' ; 30 | 31 | RightSquareBracket : ']' ; 32 | 33 | LeftCurlyBracket : '{' ; 34 | 35 | RightCurlyBracket : '}' ; 36 | 37 | Slash : '/' ; 38 | 39 | Identifier : IdentifierLetter (IdentifierLetter | Digit)* ; 40 | 41 | IdentifierLetter : 'a'..'z'|'A'..'Z'|'_' ; 42 | 43 | Digit : '0'..'9' ; 44 | 45 | LineComment : '%' .*? '\n' -> skip ; 46 | 47 | WhiteSpace : [ \t\r]+ -> skip ; 48 | 49 | AnyCharacter : . ; -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/TransitionLabelBaseVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from TransitionLabel.g4 by ANTLR 4.7.1 2 | package edu.uiowa.chart.transition.antlr; 3 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; 4 | 5 | /** 6 | * This class provides an empty implementation of {@link TransitionLabelVisitor}, 7 | * which can be extended to create a visitor which only needs to handle a subset 8 | * of the available methods. 9 | * 10 | * @param The return type of the visit operation. Use {@link Void} for 11 | * operations with no return type. 12 | */ 13 | public class TransitionLabelBaseVisitor extends AbstractParseTreeVisitor implements TransitionLabelVisitor { 14 | /** 15 | * {@inheritDoc} 16 | * 17 | *

    The default implementation returns the result of calling 18 | * {@link #visitChildren} on {@code ctx}.

    19 | */ 20 | @Override public T visitTransitionLabel(TransitionLabelParser.TransitionLabelContext ctx) { return visitChildren(ctx); } 21 | /** 22 | * {@inheritDoc} 23 | * 24 | *

    The default implementation returns the result of calling 25 | * {@link #visitChildren} on {@code ctx}.

    26 | */ 27 | @Override public T visitEventOrMessage(TransitionLabelParser.EventOrMessageContext ctx) { return visitChildren(ctx); } 28 | /** 29 | * {@inheritDoc} 30 | * 31 | *

    The default implementation returns the result of calling 32 | * {@link #visitChildren} on {@code ctx}.

    33 | */ 34 | @Override public T visitCondition(TransitionLabelParser.ConditionContext ctx) { return visitChildren(ctx); } 35 | /** 36 | * {@inheritDoc} 37 | * 38 | *

    The default implementation returns the result of calling 39 | * {@link #visitChildren} on {@code ctx}.

    40 | */ 41 | @Override public T visitConditionAction(TransitionLabelParser.ConditionActionContext ctx) { return visitChildren(ctx); } 42 | /** 43 | * {@inheritDoc} 44 | * 45 | *

    The default implementation returns the result of calling 46 | * {@link #visitChildren} on {@code ctx}.

    47 | */ 48 | @Override public T visitTransitionAction(TransitionLabelParser.TransitionActionContext ctx) { return visitChildren(ctx); } 49 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/TransitionLabelListener.java: -------------------------------------------------------------------------------- 1 | // Generated from TransitionLabel.g4 by ANTLR 4.7.1 2 | package edu.uiowa.chart.transition.antlr; 3 | import org.antlr.v4.runtime.tree.ParseTreeListener; 4 | 5 | /** 6 | * This interface defines a complete listener for a parse tree produced by 7 | * {@link TransitionLabelParser}. 8 | */ 9 | public interface TransitionLabelListener extends ParseTreeListener { 10 | /** 11 | * Enter a parse tree produced by {@link TransitionLabelParser#transitionLabel}. 12 | * @param ctx the parse tree 13 | */ 14 | void enterTransitionLabel(TransitionLabelParser.TransitionLabelContext ctx); 15 | /** 16 | * Exit a parse tree produced by {@link TransitionLabelParser#transitionLabel}. 17 | * @param ctx the parse tree 18 | */ 19 | void exitTransitionLabel(TransitionLabelParser.TransitionLabelContext ctx); 20 | /** 21 | * Enter a parse tree produced by {@link TransitionLabelParser#eventOrMessage}. 22 | * @param ctx the parse tree 23 | */ 24 | void enterEventOrMessage(TransitionLabelParser.EventOrMessageContext ctx); 25 | /** 26 | * Exit a parse tree produced by {@link TransitionLabelParser#eventOrMessage}. 27 | * @param ctx the parse tree 28 | */ 29 | void exitEventOrMessage(TransitionLabelParser.EventOrMessageContext ctx); 30 | /** 31 | * Enter a parse tree produced by {@link TransitionLabelParser#condition}. 32 | * @param ctx the parse tree 33 | */ 34 | void enterCondition(TransitionLabelParser.ConditionContext ctx); 35 | /** 36 | * Exit a parse tree produced by {@link TransitionLabelParser#condition}. 37 | * @param ctx the parse tree 38 | */ 39 | void exitCondition(TransitionLabelParser.ConditionContext ctx); 40 | /** 41 | * Enter a parse tree produced by {@link TransitionLabelParser#conditionAction}. 42 | * @param ctx the parse tree 43 | */ 44 | void enterConditionAction(TransitionLabelParser.ConditionActionContext ctx); 45 | /** 46 | * Exit a parse tree produced by {@link TransitionLabelParser#conditionAction}. 47 | * @param ctx the parse tree 48 | */ 49 | void exitConditionAction(TransitionLabelParser.ConditionActionContext ctx); 50 | /** 51 | * Enter a parse tree produced by {@link TransitionLabelParser#transitionAction}. 52 | * @param ctx the parse tree 53 | */ 54 | void enterTransitionAction(TransitionLabelParser.TransitionActionContext ctx); 55 | /** 56 | * Exit a parse tree produced by {@link TransitionLabelParser#transitionAction}. 57 | * @param ctx the parse tree 58 | */ 59 | void exitTransitionAction(TransitionLabelParser.TransitionActionContext ctx); 60 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/TransitionLabelVisitor.java: -------------------------------------------------------------------------------- 1 | // Generated from TransitionLabel.g4 by ANTLR 4.7.1 2 | package edu.uiowa.chart.transition.antlr; 3 | import org.antlr.v4.runtime.tree.ParseTreeVisitor; 4 | 5 | /** 6 | * This interface defines a complete generic visitor for a parse tree produced 7 | * by {@link TransitionLabelParser}. 8 | * 9 | * @param The return type of the visit operation. Use {@link Void} for 10 | * operations with no return type. 11 | */ 12 | public interface TransitionLabelVisitor extends ParseTreeVisitor { 13 | /** 14 | * Visit a parse tree produced by {@link TransitionLabelParser#transitionLabel}. 15 | * @param ctx the parse tree 16 | * @return the visitor result 17 | */ 18 | T visitTransitionLabel(TransitionLabelParser.TransitionLabelContext ctx); 19 | /** 20 | * Visit a parse tree produced by {@link TransitionLabelParser#eventOrMessage}. 21 | * @param ctx the parse tree 22 | * @return the visitor result 23 | */ 24 | T visitEventOrMessage(TransitionLabelParser.EventOrMessageContext ctx); 25 | /** 26 | * Visit a parse tree produced by {@link TransitionLabelParser#condition}. 27 | * @param ctx the parse tree 28 | * @return the visitor result 29 | */ 30 | T visitCondition(TransitionLabelParser.ConditionContext ctx); 31 | /** 32 | * Visit a parse tree produced by {@link TransitionLabelParser#conditionAction}. 33 | * @param ctx the parse tree 34 | * @return the visitor result 35 | */ 36 | T visitConditionAction(TransitionLabelParser.ConditionActionContext ctx); 37 | /** 38 | * Visit a parse tree produced by {@link TransitionLabelParser#transitionAction}. 39 | * @param ctx the parse tree 40 | * @return the visitor result 41 | */ 42 | T visitTransitionAction(TransitionLabelParser.TransitionActionContext ctx); 43 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/antlr-4.7.1-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/antlr-4.7.1-complete.jar -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/antlr.bat: -------------------------------------------------------------------------------- 1 | java -jar antlr-4.7.1-complete.jar TransitionLabel.g4 -visitor -package edu.uiowa.chart.transition.antlr -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/compile.bat: -------------------------------------------------------------------------------- 1 | javac *.java -cp antlr-4.7.1-complete.jar -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/grun.bat: -------------------------------------------------------------------------------- 1 | java -cp ".;antlr-4.7.1-complete.jar" org.antlr.v4.gui.TestRig TransitionLabel transitionLabel test.txt -gui 2 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/main/java/edu/uiowa/chart/transition/antlr/test.txt: -------------------------------------------------------------------------------- 1 | [x<0] -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/ChartParser/src/test/java/edu/uiowa/chart/transition/TransitionParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of CoCoSim. 3 | * Copyright (C) 2017-2018 The University of Iowa 4 | */ 5 | 6 | /** 7 | * @author Mudathir Mahgoub 8 | */ 9 | 10 | package edu.uiowa.chart.transition; 11 | 12 | import org.junit.jupiter.api.Test; 13 | 14 | import static org.junit.jupiter.api.Assertions.*; 15 | 16 | class TransitionParserTest { 17 | 18 | @Test 19 | void parseCondition() 20 | { 21 | String transitionLabel = "[x<0]"; 22 | Transition transition = TransitionParser.parse(transitionLabel); 23 | assertEquals("x<0", transition.condition); 24 | } 25 | 26 | @Test 27 | void parseConditionBoolean() 28 | { 29 | String transitionLabel = "[p]"; 30 | Transition transition = TransitionParser.parse(transitionLabel); 31 | assertEquals("p", transition.condition); 32 | } 33 | 34 | @Test 35 | void parseConditionAction1() 36 | { 37 | String transitionLabel = "[x<0] {x =1;}"; 38 | Transition transition = TransitionParser.parse(transitionLabel); 39 | assertEquals("x<0", transition.condition); 40 | assertEquals("x=1;", transition.conditionAction); 41 | } 42 | 43 | @Test 44 | void parseConditionAction2() 45 | { 46 | String transitionLabel = "[x<0] {x =1; y = 2;}"; 47 | Transition transition = TransitionParser.parse(transitionLabel); 48 | assertEquals("x<0", transition.condition); 49 | assertEquals("x=1;y=2;", transition.conditionAction); 50 | } 51 | 52 | @Test 53 | void parseConditionActionTransitionAction() 54 | { 55 | String transitionLabel = "[x<0] {x =1; y = 2;}/{z=1;}"; 56 | Transition transition = TransitionParser.parse(transitionLabel); 57 | assertEquals("x<0", transition.condition); 58 | assertEquals("x=1;y=2;", transition.conditionAction); 59 | assertEquals("z=1;", transition.transitionAction); 60 | } 61 | } -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/IRUtils.m: -------------------------------------------------------------------------------- 1 | classdef IRUtils 2 | methods (Static = true) 3 | 4 | function str_out = name_format(str) 5 | newline = sprintf('\n'); 6 | str_out = strrep(str, newline, ''); 7 | str_out = strrep(str_out, ' ', ''); 8 | str_out = strrep(str_out, '-', '_minus_'); 9 | str_out = strrep(str_out, '+', '_plus_'); 10 | str_out = strrep(str_out, '*', '_mult_'); 11 | str_out = strrep(str_out, '.', '_dot_'); 12 | str_out = strrep(str_out, '#', '_sharp_'); 13 | str_out = strrep(str_out, '(', '_lpar_'); 14 | str_out = strrep(str_out, ')', '_rpar_'); 15 | str_out = strrep(str_out, '[', '_lsbrak_'); 16 | str_out = strrep(str_out, ']', '_rsbrak_'); 17 | str_out = strrep(str_out, '{', '_lbrak_'); 18 | str_out = strrep(str_out, '}', '_rbrak_'); 19 | %hamza modification 20 | str_out = strrep(str_out, ',', '_comma_'); 21 | % str_out = strrep(str_out, '/', '_slash_'); 22 | str_out = strrep(str_out, '=', '_equal_'); 23 | 24 | str_out = regexprep(str_out, '^([^a-zA-Z]+)', 'x$1'); 25 | str_out = regexprep(str_out, '/(\d+)', '/x$1'); 26 | str_out = regexprep(str_out, '[^a-zA-Z0-9_/]', '_'); 27 | end 28 | 29 | function st = get_BlockDiagram_SampleTime(file_name) 30 | ts = Simulink.BlockDiagram.getSampleTimes(file_name); 31 | st = 1; 32 | for t=ts 33 | if ~isempty(t.Value) && isnumeric(t.Value) 34 | tv = t.Value(1); 35 | if ~(isnan(tv) || tv==Inf) 36 | st = gcd(st*100,tv*100)/100; 37 | 38 | end 39 | end 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/get_struct.m: -------------------------------------------------------------------------------- 1 | function [Object_struct] = get_struct(ir_struct, Object, handle_struct_map) 2 | global ir_handle_struct_map; 3 | if isempty(ir_handle_struct_map) && nargin >= 3 4 | ir_handle_struct_map = handle_struct_map; 5 | elseif isempty(ir_handle_struct_map) 6 | ir_handle_struct_map = containers.Map('KeyType','double', 'ValueType','any'); 7 | end 8 | Object_struct = []; 9 | if isa(Object, 'char') 10 | path = strsplit(Object, '/'); 11 | Object_search = ir_struct; 12 | if isfield(Object_search, 'Content') 13 | Object_search = Object_search.Content; 14 | end 15 | for i=1:numel(path)-1 16 | try 17 | Object_search = Object_search.(IRUtils.name_format(path{i})).Content; 18 | catch 19 | error(['error, reference to non-existent field : ', IRUtils.name_format(path{i})]); 20 | end 21 | end 22 | try 23 | Object_struct = Object_search.(IRUtils.name_format(path{numel(path)})); 24 | catch 25 | error(['error, reference to non-existent field : ', IRUtils.name_format(path{numel(path)})]); 26 | end 27 | elseif isa(Object, 'double') 28 | if isKey(ir_handle_struct_map, Object) 29 | Object_struct = ir_handle_struct_map(Object); 30 | else 31 | if isfield(ir_struct, 'Handle') && (ir_struct.Handle == Object) 32 | Object_struct = ir_struct; 33 | elseif ~isempty(ir_struct) 34 | fields = fieldnames(ir_struct); 35 | i = 1; 36 | while i <= numel(fields) && isempty(Object_struct) 37 | field = ir_struct.(fields{i}); 38 | if isa(field, 'struct') 39 | Object_struct = get_struct(ir_struct.(fields{i}), Object); 40 | end 41 | i = i + 1; 42 | end 43 | end 44 | end 45 | else 46 | error('Error. \n Specified Object must be an id or a string of a path to a block not a %s.', class(Object)); 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/jsmn.h: -------------------------------------------------------------------------------- 1 | #ifndef __JSMN_H_ 2 | #define __JSMN_H_ 3 | 4 | #include 5 | 6 | #define JSMN_STRICT 7 | #define JSMN_PARENT_LINKS 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /** 14 | * JSON type identifier. Basic types are: 15 | * o Object 16 | * o Array 17 | * o String 18 | * o Other primitive: number, boolean (true/false) or null 19 | */ 20 | typedef enum { 21 | JSMN_PRIMITIVE = 0, 22 | JSMN_OBJECT = 1, 23 | JSMN_ARRAY = 2, 24 | JSMN_STRING = 3 25 | } jsmntype_t; 26 | 27 | typedef enum { 28 | /* Not enough tokens were provided */ 29 | JSMN_ERROR_NOMEM = -1, 30 | /* Invalid character inside JSON string */ 31 | JSMN_ERROR_INVAL = -2, 32 | /* The string is not a full JSON packet, more bytes expected */ 33 | JSMN_ERROR_PART = -3 34 | } jsmnerr_t; 35 | 36 | /** 37 | * JSON token description. 38 | * @param type type (object, array, string etc.) 39 | * @param start start position in JSON data string 40 | * @param end end position in JSON data string 41 | */ 42 | typedef struct { 43 | jsmntype_t type; 44 | int start; 45 | int end; 46 | int size; 47 | #ifdef JSMN_PARENT_LINKS 48 | int parent; 49 | #endif 50 | } jsmntok_t; 51 | 52 | /** 53 | * JSON parser. Contains an array of token blocks available. Also stores 54 | * the string being parsed now and current position in that string 55 | */ 56 | typedef struct { 57 | unsigned int pos; /* offset in the JSON string */ 58 | unsigned int toknext; /* next token to allocate */ 59 | int toksuper; /* superior token node, e.g parent object or array */ 60 | } jsmn_parser; 61 | 62 | /** 63 | * Create JSON parser over an array of tokens 64 | */ 65 | void jsmn_init(jsmn_parser *parser); 66 | 67 | /** 68 | * Run JSON parser. It parses a JSON data string into and array of tokens, each describing 69 | * a single JSON object. 70 | */ 71 | jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 72 | jsmntok_t *tokens, unsigned int num_tokens); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* __JSMN_H_ */ 79 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_decode.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_decode.c -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_decode.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_decode.m -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_decode.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_decode.mexa64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_decode.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_decode.mexmaci64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_decode.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_decode.mexw64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_encode.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_encode.c -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_encode.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_encode.m -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_encode.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_encode.mexa64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_encode.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_encode.mexmaci64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/json_encode.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/IR/utils/json_encode.mexw64 -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Jos van der Geest 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /src/frontEnd/IR/utils/make.m: -------------------------------------------------------------------------------- 1 | % 2 | % make.m 3 | % 4 | % Created by L�a Strobino. 5 | % Copyright 2015. All rights reserved. 6 | % 7 | 8 | function make(varargin) 9 | 10 | if nargin > 0 && strcmpi(varargin{1},'clean') 11 | 12 | m = mexext('all'); 13 | for k = 1:length(m) 14 | delete(['*.' m(k).ext]); 15 | end 16 | 17 | else 18 | 19 | mex json_decode.c jsmn.c 20 | mex json_encode.c 21 | 22 | end 23 | -------------------------------------------------------------------------------- /src/frontEnd/pp/PreprocessingMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef PreprocessingMenu 9 | methods(Static) 10 | 11 | % Function to pre-process and simplify the Simulink model 12 | function schema = preprocess(callbackInfo) 13 | schema = sl_action_schema; 14 | schema.label = 'Simplifier'; 15 | schema.callback = @PreprocessingMenu.preprocessCallBack; 16 | end % preprocess 17 | 18 | function preprocessCallBack(callbackInfo) 19 | try 20 | [prog_path, fname, ext] = fileparts(mfilename('fullpath')); 21 | addpath(fullfile(prog_path, 'pp')); 22 | simulink_name = PreprocessingMenu.get_file_name(gcs);%gcs; 23 | pp_model = cocosim_pp(simulink_name); 24 | load_system(char(pp_model)); 25 | catch ME 26 | display_msg(ME.getReport(),Constants.DEBUG,'getPP',''); 27 | display_msg(ME.message,Constants.ERROR,'getPP',''); 28 | end 29 | end 30 | 31 | 32 | function fname = get_file_name(gcs) 33 | names = regexp(gcs,'/','split'); 34 | fname = get_param(names{1},'FileName'); 35 | end % get_file_name 36 | 37 | end 38 | 39 | end 40 | 41 | -------------------------------------------------------------------------------- /src/frontEnd/pp/README: -------------------------------------------------------------------------------- 1 | ------------------------ 2 | Pre-Processor (PP) for cocoSim 3 | ------------------------ 4 | 5 | 6 | ------------------------ 7 | REQUIREMENTS 8 | ------------------------ 9 | - Matlab r2014b or newer 10 | - Simulink 11 | - Python 12 | 13 | ------------------------ 14 | INSTRUCTIONS 15 | ------------------------ 16 | To use PP which converts a Simulink model into a CoCoSim-friendly one, 17 | open Matlab and add the folder where the script pp.m is to the Matlab 18 | path (usually add 'pp' using the right click and the option 19 | 'Add to path' then 'Selected Folders and subfolders'). 20 | Then go to the folder where is located the Simulink model you want to 21 | process (using cd or the Matlab browser) and type the following command : 22 | pp('filename') 23 | 24 | If the Simulink model needs the definition of constants in order to run, 25 | you have to give a .m file containing these values to PP with 26 | the command : 27 | pp('filename','constant_filename') 28 | 29 | You have to give the complete name of the files, including the extension 30 | as follow : 31 | pp('model.slx') or 32 | pp('model.slx','model_constants.m') 33 | 34 | PP will create : 35 | - modelname_p.slx or .mdl file which contains the CoCoSim-friendly model in 36 | the same file format as the model processed. 37 | - modelname_pp.mdl file which contains the CoCoSim-friendly model in the 38 | Matlab r2008b compatible file format, which is supported by CoCoSim. 39 | 40 | ------------------------ 41 | OPTIONS 42 | ------------------------ 43 | You can call PP with the 'verif' option which will create some 44 | simulink models containing every block processed and the block generated by 45 | PP side by side. Those models are stored in the "Verification" 46 | folder. The command is : 47 | pp('model.slx','model_constants.m','verif') or 48 | pp('model.slx','','verif') if no constant file is required 49 | 50 | ------------------------ 51 | DETAILS 52 | ------------------------ 53 | PP needs to compile the model during its execution, if it lacks 54 | values of certain parameters for example, be aware that the preprocessing 55 | will fail. 56 | 57 | Matlab r2014b is required because of its python capabilities. 58 | If you want to use PP in an older version of Matlab, you can, but any 59 | call of the Python parser script will fail and you will get error messages 60 | in the console each time this python script is called. 61 | That means that blocks needing parsing to be processed (fcn, gain and 62 | constants with calculation for example) won't be processed, nevertheless 63 | all other blocks will be processed normally. -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/chart_process.m: -------------------------------------------------------------------------------- 1 | function [ ] = chart_process( model ) 2 | %CHART_PROCESS change all charts to use Strong data typing with Simulink 3 | %I/O 4 | 5 | 6 | rt = sfroot; 7 | m = rt.find('-isa','Stateflow.Machine','Name',model); 8 | chartArr = m.find('-isa','Stateflow.Chart'); 9 | if not(isempty(chartArr)) 10 | display_msg('Processing Charts...', Constants.INFO, 'chart_process', ''); 11 | for i=1:numel(chartArr) 12 | chart = chartArr(i); 13 | display_msg(chart.Name, Constants.INFO, 'chart_process', ''); 14 | chart.StrongDataTypingWithSimulink = 1; 15 | end 16 | display_msg('Done\n\n', Constants.INFO, 'chart_process', ''); 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/clock_process.m: -------------------------------------------------------------------------------- 1 | function [] = clock_process(model) 2 | % CLOCK_PROCESS Searches for clock blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Clock blocks 7 | clock_list = find_system(model,'BlockType','Clock'); 8 | if not(isempty(clock_list)) 9 | display_msg('Processing Clock blocks...', Constants.INFO, 'clock_process', ''); 10 | for i=1:length(clock_list) 11 | display_msg(clock_list{i}, Constants.INFO, 'clock_process', ''); 12 | replace_one_block(clock_list{i},'gal_lib/clock'); 13 | % TODO : get the model sample time 14 | try 15 | clock_sample = Utils.get_BlockDiagram_SampleTime(file_name); 16 | if clock_sample==0 || isnan(clock_sample) || clock_sample==Inf 17 | clock_sample = 1; 18 | end 19 | catch 20 | clock_sample = BlockUtils.clock_sample; 21 | end 22 | set_param(strcat(clock_list{i},'/Sample'),'Gain', num2str(clock_sample)); 23 | end 24 | display_msg('Done\n\n', Constants.INFO, 'clock_process', ''); 25 | end 26 | end 27 | 28 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/deadzone_dynamic_process.m: -------------------------------------------------------------------------------- 1 | function [] = deadzone_dynamic_process(model) 2 | % DEADZONE_DYNAMIC_PROCESS Searches for deadzone dynamic blocks and 3 | % replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Dead Zone Dynamic blocks 7 | deadzone_dyn_list = find_system(model,'MaskType','Dead Zone Dynamic'); 8 | if not(isempty(deadzone_dyn_list)) 9 | display_msg('Processing Dead Zone Dynamic blocks...', Constants.INFO, 'deadzone_dynamic_process', ''); 10 | for i=1:length(deadzone_dyn_list) 11 | display_msg(deadzone_dyn_list{i}, Constants.INFO, 'deadzone_dynamic_process', ''); 12 | replace_one_block(deadzone_dyn_list{i},'gal_lib/deadzone_dyn'); 13 | end 14 | display_msg('Done\n\n', Constants.INFO, 'deadzone_dynamic_process', ''); 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/deadzone_process.m: -------------------------------------------------------------------------------- 1 | function [] = deadzone_process(model) 2 | % DEADZONE_PROCESS Searches for deadzone blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Deadzone blocks 7 | deadzone_list = find_system(model,'BlockType','DeadZone'); 8 | if not(isempty(deadzone_list)) 9 | display_msg('Processing Deadzone blocks...', Constants.INFO, 'deadzone_process', ''); 10 | for i=1:length(deadzone_list) 11 | display_msg(deadzone_list{i}, Constants.INFO, 'deadzone_process', ''); 12 | lower_value = get_param(deadzone_list{i},'LowerValue'); 13 | upper_value = get_param(deadzone_list{i},'UpperValue'); 14 | SaturateOnIntegerOverflow = get_param(deadzone_list{i},'SaturateOnIntegerOverflow'); 15 | replace_one_block(deadzone_list{i},'gal_lib/deadzone'); 16 | set_param(strcat(deadzone_list{i},'/lower_value'),... 17 | 'Value',lower_value); 18 | set_param(strcat(deadzone_list{i},'/upper_value'),... 19 | 'Value',upper_value); 20 | set_param(strcat(deadzone_list{i},'/Add'),... 21 | 'SaturateOnIntegerOverflow',SaturateOnIntegerOverflow); 22 | end 23 | display_msg('Done\n\n', Constants.INFO, 'deadzone_process', ''); 24 | end 25 | end 26 | 27 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/from_workspace_process.m: -------------------------------------------------------------------------------- 1 | function [] = from_workspace_process(model) 2 | % FROM_WORKSPACE_PROCESS Searches for From Workspace blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | Xinit = -1; 7 | 8 | % Processing From Workspace blocks 9 | from_workspace_list = find_system(model,'BlockType','FromWorkspace'); 10 | if not(isempty(from_workspace_list)) 11 | display_msg('Processing From Workspace blocks...', Constants.INFO, 'from_workspace_process', ''); 12 | for i=1:length(from_workspace_list) 13 | display_msg(from_workspace_list{i}, Constants.INFO, 'from_workspace_process', ''); 14 | tag = get_param(from_workspace_list{i},'VariableName'); 15 | 16 | parent = get_param(from_workspace_list{i},'Parent'); 17 | if strcmp(parent,model) 18 | replace_one_block(from_workspace_list{i},'built-in/Inport'); 19 | set_param(from_workspace_list{i},'Name',tag); 20 | else 21 | % Create a goto/from pattern that will be replaced after 22 | replace_one_block(from_workspace_list{i},'built-in/From'); 23 | set_param(from_workspace_list{i},'GotoTag',tag); 24 | set_param(from_workspace_list{i},'TagVisibility','global'); 25 | goto_block = strcat(model,'/tag_',tag); 26 | add_block('built-in/Goto',goto_block,... 27 | 'Position',pos(Xinit,i,'h',15)); 28 | set_param(goto_block,'GotoTag',tag); 29 | set_param(goto_block,'TagVisibility','global'); 30 | add_block('built-in/Inport',strcat(model,'/',tag),... 31 | 'Position',pos(Xinit-1,i,'h',15)); 32 | add_line(model,strcat(tag,'/1'),... 33 | strcat('tag_',tag,'/1')); 34 | % Replace the goto/from pattern 35 | goto_block_process(model,goto_block); 36 | end 37 | end 38 | display_msg('Done\n\n', Constants.INFO, 'from_workspace_process', ''); 39 | end 40 | end 41 | 42 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/gain_process.m: -------------------------------------------------------------------------------- 1 | function [] = gain_process(model) 2 | % GAIN_PROCESS Searches for gain blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Gain blocks 7 | gain_list = find_system(model,'BlockType','Gain'); 8 | if not(isempty(gain_list)) 9 | display_msg('Processing Gains blocks...', Constants.INFO, 'gain_process', ''); 10 | for i=1:length(gain_list) 11 | gain_block_process(gain_list{i}); 12 | end 13 | display_msg('Done\n\n', Constants.INFO, 'gain_process', ''); 14 | end 15 | end 16 | 17 | function err = gain_block_process(init_block) 18 | % GAIN_BLOCK_PROCESS analyses the value of a gain block and if it this 19 | % value needs to be calculated, it converts the calculation into blocks, 20 | % then replaces the block by its equivalent. 21 | % The function returns : 22 | % 0 if the function has been completed without any error. 23 | % 1 if an error occured during the execution of the function. 24 | % This can happen if a parse error occured or a function is not handled, 25 | % then the details of the error are dispayed in the command line. 26 | 27 | err = 0; 28 | 29 | gain = get_param(init_block,'Gain'); 30 | % Obtaining a tree from the matlab expression 31 | try 32 | tree = parse_math(gain); 33 | catch error 34 | msg = sprintf('%s%s%s\n%s\n',... 35 | 'error occured while parsing the expression : "',gain,... 36 | '" of block :',init_block); 37 | display_msg(msg, Constants.WARNING, 'gain_process', ''); 38 | if not(strcmp('Python:BadMatlabVersion',error.identifier)) 39 | display_msg('the block will be processed by the compiler\n', Constants.WARNING, 'gain_process', ''); 40 | end 41 | err = 1; 42 | tree = 'err'; % To go threw the next if test 43 | display_msg(error.message, Constants.DEBUG, 'gain_process', ''); 44 | return; 45 | end 46 | 47 | % If the gain contains a complex expression and needs processing 48 | if isa(tree,'cell') 49 | new_block = strcat(init_block,'_p'); 50 | % Creating a block from the expression 51 | % The variable 'u' is added to represent the input 52 | gain = strcat('u*(',gain,')'); 53 | success = expression_process(gain,new_block); 54 | if not(success) 55 | msg = sprintf('The block %s has to be handled manually\n',init_block); 56 | display_msg(msg, Constants.DEBUG, 'gain_process', ''); 57 | else 58 | display_msg('init_block', Constants.INFO, 'gain_process', ''); 59 | replace_one_block(init_block,new_block); 60 | delete_block(new_block); 61 | end 62 | end 63 | 64 | end -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/goto_process.m: -------------------------------------------------------------------------------- 1 | function [] = goto_process(model) 2 | % GOTO_PROCESS Searches for goto/from pattern and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | goto_list = find_system(model,'LookUnderMasks', 'all', 'BlockType','Goto'); 6 | if not(isempty(goto_list)) 7 | display_msg('Processing Goto/From blocks...', Constants.INFO, 'goto_process', ''); 8 | for i=1:length(goto_list) 9 | display_msg(goto_list{i}, Constants.INFO, 'goto_process', ''); 10 | goto_block_process(model,goto_list{i}); 11 | end 12 | display_msg('Done\n\n', Constants.INFO, 'goto_process', ''); 13 | end 14 | end 15 | 16 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/link_process.m: -------------------------------------------------------------------------------- 1 | function link_process( new_model_base ) 2 | %LINK_PROCESS disable all links 3 | 4 | lib_ss=libinfo (new_model_base); 5 | if not(isempty(lib_ss)) 6 | display_msg('Processing links', MsgType.INFO, 'PP', ''); 7 | for i=1:length(lib_ss) 8 | %disp(lib_ss(i)) 9 | try 10 | set_param(lib_ss(i).Block,'LinkStatus','none') 11 | catch 12 | end 13 | end 14 | display_msg('Done\n\n', MsgType.INFO, 'PP', ''); 15 | end 16 | 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/lookuptable_nD_process.m: -------------------------------------------------------------------------------- 1 | function [] = lookuptable_nD_process(model) 2 | % LOOKUPTABLE_ND_PROCESS Searches for lookuptable blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Lookup table n_D blocks 7 | lookup_nD_list = find_system(model,'BlockType','Lookup_n-D'); 8 | if not(isempty(lookup_nD_list)) 9 | display_msg('Processing Lookup table n-D blocks...', Constants.INFO,... 10 | 'lookuptable_nD_process', ''); 11 | for i=1:length(lookup_nD_list) 12 | display_msg(lookup_nD_list{i}, Constants.INFO, ... 13 | 'lookuptable_nD_process', ''); 14 | new_block_name = lookuptable_nD_block_process(lookup_nD_list{i}); 15 | replace_one_block(lookup_nD_list{i},new_block_name); 16 | delete_block(new_block_name) 17 | end 18 | display_msg('Done\n\n', Constants.INFO, 'lookuptable_nD_process', ''); 19 | end 20 | end 21 | 22 | function [new_block] = lookuptable_nD_block_process(init_block) 23 | % LOOKUPTABLE_ND_BLOCK_PROCESS Changes the lookup table into a 24 | % GAL-friendly block. 25 | % init_block is a sting containing the name of 26 | % the block to process. 27 | % ONLY HANDLE 1D LOOKUP TABLES FOR NOW 28 | 29 | % Obtaining tables 30 | if eval(get_param(init_block, 'NumberOfTableDimensions')) > 1 31 | display_msg('Only 1D lookup table', Constants.ERROR, ... 32 | 'lookuptable_nD_process', ''); 33 | error('Only 1D lookup table'); 34 | end 35 | 36 | indexes = eval(get_param(init_block, 'BreakpointsForDimension1')); 37 | datatable = eval(get_param(init_block, 'Table')); 38 | 39 | if size(indexes) ~= size(datatable) 40 | if size(indexes) ~= size(datatable') 41 | display_msg('Incompatible dimension for indexes and data',... 42 | Constants.ERROR, 'lookuptable_nD_process', ''); 43 | error('Incompatible dimension for indexes and data'); 44 | else 45 | % We have to transpose one of them 46 | if size(indexes,1) > 1 47 | indexes= indexes'; 48 | else 49 | datatable=datatable'; 50 | end 51 | end 52 | end 53 | 54 | new_block = strcat(init_block,'_p'); 55 | datatable_process(indexes,datatable,new_block); 56 | 57 | end 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/lookuptable_process.m: -------------------------------------------------------------------------------- 1 | function [] = lookuptable_process(model) 2 | % LOOKUPTABLE_PROCESS Searches for lookuptable blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Lookup table blocks 7 | lookup_list = find_system(model,'BlockType','Lookup'); 8 | if not(isempty(lookup_list)) 9 | display_msg('Processing Lookup table blocks...', Constants.INFO, 'lookuptable_process', ''); 10 | for i=1:length(lookup_list) 11 | display_msg(lookup_list{i}, Constants.INFO, 'lookuptable_process', ''); 12 | new_block_name = lookuptable_block_process(lookup_list{i}); 13 | replace_one_block(lookup_list{i},new_block_name); 14 | delete_block(new_block_name) 15 | end 16 | display_msg('Done\n\n', Constants.INFO, 'lookuptable_process', ''); 17 | end 18 | end 19 | 20 | function [new_block] = lookuptable_block_process(init_block) 21 | % LOOKUPTABLE_BLOCK_PROCESS Changes the lookup table into a 22 | % GAL-friendly block. 23 | % init_block is a sting containing the name of 24 | % the block to process. 25 | 26 | % Obtaining tables 27 | try 28 | indexes = eval(get_param(init_block, 'InputValues')); 29 | catch 30 | indexes = evalin('base',get_param(init_block, 'InputValues')); 31 | end 32 | try 33 | datatable = eval(get_param(init_block, 'Table')); 34 | catch 35 | datatable = evalin('base',get_param(init_block, 'Table')); 36 | end 37 | new_block = strcat(init_block,'_p'); 38 | datatable_process(indexes,datatable,new_block); 39 | 40 | end -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/math_process.m: -------------------------------------------------------------------------------- 1 | function [] = math_process(model) 2 | % MATH_PROCESS Searches for Math blocks with unsupported functions 3 | % and replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Math unsupported blocks 7 | math_list = find_system(model,'BlockType','Math'); 8 | if not(isempty(math_list)) 9 | display_msg('Processing Math blocks...', Constants.INFO, ... 10 | 'math_process', ''); 11 | for i=1:length(math_list) 12 | func = get_param(math_list{i},'Operator'); 13 | switch func 14 | case 'magnitude^2' 15 | disp(math_list{i}) 16 | display_msg(math_list{i}, Constants.INFO,... 17 | 'math_process', ''); 18 | new_block = strcat(math_list{i},'_p'); 19 | expression_process('u^2',new_block,1); 20 | replace_one_block(math_list{i},new_block); 21 | delete_block(new_block); 22 | %otherwise 23 | % The function is natively supported by GAL : nothing to 24 | % do. 25 | end 26 | end 27 | display_msg('Done\n\n', Constants.INFO, 'math_process', ''); 28 | end 29 | end 30 | 31 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/rate_transition_process.m: -------------------------------------------------------------------------------- 1 | function [] = rate_transition_process(model) 2 | % RATE_TRANSITION_PROCESS Searches for Rate Transition blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | % THIS VERSION OF THE PROCESS ONLY HANDLE THE INITIAL CONDITION OF THE 6 | % BLOCK AND DOESN'T HAS THE BEHAVIOUR OF THE INITIAL BLOCK 7 | 8 | % Processing Rate Transition blocks 9 | rt_list = find_system(model,'BlockType','RateTransition'); 10 | if not(isempty(rt_list)) 11 | disp('Processing Rate Transition blocks...') 12 | display_msg('Processing Rate Transition blocks...', Constants.INFO, ... 13 | 'rate_transition_process', ''); 14 | for i=1:length(rt_list) 15 | display_msg(rt_list{i}, Constants.INFO, 'rate_transition_process', ''); 16 | sample = get_param(rt_list{i},'OutPortSampleTime'); 17 | X0 = get_param(rt_list{i},'X0'); 18 | replace_one_block(rt_list{i},'gal_lib/rate_transition'); 19 | set_param(strcat(rt_list{i},'/UnitDelay'),'SampleTime',sample); 20 | set_param(strcat(rt_list{i},'/Sum'),'SampleTime',sample); 21 | set_param(strcat(rt_list{i},'/Init'),'Value',X0); 22 | end 23 | display_msg('Done\n\n', Constants.INFO, 'rate_transition_process', ''); 24 | end 25 | end 26 | 27 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/rename_numerical_prefix.m: -------------------------------------------------------------------------------- 1 | function [] = rename_numerical_prefix(model) 2 | % RENAME_NUMERICAL_PREFIX Replaces all blocks which name starts with a 3 | % number by a prefix xx 4 | 5 | % Processing all blocks 6 | block_list = find_system(model,'Regexp','on','Name','^[0-9]'); 7 | if not(isempty(block_list)) 8 | disp('Processing numerical-prefix blocks...') 9 | display_msg('Processing numerical-prefix blocks...', Constants.INFO, ... 10 | 'rename_numerical_prefix', ''); 11 | for i=1:length(block_list) 12 | display_msg(block_list{i}, Constants.INFO, 'rename_numerical_prefix', ''); 13 | name = get_param(block_list{i},'Name'); 14 | set_param(block_list{i},'Name',['xx' name]); 15 | end 16 | display_msg('Done\n\n', Constants.INFO, 'rename_numerical_prefix', ''); 17 | end 18 | end 19 | 20 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/saturation_dynamic_process.m: -------------------------------------------------------------------------------- 1 | function [] = saturation_dynamic_process(model) 2 | % SATURATION_DYNAMIC_PROCESS Searches for saturation_dynamic blocks and 3 | % replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Saturation Dynamic blocks 7 | sat_dyn_list = find_system(model,'MaskType','Saturation Dynamic'); 8 | if not(isempty(sat_dyn_list)) 9 | display_msg('Processing Saturation Dynamic blocks...', Constants.INFO, ... 10 | 'saturation_dynamic_process', ''); 11 | for i=1:length(sat_dyn_list) 12 | display_msg(sat_dyn_list{i}, Constants.INFO, ... 13 | 'saturation_dynamic_process', ''); 14 | outputDataType = get_param(sat_dyn_list{i}, 'OutDataTypeStr'); 15 | 16 | replace_one_block(sat_dyn_list{i},'gal_lib/saturation_dyn'); 17 | if ~strcmp(outputDataType, 'Inherit: Same as second input') 18 | set_param(strcat(sat_dyn_list{i},'/upper'),... 19 | 'OutDataTypeStr',outputDataType); 20 | set_param(strcat(sat_dyn_list{i},'/lower'),... 21 | 'OutDataTypeStr',outputDataType); 22 | end 23 | end 24 | display_msg('Done\n\n', Constants.INFO, ... 25 | 'saturation_dynamic_process', ''); 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/saturation_process.m: -------------------------------------------------------------------------------- 1 | function [] = saturation_process(model) 2 | % SATURATION_PROCESS Searches for saturation blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Saturation blocks 7 | saturation_list = find_system(model,'BlockType','Saturate'); 8 | if not(isempty(saturation_list)) 9 | disp('Processing Saturation blocks...') 10 | display_msg('Processing Saturation blocks...', Constants.INFO,... 11 | 'saturation_process', ''); 12 | for i=1:length(saturation_list) 13 | display_msg(saturation_list{i}, Constants.INFO, ... 14 | 'saturation_process', ''); 15 | lower_limit = get_param(saturation_list{i},'LowerLimit'); 16 | upper_limit = get_param(saturation_list{i},'UpperLimit'); 17 | outputDataType = get_param(saturation_list{i}, 'OutDataTypeStr'); 18 | 19 | replace_one_block(saturation_list{i},'gal_lib/saturation'); 20 | set_param(strcat(saturation_list{i},'/lower_limit'),... 21 | 'Value',lower_limit); 22 | set_param(strcat(saturation_list{i},'/upper_limit'),... 23 | 'Value',upper_limit); 24 | if ~contains(outputDataType, 'Same as input') 25 | set_param(strcat(saturation_list{i},'/upper_limit'),... 26 | 'OutDataTypeStr',outputDataType); 27 | set_param(strcat(saturation_list{i},'/lower_limit'),... 28 | 'OutDataTypeStr',outputDataType); 29 | else 30 | %Inherit: Inherit via back propagation 31 | set_param(strcat(saturation_list{i},'/upper_limit'),... 32 | 'OutDataTypeStr','Inherit: Inherit via back propagation'); 33 | set_param(strcat(saturation_list{i},'/lower_limit'),... 34 | 'OutDataTypeStr','Inherit: Inherit via back propagation'); 35 | end 36 | end 37 | display_msg('Done\n\n', Constants.INFO, 'saturation_process', ''); 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/to_workspace_process.m: -------------------------------------------------------------------------------- 1 | function [] = to_workspace_process(model) 2 | % TO_WORKSPACE_PROCESS Searches for To Workspace blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | Xinit = 30; 7 | 8 | % Processing To Workspace blocks 9 | to_workspace_list = find_system(model,'BlockType','ToWorkspace'); 10 | if not(isempty(to_workspace_list)) 11 | display_msg('Processing To Workspace blocks...', Constants.INFO,... 12 | 'to_workspace_process', ''); 13 | for i=1:length(to_workspace_list) 14 | display_msg(to_workspace_list{i}, Constants.INFO, ... 15 | 'to_workspace_process', ''); 16 | tag = get_param(to_workspace_list{i},'VariableName'); 17 | 18 | parent = get_param(to_workspace_list{i},'Parent'); 19 | if strcmp(parent,model) 20 | replace_one_block(to_workspace_list{i},'built-in/Outport'); 21 | set_param(to_workspace_list{i},'Name',tag); 22 | else 23 | % Create a goto/from pattern that will be replaced after 24 | replace_one_block(to_workspace_list{i},'built-in/Goto'); 25 | set_param(to_workspace_list{i},'GotoTag',tag); 26 | set_param(to_workspace_list{i},'TagVisibility','global'); 27 | from_block = strcat(model,'/tag_',tag); 28 | add_block('built-in/From',from_block,... 29 | 'Position',pos(Xinit,i,'h',15)); 30 | set_param(from_block,'GotoTag',tag); 31 | set_param(from_block,'TagVisibility','global'); 32 | add_block('built-in/Outport',strcat(model,'/',tag),... 33 | 'Position',pos(Xinit+1,i,'h',15)); 34 | add_line(model,strcat('tag_',tag,'/1'),... 35 | strcat(tag,'/1')); 36 | % Replace the goto/from pattern 37 | goto_block_process(model,to_workspace_list{i}); 38 | end 39 | end 40 | display_msg('Done\n\n', Constants.INFO, 'to_workspace_process', ''); 41 | end 42 | end 43 | 44 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/transfer_function_process.m: -------------------------------------------------------------------------------- 1 | function [] = transfer_function_process(model) 2 | % TRANSFER_FCN_PROCESS Searches for transfer function blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Transfer Functions blocks 7 | transfer_function_list = find_system(model,'BlockType','TransferFcn'); 8 | 9 | transfer_function_list = [transfer_function_list; find_system(model,'BlockType','DiscreteTransferFcn')]; 10 | 11 | if not(isempty(transfer_function_list)) 12 | % Apply the z-transform to the function block 13 | display_msg('Processing Transfer Functions blocks...', Constants.INFO,... 14 | 'transfer_function_process', ''); 15 | for i=1:length(transfer_function_list) 16 | display_msg(transfer_function_list{i}, Constants.INFO, 'transfer_function_process', ''); 17 | new_block_name = transfer_fcn_block_process(transfer_function_list{i}); 18 | replace_one_block(transfer_function_list{i},new_block_name); 19 | delete_block(new_block_name) 20 | end 21 | display_msg('Done\n\n', Constants.INFO, 'transfer_function_process', ''); 22 | end 23 | end 24 | 25 | function [new_block] = transfer_fcn_block_process(init_block) 26 | % TRANSFER_FCN_BLOCK_PROCESS Operates the ztransform over the specified 27 | % block. 28 | % init_block is a sting containing the name of 29 | % the block to process. 30 | 31 | % Obtaining z-expression parameters 32 | denum = get_param(init_block, 'Denominator'); 33 | denum = evalin('base',denum); 34 | num = get_param(init_block, 'Numerator'); 35 | num = evalin('base',num); 36 | %change from s domaine to z domaine 37 | blocktype= get_param(init_block, 'BlockType'); 38 | if strcmp(blocktype, 'TransferFcn') 39 | try 40 | Hc = tf(num, denum); 41 | Hd = c2d(Hc,1);% we suppose sample time is 1 42 | num_d = Hd.Numerator{:}; 43 | denum_d = Hd.Denominator{:}; 44 | catch 45 | num_d = num; 46 | denum_d = denum; 47 | end 48 | else 49 | num_d = num; 50 | denum_d = denum; 51 | end 52 | % Computing state space representation 53 | [A,B,C,D]=tf2ss(num_d,denum_d); 54 | 55 | % Generating null Initial Conditions 56 | sizeA=size(A); 57 | n = sizeA(1); 58 | IC = zeros(1,n); 59 | 60 | % Generate the new_block 61 | new_block = strcat(init_block,'_p'); 62 | state_matrix_process(A,B,C,D,IC,new_block); 63 | end 64 | 65 | -------------------------------------------------------------------------------- /src/frontEnd/pp/blocks/zero_pole_process.m: -------------------------------------------------------------------------------- 1 | function [] = zero_pole_process(model) 2 | % ZERO_POLE_PROCESS Searches for zero-pole blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing ZeroPole defined transfer functions blocks 7 | zero_pole_list = find_system(model,'BlockType','ZeroPole'); 8 | if not(isempty(zero_pole_list)) 9 | % Apply the z-transform to the zero-pole block 10 | display_msg('Processing ZeroPole defined transfer function blocks...',... 11 | Constants.INFO, 'zero_pole_process', ''); 12 | for i=1:length(zero_pole_list) 13 | display_msg(zero_pole_list{i}, Constants.INFO, ... 14 | 'zero_pole_process', ''); 15 | new_block_name = zero_pole_block_process(zero_pole_list{i}); 16 | replace_one_block(zero_pole_list{i},new_block_name); 17 | delete_block(new_block_name) 18 | end 19 | display_msg('Done\n\n', Constants.INFO, 'zero_pole_process', ''); 20 | end 21 | end 22 | 23 | function [new_block] = zero_pole_block_process(init_block) 24 | % ZERO_POLE_BLOCK_PROCESS Operates the ztransform over the specified block. 25 | % init_block is a sting containing the name of 26 | % the block to process. 27 | 28 | % Obtaining z-expression parameters 29 | zeros1 = eval(get_param(init_block, 'Zeros')); 30 | poles = eval(get_param(init_block, 'Poles')); 31 | gain = eval(get_param(init_block, 'Gain')); 32 | % Computing state space representation 33 | [A,B,C,D]=zp2ss(zeros1,poles,gain); 34 | 35 | % Generating null Initial Conditions 36 | sizeA=size(A); 37 | n = sizeA(1); 38 | IC = zeros(1,n); 39 | 40 | % Generate the new_block 41 | new_block = strcat(init_block,'_p'); 42 | state_matrix_process(A,B,C,D,IC,new_block); 43 | end 44 | 45 | -------------------------------------------------------------------------------- /src/frontEnd/pp/common/gal_lib.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/pp/common/gal_lib.slx -------------------------------------------------------------------------------- /src/frontEnd/pp/common/pos.m: -------------------------------------------------------------------------------- 1 | function [position] = pos(offset_x, offset_y,varargin) 2 | % Generate a position array 3 | x = 30; 4 | y = 30; 5 | w = 30; 6 | h = 30; 7 | offset = 60; 8 | if nargin>2 9 | for i=1:2:(nargin-2) 10 | switch varargin{i} 11 | case 'w' 12 | % width specified 13 | w = varargin{i+1}; 14 | case 'h' 15 | % height specified 16 | h = varargin{i+1}; 17 | otherwise 18 | throw(MException(Pos:Options,'Wrong option')) 19 | end 20 | end 21 | end 22 | position = [x+offset*offset_x y+offset*offset_y x+offset*offset_x+w y+offset*offset_y+h]; 23 | end -------------------------------------------------------------------------------- /src/frontEnd/pp/common/remove_line_tags.m: -------------------------------------------------------------------------------- 1 | function [] = remove_line_tags(file_name, tags) 2 | % REMOVE_TAGS searches for each component of tags in the provided file 3 | % and suppress the ENTIRE LINE where the tag is located. 4 | 5 | if strcmp(class(tags),'char') 6 | expr = tags; 7 | else 8 | expr = tags{1}; 9 | for i=2:length(tags) 10 | expr = strcat(expr,'|',tags{i}); 11 | end 12 | end 13 | system(['LANG=C && sed -Ei '''' "/' expr '/d" "' file_name '"']); 14 | 15 | end 16 | 17 | -------------------------------------------------------------------------------- /src/frontEnd/pp/common/replace_one_block.m: -------------------------------------------------------------------------------- 1 | function [] = replace_one_block(block,new_block,varargin) 2 | % REPLACE_ONE_BLOCK replaces block by the new block. 3 | % Full path must be provided. 4 | % If the global variable 'verif' is true, this function also creates a 5 | % slx model with both the block and the new_block for verification 6 | % purposes. 7 | % Options : 'verif_off' bypasses the value of the verif global variable 8 | 9 | % Determine wether verification model should be generated 10 | verif = false; 11 | if nargin > 2 12 | if not(strcmp(varargin{1},'verif_off')) 13 | verif = true; 14 | end 15 | else 16 | try 17 | verif = evalin('base','verif'); 18 | catch 19 | verif = false; 20 | end 21 | end 22 | 23 | % Create the verification model if necessary 24 | try 25 | if verif 26 | newline = sprintf('\n'); 27 | fname = get_param(block,'Name'); 28 | fname = strrep(fname,newline,'_'); 29 | fname = strrep(fname,'-','_'); 30 | fname = strrep(fname,' ','_'); 31 | fname = strrep(fname,'.','_'); 32 | verif_file = strcat('Verification/',fname,'_verif.slx'); 33 | verif_model = strcat(fname,'_verif'); 34 | if exist('Verification','dir') && exist(verif_file,'file') 35 | % If the file doesn't exist, we generate a new one 36 | [script_path, ~, ~] = fileparts(mfilename('fullpath')); 37 | verif_template = fullfile(script_path, 'verification_template.slx'); 38 | copyfile(verif_template,verif_file); 39 | disp('A verification file has been created'); 40 | end 41 | load_system(verif_model); 42 | replace_one_block(strcat(verif_model,'/original'),... 43 | block,'verif_off'); 44 | replace_one_block(strcat(verif_model,'/generated'),... 45 | new_block,'verif_off'); 46 | save_system(verif_model); 47 | close_system(verif_model); 48 | end 49 | catch ME 50 | display_msg(ME.message, Constants.ERROR, 'simplifier', ''); 51 | display_msg(ME.getReport(), Constants.DEBUG, 'simplifier', ''); 52 | end 53 | % Replace the block by the new_block 54 | Orient=get_param(block,'orientation'); 55 | Size=get_param(block,'position'); 56 | delete_block(block); 57 | add_block(new_block,block, ... 58 | 'MakeNameUnique', 'on', ... 59 | 'Orientation',Orient, ... 60 | 'Position',Size); 61 | end 62 | 63 | -------------------------------------------------------------------------------- /src/frontEnd/pp/common/verification_template.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/pp/common/verification_template.slx -------------------------------------------------------------------------------- /src/frontEnd/pp/default_constants.m: -------------------------------------------------------------------------------- 1 | % This file contains the default values of different sample times that will 2 | % be used during the execution of Pre-GAL. The user can modify these values 3 | % before executing Pre-GAL and they will be used. 4 | sample = -1; 5 | integrator_sample = -1; 6 | clock_sample = -1; 7 | signal_builder_sample = -1; -------------------------------------------------------------------------------- /src/frontEnd/pp/math/expr_parser.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/frontEnd/pp/math/expr_parser.pyc -------------------------------------------------------------------------------- /src/gui/CocosimWindow/CocosimWindowMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef CocosimWindowMenu 9 | 10 | methods(Static) 11 | 12 | function schema = getCompiler(callbackInfo) 13 | schema = sl_container_schema; 14 | schema.label = 'Compile (Experimental)'; 15 | schema.childrenFcns = {@CocosimWindowMenu.getRust, @CocosimWindowMenu.getC}; 16 | end 17 | 18 | function schema = getRust(callbackInfo) 19 | schema = sl_action_schema; 20 | schema.label = 'to Rust'; 21 | schema.callback = @CocosimWindowMenu.rustCallback; 22 | end 23 | 24 | function rustCallback(callbackInfo) 25 | try 26 | model_full_path = CocosimWindowMenu.get_file_name(gcs); 27 | % load preferences 28 | CoCoSimPreferences = loadCoCoSimPreferences(); 29 | if CoCoSimPreferences.irToLustreCompiler 30 | lustre_file=cocoSpecCompiler(model_full_path); 31 | else 32 | lustre_file=lustre_compiler(model_full_path); 33 | end 34 | 35 | rust (lustre_file); 36 | 37 | catch ME 38 | display_msg(ME.getReport(),Constants.DEBUG,'getRust',''); 39 | disp('run the command in the top level of the model') 40 | end 41 | end 42 | 43 | function schema = getC(callbackInfo) 44 | schema = sl_action_schema; 45 | schema.label = 'to C'; 46 | schema.callback = @CocosimWindowMenu.cCallback; 47 | end 48 | 49 | function cCallback(callbackInfo) 50 | clear; 51 | assignin('base', 'SOLVER', 'NONE'); 52 | assignin('base', 'RUST_GEN', 0); 53 | assignin('base', 'C_GEN', 1); 54 | simulink_name = CocosimWindowMenu.get_file_name(gcs);%gcs; 55 | cocosim_window(simulink_name); 56 | end 57 | 58 | function fname = get_file_name(gcs) 59 | names = regexp(gcs,'/','split'); 60 | fname = get_param(names{1},'FileName'); 61 | end 62 | end 63 | end 64 | 65 | -------------------------------------------------------------------------------- /src/gui/PropertyGeneration/PropertyGenerationMenu.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | % Copyright (C) 2018 The university of Iowa 5 | % Authors: Temesghen Kahsai, Hamza Bourbouh, Mudathir Mahgoub 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | classdef PropertyGenerationMenu 9 | methods(Static) 10 | 11 | function schema = generateProperty(callbackInfo) 12 | schema = sl_action_schema; 13 | schema.label = 'Create Property'; 14 | schema.callback = @PropertyGenerationMenu.displayPropertyGenerationGui; 15 | end 16 | 17 | function displayPropertyGenerationGui(callbackInfo) 18 | try 19 | [prog_path, fname, ext] = fileparts(mfilename('fullpath')); 20 | simulink_name = PropertyGenerationMenu.get_file_name(gcs); 21 | add_property(simulink_name); 22 | catch ME 23 | display_msg(ME.getReport(),Constants.DEBUG,'generateProperty',''); 24 | end 25 | end 26 | 27 | 28 | function fname = get_file_name(gcs) 29 | names = regexp(gcs,'/','split'); 30 | fname = get_param(names{1},'FileName'); 31 | end % get_file_name 32 | 33 | end 34 | end 35 | 36 | -------------------------------------------------------------------------------- /src/middleEnd/cocoSpecCompiler/IR_pp/cocoSpecIRPP.m: -------------------------------------------------------------------------------- 1 | function cocoSpecIRPP( file_name, output_dir, json_model) 2 | % Fix the dimensionality issue "CompiledPortDimensions": 3 | % {..."Outport": [2,1,1]...} -> {..."Outport": [1,1]...} 4 | %json_model = strrep(json_model,'"Outport":[2,1,1]','"Outport":[1,1]'); 5 | %ToDo: this is a dirty quick fix which may not work for all cases. A 6 | %revision and a better approach is needed. 7 | 8 | matches = regexp(json_model, '("Inport":|"Outport":)\[.*?2,1,1.*?\]', 'match'); 9 | for i = 1 : length(matches) 10 | newStr = strrep(matches(i), '2,1,1', '1,1'); 11 | json_model = strrep(json_model,matches(i),newStr); 12 | end 13 | 14 | %ToDo: this code is redundant in 3 places cocosim_IR.m, this file and 15 | %ir_pp.m. Needs refactoring. 16 | 17 | file_json = [file_name '_IR.json']; 18 | % Open or create the file 19 | file_path = fullfile(output_dir, file_json); 20 | fid = fopen(file_path, 'w'); 21 | % Write in the file 22 | fprintf(fid, '%s\n', char(json_model)); 23 | fclose(fid); 24 | 25 | end -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/IR_pp/README: -------------------------------------------------------------------------------- 1 | %% Pre-Processor (PP) of the IR for cocoSim -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/add_node_param.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function param = add_node_param(extern_nodes_header_param, variables_struct, token, isInner) 7 | 8 | param_i = cell(numel(extern_nodes_header_param),1); 9 | param = ''; 10 | for i=1:numel(extern_nodes_header_param) 11 | if strcmp(extern_nodes_header_param(i).Type, 'Output') || strcmp(extern_nodes_header_param(i).Type, 'Local') || strcmp(extern_nodes_header_param(i).Type, 'ID') 12 | data_index = find(strcmp({variables_struct.Name},{extern_nodes_header_param(i).Name})); 13 | if ~isempty(data_index) 14 | if variables_struct(data_index).used 15 | index = variables_struct(data_index).index; 16 | else 17 | index = 1; 18 | end 19 | else 20 | error('abnormal behavior %s does not exist in variables structure',extern_nodes_header_param(i).Name) 21 | end 22 | param_i{i} = strcat(extern_nodes_header_param(i).Name,'_',num2str(index)); 23 | else 24 | param_i{i} = extern_nodes_header_param(i).Name; 25 | end 26 | end 27 | if ~isempty(param_i) 28 | param = Utils.concat_delim(param_i,', '); 29 | end 30 | 31 | 32 | if strcmp(token,'en') || strcmp(token,'ex') 33 | if isInner 34 | inner = 'true'; 35 | else 36 | inner = 'false'; 37 | end 38 | param = ['(' param ', ' inner ')']; 39 | else 40 | param = ['(' param ')']; 41 | end 42 | 43 | end -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/add_unchanged_variables.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [action_code, variables] = add_unchanged_variables(extern_nodes_header_return, variables_struct) 7 | 8 | [~, outputs] = add_variables(extern_nodes_header_return,false,variables_struct, true); 9 | [variables, right_vars] = add_variables(extern_nodes_header_return,false,variables_struct); 10 | 11 | if ~strcmp(variables,'') 12 | variables = ['var ', variables]; 13 | end 14 | action_code = [outputs ' \n\t= ' right_vars ';\n\t' ]; 15 | end -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/add_variables.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [variables, outputs] = add_variables(extern_nodes_header_return, firstAction, variables_struct, isOutput, global_node,variables_struct_old) 7 | if ~exist('global_node','var') 8 | global_node = false; 9 | end 10 | if ~exist('isOutput','var') 11 | isOutput = false; 12 | end 13 | to_start_from = true; 14 | if ~exist('variables_struct_old','var') 15 | variables_struct_old = variables_struct; 16 | to_start_from = false; 17 | end 18 | variables = ''; 19 | outputs = ''; 20 | output_i = {}; 21 | for i=1:numel(extern_nodes_header_return) 22 | data_index = find(strcmp({variables_struct.Name},{extern_nodes_header_return(i).Name})); 23 | if ~isempty(data_index) 24 | real_index = variables_struct(data_index).index; 25 | if variables_struct(data_index).used 26 | index = variables_struct(data_index).index; 27 | else 28 | index = 1; 29 | end 30 | else 31 | error('abnormal behavior %s does not exist in variables structure',extern_nodes_header_return(i).Name) 32 | end 33 | if firstAction 34 | output_i{i} = strcat(extern_nodes_header_return(i).Name,'_1'); 35 | elseif isOutput 36 | output_i{i} = extern_nodes_header_return(i).Name; 37 | else 38 | output_i{i} = strcat(extern_nodes_header_return(i).Name,'_',num2str(index)); 39 | end 40 | vars = {}; 41 | if global_node 42 | start = 1; 43 | elseif to_start_from 44 | start = variables_struct_old(data_index).index + 1; 45 | else 46 | start = 2; 47 | end 48 | for j=start:real_index 49 | vars{j-start+1} = strcat(extern_nodes_header_return(i).Name,'_',num2str(j)); 50 | end 51 | if ~isempty(vars) 52 | variables = [variables, '\t' Utils.concat_delim(vars,', '), ':', extern_nodes_header_return(i).DataType, ';\n']; 53 | end 54 | end 55 | if ~isempty(output_i) 56 | outputs = strcat('(',Utils.concat_delim(output_i,', '),')'); 57 | end 58 | 59 | end -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/construct_node_header.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [extern_nodes_header_param, extern_nodes_header_return] = construct_node_header(extern_nodes_header_param_struct,extern_nodes_header_return_struct, token, xml_trace) 7 | variables_param = {}; 8 | variables_return = {}; 9 | n = numel(extern_nodes_header_param_struct); 10 | if n>=1 && exist('xml_trace', 'var') && ~isempty(find(strcmp({extern_nodes_header_param_struct.Type},'Input'),1)) 11 | xml_trace.create_Inputs_Element(); 12 | end 13 | for i=1:n 14 | par = extern_nodes_header_param_struct(i); 15 | if strcmp(par.Type, 'Output') || strcmp(par.Type, 'Local') || strcmp(par.Type, 'ID') 16 | variables_param{i} = strcat(par.Name,'_1:',par.DataType); 17 | else 18 | variables_param{i} = strcat(par.Name,':',par.DataType); 19 | end 20 | if exist('xml_trace', 'var') && strcmp(par.Type, 'Input') 21 | xml_trace.add_Input(par.Name, par.Name, 1, 1); 22 | end 23 | end 24 | n = numel(extern_nodes_header_return_struct); 25 | if n>=1 && exist('xml_trace', 'var') && ~isempty(find(strcmp({extern_nodes_header_return_struct.Type},'Output'),1)) 26 | xml_trace.create_Outputs_Element(); 27 | end 28 | for i=1:n 29 | par = extern_nodes_header_return_struct(i); 30 | variables_return{i} = strcat(par.Name,':',par.DataType); 31 | if exist('xml_trace', 'var') && strcmp(par.Type, 'Output') 32 | xml_trace.add_Output(par.Name, par.Name, 1, 1); 33 | end 34 | end 35 | 36 | if ~isempty(variables_param) 37 | extern_nodes_header_param = Utils.concat_delim(variables_param,';\n\t'); 38 | else 39 | extern_nodes_header_param = 'noInput :bool'; 40 | end 41 | if ~isempty(variables_return) 42 | extern_nodes_header_return = Utils.concat_delim(variables_return,';\n\t'); 43 | else 44 | extern_nodes_header_return = ' '; 45 | end 46 | if strcmp(token,'en') || strcmp(token,'ex') 47 | extern_nodes_header_param = [extern_nodes_header_param, ';\n\tisInner:bool']; 48 | end 49 | 50 | end -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/get_full_name.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ object_full_name ] = get_full_name( object,isChart ) 7 | %GET_FULL_NAME Summary of this function goes here 8 | % Detailed explanation goes here 9 | if ~exist('isChart', 'var') 10 | isChart = false; 11 | end 12 | % object_full_name = regexprep(strcat(object.path,'_',object.Name),expression,replace); 13 | object_parent_name= regexp(object.Path, '/','split'); 14 | if isChart 15 | str = object_parent_name(1:end-1); 16 | object_parent_name = Utils.concat_delim(str, '_');%object_parent_name{1}; 17 | else 18 | object_parent_name = object_parent_name{end}; 19 | end 20 | expression = '(\s*|\-|/)'; 21 | replace = ''; 22 | try 23 | object_name = regexprep(object.Name,expression,replace); 24 | catch 25 | object_name = strcat('Junction',num2str(object.Id)); 26 | end 27 | object_parent_name = regexprep(object_parent_name,expression,replace); 28 | if isChart 29 | object_full_name = Utils.name_format(strcat(object_parent_name,'_',object_name)); 30 | else 31 | object_full_name = Utils.name_format(strcat(object_parent_name,'_',object_name,num2str(object.Id))); 32 | end 33 | end 34 | 35 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/sT2fT.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ Lustre_type, initial_value ] = sT2fT( stateflow_Type, data_name ) 7 | 8 | 9 | if strcmp(stateflow_Type, 'real') || strcmp(stateflow_Type, 'int') || strcmp(stateflow_Type, 'bool') 10 | Lustre_type = simulink_dt; 11 | else 12 | if strcmp(stateflow_Type, 'logical') || strcmp(stateflow_Type, 'boolean') 13 | Lustre_type = 'bool'; 14 | initial_value = 'false'; 15 | elseif strncmp(stateflow_Type, 'int', 3) || strncmp(stateflow_Type, 'uint', 4) || strncmp(stateflow_Type, 'fixdt(1,16,', 11) || strncmp(stateflow_Type, 'sfix64', 6) 16 | Lustre_type = 'int'; 17 | initial_value = '0'; 18 | else 19 | Lustre_type = 'real'; 20 | initial_value = '0.0'; 21 | end 22 | end 23 | end 24 | 25 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/common/temporal_operators.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ fun_code ] = temporal_operators( fun ) 7 | %MATH_FUNCTIONS Summary of this function goes here 8 | % Detailed explanation goes here 9 | 10 | fun_code = ''; 11 | 12 | if strcmp(fun.Name, 'after') 13 | header = 'node after(n:int; E : bool; id:int ) returns ( Y : bool );\nvar count:int;\nlet\n\t'; 14 | counter = 'count = 0 -> if (pre id <> id) then\n\t\t if E then 1 else 0 \n\telse\n\t if E then (pre count) + 1 else pre count;\n\t'; 15 | output = ' Y = count >= n ;\ntel'; 16 | body = [counter, output]; 17 | fun_code = [header, body]; 18 | end 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/Stateflow/write_Chart.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ nodes_string, external_nodes] = write_Chart( chart, Debug, xml_trace, file_name) 7 | 8 | nodes_string = ''; 9 | external_nodes = []; 10 | 11 | transitions_fcts = []; 12 | data_fcts = []; 13 | %this is a structure array that contains the following fields for every 14 | %generated node in Lustre file : 15 | % Name : the name of the node in Lustre file 16 | % Parameters : a structure containing informations about node parameters, 17 | % the name, dataType and type of parameter (output, input, ...) 18 | % Outputs : The same as Parameters, has informations about node outputs. 19 | global_nodes_struct = struct('Parameters',[],'Outputs',[],'Name',[]); 20 | 21 | %TODO : 22 | %We can have a problem if a function call another function, but this second 23 | %function that is called by the first is not generated yet. So we should 24 | %make sure that functions are generated with the right order. It has 25 | %never happened but it could be. 26 | % To do it we should 27 | functions = chart.find('-isa','Stateflow.Function'); 28 | for i=1:numel(functions) 29 | if Debug 30 | fprintf('Start generating code for function : %s in chart : %s\n',functions(i).Name, chart.Name); 31 | end 32 | [nodes_string_i,... 33 | external_nodes_i, ... 34 | global_nodes_struct, ... 35 | nb_actions_i, ... 36 | nb_nodes_i] = chart_and_function_code(functions(i),global_nodes_struct, true,[],[], Debug, xml_trace,file_name); 37 | nodes_string = [nodes_string nodes_string_i '\n']; 38 | external_nodes = [external_nodes, external_nodes_i]; 39 | transitions_fcts = [transitions_fcts; functions(i).find('-isa', 'Stateflow.Transition')]; 40 | data_fcts = [data_fcts; functions(i).find('-isa', 'Stateflow.Data')]; 41 | 42 | end 43 | 44 | 45 | if Debug 46 | fprintf('Start generating code for chart : %s\n',get_full_name(chart)); 47 | end 48 | [nodes_string_i,... 49 | external_nodes_i, ... 50 | ~, ... 51 | nb_actions_i, ... 52 | nb_nodes_i] = chart_and_function_code(chart, global_nodes_struct, false,transitions_fcts ,data_fcts, Debug, xml_trace,file_name); 53 | nodes_string = [nodes_string nodes_string_i '\n']; 54 | external_nodes = [external_nodes, external_nodes_i]; 55 | 56 | end 57 | 58 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Abs.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Abs block 7 | % 8 | % Computes the absolute value of the only input of the block. 9 | % 10 | %% Generation scheme 11 | % 12 | %%% Input is real 13 | % Example provided for a 2 elements vector 14 | % 15 | % Output_1_1 = if Input_1_1 >= zero then Input_1_1 else - Input_1_1; 16 | % Output_1_2 = if Input_1_2 >= zero then Input_1_2 else - Input_1_2; 17 | % 18 | %%% Input is complex 19 | % Example provided for a 2 elements vector 20 | % 21 | % Output_1_1 = sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 22 | % Output_1_2 = sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 23 | % 24 | %% Code 25 | % 26 | function [output_string, var_out] = write_Abs(block, ir_struct, varargin) 27 | 28 | output_string = ''; 29 | ext_fun = ''; 30 | 31 | [list_out] = list_var_sortie(block); 32 | [list_in] = list_var_entree(block, ir_struct); 33 | 34 | dt = LusUtils.get_lustre_dt(block.CompiledPortDataTypes.Inport(1)); 35 | if strcmp(dt, 'real') 36 | zero = '0.0'; 37 | else 38 | zero = '0'; 39 | end 40 | 41 | if block.CompiledPortComplexSignals.Inport(1) 42 | for idx_dim=1:block.CompiledPortWidths.Outport 43 | sqrt_str = sprintf('(%s.r * %s.r) + (%s.i * %s.i)', list_in{idx_dim}, list_in{idx_dim}, list_in{idx_dim}, list_in{idx_dim}); 44 | output_string = app_sprintf(output_string, '\t%s = sqrt(%s);\n', list_out{idx_dim}, sqrt_str); 45 | end 46 | ext_fun{1} = sprintf('sqrt %s', block.CompiledPortDataTypes.Outport(1)); 47 | else 48 | for idx_dim=1:block.CompiledPortWidths.Outport 49 | if_cond = [list_in{idx_dim} ' >= ' zero]; 50 | then_branch = list_in{idx_dim}; 51 | else_branch = ['-' list_in{idx_dim}]; 52 | output_string = app_sprintf(output_string, '\t%s = if %s then %s else %s;\n', list_out{idx_dim}, if_cond, then_branch, else_branch); 53 | end 54 | end 55 | 56 | var_out{1} = 'extern_functions'; 57 | var_out{2} = ext_fun; 58 | 59 | end 60 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_ActionPort.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_ActionPort( block, ir_struct, varargin ) 2 | %WRITE_ACTIONPORT 3 | 4 | var_out = {}; 5 | output_string = ''; 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_BusCreator.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% BusCreator block 7 | % 8 | % Creates a bus from a set of input values. 9 | % 10 | %% Generation scheme 11 | % Every example is provided for 2 elements as input of respective data types scalar, vector of 2 elements and scalar. 12 | % The output is a bus of the corresponding structure (we will use f1, f2 13 | % and f3 as the three fields of this created bus). 14 | % 15 | %%% Output is a non_virtual bus 16 | % 17 | % Output_1_1.f1 = Input_1_1; 18 | % Output_1_1.f2_1 = Input_2_1; 19 | % Output_1_1.f2_2 = Input_2_2; 20 | % Output_1_1.f3 = Input_3_1; 21 | % 22 | %%% Output is a virtual bus 23 | % 24 | % Output_1_1 = Input_1_1; 25 | % Output_1_2 = Input_2_1; 26 | % Output_1_3 = Input_2_2; 27 | % Output_1_4 = Input_3_1; 28 | % 29 | %% Code 30 | % 31 | function [output_string, var_out] = write_BusCreator(block, ir_struct, varargin) 32 | 33 | var_out = {}; 34 | 35 | non_virtual = block.NonVirtualBus; 36 | 37 | output_string = ''; 38 | 39 | [list_out] = list_var_sortie(block); 40 | [list_in] = list_var_entree(block, ir_struct); 41 | 42 | non_virtual = strcmp(non_virtual, 'on'); 43 | [is_bus bus] = BusUtils.is_bus(block.CompiledPortDataTypes.Outport(1)); 44 | is_virtual = ~is_bus; 45 | 46 | if non_virtual 47 | nb_assigned = 0; 48 | for idx_elem=1:numel(bus.Elements) 49 | elem = bus.Elements(idx_elem); 50 | field_name = elem.Name; 51 | if numel(elem.Dimensions) == 1 52 | for idx_dim=1:elem.Dimensions 53 | output_string = app_sprintf(output_string, '\t%s.%s_%d = %s;\n', list_out{1}, field_name, idx_dim, list_in{idx_dim + nb_assigned}); 54 | end 55 | nb_assigned = nb_assigned + elem.Dimensions; 56 | else 57 | for idx_r=1:elem.Dimensions(1) 58 | for idx_c=1:elem.Dimensions(2) 59 | idx = idx_c + (idx_r-1) * elem.Dimensions(2); 60 | output_string = app_sprintf(output_string, '\t%s.%s_%d = %s;\n', list_out{1}, field_name, idx, list_in{idx + nb_assigned}); 61 | end 62 | end 63 | nb_assigned = nb_assigned + (elem.Dimensions(1) * elem.Dimensions(2)); 64 | end 65 | end 66 | else 67 | for idx_out=1:numel(list_out) 68 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_out}, list_in{idx_out}); 69 | end 70 | end 71 | 72 | end 73 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_CoCoSimImplies.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_CoCoSimImplies( block, ir_struct, varargin ) 2 | %WRITE_COCOSIMIMPLIES 3 | var_out = {}; 4 | 5 | output_string = ''; 6 | 7 | [list_out] = list_var_sortie(block); 8 | [list_in] = list_var_entree(block, ir_struct); 9 | 10 | list_in = LusUtils.expand_all_inputs(block, list_in); 11 | for idx_dim=1:block.CompiledPortWidths.Outport 12 | list_in_nth = LusUtils.get_elem_nth_shift(list_in, idx_dim, block.CompiledPortWidths.Outport(1)); 13 | right_string = Utils.concat_delim(list_in_nth, [' ' '=>' ' ']); 14 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, right_string); 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Create3x3Matrix.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [output_string, var_out] = write_Create3x3Matrix(block, ir_struct, varargin) 7 | 8 | output_string = ''; 9 | var_out = {}; 10 | 11 | [list_out] = list_var_sortie(block); 12 | [list_in] = list_var_entree(block, ir_struct); 13 | 14 | for k1 = 1:numel(list_out) 15 | output_string = app_sprintf(output_string,'\t%s = %s ;\n',list_out{k1}, list_in{k1}); 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_DataTypeConversion.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% DataTypeConversion block 7 | % 8 | % Converts the input signal to a certain data type specified in a 9 | % parameter. 10 | % 11 | %% Generation scheme 12 | % The actual conversion of the value is done in the printing of the Input 13 | % variables (the call to list_var_entree) which is based on the work done 14 | % in the blocks_dt_conversion function. 15 | % 16 | %% Conversion from int to real 17 | % 18 | % Output = int_to_real(Input); 19 | % 20 | %% Conversion from real to int 21 | % The conversion is done according to the RndMeth parameter value of the 22 | % block. A node is generated to do the conversion (dummy node). 23 | % 24 | % Output = conv_fun(Input); 25 | % 26 | %% Conversion from int to bool 27 | % 28 | % Output = if Input = 0 then false else true; 29 | % 30 | %% Conversion from real to bool 31 | % 32 | % Output = if Input = 0.0 then false else true; 33 | % 34 | %% Conversion from bool to real 35 | % 36 | % Output = if Input then 1.0 else 0.0; 37 | % 38 | %% Conversion from bool to int 39 | % 40 | % Output = if Input then 1 else 0; 41 | % 42 | %% Code 43 | % 44 | function [output_string, var_out] = write_DataTypeConversion(block, ir_struct, varargin) 45 | 46 | var_out = {}; 47 | 48 | output_string = ''; 49 | 50 | [list_out] = list_var_sortie(block); 51 | [list_in] = list_var_entree(block, ir_struct); 52 | 53 | for idx_dim=1:block.CompiledPortWidths.Outport 54 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, list_in{idx_dim}); 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Demux.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Demux block 7 | % 8 | % Splits a multi dimentional Input to multiple Outputs 9 | % 10 | %% Generation scheme 11 | % We take the example of a 3 elements vector provided as input of the 12 | % block. The Output is parametrized in the block to have 2 outputs, the 13 | % first that is a scalar and the second that is a 2 elements vector. 14 | % 15 | %%% We directly assign the Input values to the Outputs values. The correction of the assignment is actually ensured by the variables names generation functions. 16 | % 17 | % Output_1_1 = Input_1_1; 18 | % Output_2_1 = Input_1_2; 19 | % Output_2_2 = Input_1_3; 20 | % 21 | %% Code 22 | % 23 | function [output_string, var_out] = write_Demux(block, ir_struct, varargin) 24 | 25 | var_out = {}; 26 | 27 | output_string = ''; 28 | 29 | [list_out] = list_var_sortie(block); 30 | [list_in] = list_var_entree(block, ir_struct); 31 | 32 | for k1=1:numel(list_out) 33 | output_string = [output_string sprintf('\t%s = %s ;\n', list_out{k1}, list_in{k1})]; 34 | end 35 | 36 | end 37 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_DiscretizedZeroPole.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_DiscretizedZeroPole( block, ir_struct, varargin ) 2 | %WRITE_DISCRETIZEDZEROPOLE 3 | 4 | [output_string, var_out] = write_DiscreteZeroPole(block, ir_struct, varargin); 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_EnablePort.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Enable block 7 | % 8 | % The Enable block equips the sursubsytem with an enable port. It 9 | % the block has no output (the parameter ShowOutputPort is disabled) then 10 | % nothing is printed for this block. Else it provides the value of the 11 | % surrounding SubSystem enable port. 12 | % 13 | %% Generation scheme 14 | % 15 | % Output = Value of the enable input of the surrounding node; 16 | % 17 | %% Code 18 | % 19 | function [output_string, var_out] = write_EnablePort(unbloc, ir_struct, varargin) 20 | 21 | var_out = {}; 22 | output_string = ''; 23 | 24 | show_port = unbloc.ShowOutputPort; 25 | if strcmp(show_port, 'on') 26 | [list_out] = list_var_sortie(unbloc); 27 | 28 | out_dt = LusUtils.get_lustre_dt(unbloc.CompiledPortDataTypes.Outport); 29 | 30 | name_cell = regexp(unbloc.Path, '/', 'split'); 31 | name = Utils.concat_delim(name_cell, '_'); 32 | for idx_dim=1:numel(list_out) 33 | str_val{idx_dim} = sprintf('%s_1_%d', name, idx_dim); 34 | end 35 | 36 | for idx_dim=1:numel(list_out) 37 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, str_val{idx_dim}); 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_From.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Goto/From blocks 7 | % 8 | % Same backend file for both Goto and From blocks. Goto/From blocks are 9 | % identified by their unique goto_tag parameter. 10 | % For the Goto block, generates a new variable for each element of the 11 | % Input of the Goto block. For the From block, set eh output of the block 12 | % to the values of the corresponding Goto block. 13 | % 14 | %% Generation scheme 15 | % We take the example of a vector signal of 3 elements with goto_tag = 'A' 16 | % 17 | %%% Goto 18 | % 19 | % Goto_A_1 = Input_1_1; 20 | % Goto_A_2 = Input_1_2; 21 | % Goto_A_3 = Input_1_3; 22 | % 23 | %%% From 24 | % 25 | % Output_1_1 = Goto_A_1; 26 | % Output_1_2 = Goto_A_2; 27 | % Output_1_3 = Goto_A_3; 28 | % 29 | %% Code 30 | % 31 | function [output_string, var_out] = write_From(unbloc, ir_struct, varargin) 32 | 33 | var_out = {}; 34 | 35 | goto_tag = unbloc.GotoTag; 36 | 37 | output_string = ''; 38 | 39 | [list_out] = list_var_sortie(unbloc); 40 | for idx_dim=1:unbloc.CompiledPortWidths.Outport 41 | var_name = sprintf('Goto_%s_%s', goto_tag, num2str(idx_dim)); 42 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, var_name); 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Goto.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Goto/From blocks 7 | % 8 | % Same backend file for both Goto and From blocks. Goto/From blocks are 9 | % identified by their unique goto_tag parameter. 10 | % For the Goto block, generates a new variable for each element of the 11 | % Input of the Goto block. For the From block, set eh output of the block 12 | % to the values of the corresponding Goto block. 13 | % 14 | %% Generation scheme 15 | % We take the example of a vector signal of 3 elements with goto_tag = 'A' 16 | % 17 | %%% Goto 18 | % 19 | % Goto_A_1 = Input_1_1; 20 | % Goto_A_2 = Input_1_2; 21 | % Goto_A_3 = Input_1_3; 22 | % 23 | %%% From 24 | % 25 | % Output_1_1 = Goto_A_1; 26 | % Output_1_2 = Goto_A_2; 27 | % Output_1_3 = Goto_A_3; 28 | % 29 | %% Code 30 | % 31 | function [output_string, var_out] = write_Goto(block, ir_struct, varargin) 32 | 33 | goto_tag = block.GotoTag; 34 | 35 | output_string = ''; 36 | add_vars = ''; 37 | 38 | [list_in] = list_var_entree(block, ir_struct); 39 | add_vars = '\t'; 40 | in_dt = LusUtils.get_lustre_dt(block.CompiledPortDataTypes.Inport(1)); 41 | for idx_dim=1:block.CompiledPortWidths.Inport 42 | var_name = sprintf('Goto_%s_%s', goto_tag, num2str(idx_dim)); 43 | output_string = app_sprintf(output_string, '\t%s = %s;\n', var_name, list_in{idx_dim}); 44 | add_vars = [add_vars var_name]; 45 | if idx_dim == block.CompiledPortWidths.Inport 46 | add_vars = [add_vars ': ' in_dt ';\n']; 47 | else 48 | add_vars = [add_vars ', ']; 49 | end 50 | 51 | % Add traceability for additional variables 52 | varargin{1}.add_Variable(var_name, block.Origin_path, 1, idx_dim, true); 53 | end 54 | 55 | var_out{1} = 'additional_variables'; 56 | var_out{2} = add_vars; 57 | end 58 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Inport.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_Inport( block, ir_struct, varargin ) 2 | %WRITE_INPORT 3 | 4 | var_out = {}; 5 | output_string = ''; 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Merge.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Merge block 7 | % 8 | % Merge the inputs values to the output. Merging is done according ot the 9 | % last refreshed input value. 10 | % 11 | %% Generation scheme 12 | % Example taken for a 3 elements vector for all inputs. 13 | % 14 | % Output_1_1 = Input_1_1; 15 | % Output_1_2 = Input_1_2; 16 | % Output_1_3 = Input_1_3; 17 | % 18 | %% Code 19 | % 20 | function [output_string, var_out] =write_Merge(block, ir_struct, varargin) 21 | 22 | var_out = {}; 23 | 24 | output_string = ''; 25 | % unbloc 26 | [list_out] = list_var_sortie(block); 27 | [list_in] = list_var_entree(block,ir_struct); 28 | numel_out = numel(list_out); 29 | numel_in = numel(list_in); 30 | right_exp = ''; 31 | annotation = regexprep(num2str(block.Handle),'\.','_'); 32 | for ind_in=1:numel_out:numel_in 33 | %this version has the problem if an input change its value but it still 34 | %equal to previous value. 35 | % condition={}; 36 | % for k=1:numel_out 37 | % condition{k} = ['(' char(list_in(ind_in+k-1)) ' <> pre ' char(list_in(ind_in+k-1)) ')']; 38 | % end 39 | % condition_str = ['(' Utils.concat_delim(condition, ' or ') ')']; 40 | 41 | %this version rely on creating local variables, that save who changed. 42 | if numel_out==1 43 | ind_src = ind_in-1; 44 | else 45 | ind_src = (ind_in-mod(ind_in, numel_out))/numel_out; 46 | end 47 | condition_str = strcat('Merge_',annotation,'_input',num2str(ind_src),'_hasChanged'); 48 | 49 | inputs = ['(' Utils.concat_delim(list_in(ind_in:ind_in+numel_out-1), ', ') ')']; 50 | right_exp = app_sprintf(right_exp,'\tif %s then %s else\n', condition_str,inputs); 51 | end 52 | 53 | if numel_out > 1 54 | list_def_out = ['(pre ' Utils.concat_delim(list_out, ', pre ') ')']; 55 | left_exp = ['(' Utils.concat_delim(list_out, ', ') ')']; 56 | else 57 | list_def_out = ['pre ' list_out{1}]; 58 | left_exp = list_out{1}; 59 | end 60 | output_string = app_sprintf(output_string,'\t%s = %s \t%s;\n', left_exp,right_exp,list_def_out); 61 | end 62 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Mux.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Mux block 7 | % 8 | % The mux block is grouping the values on its input as values on its 9 | % output. The backend only consist in assigning the values of the output to 10 | % the values of the inputs. The whole muxing is handled in the generation 11 | % of the names of the variables. 12 | % 13 | %% Code 14 | % 15 | function [output_string, var_out] = write_Mux(block, ir_struct, varargin) 16 | 17 | var_out = {}; 18 | output_string = ''; 19 | 20 | [list_out] = list_var_sortie(block); 21 | [list_in] = list_var_entree(block, ir_struct); 22 | 23 | for k1 = 1:numel(list_out) 24 | output_string = app_sprintf(output_string,'\t%s = %s ;\n',list_out{k1}, list_in{k1}); 25 | end 26 | 27 | end 28 | 29 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Outport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Outport block 7 | % 8 | % The outport block is output value of the computation in a block. 9 | % This backend is very simple but may need to be improved as Outport block 10 | % may be latched and thus may contain a memory. 11 | % 12 | %% Code 13 | % 14 | function [output_string, var_out] = write_Outport(block, ir_struct, varargin) 15 | 16 | var_out = {}; 17 | output_string = ''; 18 | 19 | [list_in] = list_var_entree(block, ir_struct); 20 | list_out = ''; 21 | 22 | block_full_name = regexp(block.Path, '/', 'split'); 23 | block_name = Utils.concat_delim(block_full_name(end - block.name_level : end), '_'); 24 | for idx_dim_in=1:block.CompiledPortWidths.Inport 25 | %list_out{idx_dim_in} = ['out' num2str(unbloc.portnumber) '_' num2str(idx_dim_in) '_']; 26 | list_out{idx_dim_in} = [block_name '_' num2str(block.Port) '_' num2str(idx_dim_in)]; 27 | %if strcmp(inter_blk{1}.type, 'SubSystem') 28 | % [a b] = regexp(inter_blk{1}.name{1}, '/', 'split'); 29 | % list_out{idx_dim_in} = [list_out{idx_dim_in} a{end}]; 30 | %else 31 | % [model_path, embedding_node_name, ext] = fileparts(nom_lustre_file); 32 | % list_out{idx_dim_in} = [list_out{idx_dim_in} embedding_node_name]; 33 | %end 34 | %list_out{idx_dim_in} = [list_out{idx_dim_in} '_' embedding_node_name]; 35 | end 36 | 37 | for idx_dim_in=1:block.CompiledPortWidths.Inport 38 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim_in}, list_in{idx_dim_in}); 39 | end 40 | 41 | end 42 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Polyval.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Polyval block 7 | % 8 | % Computes the result of the use of the input values as the variable of a 9 | % polynome. The polynome coeficients are provided in the coefs parameter. 10 | % The computation is done on each element of the input. 11 | % 12 | %% Generation scheme 13 | % We take the example of an input as a 3 elements vector. The coefs 14 | % parameter is equal to [3 0 .5 8]. If x is the input value then the 15 | % polynome is: 3*u*u*u + 0.5*u + 8 16 | % 17 | % Output_1_1 = 3 * Input_1_1 * Input_1_1 * Input_1_1 + 0.5 * Input_1_1 + 8.0; 18 | % Output_1_2 = 3 * Input_1_2 * Input_1_2 * Input_1_2 + 0.5 * Input_1_2 + 8.0; 19 | % Output_1_3 = 3 * Input_1_3 * Input_1_3 * Input_1_3 + 0.5 * Input_1_3 + 8.0; 20 | % 21 | %% Code 22 | % 23 | function [output_string, var_out] = write_Polyval(block, ir_struct, varargin) 24 | 25 | var_out = {}; 26 | coefs = LusUtils.getParamValue(ir_struct, block, block.Coefs) 27 | 28 | output_string = ''; 29 | 30 | [list_out] = list_var_sortie(block); 31 | [list_in] = list_var_entree(block, ir_struct); 32 | 33 | for idx_out=1:numel(list_out) 34 | mul_str = ''; 35 | for idx_coef=1:numel(coefs) 36 | if coefs(idx_coef) ~= 0 37 | mul_str = sprintf('%s (%.10f', mul_str, coefs(idx_coef)); 38 | for idx_mul=1:numel(coefs)-idx_coef 39 | mul_str = [mul_str ' * ' list_in{idx_out}]; 40 | end 41 | if idx_coef ~= numel(coefs) 42 | mul_str = [mul_str ') +']; 43 | else 44 | mul_str = [mul_str ')']; 45 | end 46 | end 47 | end 48 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_out}, mul_str); 49 | end 50 | 51 | end 52 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Reshape.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Reshape block 7 | % 8 | % Reshape the input signal according to the 'Output Dimentionality' 9 | % parameter or according to a second optional input dimensions. 10 | % The conversion is done along the first dimension. 11 | % 12 | %% Generation scheme 13 | % We take the example of a 2x3 matrix: [1 2 3; 4 5 6] 14 | % It is converted as a 3x2 matrix ('Custom' value of the 'Output 15 | % Dimentionality' parameter set to [3 2]) 16 | % The result is [1 5; 4 3; 2 6] as teh conversion is done by browsing the 17 | % input value each column at a time. 18 | % 19 | % Output_1_1 = Input_1_1 ; 20 | % Output_1_3 = Input_1_4 ; 21 | % Output_1_5 = Input_1_2 ; 22 | % Output_1_2 = Input_1_5 ; 23 | % Output_1_4 = Input_1_3 ; 24 | % Output_1_6 = Input_1_6 ; 25 | % 26 | %% Code 27 | % 28 | function [output_string, var_out] = write_Reshape(block, ir_struct, varargin) 29 | 30 | var_out = {}; 31 | 32 | output_string = ''; 33 | 34 | [list_out] = list_var_sortie(block); 35 | [list_in] = list_var_entree(block, ir_struct); 36 | 37 | [in_dim_r in_dim_c] = Utils.get_port_dims_simple(block.CompiledPortDimensions.Inport, 1); 38 | [out_dim_r out_dim_c] = Utils.get_port_dims_simple(block.CompiledPortDimensions.Outport, 1); 39 | 40 | cpt = 1; 41 | for idx_c=1:in_dim_c 42 | for idx_r=1:in_dim_r 43 | idx_in = ((idx_r - 1) * in_dim_c) + idx_c; 44 | reorder_list_in{cpt} = list_in{idx_in}; 45 | cpt = cpt + 1; 46 | end 47 | end 48 | 49 | cpt = 1; 50 | for idx_c=1:out_dim_c 51 | for idx_r=1:out_dim_r 52 | idx_out = ((idx_r - 1) * out_dim_c) + idx_c; 53 | output_string = app_sprintf(output_string,'\t%s = %s ;\n', list_out{idx_out}, reorder_list_in{cpt}); 54 | cpt = cpt + 1; 55 | end 56 | end 57 | 58 | end 59 | 60 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_SFunction.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% S-Function block 7 | % 8 | % Generates a call to the node containig the definition (link to the m 9 | % file) for the S-Function. Adds additional parameters to the call if some 10 | % parameters are to be used in the Function. 11 | % 12 | %% Generation scheme 13 | % We take the example of a S-Function having two scalar inputs, one scalar 14 | % parameter and outputing two scalar values. 15 | % 16 | % (Output_1_1, Output_2_1) = function_name(Input_1_1, Input_2_1, param_1_value); 17 | % 18 | %% Code 19 | % 20 | function [output_string, var_out] = write_SFunction(block, ir_struct, varargin) 21 | 22 | var_out = {}; 23 | 24 | output_string = ''; 25 | 26 | [list_out] = list_var_sortie(block); 27 | [list_in] = list_var_entree(block, ir_struct); 28 | 29 | block_full_name = regexp(block.Path, '/', 'split'); 30 | node_name = block_full_name{end}; 31 | 32 | % Format list_in and list_out as string 33 | list_in = Utils.concat_delim(list_in, ', '); 34 | list_out = Utils.concat_delim(list_out, ', '); 35 | 36 | if numel(list_out) > 1 37 | list_out = ['(' list_out ')']; 38 | end 39 | 40 | % if ~strcmp(parameters, '') 41 | % parameters_strings = regexp(parameters, ',', 'split'); 42 | % for param_idx=1:numel(parameters_strings) 43 | % param_string_value = parameters_strings{param_idx}; 44 | % matched_value = Utils.convert_literal_value(param_string_value); 45 | % list_in = strcat(list_in, ',', {' '}, matched_value); 46 | % end 47 | % else 48 | % list_in = {''}; 49 | % end 50 | 51 | block_name = Utils.naming(block.Path); 52 | output_string = app_sprintf(output_string, '\t%s = %s(%s);\n', list_out, block_name, list_in); 53 | 54 | var_out{1} = 'extern_s_functions'; 55 | [var_out{2}, var_out{4}] = write_extern_SFunction(block, ir_struct); 56 | var_out{3} = 'c_code'; 57 | end 58 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Scope.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_Scope( block, ir_struct, varargin ) 2 | %WRITE_SCOPE 3 | 4 | warning_msg = ['A Scope block have been found. No code will be generated for it:\n' block.Origin_path]; 5 | display_msg(warning_msg, 2, 'write_code', ''); 6 | 7 | output_string = ''; 8 | var_out = {}; 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_SignalConversion.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% SignalConversion block 7 | % 8 | % The mux block is grouping the values on its input as values on its 9 | % output. The backend only consist in assigning the values of the output to 10 | % the values of the inputs. The whole muxing is handled in the generation 11 | % of the names of the variables. 12 | % 13 | %% Code 14 | % 15 | function [output_string, var_out] = write_SignalConversion(block, ir_struct, varargin) 16 | 17 | var_out = {}; 18 | output_string = ''; 19 | 20 | [list_out] = list_var_sortie(block); 21 | [list_in] = list_var_entree(block, ir_struct); 22 | 23 | for k1 = 1:numel(list_out) 24 | output_string = app_sprintf(output_string,'\t%s = %s ;\n',list_out{k1}, list_in{k1}); 25 | end 26 | 27 | error_msg = [' SignalConversion block could be not well translated.\n']; 28 | display_msg(error_msg, Constants.WARNING, 'write_code', ''); 29 | 30 | end 31 | 32 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_SignalSpecification.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% SignalSpecification block 7 | % 8 | % This block is used to ensure that an input signal has the correct type. 9 | % It is then used for debug purposes and has no impact on the generated 10 | % code. We thus encode it as a signal. 11 | % 12 | %% Generation scheme 13 | % 14 | %%% 15 | % 16 | % Output = Input; 17 | % 18 | %% Code 19 | % 20 | function [output_string, var_out] = write_SignalSpecification(block, ir_struct, varargin) 21 | 22 | var_out = {}; 23 | 24 | output_string = ''; 25 | 26 | [list_out] = list_var_sortie(block); 27 | [list_in] = list_var_entree(block, ir_struct); 28 | 29 | for idx_dim=1:numel(list_out) 30 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, list_in{idx_dim}); 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Signum.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Signum block 7 | % 8 | % For real values provides the output -1, 0, 1, if the input is negative, 9 | % null or positive. 10 | % For complex values computes the values of Input / abs(Input). 11 | % 12 | %% Generation scheme 13 | % 14 | %%% Input is real 15 | % Example provided for a 2 elements vector 16 | % 17 | % Output_1_1 = if Input_1_1 = zero then zero else if Input_1_1 < zero then -one else one; 18 | % Output_1_2 = if Input_1_2 = zero then zero else if Input_1_2 < zero then -one else one; 19 | % 20 | %%% Input is complex 21 | % Example provided for a 2 elements vector 22 | % 23 | % Output_1_1.r = Input_1_1.r / sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 24 | % Output_1_1.i = Input_1_1.i / sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 25 | % Output_1_2.r = Input_1_2.r / sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 26 | % Output_1_2.i = Input_1_2.i / sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 27 | % 28 | %% Code 29 | % 30 | function [output_string, var_out] = write_Signum(block, ir_struct, varargin) 31 | 32 | output_string = ''; 33 | ext_funs = ''; 34 | 35 | [list_out] = list_var_sortie(block); 36 | [list_in] = list_var_entree(block, ir_struct); 37 | 38 | dt = LusUtils.get_lustre_dt(block.CompiledPortDataTypes.Inport(1)); 39 | if ~block.CompiledPortComplexSignals.Inport(1) 40 | if strcmp(dt, 'real') 41 | zero = '0.0'; 42 | one = '1.0'; 43 | else 44 | zero = '0'; 45 | one = '1'; 46 | end 47 | for idx=1:numel(list_out) 48 | output_string = app_sprintf(output_string, '\t%s = if %s = %s then %s else if %s < %s then -%s else %s;\n', list_out{idx}, list_in{idx}, zero, zero, list_in{idx}, zero, one, one); 49 | end 50 | else 51 | for idx=1:numel(list_out) 52 | sqrt_val = sprintf('%s.r * %s.r + %s.i * %s.i', list_in{idx}, list_in{idx}, list_in{idx}, list_in{idx}); 53 | output_string = app_sprintf(output_string, '\t%s.r = %s.r / sqrt(%s);\n', list_out{idx}, list_in{idx}, sqrt_val); 54 | end 55 | ext_funs{1} = ['sqrt ' dt]; 56 | end 57 | var_out{1} = 'extern_functions'; 58 | var_out{2} = ext_funs; 59 | end 60 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_Terminator.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_Terminator( block, ir_struct, varargin ) 2 | %WRITE_TERMINATOR 3 | 4 | warning_msg = ['A Terminator block have been found. No code will be generated for it:\n' block.Origin_path]; 5 | display_msg(warning_msg, 2, 'write_code', ''); 6 | 7 | output_string = ''; 8 | var_out = {}; 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/blocks/write_ToWorkspace.m: -------------------------------------------------------------------------------- 1 | function [ output_string, var_out ] = write_ToWorkspace( block, ir_struct, varargin ) 2 | %WRITE_TOWORKSPACE 3 | output_string = ''; 4 | var_out = {}; 5 | 6 | warning_msg = ['A ToWorkspace block have been found. No code will be generated for it:\n' block.Origin_path]; 7 | display_msg(warning_msg, 2, 'write_code', ''); 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/CoCoSpec.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | classdef CoCoSpec 8 | methods (Static = true) 9 | function [contract]= get_cocospec(cocospec_file) 10 | contract = []; 11 | cs_id = fopen(cocospec_file, 'r'); 12 | line = fgets(cs_id); 13 | is_cs = 'no'; 14 | while ischar(line) 15 | if regexp(line, '^%{') 16 | is_cs = 'yes'; 17 | elseif regexp(line, '^%}') 18 | is_cs = 'no'; 19 | else 20 | if strcmp(is_cs, 'yes') 21 | if regexp(line, '^%{') 22 | [con, remain] = strtok(line, '%{'); 23 | contract=[contract;{con}]; 24 | elseif regexp(line, '^%}') 25 | [con, remain] = strtok(line, '%}'); 26 | contract=[contract;{con}]; 27 | else 28 | contract=[contract;{line}]; 29 | end 30 | end 31 | end 32 | % if regexp(line, '^%') 33 | % r = strrep(line,'%',''); 34 | % if regexp(r, '^ contract') 35 | % 36 | % [contract, remain] = strtok(r, ' contract'); 37 | % spec_names=[spec_names;{contract}]; 38 | % end 39 | % spec = app_sprintf(spec, '%s', r); 40 | % end 41 | line = fgets(cs_id); 42 | end 43 | fclose(cs_id); 44 | end 45 | end 46 | end 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/blockType_format.m: -------------------------------------------------------------------------------- 1 | function [ blockType_out ] = blockType_format( blockType ) 2 | %BLOCKTYPE_FORMAT 3 | 4 | if BlockUtils.isCompareToMask(blockType) 5 | blockType_out = 'CompareTo'; 6 | elseif BlockUtils.isDetectMask(blockType) 7 | blockType_out = 'Detect'; 8 | else 9 | blockType_out = strrep(blockType, ' ', ''); 10 | blockType_out = strrep(blockType_out, '-', ''); 11 | end 12 | end 13 | 14 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/complex_arith_int.lus: -------------------------------------------------------------------------------- 1 | node complex_mult_int(x: complex_int; y: complex_int) 2 | returns (z: complex_int) 3 | let 4 | z.r = x.r * y.r - x.i * y.i; 5 | z.i = x.r * y.i + x.i * y.r; 6 | tel 7 | 8 | node complex_inv_int(x: complex_int) 9 | returns (z: complex_int) 10 | let 11 | z.r = x.r / (x.r * x.r - x.i * x.i); 12 | z.i = x.i / (x.r * x.r - x.i * x.i); 13 | tel 14 | 15 | node complex_sum_int(x: complex_int; y: complex_int) 16 | returns (z: complex_int) 17 | let 18 | z.r = x.r + y.r; 19 | z.i = x.i + y.i; 20 | tel 21 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/complex_arith_real.lus: -------------------------------------------------------------------------------- 1 | node complex_mult_real(x: complex_real; y: complex_real) 2 | returns (z: complex_real) 3 | let 4 | z.r = x.r * y.r - x.i * y.i; 5 | z.i = x.r * y.i + x.i * y.r; 6 | tel 7 | 8 | node complex_inv_real(x: complex_real) 9 | returns (z: complex_real) 10 | let 11 | z.r = x.r / (x.r * x.r - x.i * x.i); 12 | z.i = x.i / (x.r * x.r - x.i * x.i); 13 | tel 14 | 15 | node complex_sum_real(x: complex_real; y: complex_real) 16 | returns (z: complex_real) 17 | let 18 | z.r = x.r + y.r; 19 | z.i = x.i + y.i; 20 | tel 21 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/compute_complex_structs.m: -------------------------------------------------------------------------------- 1 | function [ complex_structs ] = compute_complex_structs( ir_struct, file_name ) 2 | %COMPUTE_COMPLEX_STRUCTS 3 | 4 | fields = fieldnames(ir_struct.(file_name).Content); 5 | fields(cellfun('isempty', regexprep(fields, '^Annotation.*', ''))) = []; 6 | complex_data = {}; 7 | 8 | for i=1:numel(fields) 9 | sub_blk = ir_struct.(file_name).Content.(fields{i}); 10 | indexes_in = find(sub_blk.CompiledPortComplexSignals.Inport); 11 | [inport_complex_data] = sub_blk.CompiledPortDataTypes.Inport(indexes_in); 12 | indexes_out = find(sub_blk.CompiledPortComplexSignals.Outport); 13 | [outport_complex_data] = sub_blk.CompiledPortDataTypes.Outport(indexes_out); 14 | complex_data = [complex_data inport_complex_data outport_complex_data]; 15 | end 16 | 17 | complex_data = unique(complex_data); 18 | for i=1:numel(complex_data) 19 | complex_data{i} = LusUtils.get_lustre_dt(complex_data{i}); 20 | end 21 | complex_data = unique(complex_data); 22 | 23 | complex_structs = ''; 24 | for i=1:numel(complex_data) 25 | complex_structs = [complex_structs BusUtils.get_complex_struct(complex_data{i})]; 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/get_subsystem_struct.m: -------------------------------------------------------------------------------- 1 | function [ sub_struct ] = get_subsystem_struct( ir_struct, block ) 2 | %GET_SUBSYSTEM_STRUCT 3 | 4 | % Model_name 5 | block_path = block.Path; 6 | sub_path = fileparts(block_path); 7 | sub_struct = get_struct(ir_struct, sub_path); 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/list_var_action.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [lo] = list_var_action(unbloc, type, ir_struct) 7 | lo ={}; 8 | if strcmp(type, 'Action') 9 | for idx=1:numel(unbloc.action) 10 | action_block = get_struct(ir_struct, unbloc.action(idx)); 11 | preceding_block_full_name = regexp(action_block.Path, '/', 'split'); 12 | pre_block_level = action_block.name_level; 13 | preceding_block_name = Utils.concat_delim(preceding_block_full_name(end - pre_block_level : end), '_'); 14 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.CompiledPortDimensions.Ifaction, 1); 15 | dim = dim_r * dim_c; 16 | for idx_dim=1:dim 17 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.actionport(idx) + 1) '_' num2str(idx_dim)]; 18 | end 19 | end 20 | elseif strcmp(type, 'Trigger') 21 | for idx=1:numel(unbloc.trigger) 22 | trigger_block = get_struct(ir_struct, unbloc.trigger(idx)); 23 | preceding_block_full_name = regexp(trigger_block.Path, '/', 'split'); 24 | pre_block_level = trigger_block.name_level; 25 | preceding_block_name = Utils.concat_delim(preceding_block_full_name(end - pre_block_level : end), '_'); 26 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.CompiledPortDimensions.Trigger, 1); 27 | dim = dim_r * dim_c; 28 | for idx_dim=1:dim 29 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.triggerport(idx) + 1) '_' num2str(idx_dim)]; 30 | end 31 | end 32 | elseif strcmp(type, 'Enable') 33 | for idx=1:numel(unbloc.enable) 34 | enable_block = get_struct(ir_struct, unbloc.enable(idx)); 35 | preceding_block_full_name = regexp(enable_block.Path, '/', 'split'); 36 | pre_block_level = enable_block.name_level; 37 | preceding_block_name = Utils.concat_delim(preceding_block_full_name(end - pre_block_level : end), '_'); 38 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.CompiledPortDimensions.Enable, 1); 39 | dim = dim_r * dim_c; 40 | for idx_dim=1:dim 41 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.enableport(idx) + 1) '_' num2str(idx_dim)]; 42 | end 43 | end 44 | end 45 | 46 | end 47 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/list_var_outport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function li_index = list_var_outport(block_outport) 7 | li_index = {}; 8 | dim_outport= block_outport.srcport_size; 9 | block_full_name = regexp(block_outport.name, '/', 'split'); 10 | block_name = Utils.concat_delim(block_full_name{1}(end - block_outport.name_level : end), '_'); 11 | for k2=1:dim_outport 12 | li_index{k2} = [block_name '_' block_outport.portnumber '_' num2str(k2) '_']; 13 | %li_index{k2} = ['out' block_outport.portnumber '_' num2str(k2) '_']; 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/list_var_sortie.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [list_out] = list_var_sortie(unbloc) 7 | list_out = {}; 8 | block_full_name = regexp(unbloc.Path, '/', 'split'); 9 | if unbloc.name_level >= numel(block_full_name{1}) 10 | block_name = Utils.concat_delim(block_full_name, '_'); 11 | else 12 | block_name = Utils.concat_delim(block_full_name(end - unbloc.name_level : end), '_'); 13 | end 14 | 15 | dims = unbloc.CompiledPortDimensions.Outport; 16 | num_pred = 0; 17 | idx_dim = 1; 18 | 19 | for k1=1:unbloc.Ports(2) 20 | [is_bus, ~] = BusUtils.is_bus(unbloc.CompiledPortDataTypes.Outport(k1)); 21 | if is_bus 22 | for idx=1:unbloc.CompiledPortWidths.Outport(k1) 23 | list_out{num_pred + 1} = [block_name '_' num2str(k1) '_' num2str(idx)]; 24 | num_pred = num_pred + 1; 25 | idx_dim = idx_dim + 1; 26 | end 27 | else 28 | if dims(idx_dim) == -2 29 | % Here we have a virtual bus, the shape of dims is: 30 | % [-2 {nb_bus_fields}] 31 | nb_bus_fields = dims(idx_dim + 1); 32 | cpt = 0; 33 | for idx=1:nb_bus_fields 34 | [dim_r, dim_c] = Utils.get_port_dims_simple(dims((idx_dim+2:numel(dims))), 1); 35 | for idx_row=1:dim_r 36 | for idx_col=1:dim_c 37 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 38 | list_out{num_pred + in_out_idx} = [block_name '_' num2str(k1) '_' num2str(cpt + 1)]; 39 | cpt = cpt + 1; 40 | end 41 | end 42 | num_pred = num_pred + (dim_r * dim_c); 43 | [nb_dims, ~] = Utils.get_port_dims(dims((idx_dim+2:numel(dims))), 1); 44 | idx_dim = idx_dim + nb_dims + 1; 45 | end 46 | %correction of the old code (Hamza) 47 | idx_dim = idx_dim+2; 48 | else 49 | % This is a normal output 50 | [dim_r, dim_c] = Utils.get_port_dims_simple(dims((idx_dim:numel(dims))), 1); 51 | for idx_row=1:dim_r 52 | for idx_col=1:dim_c 53 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 54 | list_out{num_pred + in_out_idx} = [block_name '_' num2str(k1) '_' num2str(in_out_idx)]; 55 | end 56 | end 57 | num_pred = num_pred + (dim_r * dim_c); 58 | [nb_dims, ~] = Utils.get_port_dims(dims((idx_dim:numel(dims))), 1); 59 | idx_dim = idx_dim + nb_dims + 1; 60 | end 61 | end 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/math_functions.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ fun_code ] = math_functions( fun ) 7 | %MATH_FUNCTIONS Summary of this function goes here 8 | % Detailed explanation goes here 9 | 10 | fun_code = ''; 11 | 12 | if strcmp(fun.Name, 'min') && strcmp(fun.Type, 'int*int') 13 | fun_code = 'node min(x,y:int) \n returns (z:int) \nlet \n\t z=if x1 26 | if isFunction 27 | label = chart.LabelString; 28 | for i=1:n 29 | ind = strfind(label,objects(i).Name); 30 | if ~isempty(ind) 31 | execution_order(i) = ind(1); 32 | else 33 | execution_order(i) = Inf; 34 | end 35 | end 36 | [~, sorted_ind] = sort(execution_order); 37 | sorted_objects = objects(sorted_ind); 38 | else 39 | if strcmp(port_or_order,'port') 40 | 41 | for i=1:n 42 | execution_order(i) = objects(i).Port; 43 | end 44 | [~, sorted_ind] = sort(execution_order); 45 | sorted_objects = objects(sorted_ind); 46 | 47 | elseif strcmp(port_or_order,'name') 48 | % sorted_objects = sort(objects); 49 | names = cell(1,n); 50 | for i=1:n 51 | names{i} = objects(i).Name; 52 | end 53 | [~, sorted_ind] = sort(names); 54 | sorted_objects = objects(sorted_ind); 55 | 56 | elseif strcmp(port_or_order,'order') 57 | for i=1:n 58 | execution_order(i) = objects(i).ExecutionOrder; 59 | end 60 | [~, sorted_ind] = sort(execution_order); 61 | sorted_objects = objects(sorted_ind); 62 | 63 | elseif strcmp(port_or_order,'states') 64 | execution_order = zeros(n,2); 65 | for i=1:n 66 | execution_order(i,:) = objects(i).Position(1:2); 67 | end 68 | [~, sorted_ind] = sortrows(execution_order); 69 | sorted_objects = objects(sorted_ind); 70 | end 71 | end 72 | end 73 | 74 | 75 | end 76 | 77 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/traceability_annotation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [pre_annot post_annot] = traceability_annotation(inter_blk) 7 | 8 | pre_annot = '\t'; 9 | post_annot = '\t'; 10 | 11 | blk_name = ''; 12 | for idx_name=1:numel(inter_blk.Path) 13 | blk_name = [blk_name inter_blk.Path{idx_name}]; 14 | end 15 | 16 | pre_annot = [pre_annot '-- Trace_begin: ' blk_name ';\n']; 17 | post_annot = [post_annot '-- Trace_end: ' blk_name ';\n']; 18 | 19 | end 20 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/common/write_buses.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Outputs the lustre string representation for the bus provided as input. 7 | function [bus_decl] = write_buses(bus_struct) 8 | 9 | bus_decl = ''; 10 | for idx=1:numel(bus_struct) 11 | bus = bus_struct(idx); 12 | name = bus.name; 13 | struct_str = sprintf('type %s = struct { ', name); 14 | fields = {}; 15 | for idx_elem=1:numel(bus.Elements) 16 | elem = bus.Elements(idx_elem); 17 | elem_fields = {}; 18 | dt = LusUtils.get_lustre_dt(elem.DataType); 19 | if numel(elem.Dimensions) == 1 20 | for idx_dim=1:elem.Dimensions 21 | elem_fields{idx_dim} = sprintf('%s_%d: %s', elem.Name, idx_dim, dt); 22 | end 23 | elseif numel(elem.Dimensions) == 2 24 | for idx_r=1:elem.Dimensions(1) 25 | for idx_c=1:elem.Dimensions(2) 26 | index = idx_c + elem.Dimensions(2) * (idx_r-1); 27 | elem_fields{index} = sprintf('%s_%d: %s', elem.Name, index, dt); 28 | end 29 | end 30 | else 31 | disp('error'); 32 | end 33 | fields{idx_elem} = Utils.concat_delim(elem_fields, '; '); 34 | end 35 | fields_str = Utils.concat_delim(fields, '; '); 36 | bus_decl = [bus_decl struct_str fields_str '};\n']; 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /src/middleEnd/lustre_compiler/frontEnd/write_config.m: -------------------------------------------------------------------------------- 1 | %% The map contains BlockTypes or MaskTypes associate with the function's name you want to call 2 | % If you don't want the basic write of a certain blocks, you can whether 3 | % change its code, or add your new function into lustre_ME/blocks/. If you 4 | % add a new function don't forget to specify it in this map. 5 | 6 | %% You must respect the Inputs and Outputs 7 | % Here is the signature your function must always have : 8 | % [string_output, varargout] = write_X(block, ir_struct, varargin); 9 | % here is how the function is called : 10 | % [string_output, varargout] = write_X(block, ir_struct, xml_trace). 11 | % So be aware that varargin{1} is xml_trace. You can add more inputs if you 12 | % want but don't delete them. 13 | % varargout is organized as follow : 14 | % varargout{i} = 'Name' 15 | % varargout{i+1} = Value 16 | % Here is the actual Name in varargout that are treated : 17 | % 'extern_functions', 'additional_variables', 'extern_s_functions', 18 | % 'extern_math_functions', 'c_code'. If you add others, you must add as 19 | % well their treatments in the code. 20 | 21 | %% Example : if you want to add the function my_function_name for the Sum 22 | % BlockType : 23 | % write_func_map('Sum') = 'my_function_name'; 24 | 25 | global write_func_map; 26 | 27 | write_func_map = containers.Map(); 28 | 29 | %% Add new functions here 30 | % write_func_map('BlockType or MaskType or SFBlockType') = 'your_function_path/name' 31 | -------------------------------------------------------------------------------- /src/preferences/loadCoCoSimPreferences.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2018 The university of Iowa 4 | % Author: Mudathir Mahgoub 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | function [ CoCoSimPreferences, modified ] = loadCoCoSimPreferences() 8 | % check if the preferences mat file is there 9 | path = fileparts(mfilename('fullpath')); 10 | preferencesFile = fullfile(path, 'preferences.mat'); 11 | if exist(preferencesFile, 'file') == 2 12 | load(preferencesFile, 'CoCoSimPreferences'); 13 | end 14 | 15 | modified = false; 16 | 17 | % check if the variable CoCoSimPreferences is defined 18 | if exist('CoCoSimPreferences', 'var') ~= 1 19 | CoCoSimPreferences = {}; 20 | modified = true; 21 | end 22 | 23 | % check if the modelChecker is defined 24 | if ~ isfield(CoCoSimPreferences,'modelChecker') 25 | CoCoSimPreferences.modelChecker = 'Kind2'; 26 | modified = true; 27 | end 28 | 29 | % check if irToLustreCompiler is defined 30 | if ~ isfield(CoCoSimPreferences,'irToLustreCompiler') 31 | CoCoSimPreferences.irToLustreCompiler = true; 32 | modified = true; 33 | end 34 | % check if compositionalAnalysis is defined 35 | if ~ isfield(CoCoSimPreferences,'compositionalAnalysis') 36 | CoCoSimPreferences.compositionalAnalysis = true; 37 | modified = true; 38 | end 39 | 40 | % check if kind2Binary is defined 41 | if ~ isfield(CoCoSimPreferences,'kind2Binary') 42 | % for windows the web service is the default 43 | if ispc 44 | CoCoSimPreferences.kind2Binary = 'Kind2 web service'; 45 | else 46 | CoCoSimPreferences.kind2Binary = 'Local'; 47 | end 48 | modified = true; 49 | end 50 | 51 | % check if verificationTimeout is defined 52 | if ~ isfield(CoCoSimPreferences,'verificationTimeout') 53 | CoCoSimPreferences.verificationTimeout = 60; % 60 seconds 54 | modified = true; 55 | end 56 | 57 | % save if CoCoSimPreferences is modified 58 | if modified 59 | save(preferencesFile, 'CoCoSimPreferences'); 60 | end 61 | end 62 | 63 | -------------------------------------------------------------------------------- /src/utils/Constants.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | classdef Constants 7 | properties (Constant) 8 | % Display message type constants 9 | INFO = 1; 10 | WARNING = 2; 11 | ERROR = 3; 12 | DEBUG = 4; 13 | RESULT = 5; 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /src/utils/app_sprintf.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [out_str] = app_sprintf(str, formatSpec, varargin) 7 | tmp = sprintf(formatSpec, varargin{:}); 8 | out_str = [str tmp]; 9 | end 10 | -------------------------------------------------------------------------------- /src/utils/cprintf.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim2/c179a83979512d8db1e7b7d98dbfd5688ad80d04/src/utils/cprintf.m --------------------------------------------------------------------------------