Language-Cil is a Haskell library for manipulating CIL abstract syntax and generating .il files using the concrete syntax of CIL.
Common Intermediate Language (CIL), formerly known as Microsoft Intermediate Language (MSIL), is the lowest level language that runs on the Microsoft .NET and Mono platforms.
The examples directory has a couple of files showing how to construct different CIL ASTs.
Read more on the Wikipedia page on Common Intermediate Language.
This library is still very much under development. Only a subset of the full CIL AST is implemented.
A parser for concrete syntax has not yet been implemented.
pr
. Returns a ShowS
.Create an AST, eg: module Example where
import Language.Cil
main :: IO ()
main = writeAssembly "Test.il" ass
ass :: Assembly
ass = simpleAssembly
[ nop
-- Print message to stdout
, ldstr "Enter an integer and press return."
, call [] Void "mscorlib" "System.Console" "WriteLine" [String]
-- Reads an integer from stdin, add one to it, print result to stdout.
, call [] String "mscorlib" "System.Console" "ReadLine" []
, call [] Int32 "" "int32" "Parse" [String]
, ldc_i4 1
, add
, call [] Void "mscorlib" "System.Console" "WriteLine" [Int32]
, ret
]
main
.ilasm Test.il
mono Test.exe
(or Test.exe
on Windows)