JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
CodeSonar ships with compiler models for many industry standard compilers. In cases where none of these models are suitable, a custom compiler model may be required.
Compiler models can be authored in C++ or Python.
Note: STk compiler models are no longer supported. If you have previously implemented a custom STk compiler model and need assistance converting it to C++ or Python, contact CodeSecure.
In most cases you will not need a custom compiler model. Before reading the rest of this section, check the following to see it that there is a simpler solution for your build.
Even if your compiler is not directly based on any of the existing models, it may be similar enough to an existing model to work with no modification. Therefore, you should try mapping your compiler name to each model in turn to see if the build works before resorting to a custom model. Try the gcc model first: it is the most flexible, versatile, and tolerant.
If your project compiles correctly under your normal build system but you get errors when you run the CodeSonar build system, you may need to modify the compiler model.
The compiler model is responsible for obtaining all relevant information from a native compiler invocation and translating this information to individual compilation units for the CodeSonar front end.
Typical tasks for a compiler model include the following.
Some native command arguments have no effect on the compilation and so will not influence the CodeSonar front end command constructed by the compiler model. For example, the argument that controls warning message verbosity can be simply ignored by the compiler model.
The process for creating a new compiler model can be divided into five steps.
The remainder of this page describes these steps, with links to the sections about authoring compiler models in C++ and authoring compiler models in Python when the details are language-specific.
In this section (and throughout this manual), $CSONAR indicates the CodeSonar installation directory.
Compiler models need to account for the following. The compiler should have documentation that provides the necssary information.
You will also need to choose a name for your compiler model. This is the name that you will use in COMPILER_MODELS rules for mapping compiler executables to this model. The model name can be the same as the compiler executable name (without file extension), but does not have to be.
You can implement the model in either C++ or Python. Detailed implementation information is provided in separate sections:
| C++ | Implementing a compiler model in C++ |
|---|---|
| Python | Implementing a compiler model in Python |
In both cases, compiler models are implemented as classes that must must...
Illustrated example compiler models are provided:
Compiler models implemented in C++ must be built into shared libraries before installation; models implemented in Python are installed directly. In both cases, you will also need to set up one or more COMPILER_MODELS rules to map the relevant native compiler executables to your model.
| C++ | Build and Install |
|---|---|
| Python | Installing the Model |
When you use your new model to build a CodeSonar project, CodeSonar will load a corresponding project-compiler configuration file to control aspects of the process, creating it if necessary.
The process for creating a new compiler model therefore includes establishing whether or not you need to provide specific compiler template configuration files, and implementing them if necessary.
For a new compiler model called cmname:
| C++ | cmname.c++.32.conf and cmname.c++.64.conf. |
|---|---|
| Python | pya_cmname.c++.32.conf and pya_cmname.c++.64.conf. |
| C++ |
cp
$CSONAR/csurf/compiler_confs/unknown.c++.32.conf
$CSONAR/csurf/compiler_confs/cmname.c++.32.conf
cp $CSONAR/csurf/compiler_confs/unknown.c++.64.conf $CSONAR/csurf/compiler_confs/cmname.c++.64.conf |
|---|---|
| Python |
cp
$CSONAR/csurf/compiler_confs/unknown.c++.32.conf
$CSONAR/csurf/compiler_confs/pya_cmname.c++.32.conf
cp $CSONAR/csurf/compiler_confs/unknown.c++.64.conf $CSONAR/csurf/compiler_confs/pya_cmname.c++.64.conf |
Suppose you have created a model mycompilermodel for native compiler mycompiler, where the path to the native compiler executable is path/to/compilers/mycomp/bin/mycompiler. To test the model, proceed as follows.
If there are parse errors, then the compiler model is doing something wrong. Use the error messages to determine what constructs are being handled incorrectly, and amend your model (or configuration templates) to address the problems.
To report problems with this documentation, please visit https://support.codesecure.com/.