Git Product home page Git Product logo

language-cil's Introduction

language-cil: Manipulating Common Intermediate Language AST

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.

Current status

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.

Module overview

  • Language.Cil Top level module, reexports sub modules
  • Language.Cil.Analysis Some analysis functions over AST, not really used yet.
  • Language.Cil.Build Smart constructors and convenience functions, it is suggested to use these over raw AST constructors.
  • Language.Cil.Pretty Pretty printer function pr. Returns a ShowS.
  • Language.Cil.Syntax Concrete AST data types.

Getting started

  1. Make sure you have Mono or .NET installed.

  2. Install the library.

  3. 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
      ]
    
  4. Write the AST to a file by running main.

  5. Run the IL assembler: ilasm Test.il

  6. Run the generated executable: mono Test.exe (or Test.exe on Windows)

language-cil's People

Contributors

dmcclean avatar tomlokhorst avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.