TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

No Compiler – On LLVM, and writing software without a compiler

193 点作者 btrask大约 9 年前

14 条评论

pcwalton大约 9 年前
&gt; And actually we’re now entering a world where at minimum supporting LLVM as a backend option is mandatory.<p>I would have said this too a few years ago, but Go is a huge counterexample. It&#x27;s become very popular without using LLVM, and the compiler that does use a mature, optimizing backend (gccgo) doesn&#x27;t get nearly as much use as the Plan 9-based one.<p>I should also mention that increasingly it&#x27;s become popular to have a mid-level IR that you lower the AST to before lowering to LLVM IR. GHC does it, Swift is doing it, and Rust is working on doing it. The reasons are (a) you can do language-specific optimizations like devirtualization, which are often pretty hard to do in LLVM; (b) going from AST to LLVM IR is often a big, messy leap for any language that isn&#x27;t C.
评论 #11222395 未加载
评论 #11223512 未加载
评论 #11222722 未加载
评论 #11223041 未加载
评论 #11223477 未加载
评论 #11226232 未加载
erichocean大约 9 年前
You may be better off building up the LLVM IR as text, vs. using the FFI builder. (If you want&#x2F;need type safety as opposed to just waiting for the LLVM verifier to tell you what went wrong, you could write the builder in Lua.)<p>Here&#x27;s a link with a Python example (along with a justification for this approach): <a href="http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2015&#x2F;building-and-using-llvmlite-a-basic-example&#x2F;" rel="nofollow">http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2015&#x2F;building-and-using-llvmlit...</a>
drmeister大约 9 年前
So I&#x27;ve done basically the same thing with a few differences: (1) I chose Common Lisp as the language I would implement (2) I used C++ template programming to automatically generate wrappers for C++ library functions (like boost::python and luabind) so that I could expose C++ functions directly to Common Lisp. That allowed me to use the llvm C++ API directly.<p>The project is called clasp -&gt; github.com&#x2F;drmeister&#x2F;clasp Send me a message - we should talk and compare notes.
vbit大约 9 年前
Instead of generate LLVM code, you could instead generate &#x27;typed Lua&#x27; using Lua as a metaprogramming language. Then the &#x27;typed Lua&#x27; can get compiled down by LLVM into object code.<p>This is what <a href="http:&#x2F;&#x2F;terralang.org" rel="nofollow">http:&#x2F;&#x2F;terralang.org</a> does.
评论 #11221600 未加载
daniel-kun大约 9 年前
Been there, done that.<p>See <a href="https:&#x2F;&#x2F;github.com&#x2F;daniel-kun&#x2F;omni" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;daniel-kun&#x2F;omni</a> (look at the little gif in the “Status Quo” section, it will say more than 100 words).<p>I have the “Code Model” (that is what I call the AST, because there is no Syntax) up for a very little, C-like language, and I have a frontend that can manipulate parts of it. However, these are not yet combined, and I stopped working on it because I am in the middle of transforming my efforts into a Web App. This will allow you to edit and run a code model in your browser, and download a compiled binary when you are finished. Btw., you will be able to link code elements such as classes to online-ressources such as a task tracker, a diagram, a mindmap, etc. to have the whole ALM process embedded into your code base.<p>Sounds good? Sounds good to me.
smaddox大约 9 年前
Interesting article. Looking at the code, it&#x27;s pretty clear that this is not a particularly practical approach, but I think it points in the direction of where language design should head. Abstractions shouldn&#x27;t be forced, unless absolutely necessary; forced abstractions lead to inefficiency.<p>I&#x27;ve been working on a related concept, but more along the lines of developing a low-level IR (LLIR) and corresponding syntax that allows direct coding in the LLIR. It would essentially be a portable assembly language. The LLIR could be then be compiled down to machine code for different architectures, or even run directly in a VM.<p>This isn&#x27;t too different from the LLVM concept, except the IR would be a practical programming language, much like assembly. Furthermore, the IR would provide access control primitives (reference capabilities) that most languages do not support, but that are extremely useful for low-overhead secure computing and concurrent computing. These primitives could be especially useful in the design of exokernel OS&#x27;s, and related applications.
评论 #11222105 未加载
评论 #11222083 未加载
couchand大约 9 年前
I&#x27;ve run into so many of these issues myself, trying to work through the forest of LLVM. The abysmal state of the generated docs and those cryptic segfaults are the bane of my existence.<p>So I started to slap together a little library that gives some order to the madness. I call it petard [0], for reasons that should be obvious if you&#x27;ve heard that word. At the moment I&#x27;m focused on JavaScript bindings, but the idea is to build a sensible object-based API that&#x27;s simple enough to export pure C bindings to make FFI easy.<p>There&#x27;s currently support for lots of the basics, but some significant issues too (lack of features as well as poor C++ style). Stern memory-management focused pull requests would be very welcome, and feature additions would be helpful, too.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;couchand&#x2F;petard" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;couchand&#x2F;petard</a>
a-dub大约 9 年前
This seems like a fun way to poke around with LLVM but I don&#x27;t see how this is any easier than writing down a grammar and feeding it into a parser generator...<p>&quot;Writing a parser&quot; sounds really annoying and complicated, but in my admittedly limited experience with ocamlyacc, it was easy peasy and dare I say it, fun!<p>The hard part I guess was defining the language and maybe that&#x27;s what he&#x27;s trying to avoid.<p>But even still, scripting around the AST building functions in LLVM and coding directly to them seems way more annoying to me in the long run. (especially the writing programs part)<p>But who knows, maybe I&#x27;m missing the point...
评论 #11223373 未加载
评论 #11223495 未加载
评论 #11226444 未加载
barrkel大约 9 年前
There&#x27;s an enormous lump of complexity that this chap seems to be unaware of: the type system. This is the semantic analysis bit that he seems to think is done by LLVM, but it isn&#x27;t.<p>It&#x27;s like he mostly thinks of compilers as turning statements and expressions into executable code, but IMO that&#x27;s one of the easier bits. Defining how different values interact, what operations are legal and aren&#x27;t, and the runtime support - this is a lot of work, and in particular, it&#x27;s different for every language, because it&#x27;s what makes languages distinct.
评论 #11222933 未加载
benjismith大约 9 年前
This is the most kickass thing I&#x27;ve read all day.
prewett大约 9 年前
Seems like what he really wants is an LLVM assembler.
评论 #11223617 未加载
greydius大约 9 年前
Excellent post highlighting the problem solving skills and tenacity of a talented engineer. Of course, this is also the &quot;duct tape and paper clips&quot; approach to writing software that I certainly would not advocate for production systems.
评论 #11221813 未加载
sklogic大约 9 年前
For everyone here who mentioned building wrappers around llvm-c or llvm c++ api: there is a nice tool for automating this job (and many other similar things), it&#x27;s called &quot;Clang&quot;. Or, more specifically, cindex. It&#x27;s easy to use Python + cindex to parse LLVM headers and spit out nice wrapper library for your language of choice.<p>And example of this approach: <a href="https:&#x2F;&#x2F;github.com&#x2F;combinatorylogic&#x2F;clike&#x2F;blob&#x2F;master&#x2F;llvm-wrapper&#x2F;rebuild.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;combinatorylogic&#x2F;clike&#x2F;blob&#x2F;master&#x2F;llvm-w...</a>
kungfooman大约 9 年前
I really like the idea, why not hack a scripting engine to add bindings to itself, e.g. in Duktape JavaScript engine. Then a JavaScript function could use the C-API of Duktape to generate AST&#x27;s at runtime for itself. But I think the VM would be the limit then... support for coroutines etc.