Supported Keil or IAR Language Extensions
Polyspace® analysis can interpret a subset of common C/C++ language constructs and
extended keywords by default. For compiler-specific keywords, you must specify your
choice of compiler. If you specify keil
or
iar
for Compiler
(-compiler)
, the Polyspace verification allows language extensions specific to the Keil or IAR
compilers.
Note
If you use an IAR Embedded Workbench compiler, use the option IAR Embedded Workbench Compiler (-compiler
iar-ew)
to enable IAR-specific extensions of the C
language.
Special Function Register Data Type
Embedded control applications frequently read and write port data, set timer
registers, and read input captures. To deal with these requirements without using
assembly language, some microprocessor compilers define special data types such as
sfr
and sbit
. Typical declarations
are:
sfr A0 = 0x80; sfr A1 = 0x81; sfr ADCUP = 0xDE; sbit EI = 0x80;
The declarations reside in header files such as
regxx.h
for the basic 80Cxxx
micro
processor. The declarations customize the compiler to the target processor.
You access a register or a port by using the
sfr
and sbit
data as follows. However,
these data types are not part of the C99
Standard.
int status,P0; void main (void) { ADCUP = 0x08; /* Write data to register */ A1 = 0xFF; /* Write data to Port */ status = P0; /* Read data from Port */ EI = 1; /* Set a bit (enable all interrupts) */ }
To analyze this type of code, use these options:
Compiler (-compiler)
— Specifykeil
.Sfr type support (-sfr-types)
— Specify the data type and size in bits.
For example, if you define the sbit
data type
as:
sbit ADST = ADCUP^7;
-compiler keil -sfr-types sfr=8
The analysis then supports the Keil language extensions even if some structures, keywords, and syntax are not part of the C99 standard.
Support Additional sbit
Syntax
If you use a dot (.
) or colon (:
) as a
bit selector in the sbit
definition instead of a caret
(^
), for
example:
sbit ADST = ADCUP.7; // or sbit ADST = ADCUP:7;
#!/usr/bin/perl binmode STDOUT; # Process every line from STDIN until EOF while ($line = <STDIN>) { # Replace bit selector "." in sbit declarations by "^" # For example, the following line # sbit readybit = ADC.2; # Will be replaced by: # sbit readybit = ADC^2; $line =~ s/(sbit\s*[A-Za-z0-9_]+\s*=.*)\.([0-9])/\1^\2/g; # Same kind of replacement for the case where the bit selector is ":" $line =~ s/(sbit\s*[A-Za-z0-9_]+\s*=.*):([0-9])/\1^\2/g; # Print the current processed line to STDOUT print $line; }
Command/script to apply to preprocessed files
(-post-preprocessing-command)
.Keywords Removed During Preprocessing
Once you specify the Keil or IAR compiler, the analysis recognizes compiler-specific keywords in your code. If a keyword is not relevant for the analysis, it is removed from the source code during preprocessing.
If you disable the keyword and use it as an identifier instead, you can encounter a compilation error when you compile your code with Polyspace. See Fix Polyspace Compilation Errors Related to Keil or IAR Compiler.
These keywords are removed during preprocessing:
Keil —
bdata
,idata
,interrupt
,reentrant
,__interrupt
.If macro
__C51__
is defined, these keywords are also removed during preprocessing:code
,data
,far
,huge
,large
,pdata
,sdata
,xdata
,xhuge
.IAR —
bdata
,code
,idata
,interrupt
,non_banked
,pdata
,plm
,reentrant
,__interrupt
,__intrinsic
.