HelloCodeModel Sample Walkthrough

CCI Code Model

HelloCodeModel is a Common Compiler Infrastructure Code Model (CCI Code) application that creates an assembly from scratch for a simple console application, Hello.exe. Although CCI Code applications often start with an existing assembly, this sample is a convenient way to introduce the basics of how to use the CCI Code API. For details on how to obtain the HelloCodeModel sample, see How to Compile and Run HelloCodeModel.
HelloCodeModel uses the CCI Code API to create the assembly that would be produced by compiling the following C# code.
public class Test
{
  static void main()
  {
    Console.WriteLine(“Hello”);
  }
}

HelloCodeModel follows the programming pattern that is described in the following set of topics. This general pattern can be adapted to a variety of more sophisticated applications.

Create a Host
Create and Configure an Assembly Object
Add Type Metadata to the Assembly
Add Method Metadata to the Types
Add Code
Write the Assembly to a File

Note: CCI Code is an extension of CCI Metadata that simplifies the process of constructing code blocks. Most CCI Code applications, including HelloCodeModel, must also work with metadata, and use CCI Metadata for that purpose. Much of the code discussed in this wiki is actually based on the CCI Metadata API, and is similar to corresponding code from the HelloIL CCI Metadata sample. If you are already familiar with HelloIL, you can go directly to Add Code, which discusses how to use CCI Code to create a method body and code block.
Next: Create a Host

Last edited Mar 9, 2010 at 8:50 PM by Guy_Smith, version 4

Comments

No comments yet.