Skip to content
forked from ltcmelo/psychec

A compiler frontend for the C programming language

License

Notifications You must be signed in to change notification settings

zeta1999/psychec

 
 

Repository files navigation

Psyche-C

Psyche is a compiler frontend for the C programming language. Psyche-C is specifically designed for the implementation of static analysis tools. These are the distinct features that make Psyche-C rather unique:

  • Clean separation between the syntactic and semantic compiler phases.
  • Both algorithmic- and heuristic-based syntax disambiguation strategies.
  • Independent of #include, with type inference for missing struct, union, enum, and typedef.
  • API inspired by that of the Roslyn .NET compiler.
  • A parser's AST resembling that of the LLVM's Clang frontend.

Applications:

  • Enabling, on incomplete source-code, static analysis techniques that require fully-typed programs.
  • Compiling partial code (e.g., a snippet retrieved from a bug tracker) for object-code inspection.
  • Generating test-input data for a function in isolation (without its dependencies).
  • Quick prototyping of an algorithm, without the need of explicit types.

NOTE: The master branch is going through a major overhaul; it's expected that syntax analysis (parsing and AST construction) already is functional, though. The original version of Psyche-C is available in this branch.

The cnippet Driver Adaptor

While Psyche-C is primarily used as a library for the implementation of static analysis tools, it still is a compiler frontend, and may also be used as an ordinary C parser through the cnippet driver adaptor.

// node.c
void f()
{
    T v = 0;
    v->value = 42;
    v->next = v;
}

If you compile the above snippet with GCC or Clang, you'd see the diagnostic "declaration forTis not available". But with cnippet the compilation would succeed: a definition for T is inferred.

Documentation and Resources

Building and Testing

Except for type inference, which is written in Haskell, Psyche-C is written in C++17; cnippet is written in Python 3.

To build:

cmake CMakeLists.txt && make -j 4

To run the tests:

./test-suite

Related Publications

About

A compiler frontend for the C programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 78.1%
  • SWIG 16.0%
  • Haskell 2.5%
  • Python 1.6%
  • CMake 0.8%
  • C 0.7%
  • Other 0.3%