TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Implementing a LLVM Micro C compiler in Haskell

155 pointsby goranmoominabout 4 years ago

6 comments

winter_blueabout 4 years ago
This is awesome. This essentially will serve as a more up-to-date tutorial on the LLVM bindings for Haskell. So programming language designers could use this tutorial to build a new language using Haskell. Currently, the state of LLVM documentations, and its tutorial leaves much wanting. This work remedies things on the Haskell side of things by quite a bit.<p>I especially love the fact that instead of implementing a novel language like Kaleidoscope (which the official LLVM does), it implements a subset of C (a language that&#x27;s low-level enough and widely understood). C has all of the basic constructs, which if you understand how to write a compiler (to LLVM) for, would allow you to implement far more advanced languages.<p>Thank you Joseph Morag for this wok, and Théophile Choutri, Moritz Kiefer, et al for making it possible.
评论 #27397952 未加载
kubbabout 4 years ago
This reminds me of a project that I did in my university. It was a compiler of my programming language similar to C straight to x86 assembly. It had typechecking, basic primitive types, local and global variables, arrays and function calls. My professor recommended Haskell saying that it&#x27;ll make the job easier for me, and he was right. The thing basically worked as soon as I got it to compile. I remember that another student used Java for the project, and he ended up with a 10x larger codebase, riddled with bugs.<p>The code is still on my github. I recently took a look at it and I was surprised how readable it was. It&#x27;s a shame that in my professional career I didn&#x27;t get the chance to use neither Haskell nor any of the PL skills that I picked up in uni, because I really had fun with that project. Though maybe that&#x27;s for the best. If you have to do it for work, you sometimes end up hating it.
sirabenabout 4 years ago
This is amazing. I tried following Stephen Diehl&#x27;s JIT compiler in LLVM tutorial[0] a few years ago but it was already outdated (the llvm-hs library changed quite a bit), and subsequent web searches didn&#x27;t turn up much.<p>For those interested in tutorials like this, I&#x27;d also recommend a very literate Haskell compiler for the PCF language to C[1], which is essentially lambda calculus with some primitives and pattern matching. It details a number of transformations such as closure conversion and lambda lifting.<p>[0] <a href="https:&#x2F;&#x2F;www.stephendiehl.com&#x2F;llvm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.stephendiehl.com&#x2F;llvm&#x2F;</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;jozefg&#x2F;pcf&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jozefg&#x2F;pcf&#x2F;</a>
HexDecOctBinabout 4 years ago
Are there any similar tutorials written for the LLDB bindings? Since the only LLDB documentation I could find was auto-generated doxygen with no usage code.
helltoneabout 4 years ago
This looks great, are there any similar tutorials written for languages other than Haskell?
andi999about 4 years ago
Why not go for the full C language. C was made to make compilers easy to build. Also it might expose&#x2F;help to see difficulties in the chosen approach.
评论 #27396255 未加载
评论 #27398012 未加载
评论 #27397069 未加载
评论 #27396285 未加载
评论 #27396221 未加载