CIL Assembler (Ilasm.exe)

The Common Intermediate Language (CIL) Assembler generates a portable executable (PE) file from CIL assembly language. You can run the resulting executable, which contains CIL and the required metadata, to determine whether the CIL performs as expected.

The application file for the CIL assembler is named ilasm.exe in the Shared Source CLI (SSCLI) when built on Microsoft Windows®. 

Usage

ilasm [options] filename [[options]filename...]
Argument Description
filename The name of the .il source file. This file consists of metadata declaration directives and symbolic CIL instructions. Multiple source file arguments can be supplied to produce a single PE file with the CIL Assembler.

Options

Note: The SSCLI implementation does not support Microsoft Win32® resources or cryptographic key containers.  The following options in the Microsoft .NET Framework implementation of the Microsoft Intermediate Language Assembler are not be supported by the SSCLI implementation of the CIL assembler.

The following options are supported in the SSCLI Ilasm implementation.

Options can be specified using either a dash (-) or a slash (/).

Option Description
/alignment=integer Sets FileAlignment to the value specified by integer in the Microsoft Windows NT® Optional header. If the .alignment CIL directive is specified in the file, this option overrides it.
/base=integer Sets ImageBase to the value specified by integer in the Windows NT Optional header. If the .imagebase CIL directive is specified in the file, this option overrides it.

The resulting portable executable (PE) file modification has significance only on the Windows platform.

/clock Measures and reports the following compilation times in milliseconds for the specified .il source file:
  • Total Run
    • The total time spent performing all the specific operations that follow.
  • Startup
    • Loading and opening the file.
  • Parsing
    • Reading the .il file into memory and generating parse-tree data structures.
  • Emitting MD
    • Emitting metadata.
  • Ref to Def Resolution
    • Resolving references to definitions in the file.
  • Fixup and Linking
    • RVA location resolution and name resolution.
  • CEE File Generation
    • Generating the file image in memory.
  • PE File Writing
    • Writing the image to a PE file.
/debug Includes debug information (local variable and argument names, and line numbers).
/dll Produces a .dll file as output.
/exe Produces an executable file as output. This is the default.
/flags=integer Sets ImageFlags to the value specified by integer in the common language runtime header. If the .corflags CIL directive is specified in the file, this option overrides it. See CorHdr.h , COMIMAGE_FLAGS for a list of valid values for integer.
/key:keyFile Compiles filename with a strong signature using the private key contained in keyFile.
/listing Sends a listing file to the standard output. If you omit this option, no listing file is produced.
/nologo Suppresses the Microsoft startup banner display.
/output:file.ext Specifies the output file name and extension. By default, the output file name is the same as the name of the first source file. The default extension is .exe. If you specify the /dll option, the default extension is .dll.

Note: Specifying /output:myfile.dll does not set the /dll option. If you do not specify /dll, the result will be an executable file named myfile.dll.

/quiet Specifies quiet mode; does not report assembly progress.
/subsystem=integer Sets subsystem to the value specified by integer in the Windows NT Optional header. If the .subsystem IL directive is specified in the file, this command overrides it. See winnt.h, IMAGE_SUBSYSTEM for a list of valid values for integer.

The resulting PE file modification has significance only on the Windows platform.

/? Displays command syntax and options for the tool.

Note: All options for the CIL Assembler are case-insensitive and recognized by the first three letters. For example, /lis is equivalent to /listing and /res:myresfile.res is equivalent to /resource:myresfile.res. Options that specify arguments accept either a colon (:) or an equal sign (=) as the separator between the option and the argument. For example, /output:file.ext is equivalent to /output=file.ext.

Remarks

The CIL Assembler helps tool vendors design and implement CIL generators. Using the CIL Assembler, tool and compiler developers can concentrate on CIL and metadata generation without being concerned with emitting CIL in the PE file format.

Similar to other compilers that target the runtime, such as C#,  the CIL Assembler does not produce intermediate object files and does not require a linking stage to form a PE file.

The CIL Assembler can express all the existing metadata and CIL features of the programming languages that target the runtime. This allows managed code written in any of these programming languages to be adequately expressed in CIL Assembler and compiled with the CIL Assembler.

You can use the CIL Assembler in conjunction with its companion tool, CIL Disassembler. The CIL Disassembler takes a PE file that contains CIL code and creates a text file suitable as input to the CIL Assembler. This is useful, for example, when compiling code in a programming language that does not support all the runtime metadata attributes. After compiling the code and running the output through Ildasm.exe, the resulting CIL text file can be hand-edited to add the missing attributes. You can then run this text file through the CIL Assembler to produce a final executable file.

You can also use this technique to produce a single PE file from several PE files originally generated by different compilers.

To make this combined use of the CIL Disassembler and CIL Assembler as accurate as possible, the assembler does not perform some simple optimizations; it does not deduce whether to use short or long forms of instructions. For example, the tool does not try to determine whether it could substitute a short encoding for a long one you might have written in your CIL sources (or that might be emitted by another compiler). If you want the short encoding, you must explicitly write that form. However, the assembler does check for out-of-range conditions where this is possible.

Examples

The following command assembles the CIL file myTestFile.il and produces the executable myTestFile.exe.

ilasm myTestFile

The following command assembles the CIL file myTestFile.il and produces the .dll file myTestFile.dll.

ilasm myTestFile /dll 

The following command assembles the CIL file myTestFile.il and produces the .dll file myNewTestFile.dll.

ilasm myTestFile /dll /output:myNewTestFile.dll
See Also

Tools Index | CIL Disassembler(Ildasm.exe)


Copyright (c) 2006 Microsoft Corporation. All rights reserved.