Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:59:43+00:00 2026-05-23T04:59:43+00:00

Background: I am writing a toy Lisp interperter/compiler in Haskell for my own amusement/edification.

  • 0

Background: I am writing a toy Lisp interperter/compiler in Haskell for my own amusement/edification. I am trying to add the ability to compile to LLVM bytecode.

Context: I have been reading the documentation for LLVM.Core and a code example (here) attempting to understand the means of combination and means of abstraction (as described in Abelson and Sussman Structure and Interpretation
of Computer Programs
.) used in the Haskell LLVM bindings. There are a lot of small pieces and I am not clear how they are intended to work together. It seems like there is a level of abstraction above the basic LLVM machine instructions that is obvious to someone with lots of experience with LLVM, but not documented for those, like me, who are just getting their feet wet.

Question: What are CodeGenModule and CodeGenFunction and how are they used to build up Functions and Modules?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:59:43+00:00Added an answer on May 23, 2026 at 4:59 am

    The Module and Function types are just thin wrappers around pointers to the corresponding C++ objects (that is, Module* and Value*):

    -- LLVM.Core.Util
    newtype Module = Module {
          fromModule :: FFI.ModuleRef
        }
        deriving (Show, Typeable)
    
    type Function a = Value (Ptr a)    
    
    newtype Value a = Value { unValue :: FFI.ValueRef }
        deriving (Show, Typeable)
    
    -- LLVM.FFI.Core
    data Module
        deriving (Typeable)
    type ModuleRef = Ptr Module
    
    data Value
        deriving (Typeable)
    type ValueRef = Ptr Value
    

    The CodeGenModule and CodeGenFunction types are parts of the EDSL built on top of the LLVM.FFI.* modules. They use Function, Module and the functions from LLVM.FFI.* internally and allow you to write LLVM IR in Haskell concisely using do-notation (example taken from Lennart Augustsson’s blog):

    mFib :: CodeGenModule (Function (Word32 -> IO Word32))
    mFib = do
        fib <- newFunction ExternalLinkage
        defineFunction fib $ \ arg -> do
            -- Create the two basic blocks.
            recurse <- newBasicBlock
            exit <- newBasicBlock
    
            [...]
            ret r
        return fib
    

    You can think of CodeGenModule as an AST representing a parsed LLVM assembly file (.ll). Given a CodeGenModule, you can e.g. write it to a .bc file:

    -- newModule :: IO Module
    mod <- newModule
    -- defineModule :: Module -> CodeGenModule a -> IO a
    defineModule mod $ do [...]
    
    -- writeBitcodeToFile :: FilePath -> Module -> IO ()
    writeBitcodeToFile "mymodule.bc" mod
    
    --- Alternatively, just use this function from LLVM.Util.File:
    writeCodeGenModule :: FilePath -> CodeGenModule a -> IO () 
    

    I also recommend you to acquaint yourself with core classes of LLVM, since they also show through in the Haskell API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm trying to implement a messenging system in my app, and I'm writing
As a newbie to Python, and mainly having a background of writing scripts for
Background I'm writing an web application so I can control an Ubuntu Server from
Background: I'm writing a 'standard' (nothing special) web application in Ruby (not Rails) and
Background: I am writing a C++ program working with large amounts of geodata, and
Background I am writing a program that targets several different phones, including the iPhone.
Background I'm writing an adapter for ESE to .NET and LINQ in a Google
Background I am writing a survey that is going to a large audience. It
A little background: I'm writing a small word based maze game starting with a
I've been writing a background service which enforces my client's security policies on company

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.