This chapter contains the following sections:
Control Program
Compiler
Detailed Description of the Compiler Options
Include Files
Pragmas
Compiler Limits
The control program cctri facilitates the invocation of the various components of the TriCore toolchain, from a single command line. The control program accepts source files and options on the command line in random order.
The invocation syntax of the control program is:
Options are preceded by a '-' (minus sign). The input file can have one of the extensions explained below.
When you use a UNIX shell (Bourne shell,
C-shell), arguments containing special characters (such as '( )' and '?') must be enclosed
with "" or escaped. The -? option
(in the C-shell) becomes: "-?"
or -\?.
The control program recognizes the following argument types:
Normally, a control program tries to compile and assemble all source files to object files, followed by a link and locate phase which produces an absolute output file. There are however, options to suppress the assembler, linker or locator stage. The control program produces unique filenames for intermediate steps in the compilation process, which are removed afterwards.
The following options are interpreted by the control program:
Option | Description | ||||||||||||||||||||||||||||||||||||
-? or none | Display invocation syntax | ||||||||||||||||||||||||||||||||||||
-Waarg | Pass argument directly to the assembler | ||||||||||||||||||||||||||||||||||||
-Wcarg | Pass argument directly to the C compiler | ||||||||||||||||||||||||||||||||||||
-Wcparg | Pass argument directly to the C++ compiler | ||||||||||||||||||||||||||||||||||||
-Wlkarg | Pass argument directly to the linker | ||||||||||||||||||||||||||||||||||||
-Wlcarg | Pass argument directly to the locator | ||||||||||||||||||||||||||||||||||||
-Wplarg | Pass argument directly to the C++ pre-linker | ||||||||||||||||||||||||||||||||||||
-V | Display version header only | ||||||||||||||||||||||||||||||||||||
-c++ | Force .c files to C++ mode | ||||||||||||||||||||||||||||||||||||
-c |
Do not link: stop at .obj
-cc |
Compile C++ files to .c and stop |
-cl |
Do not locate: stop at .out |
-cm |
Always also invokes the C++ muncher |
-cp |
Always also invokes the C++ pre-linker |
-cs |
Do not assemble: compile C files to .src and stop |
-elf |
Set locator output file format to ELF/DWARF |
-f file |
Read arguments from file ("-" denotes
standard input) |
-fptrap |
Use a floating point library with trap handler. |
-ieee |
Set locator output file format to IEEE-695 (default) |
-ihex |
Set locator output file format to Intel Hex |
-nolib |
Do not link with the standard libraries |
-o file |
Specify the output file |
-srec |
Set locator output file format to Motorola S-records |
-tiof |
Set locator output file format to TIOF-695 |
-tmp |
Keep intermediate files |
-v |
Show command invocations |
-v0 |
Show command invocations, but do not start them |
-wc++ |
Enable C and assembler warnings for C++ files | |
Table 4-1: Control program options
For more detailed information about
the control program cctri, refer to section cctri in Chapter
Utils of the Cross-Assembler Linker/Locator, Utilities User Guide.
The invocation syntax of the C compiler is:
When you use a UNIX shell (Bourne shell,
C-shell), arguments containing special characters (such as '( )' and '?') must be enclosed
with "" or escaped. The -? option
(in the C-shell) becomes: "-?"
or -\?.
The C compiler accepts C source file names and command line options in random order. Source files are processed in the same order as they appear on the command line (left-to-right). Options are indicated by a leading '-' character. Each C source file is compiled separately and the compiler generates an output file with suffix .src per C source module, containing assembly source code.
The priority of the options is left-to-right: when two options conflict, the first (most left) one takes effect. The -D and -U options are not considered conflicting options, so they are processed left-to-right for each source file. You can overrule the default output file name with the -o option. The compiler uses each -o option only once, so it is possible to specify multiple -o options for multiple source files.
When you invoke ctri without any argument, the invocation syntax is displayed (same as -? option).
A summary of the options is given below. The next section describes the options in more detail.
Option | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-? | Display invocation syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-A[flag...] | Control language extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-Ccpu | Include SFR definition file regcpu.sfr before source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-Dmacro[=def] |
Define preprocessor macro
-E[m|l] |
Preprocess only or emit dependencies or enable multi-line macros |
-F |
Treat 'double' as 'float' |
-Fc |
Enable 'float' constants |
-FPU |
Allow the use of single precision floating point hardware instructions |
-Hfile |
Include file before starting compilation |
-Idirectory |
Look in directory for include files |
-K |
No type-checking for old-style (K&R) function calls |
-N |
Allocate all data in _near memory |
-Nthreshold |
Threshold for _near/_far allocation (default 8) |
-Oflag... |
Control optimization |
-R[name] |
Change default section name |
-TC2 |
Allow use of TriCore2 instructions |
-Umacro |
Remove preprocessor macro |
-V |
Display version header only |
-WAE |
Treat warning messages as errors |
-Z |
Allocate all data in _a0 memory |
-Zthreshold |
Threshold for _a0 allocation (default 0) |
-builtin |
Display the list of builtin (intrinsic) functions |
-c |
Allocate strings in code memory |
-e |
Remove output file if compiler errors occur |
-err |
Send diagnostics to error list file (.err) |
-f file |
Read options from file |
-g[f|l|n]... |
Enable symbolic debug information (unless -gn is used) |
-indirect |
Generate indirect call and jump instructions for indirect function calling |
-misracn,n,... |
Enable individual MISRA C checks |
-n |
Send output to standard output |
-o file |
Specify name of output file |
-s |
Merge C-source code with assembly output |
-u |
Treat all 'char' variables as unsigned |
-w[num] |
Suppress one or all warning messages |
-wstrict |
Suppress strict warnings (196,303) |
-zpragma |
Identical to '#pragma pragma' in
the C source | |
Table 4-2: Compiler options (alphabetical)
Description | Options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Include options | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Read options from file |
-f file
Include SFR definition file regcpu.sfr before source |
-Ccpu |
Include file before starting compilation |
-Hfile |
Look in directory for include files |
-Idirectory |
Preprocess options |
|
Preprocess only or emit dependencies or enable multi-line macros |
-E[m|l] |
Define preprocessor macro |
-Dmacro[=def] |
Remove preprocessor macro |
-Umacro |
Allocation control options |
|
Allocate all data in _near memory |
-N |
Threshold for _near/_far allocation (default 8) |
-Nthreshold |
Allocate all data in _a0 memory |
-Z |
Threshold for _a0 allocation (default 0) |
-Zthreshold |
Change default section name |
-R[name] |
Allocate strings in code memory |
-c |
Code generation options |
|
Allow the use of single precision floating point hardware instructions |
-FPU |
Control optimization |
-Oflag...
|
Allow use of TriCore2 instructions |
-TC2 |
Generate indirect call and jump instructions for indirect function calling |
-indirect |
Identical to '#pragma pragma' in
the C source |
-zpragma |
Language control options |
|
Enable/disable specific language extensions |
-A[flag...] |
Treat 'double' as 'float' |
-F |
Enable 'float' constants |
-Fc |
No type-checking for old-style (K&R) function calls |
-K |
Treat all 'char' variables as unsigned |
-u |
Output file options |
|
Display the list of builtin (intrinsic) functions |
-builtin |
Remove output file if compiler errors occur |
-e |
Send output to standard output |
-n |
Specify name of output file |
-o file |
Merge C-source code with assembly output |
-s |
Diagnostic options |
|
Display invocation syntax |
-? |
Display version header only |
-V |
Treat warning messages as errors |
-WAE |
Send diagnostics to error list file (.err) |
-err |
Enable symbolic debug information (unless -gn
is used) |
-g[f|l|n]...
|
Enable individual MISRA C checks |
-misracn,n,... |
Suppress one or all warning messages |
-w[num] |
Suppress strict warnings (196,303) |
-wstrict | |
Table 4-3: Compiler options (functional)
Option letters are listed below. Each option (except -o; see description of the -o option ) is applied to every source file. If the same option is used more than once, the first (most left) occurrence is used. The placement of command line options is of no importance except for the -I and -o options. For the -o option, the filename may not start immediately after the option. There must be a tab or space in between. All other option arguments must start immediately after the option. Source files are processed in the same order as they appear on the command line (left-to-right).
Some options have an equivalent pragma.
With options that can be set from within EDE, you will
find a mouse icon that describes the corresponding action.
-?
Display an explanation of options at stdout.
ctri -?
Select the Project | C Compiler Options | Project Options... menu item. Set or disable the
Language Extensions in the Language
tab.
-A[flags]
Optionally one or more language extension flags.
-A1
Control language extensions. -A without any flags, specifies strict ANSI mode; all language extensions are disabled. This is equivalent to -ACKLPRSTV and -A0.
Flags which are controlled by a letter, can be switched on with the lower case letter and switched off with the uppercase letter. Note that the usage of these options might have effect on code density and code execution performance. The following flags are allowed:
c Default. Do not check for assignments of a constant string to a non-constant string pointer. With this option the following example produces no warning:
char *p; void main( void ) { p = "hello"; }
C Conform to ANSI-C by checking for assignments of a constant string to a non-constant string pointer. The example above produces warning W130: "operands of '=' are pointers to different types".
k Default. Allow keyword language extensions such as _near, _far and _at.
K Keyword extensions are not allowed.
l Default. 500 significant characters are allowed in an identifier instead of the minimum ANSI-C translation limit of 31 significant characters. Note: more significant characters are truncated without any notice.
L Conform to the minimum ANSI-C translation limit of 31 significant characters. This makes it possible to translate your code with any ANSI-C conforming C-compiler. Note: more significant characters are truncated without any notice.
p Default. Allow C++ style comments in C source code. For example:
// e.g this is a C++ comment line.
P Do not allow C++ style comments in C source code, to conform to strict ANSI-C.
r Default. Allow the use of the restrict qualifier.
R Do not alow the use of the restrict qualifier.
s Default. __STDC__ is defined as '0'. The decimal constant '0', intended to indicate a non-conforming implementation. When one of the language extensions are enabled __STDC__ should be defined as '0'.
S __STDC__ is defined as '1'. In strict ANSI-C mode (-A) __STDC__ is defined as '1'.
t Default. Do not promote old-style function parameters when prototype checking.
T Perform default argument promotions on old-style function parameters for a strict ANSI-C implementation. char type arguments are promoted to int type and float type arguments are then promoted to double type.
v Default. Allow type cast of an lvalue object with incomplete type void and lvalue cast which does not change the type and memory of an lvalue object.
Example:
void *p; ((int*)p)++; /* allowed */ int i; (char)i=2; /* NOT allowed */
V A cast may not yield an lvalue, to conform strict ANSI-C mode.
0 - same as -ACKLPRSTV (disable all, strict ANSI-C)
1 - same as -Acklprstv (default, enable all)
To disable language keyword extensions and C++ comments enter:
ctri -AKP test.c
-builtin
Displays a list of function prototypes for all intrinsic functions.
ctri -builtin test.c
Select the Project | Processor Options... menu item and choose the CPU tab. Select a CPU type in the CPU type field.
If you select User defined in the CPU type field, type the name of your TriCore derivative in the User specified CPU name field.
If you select User defined in the CPU type field and leave the User specified CPU name field empty, the option -C is not used.
-Ccpu
The CPU name which identifies your TriCore derivative.
Use special function register definitions for cpu. The filename looked for is "regcpu.sfr". The search algorithm for .sfr files is the same as for include files that are enclosed in "" at the beginning of the C source. The file is included before the source.
To use SFR definitions from the file regtc10gp.sfr, enter:
ctri -Ctc10gp test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the Allocate strings in code memory check box in the Allocation tab.
-c
Use this option to force allocation of strings or floating point constants in code memory. By default, these constants are allocated in data memory.
ctri -c test.c
Select the Project | C Compiler Options | Project Options... menu item. Define a macro (syntax: macro[=def]) in the Define user macros field in the Preprocessing tab. You can define more macros by separating them with commas.
-Dmacro[=def]
The macro you want to define and optionally its definition.
Define macro to the preprocessor, as in #define. If def is not given ('=' is absent), '1' is assumed. Any number of symbols can be defined. The definition can be tested by the preprocessor with #if, #ifdef and #ifndef, for conditional compilations. If the command line is getting longer than the limit of the operating system used, the -f option is needed.
The following command defines the symbol NORAM as 1 and defines the symbol PI as 3.1416.
ctri -DNORAM -DPI=3.1416 test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the Preprocess only and capture output check box in the Preprocessing tab.
-E[m|l]
Run the preprocessor of the compiler only and send the output to stdout. When you use the -E option, use the -o option to separate the output from the header produced by the compiler.
When you use the -Em option, the compiler generates dependency rules which can be used by a 'make' utility.
When you use the -El option, you can use multi-line macros. A backslash used to continue a macro on the next source line will be expanded as a new line instead of a concatenation of the lines.
The following command preprocesses the file test.c and sends the output to the file preout.
ctri -E -o preout test.c
The following command preprocesses the file test.c which may contain multi-line macros, and sends the output to the file multi.
ctri -El test.c -o multi
The following command generates dependency rules for the file test.c which can be used by mktri (the TriCore 'make' utility).
ctri -Em test.c test.src : test.c
EDE always removes the output file on errors.
-e
Remove the output file when an error has occurred. With this option the 'make' utility always does the proper productions.
ctri -e test.c
In EDE this option is not so useful. If you would use
this option you would not see the error messages in the
Build tab.
-err
Write errors to the file source.err instead of stderr.
To write errors to the test.err instead of stderr, enter:
ctri -err test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the Treat type 'double' as 'float' and/or Use type 'float' instead of 'double' for floating point constants check box in the
Misc tab.
-F[c]
-F forces using single precision floating point only, even when double or long double is used. In fact double and long double are treated as float and default argument promotion from float to double is suppressed. When you use this option, you must use the single precision version of the C library.
See the chapter
Libraries for the naming conventions of the standard libraries.
-Fc enables the use of 'float' constants. In ANSI C floating point constants are treated having type double, unless the constant has the suffix 'f'. So '3.0' is a double precision constant, while '3.0f' is a single precision constant. This option tells the compiler to treat all floating point constants as single precision float types (unless they have an explicit 'l' suffix).
To force double to be treated as float, enter:
ctri -F test.c
-f file
A filename for command line processing. The filename "-" may be used to denote standard input.
Use file for command line processing. To get around the limits on the size of the command line, it is possible to use command files. These command files contain the options that could not be part of the real command line. Command files can also be generated on the fly, for example by the make utility.
More than one -f option is allowed.
Some simple rules apply to the format of the command file:
1. It is possible to have multiple arguments on the same line in the command file.
2. To include whitespace in the argument, surround the argument with either single or double quotes.
3. If you use quotes inside a quoted argument, use the following syntax:
a. If you use a single quote, surround the argument with double quotes. If you use a double quote, surround the argument with single quotes.
Example:
"Single quote ' embedded"
'Double quote " embedded'
b. If you use both types of quotes, split the argument in such a way that each embedded quote is surrounded by the opposite type of quote.
'Double quote " and single quote '"' embedded"
4. Some operating systems impose limits on the length of lines within a text file. To circumvent this limitation it is possible to use continuation lines. These lines end with a backslash and newline. In a quoted argument, continuation lines will be appended without stripping any whitespace on the next line. For non-quoted arguments, all whitespace on the next line will be stripped.
Example:
"This is a continuation \ line" -> "This is a continuation line" control(file1(mode,type),\ file2(type)) -> control(file1(mode,type),file2(type))
5. It is possible to nest command line files up to 25 levels.
Suppose the file mycmds containts the following line:
-err test.c
The command line can now be:
ctri -f mycmds
Select the Project | C Compiler Options | Project Options... menu item. Enable the Use hardware single precision floating point instructions check box in the
Misc tab.
This option is only available (and relevant) when you
enable the FPU present (on user defined CPU) check box on the CPU tab in the Project | Processor Options... menu item.
-FPU
The -FPU option allows the generation of single precision floating point instructions in the generated assembly file. When you select this option, the macro _FPU is defined in the C source file. For a more detailed description about the floating point arithmetic see Section 7.5, Floating Point Arithmetic in Chapter 7, Run-time Environment.
To allow the use of floating point unit (FPU) instructions in the generated assembly file, enter:
ctri -FPU test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the Generate symbolic debug information check box in the Debug tab. Optionally enable the Include debug information for non referenced types and Disable lifetime info for all types check boxes.
-g[f|l|n]...
Add directives to the output files, incorporating symbolic information to facilitate high level debugging.
With -gn you disable all debug, including type checking.
With -gl you disable lifetime information for all types.
If you use -gf, high level language type information is also emitted for types which are not referenced by variables. Therefore, this sub-option is not recommended.
To add symbolic debug information to the output files, enter:
ctri -g test.c
To add symbolic debug information to the output files but disable lifetime information for all types, enter:
ctri -gl test.c
To disable all symbolic debug information including type checking, enter:
ctri -gn test.c
Select the Project | C Compiler Options | Project Options... menu item. Enter a filename in the
First #include this file field in the Preprocessing tab.
-Hfile
The name of an include file.
Include file before compiling the C-source. This is the same as specifying #include "file" at the first line of your C-source.
ctri -Hstdio.h test.c
Select the Project | C Compiler Options | Project Options... menu item. Enter one or more directory paths
to the Include search path field in the Preprocessing tab.
-Idirectory
The name of the directory to search for include file(s).
Change the algorithm for searching #include files whose names do not have an absolute pathname to look in directory. Thus, #include files whose names are enclosed in "" are searched for first in the directory of the file containing the #include line, then in directories named in -I options in left-to-right order. If the include file is still not found, the compiler searches in a directory specified with the environment variable CTRIINC. CTRIINC may contain more than one directory. Finally, the directory ../include relative to the directory where the compiler binary is located is searched. This is the standard include directory supplied with the compiler package.
For #include files whose names are in <>, the directory of the file containing the #include line is not searched. However, the directories named in -I options (and the one in CTRIINC and the relative path) are still searched.
ctri -I/proj/include test.c
Section Include Files.
Select the Project | C Compiler Options | Project Options... menu item. Enable the Call functions indirect check box in the Misc tab.
-indirect
With the -indirect option you can globally enable code generation for indirect function calling.
ctri -indirect test.c
See
Far Function Storage Qualifier.
Select the Project | C Compiler Options | Project Options... menu item. Disable the
Type checking for old (K&R) function calls check box in the Misc tab.
-K
Do not perform type-checking for old-style (K&R) function calls.
When a function is called without a visible prototype, the compiler will synthesize a prototype from the types of the function arguments. This prototype is then used for type checking of further calls to the same function. The -K option disables this type checking.
Consider the following two calls to a function without a visible prototype:
unknown(1,2); unknown(3);
The compiler will issue an error message for the second call, because it is not compatible with the prototype systhesized for the first call.
Select the Project | MISRA C Compiler Options | Project Options... menu item. Select one of the MISRA
C options. If you select Custom MISRA C configuration you can enable or disable specific rules in the numbered tabs.
-misracn,n,....
The MISRA C rules to be checked.
With this option, the MISRA C rules to be checked can be specified. Refer to Appendix B MISRA C for a list of supported and unsupported MISRA C rules.
ctri -misrac9 test.c
Will generate an error in case 'test.c' contains nested comments.
Select the Project | C Compiler Options | Project Options... menu item. Select a _near allocation radio button in the Allocation
tab. Optionally enter a threshold value.
-N[threshold]
Optionally the threshold size of an object (in bytes).
-N8
Specify the threshold for _near/_far allocation. When you do not specify either _near or _far in a declaration, the compiler uses a default based on the size of the object. Objects smaller or equal to the threshold will be allocated _near. Larger objects, arrays and strings will be allocated _far.
The default threshold is eight bytes.
When the -N option is specified without a threshold value, all objects will be allocated _near., including arrays and string constants.
To specify a threshold of 12 bytes, enter:
ctri -N12 test.c
-n
Do not create output files; instead, the output is sent to stdout.
ctri -n test.c
Select the Project | C Compiler Options | Project Options... menu item. You can control optimizations
in the Optimization
tab.
-Oflags
optimize flags
One or more optimization flags.
-O1
Control optimization. If you do not use this option, the default optimization of ctri is -O1, which is an optimization level to let ctri generate the smallest code.
Flags which are controlled by a letter, can be switched on with the lower case letter and switched off with the uppercase letter. These options are described together.
All optimization flags can also be given in the source file after a #pragma optimize.
An overview of the flags is given below.
a - relax alias checking (needs -Oc)
c - common subexpression elimination
e - expression propagation (needs -Oc)
f - code flow, order rearranging
i - move invariant code outside loop (needs -Oc)
l - fast loops (increases code size)
o - software pipelining (needs -Ocfv,
increases code size)
p - data flow, constant/copy propagation
s - optimize for speed
t - tail call conversion
u - loop unrolling
v - subscript strength reduction
w - global variable writeback caching
y - peephole optimization
z - pipeline scheduler
0 - same as -OACEFILOPSTUVWYZ (no
optim)
1 - same as -OacefiLOpStUvwyz (default,
size)
2 - same as -OacefilopstUvwyz (speed)
ctri -OACfILPv test.c
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Choose an Optimization level in the Optimization
tab.
-Onumber
A number in the range 0 - 2.
-O1
Control optimization. You can specify a single number in the range 0 - 2, to enable or disable optimization. The options are a combination of the other optimization flags:
-O0 - same as -OACEFILOPSTUVWYZ
Switchable optimizations switched off
-O1 - same as -OacefiLOpStUvwyz
Default. Set optimization flages to let ctri generate
the smallest code.
-O2 - same as -OacefilopstUvwyz
Set optimization flags to let ctri generate the fastest
code.
The flags 0 to 2 cannot be concatenated with other flags.
For example, -Oa2c is not allowd, -OacF
is allowed.
To optimize for code size, enter:
ctri -O1 test.c
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Relax alias checking check box.
-Oa / -OA
optimize a / optimize A
-OA
With -Oa you relax alias checking. If you specify this option, ctri will not erase remembered register contents of user variables if a write operation is done via an indirect (calculated) address to a variable with a different type.
It is quite safe to enable this optimization, unless
you are assigning the address of a variable to a pointer of a different type.
With -OA you specify strict alias checking. If you specify this option, the compiler erases all register contents of user variables when a write operation is done via an indirect (calculated) address.
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Common subexpression elimination (CSE) check box.
-Oc / -OC
optimize c / optimize C
-Oc
With -Oc you enable CSE (common subexpression elimination). With this option specified, the compiler tries to detect common subexpressions within the C code. The common expressions are evaluated only once, and their result is temporarily held in registers.
Note that the -Oc option must be on to enable moving invariant code outside a loop (-Oi).
With -OC you disable CSE (common subexpression elimination). With this option specified, the compiler will not try to search for common expressions. Also expression propagation and moving invariant code outside a loop will be disabled.
/* * Compile with -OC -O0, * Compile with -Oc -O0, common subexpressions are found * and temporarily saved. */ char x, y, a, b, c, d; void main( void ) { x = (a * b) - (c * d); y = (a * b) + (c * d);/*(a*b) and (c*d) are common */ }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Expression propagation check box.
-Oe / -OE
optimize e / optimize E
-Oe
With -Oe you enable expression propagation. With this option, the compiler tries to find assignments of expressions to a variable, a subsequent assignment of the variable to another variable can be replaced by the expression itself. Note that the option -Oc must be on to use this option.
With -OE you disable expression propagation.
/* * Compile with -OE -Oc -O0, normal cse is done * Compile with -Oe -Oc -O0, 'i+j' is propagated. */ unsigned i, j; int main( void ) { static int a; a = i + j; return (a); }
-Oc
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Control flow optimization and code reordering check box.
-Of / -OF
optimize f / optimize F
-Of
With -Of you enable control flow optimizations and code order rearranging on the intermediate code representation, such as jump chaining and conditional jump reversal.
With -OF you disable control flow optimizations.
The following example shows a control optimization:
/* * Compile with -OF -O0 * Compile with -Of -O0, compiler finds first time 'i' * is always < 10, the unconditional jump is removed. */ int i; void main( void ) { for( i=0; i<10; i++ ) { do_something(); } }
The following example shows a conditional jump reversal:
/* * Compile with -OF -O0, code as written sequential * Compile with -Of -O0, code is rearranged * * Code rearranging enables other optimizations to * optimize better, e.g. CSE */ int i; extern void dummy( void ); void main () { do { if ( i ) { i--; } else { i++; break; } dummy(); } while ( i ); }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Move invariant code outside loop check box.
-Oi / -OI
optimize i / optimize I
-Oi
With -Oi you move invariant code outside a loop. Note that the option -Oc must be on to use this option.
With -OI you disable moving invariant code outside a loop.
/* * Compile with -OI -Oc -O0, normal cse is done * Compile with -Oi -Oc -O0, invariant code is found in * the loop, code is moved outside the loop. */ void main( void ) { char x, y, a, b; int i; for( i=0; i<20; i++ ) { x = a + b; y = a + b; } }
-Oc
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Fast loops (more code size) check box.
-Ol / -OL
optimize l / optimize L
-OL
With -Ol you enable fast loops. Duplicate the loop condition. Evaluate the loop condition one time outside the loop, just before entering the loop, and at the bottom of the loop. This saves one unconditional jump and gives less code inside a loop.
With -OL you disable fast loops.
/* * Compile with -OL -O0 * Compile with -Ol -O0, compiler duplicates the loop * condition, the unconditional jump is removed. */ int i; void main( void ) { for( ; i<10; i++ ) { do_something(); } }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Software pipelining (increases code size) check box.
-Oo / -OO
optimize o / optimize O
-OO
With -Oo you enable software pipelining. Software Pipelining is a technique which increases parallelism in loops by executing iterations in an overlapped fashion. This includes the use of SIMD (single instruction multiple data) instructions. The optimization requires -Ocfv. Loops may execute up to four times faster with this optimization at the expense of an increased code size.
A loop must meet the following requirements:
When the loop updates an array it is necessary in most cases to tell the compiler that the array cannot overlap with other arrays used in the same loop. This can be achieved by declaring the arrays as restrict qualified pointers.
With -OO you disable software pipelining.
/* * With software pipelining enabled two iterations * will be done in parallel using SIMD instructions. */ _sat _sfract acc; void vquant(_sat _sfract *x, _sat _sfract *k) { int i; acc = 0; for (i = 0; i < 64; ++i) { acc += (k[i] - x[i]) * (k[i] - x[i]); } }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Constant and copy propagation check box.
-Op / -OP
optimize p / optimize P
-Op
With -Op you enable constant and copy propagation. With this option, the compiler tries to find assignments of constant values to a variable, a subsequent assignment of the variable to another variable can be replaced by the constant value.
With -OP you disable constant and copy propagation.
/* * Compile with -OP -O0, 'i' is actually assigned to 'j' * Compile with -Op -O0, 15 is assigned to 'j', 'i' was * propagated */ int i; int j; void main( void ) { i = 10; j = i + 5; }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Optimize for speed instead of size check box.
-Os / -OS
optimize s / optimize S
-Os
With -Os you tell the compiler to generate faster code. Whenever possible instructions are used that use less instruction cycles.
With -OS you disable optimization for speed, favor code size over execution speed.
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Tail call conversion check box.
-Ot / -OT
optimize t / optimize T
-Ot
With -Ot you tell the compiler to replace a CALL directly followed by a RET with a J instruction.
With -OT you disable this optimization. This may be the case for debugging.
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Loop unrolling check box.
-Ou / -OU
optimize u / optimize U
-OU
With -Ou you enable loop unrolling. With this option specified, the compiler tries to eliminate short loops by duplicating a loop body 2, 4 or 8 times. This reduces the number of branches and creates a longer linear code part.
With -OU you disable loop unrolling.
/* * Compile with -OU, normal loop handling * Compile with -Ou, loop is eliminated, body is duplicated */ int i, j; void main( void ) { for( i=0; i<2; i++ ) /* short loop */ { j = 2 * i; } }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Subscript strength reduction check box.
-Ov / -OV
optimize v / optimize V
-Ov
With -Ov you enable subscript strength reduction. With this option specified, the compiler tries to reduce expressions involving an index variable in strength.
With -OV you disable subscript strength reduction.
/* * Compile with -OV -O0, disable subscript strength reduction * Compile with -Ov -O0, begin and end address of 'a' are * determined before the loop and temporarily put in registers * instead of determining the address each time inside the loop */ int a[4]; void main( void ) { int i; for( i=0; i<4; i++ ) { a[i] = 0; } }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Global variable writeback caching check box in the
... Optimization tab.
-Ow / -OW
optimize w / optimize W
-Ow
With -Ow the compiler will cache multiple writes to a global variable in a register in some situations.
With -OW all updates of a global variable are directly written to memory.
/* * Compile with -OW -O0, 'sum' is updated twice * Compile with -Ow -O0, 'sum' is updated only once */ int sum; void add( int a, int b ) { sum += a; sum += b; }
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Peephole optimizer (remove redundant code) check box in the
... Optimization tab.
-Oy / -OY
optimize y / optimize Y
-Oy
With -Oy you enable peephole optimization. Remove redundant code. The peephole optimizer searches for redundent instructions or for instruction sequences which can be combined to minimize the number of instructions.
With -OY you disable peephole optimization.
Pragma optimize in section
Pragmas.
Select the Project | C Compiler Options | Project Options... menu item. Select the
Advanced optimization
level in the Optimization
tab. Enable or disable the Instruction pipeline scheduler check box in the ... Optimization tab.
-Oz / -OZ
optimize z / optimize Z
-Oz
With -Oz you enable instruction scheduling. The instruction scheduler will try to rearrange instructions in order to make better use of the parallel execution capabilities of the TriCore CPU. As a result, the program will run faster. A disadvantage of this optimization is that the assembly code generated by the C compiler is more difficult to read.
With -OZ you disable instruction scheduling.
Pragma optimize in section
Pragmas.
-o file
An output filename. The filename may not start immediately after the option. There must be a tab or space in between.
Module name with .src suffix.
Use file as output filename, instead of the module name with .src suffix. Special care must be taken when using this option, the first -o option found acts on the first file to compile, the second -o option acts on the second file to compile, etc.
When specified:
ctri file1.c file2.c -o file3.src -o file2.src
two files will be created, file3.src for the compiled file file1.c and file2.src for the compiled file file2.c.
Select the Project | C Compiler Options | Project Options... menu item. Add the option to the
Additional options field in the Misc tab.
-R[name]
section
Optionally, a section name.
The compiler defaults to a section naming convention, using a memory type abbreviation and the module name: code.name for code sections, bss.name for cleared direct addressable data, etc. In case a module must be loaded at a fixed address or a data section needs a special place in memory, you can use the -R option to generate a different section name. This way the order lctri allocates these sections can be specified in the locator description file.
To generate the section name section_type.NEW instead of the default section name section_type.mod_name, enter:
ctri -RNEW test.c
To generate the section name section_type instead of the default section name section_type.mod_name, enter:
ctri -R test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the
Merge C source code with assembly in output file (.src) check box in the
Output tab.
-s
source
Merge C source code with generated assembly code in output file.
ctri -s test.c
; test.c: ; 1 |int i; ; 2 | ; 3 |int ; 4 |main( void ) ; 5 |{ .global main .extern _START
Pragmas source and nosource in section
Pragmas.
Select the Project | Processor Options... menu item. Select the CPU tab. Select TC2 in the CPU type box.
-TC2
The -TC2 option allows the generation of TriCore2 instructions in the generated assembly file. When you select this option, the macro _TC2 is defined in the C source file.
To allow the use of TriCore2 instructions in the generated assembly file, enter:
ctri -TC2 test.c
Select the Project | C Compiler Options | Project Options... menu item. Undefine one or more of the predefined symbols _TASKING or _CTRI by disabling the corresponding check box
in the Preprocessing tab.
-Uname
The name macro you want to undefine.
Remove any initial definition of identifier name as in #undef, unless it is a predefined ANSI standard macro. ANSI specifies the following predefined symbols to exist, which cannot be removed:
__FILE__ "current source filename"
__LINE__ current source line number (int type)
__TIME__ "hh:mm:ss"
__DATE__ "Mmm dd yyyy"
__STDC__ level of ANSI standard. This macro is set to 1 when the option to disable language extensions (-A) is effective. Whenever language extensions are excepted, __STDC__ is set to 0 (zero).
When ctri is invoked, also the following predefined symbols exist:
_CTRI predefined symbol to identify the compiler. This symbol can be used to flag parts of the source which must be recognized by the ctri compiler only. It expands to the version number of the compiler.
_TASKING identifies the compiler. This symbol can be used to flag parts of the source which must be recognized by TASKINGs ctri only. It expands to 1.
_SINGLE_FP This symbol is defined when the -F option is used to map type double onto type float.
_DOUBLE_FP
This symbol is defined when the -F option is not used.
These symbols can be turned off with the -U option.
ctri -U_TASKING test.c
Select the Project | C Compiler Options | Project Options... menu item. Enable the
Treat 'char' variables as unsigned check box in the Misc tab.
-u
Treat 'character' type variables as 'unsigned character' variables. By default char is the same as specifying signed char. With -u char is the same as unsigned char.
With the following command char is treated as unsigned char:
ctri -u test.c
-V
Display version information.
ctri -V
TASKING TriCore C compiler vx.yrz Build nnn Copyright 1996-year Altium BV Serial# 00000000
-WAE
Treat warning messages as errors. This also affects the return value of the application when only warnings occur. A build process will now stop when warnings occur.
ctri -WAE test.c
Select the Project | C Compiler Options | Project Options... menu item. Select one of the
Diagnostics
options in the Output tab
and optionally fill in specific message numbers to suppress.
-w[num]
-wstrict
Optionally the warning number to suppress.
-w suppress all warning messages. -wnum only suppresses the given warning. -wstrict suppresses all "strict" warning messages (183, 196, 303).
To suppress warning 135, enter:
ctri file1.c -w135
Select the Project | C Compiler Options | Project Options... menu item. Select a _near allocation radio button in the Allocation
tab. Optionally enter a threshold value.
-Z[threshold]
Optionally the threshold size of an object (in bytes).
-Z0
Specify the threshold for _a0 allocation. When you do not specify any memory specifier such as _near or _far in a declaration, the compiler uses a default based on the size of the object
First, the size of the object is checked against the -N threshold, according to the description of the -N option. If the size is larger that the -N threshold, but lower or equal to the -Z threshold, the object is allocated in _a0 memory. Larger objects, arrays and strings will be allocated _far.
The default -Z threshold is zero, which means that the compiler will never use _a0 memory unless you specify the -Z option. When you use the -Z option without a threshold value, all objects not allocated _near, including arrays and string constants, will be allocated in _a0 memory.
Allocation in _a0 memory means that the object is addressed indirectly, using A0 as the base pointer. The total amount of memory that can be addressed this way is 64 Kbytes.
To specify a threshold of 12 bytes, enter:
ctri -Z12 test.c
Select the Project | C Compiler Options | Project Options... menu item. Add the option to the
Additional options field in the Misc tab.
-zpragma
A pragma. PragmasThe compiler recognizes all pragmas that are mentioned in section 4.4 Pragmas as well as pragmas that can be used to solve CPU functional problems (see Appendix C , CPU Functional Problems).
With this option you can give a pragma on the command line. This is the same as specifying '#pragma pragma' in the C source. Dashes ('-') on the command line in the pragma are converted to spaces. A dash prefixed by another dash or space is never translated, so it is still possible to specify a dash for negative numbers as pragma argument.
If you use quotes inside a quoted argument, use the following syntax:
a. If you use a single quote, surround the argument with double quotes. If you use a double quote, surround the argument with single quotes.
Example:
"Single quote ' embedded"
'Double quote " embedded'
b. If you use both types of quotes, split the argument in such a way that each embedded quote is surrounded by the opposite type of quote.
'Double quote " and single quote '"' embedded"
The following option
-zoptimize-p
is equivalent with:
#pragma optimize p
To include pragmas to enable bypasses for CPU functional problems, you can also use EDE:
Select the Project | Processor Options... menu and chooose the Bypasses TC1 v1.2 tab or the Bypasses TC1 v1.3 tab. Then select the bypasses you want to enable.
Section 4.4
,
Pragmas,
Appendix C,
CPU Functional Problems.
You may specify include files in two ways: enclosed in <> or enclosed in "". When an #include directive is seen, ctri used the following algorithm trying to open the include file:
1. If the filename is enclosed in "", and it is not an absolute pathname (does not begin with a '\' for PC, or a '/' for UNIX), the include file is searched for in the directory of the file containing the #include line. For example, in:
PC:
ctri ..\..\source\test.c
UNIX:
ctri ../../source/test.c
ctri first searches in the directory ..\..\source (../../source for UNIX) for include files.
If you compile a source file in the directory where the file is located (ctri test.c), the compiler searches for include files in the current directory.
This first step is not done for include files enclosed
in <>.
2. Use the directories specified with the -I options, in a left-to-right order. For example:
PC:
ctri -I..\..\include demo.c
UNIX:
ctri -I../../include demo.c
3. Check if the environment variable CTRIINC exists. If it does exist, use the contents as a directory specifier for include files. You can specify more than one directory in the environment variable CTRIINC by using a separator character. Instead of using -I as in the example above, you can specify the same directory using CTRIINC:
PC:
set CTRIINC=..\..\include ctri demo.c
UNIX:
CTRIINC=../../include export CTRIINC ctri demo.c
setenv CTRIINC ../../include ctri demo.c
4. When an include file is not found with the rules mentioned above, the compiler tries the subdirectory include, one directory higher than the directory containing the ctri binary. For example:
PC:
UNIX:
The compiler determines run-time which directory the binary is executed from to find this include directory.
A directory name specified with the -I option or in CTRIINC may or may not be terminated with a directory separator, because ctri inserts this separator, if omitted.
When you specify more than one directory to the environment variable CTRIINC, you have to use one of the following separator characters:
PC:
e.g. set CTRIINC=..\..\include;\proj\include
UNIX:
e.g. setenv CTRIINC ../../include:/proj/include
According to ANSI (3.8.6) a preprocessing directive of the form:
#pragma pragma-token-list new-line
causes the compiler to behave in an implementation-defined manner. The compiler recognizes all pragmas that are mentioned below as well as pragmas that can be used to solve CPU functional problems (see Appendix C, CPU Functional Problems). Other pragmas will be ignored. Pragmas give directions to the code generator of the compiler. Besides the pragmas there are two other possibilities to steer the code generation process: command line options and keywords (e.g., _near type variables) in the C application itself. The compiler acknowledges these three groups using the following rules:
Command line options can be overruled by keywords and pragmas. Keywords can be overruled by pragmas. Hence, pragmas have the highest priority.
This approach makes it possible to set a default optimization level for a source module, which can be overridden temporarily within the source by a pragma.
The C compiler ctri supports the following pragmas:
Align objects of four bytes or larger to a word boundary. By default, the minimum alignment dictated by the hardware is used. Depending on the cache configuration, using a larger alignment may be faster.
This pragma optionally accepts one of the following arguments:
Insert the following (non preprocessor lines) as assembly language source code into the output file. The inserted lines are not checked for their syntax. The code buffer of the peephole optimizer is flushed. Thus the compiler will stop optimizations like peephole pattern replacement and resumes these optimizations after the endasm pragma as if it starts at the beginning of a function.
See section 3.15
, Inline Assembly, for a description of the optional C variable interface.
For advanced assembly in-lining, intrinsic functions can be used. The defined set of intrinsic functions cover most of the specific TriCore features which could otherwise not be accessed by the C language.
For more information on intrinsic functions
see section 3.16, Intrinsic Functions.
Same as pragma asm, except that the except that the optimizer does not flush its information at this point, so that copy and constant propagation may be performed across the inline assembly fragment.
Perform 'clearing' of non-initialized static/public variables.
No 'clearing' of non-initialized static/public variables.
Switch back to the C language.
Force all enumeration types to type int. By default, the compiler uses char or short when that is sufficient to represent all enum values.
This pragma optionally accepts one of the following arguments:
Expand include files in generated list file.
Default. Do not expand include files in list file.
Controls the amount of optimization. The remainder of the source line is scanned for option characters, which are processed like the flags of the -O command line option. Please refer to the -O option for the list of available flags.
End a region that was optimized with a #pragma optimize. The pragma optimize restore restores the situation as it was before the corresponding pragma optimize. #pragma optimize/optimize restore pairs can be nested.
Example:
#pragma optimize 0 /* disable all optimizations */ . . . #pragma optimize 2 /* enable all optimizations */ switch(...) { . . . } #pragma optimize restore /* back to all optimizations disabled */ #pragma optimize restore /* back to default optimizations */
Qualify a structure or union type for halfword packing. The structure or union to be packed cannot have members that require an alignment larger than 2-byte.
Example:
#pragma pack 2 typedef struct { unsigned char uc1; unsigned char uc2; unsigned short us1; unsigned short us2; unsigned short us3; } packed_struct; #pragma pack 0
The #pragma pack directives can be nested.
See also Halfword Packed Unions and Structures.
Turn off halfword packing for structures and unions.
When you place a #pragma 0 before a structure or union, its alignment will not be changed:
#pragma pack 0 packed_struct pstruct;
Change the default section names for new objects. The default name used by the compiler consists of a prefix denoting the section type, and a suffix derived from the module name. For example, the default name for the code section of the module hello.c is code.hello. After a #pragma section, the current state will be the default situation plus all modifications from the last #pragma section. All modifications from previous #pragma section statements will be lost.
With #pragma section, you can change the default section name suffix or specify an alternative name for specific sections. To change the default suffix, specify the new suffix as a string after the pragma:
#pragma section "my_suffix"
You can also change the default section name suffix from
the command line with the -R option.
To change a specific section name, you have to specify the section type, an equal sign, followed by the new section name. For example:
#pragma section code="my_code" data="my_data"
The following section types are available:
Type | Description |
code | program code |
data | initialized _near data |
fardata | initialized _far data |
bss | uninitialized _near data (cleared) |
farbss | uninitialized _far data (cleared) |
rom | constant _near data |
farrom | constant _far data |
noclear | uninitialized _near data |
farnoclear | uninitialized _far data |
Table 4-4: Section types
#pragma section code_init
With the pragma above, the code section is copied from ROM to RAM when the program is started.
#pragma section data_overlay
The pragma above allows the noclear and farnoclear section to be overlayed with other sections with the same name. Because of the default naming scheme, you must force the existence of identical section names with #pragma section [sect_type =]"name". The use of the noclear sections must be forced with #pragma noclear.
The following pragmas allow the noclear overlay and the farnoclear overlay sections to be overlayed with similar named sections in other modules:
#pragma noclear #pragma section data_overlay "overlay"
To restore the default section naming scheme, use:
#pragma section
Same as -s option. Enable mixing C source with assembly code.
Default. Disable generation of C source within assembly code.
Use the alternative "stack" calling convention for the function or function pointer immediately following this pragma. This pragma is equivalent with the function qualifier _stackparm.
Default. The compiler decides what code to generate on a switch statement. In general, the compiler chooses the most efficient method in terms of code density and execution speed. See also the paragraph Switch Statement.
Force the compiler to generate linear jump code for switch statements. See also the paragraph Switch Statement.
Force the compiler to generate jump tables for switch statements. See also the paragraph Switch Statement.
Force the compiler to generate lookup tables for switch statements. See also the paragraph Switch Statement.
The compiler restores the previous switch method. See also the paragraph Switch Statement. Example:
#pragma switch linear /* linear jump code */ . . . #pragma switch lookup /* lookup tables */ switch(...) { . . . } #pragma switch restore /* back to switch linear */ #pragma switch restore /* back to default switch auto */
Switch StatementEnables all C compiler bypases for the TC112 CPU functional problems.
Switch StatementEnables all C compiler bypases for the TC113 CPU functional problems.
Switch StatementPragmas are also available to enable individual bypasses for CPU functional problems. These pragmas have the names of the functional problems as defined by Infineon. Refer to Appendix C, CPU Functional Problems for a complete overview of these pragmas.
The ANSI C standard [1-2.2.4] defines a number of translation limits, which a C compiler must support to conform to the standard. The standard states that a compiler implementation should be able to translate and execute a program that contains at least one instance of every one of the limits listed below. ctri's actual limits are given within parentheses.
Most of the actual compiler limits are determined by the amount of free memory in the host system. In this case a 'D' (Dynamic) is given between parentheses. Some limits are determined by the size of the internal compiler parser stack. These limits are marked with a 'P'. Although the size of this stack is 200, the actual limit can be lower and depends on the structure of the translated program.