How to use Polyspace inside IAR Embbeded Workbench?

32 views (last 30 days)
I'm using IAR Embedded Workbench to edit and compile my code. Is it possible to launch Polyspace (Code Prover or Bug Finder) within this IDE?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 May 2018

It is possible to launch Polyspace from the IDE on your projects since IAR EW allows custom commands and menus (that can be used with environment variables), and because the compiler can be called in command line.

This integration described below will be based on the call to polyspace-configure to create an options file from the build command. A second command will be used to launch Bug Finder using this options file.

The first step is to create two .bat files, one to launch polyspace-configure and the other to call Polyspace Bug Finder.

Here is the contents of the first script, let's call it launch_configure.bat:

@echo off
REM Script that will launch polyspace-configure on the current IAR EW project. 
REM first parameter : path to the project (.ewp)
REM second parameter : configuration of the project (Debug, Release...)
set PRODUCT=E:\Program Files\MATLAB\R2018a
set BUILD_COMMAND=C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\common\bin\IarBuild.exe
set OPTIONS_FILE=.\options.opts
set PROJECT_PATH=%1
set CONFIG=%2
REM The build command is:
REM C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\common\bin\IarBuild.exe "path\to\the_project.eww" -build Debug
echo( 
echo ***************************
echo * Working, please wait... *
echo ***************************
echo(
REM launch polyspace-configure on the build command
"%PRODUCT%\polyspace\bin\polyspace-configure.exe" -allow-overwrite -output-options-file "%OPTIONS_FILE%" "%BUILD_COMMAND%" %PROJECT_PATH% -build %CONFIG%
echo( 
echo ********
echo * Done *
echo ********
Exit /B 0

And here is the contents of the second script, let's call it launch_bug_finder.bat:

@echo off
set PRODUCT=E:\Program Files\MATLAB\R2018a
set OPTIONS_FILE=.\options.opts
set EXTRA_OPTIONS_FILE=.\extra_options.txt
set RESULTS_DIR=E:\results
REM launch Bug Finder 
"%PRODUCT%\polyspace\bin\polyspace-bug-finder-nodesktop.exe" -options-file "%OPTIONS_FILE%" -options-file "%EXTRA_OPTIONS_FILE%" -results-dir "%RESULTS_DIR%"
REM launch the UI to view the results
"%PRODUCT%\polyspace\bin\polyspace.exe" -results-dir "%RESULTS_DIR%"
Exit /B 0

We will need a working folder where the scripts will be located and launched. Let's say it's : C:\EW_Integration.

To adapt the scripts to your environment, open each file and change the value of these variables:

  • PRODUCT: Enter your Polyspace installation folder.
  • RESULTS_DIR: Enter the folder where you want the Polyspace results to be saved.

The next step is to create two items in the Tools menu of your IDE will call these scripts.

Select Tools > Configure Tools.

Create two new entries. Each entry runs a .bat file.

Provide the path to the script <your_working_folder>\launch_configure.bat.

Enter the following:

Menu Text:

Polyspace Configure

Command:

<your_working_folder>\launch_configure.bat

Argument:

$PROJ_PATH$ $CONFIG_NAME$

Initial Directory:

<your_working_folder>

Make sure that the box 'Redirect to Output Window' is selected.

For the command Polyspace Bug Finder:

Provide the path to the script <your_working_folder>\launch_bug_finder.bat

Enter the following:

Menu Text:

Polyspace Bug Finder

Command:

<your_working_folder>\launch_configure.bat

Argument:

None

Initial Directory:

<your_working_folder>

Usage

Now that the tool commands have been added, here is how to use them.

  • For Polyspace Configure

Open your IAR EW project. Select Tools > Polyspace Configure. The script uses the polyspace-configure command which invokes your build configuration and builds your project. Note that the operation takes more time than the regular build process because of additional instrumentation.

If the polyspace-configure command completes execution, you see this message:

An options file is created in the working folder. The options file contains information about source files and compiler options.+ You use this options file to launch Polyspace Bug Finder.

  • For Polyspace Bug Finder

Select Tools > Polyspace Bug Finder. Follow the progress of analysis in the Tool Output window:

After analysis, the Polyspace results open automatically.

The analysis uses default Bug Finder options.

To modify them, use the file extra_options in your working folder.

The file is empty by default. Enter one Polyspace Bug Finder option per line.

For example, to enable checking of the mandatory and required subset of MISRA-C:2012 rules, add this line:

   -misra3 mandatory-required

Repeat these two steps each time you change something related to compilation, for instance, when you add or remove a new file or define a new symbol.

If you modify an existing source file, use the Polyspace Bug Finder menu item only.

Creating a project file

If you prefer to change Polyspace options graphically and launch the analysis in the Polyspace user interface, create a third menu item.

This menu item uses the polyspace-configure command with the -output-project option so that a project is created instead of an options file.

Similar to the previous scripts, add a new entry to the Tools menu:

Menu Text:

Create Polyspace project

Command:

<your_working_folder>\create_project_file.bat

Argument:

$PROJ_PATH$ $CONFIG_NAME$

Initial Directory:

<your_working_folder>

When you select Tools > Create Polyspace project, a project file (with extension .psprj) is created in the working folder.

Open this project file in the Polyspace user interface:

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!