This project is read-only.

What is CCI Code?

CCI Code

The Common Compiler Infrastructure (CCI) is a collection of frameworks for working with .NET source code, assemblies, modules, and debug files. In part, CCI supports a more efficient version of the functionality provided by System.Reflection, System.Reflection.Emit, and System.CodeDom. However, CCI goes beyond those components to provide a unified framework for static analysis and rewriting of assembly metadata and code. CCI supports a broad range of scenarios, including:
  • Compilers, which start with source code and transform it to .NET assemblies and modules.
  • Static analysis tools, which analyze the contents of .NET assemblies.
  • Rewriting tools, which add code or metadata to assemblies or modify existing code or metadata.
CCI consists of two components, CCI Metadata and CCI Code, which represent a .NET portable executable (PE) or debug file as an object model. Applications can then use the object model to analyze or modify the contents of the file.
  • CCI Metadata’s primary purpose is to support working with metadata. You can use CCI Metadata to work with code blocks, but only as flat lists of Microsoft intermediate language (MSIL) instructions.
  • CCI Code is an extension of CCI Metadata that simplifies working with code blocks. CCI Code represents method bodies with a language-independent structured object model that is similar to source code structure and usually easier to work with than MSIL.
Note: Because most CCI Code applications also work with metadata, they typically use both APIs.

CCI Code supports two object models:
  • The code model represents MSIL instructions in a tree-structured language-independent form that is similar to source code.
  • The abstract syntax tree (AST) model provides base classes for language-specific nodes that can be constructed by a parser and then projected onto the code model.
Examples of how CCI Code can be used include:
  • Insert instrumentation or tracing code into method bodies. Tools that modify assemblies are usually easier to write if they operate on a tree like object model such CCI Code, instead of a flat list of MSIL instructions.
  • Perform language-agnostic error checking, such as the static checker in Code contracts tool.
  • Write a simple flow-insensitive anti-pattern checker such as FxCop.
  • Generate source code for multiple languages from a single object model representation. For example, a UI designer must usually generate source code for any of several supported languages. CCI Code provides a single unambiguous code representation that can be used to generate source code for a variety of .NET languages.
This wiki is devoted to CCI Code and is primarily of interest to developers who want to implement CCI-based tools that create, modify, or analyze code blocks. For general background, see An Introduction to the Common Compiler Infrastructure. For information on the CCI Metadata API, see CCI Metadata API.

Last edited Feb 17, 2010 at 4:48 PM by Guy_Smith, version 1


No comments yet.