A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/paulross/cpip below:

GitHub - paulross/cpip: CPIP - a C/C++ preprocessor implemented in Python.

CPIP is a C/C++ Preprocessor implemented in Python. It faithfully records all aspects of preprocessing and can produce visualisations that make debugging preprocessing far easier.

Install cpip from PyPi:

(CPIP) $ pip install cpip

This will give you access to the command line entry point cpipmain, to check this:

(CPIP) $ cpipmain --help
...

You can check CPIP on some demonstration C code, for example, from the CPIP directory there is a demo directory. You can process this thus:

(CPIP) $ cpipmain -l20 -j1 -o demo/output -J demo/sys/ -I demo/usr/ demo/src/main.cpp
2017-11-17 10:29:16,370 INFO     preprocessFileToOutput(): demo/src/main.cpp
2017-11-17 10:29:16,371 INFO     TU in HTML:
2017-11-17 10:29:16,372 INFO       tmp/output_normal_02/main.cpp.html
2017-11-17 10:29:16,391 INFO     preprocessFileToOutput(): Processing TU done.
2017-11-17 10:29:16,391 INFO     Macro history to:
2017-11-17 10:29:16,391 INFO       tmp/output_normal_02
2017-11-17 10:29:16,400 INFO     Include graph (SVG) to:
2017-11-17 10:29:16,401 INFO       tmp/output_normal_02/main.cpp.include.svg
2017-11-17 10:29:16,423 INFO     Writing include graph (TEXT) to:
2017-11-17 10:29:16,423 INFO       tmp/output_normal_02/main.cpp.include.svg
2017-11-17 10:29:16,424 INFO     Conditional compilation graph in HTML:
2017-11-17 10:29:16,424 INFO       tmp/output_normal_02/main.cpp.ccg.html
2017-11-17 10:29:16,431 INFO     Done: demo/src/main.cpp
2017-11-17 10:29:16,432 INFO     ITU in HTML: .../main.cpp
2017-11-17 10:29:16,448 INFO     ITU in HTML: .../system.h
2017-11-17 10:29:16,453 INFO     ITU in HTML: .../user.h
2017-11-17 10:29:16,462 INFO     preprocessFileToOutput(): demo/src/main.cpp DONE
CPU time =    0.087 (S)
Bye, bye!

The result will be in demo/output/index.html.

There are other installation methods including directly from source.

Visualising Preprocessing

The top level entry point cpipmain (the script CPIPMain.py) acts like a preprocessor that generates HTML and SVG output for a source code file or directory. This output makes it easy to understand what the preprocessor is doing to your source.

Here is some of that output when preprocessing a single Linux kernel file cpu.c (complete output). The index.html page shows how CPIPMain.py was invoked [1], this has a link to to preprocessing pages for that file:

This page has a single link that takes you to the landing page for the file cpu.c, at the top this links to other pages that visualise source code, #include dependencies, conditional compilation and macros:

Lower down this page is a table of files that were involved in preprocessing:

Visualising the Source Code

From the cpu.c landing page the link "Original Source" takes you to a syntax highlighted page of the original source of cpu.c.

The cpu.c landing page link "Translation Unit" takes you to a page that shows the complete translation unit of cpu.c (i.e. incorporating all the #include files). This page is annotated so that you can understand what part of the translation unit comes from which file.

Visualising the #include Dependencies

The cpu.c landing page link "Normal [SVG]" takes you to a page that shows the dependencies created by #include directives. This is a very rich page that represents a tree with the root at center left. #include's are in order from top to bottom. Each block represents a file, the size is proportional to the number of preprocessing tokens.

Zooming in with the controls at the top gives more detail. If the box is coloured cyan it is because the file does not add any content to the translation unit, usually because of conditional compilation:

The page is dynamic and hovering over various areas provides more information:

How and Why the File was Included

Hovering just to the left of the file box produces a popup that explains how the file inclusion process worked for this file, it has the following fields:

Hovering over the filename above the file box shows the file stack (children are below parents).

This plot can also tell you what types of preprocessor tokens were processed for each file. The coloured bars on the left of the file box indicate the proportion of preprocessing token types, the left is the file on its own, the right is the file and its child files. To understand the legend hover over those bars:

To see the actual count of preprocessing tokens hover over the file box:

Visualising Conditional Compilation

The preprocessor is also responsible for handling conditional compilation which becomes very complicated for large projects. CPIPMain.py produces a succinct representation showing only the conditional directives. The links in each comment takes you to the syntax highlighted page for that file.

CPIP tracks every macro definition and usage and CPIPMain.py produces a page that describes all the macros encountered:

Each link on the page takes you to a description of the macro containing:

CPIP is a C/C++ Preprocessor implemented in Python. Copyright (C) 2008-2017 Paul Ross

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Also many thanks to SourceForge that hosted this project for many years.

Footnotes

$ python3 CPIPMain.py -kp -l20 -o ../../output/linux/cpu -S __STDC__=1 -D __KERNEL__ -D __EXPORTED_HEADERS__ -D BITS_PER_LONG=64 -D CONFIG_HZ=100 -D __x86_64__ -D __GNUC__=4 -D __has_feature(x)=0 -D __has_extension=__has_feature -D __has_attribute=__has_feature -D __has_include=__has_feature -P ~/dev/linux/linux-3.13/include/linux/kconfig.h -J /usr/include/ -J /usr/include/c++/4.2.1/ -J /usr/include/c++/4.2.1/tr1/ -J /Users/paulross/dev/linux/linux-3.13/include/ -J /Users/paulross/dev/linux/linux-3.13/include/uapi/ -J ~/dev/linux/linux-3.13/arch/x86/include/uapi/ -J ~/dev/linux/linux-3.13/arch/x86/include/ -J ~/dev/linux/linux-3.13/arch/x86/include/generated/ ~/dev/linux/linux-3.13/kernel/cpu.c

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4