News for hackers. Stuff that matters.
Re:Amplifying C (2010) by dang on Sunday February 07, 2016 @03:36PM (#11054682)
You may be right, but learning curve is an issue. If you're already familiar with C, writing a sexpr C generator is super easy. I can see why someone would balk at learning a new conceptual model and toolset, and just take the path of least resistance, especially if they already know the kind of C program they'd like to write. This would have been even more true in 2010 of course.

So what's the best way to tackle the learning curve of what you're suggesting? If I know zero about LLVM and I want to make something like the OP, what should I do?

Re:Amplifying C (2010) by mpweiher on Sunday February 07, 2016 @05:38PM (#11055295)
Another good option is to use Joe Armstrong's approach: look at the LLVM IR generated by clang for example and then emit those.

My first attempt at using LLVM was using the C++ API. It was...a struggle. Using this approach (IR snippets), I made more progress in a day than I had in months using the API.

Re:Amplifying C (2010) by sklogic on Sunday February 07, 2016 @06:31PM (#11055526)
Also worth mentioning an invaluable learning tool: 'cpp' backend in LLVM. It emits an idiomatic C++ code that generates any given IR module using the LLVM API.
Re:Amplifying C (2010) by mpweiher on Wednesday February 10, 2016 @12:04PM (#11074135)
Yup, that's what I used in my first attempt. Didn't work for me. (Actually: a later part of my first attempt, I think I initially tried with the straight API. Good luck with that).
Re:Amplifying C (2010) by sklogic on Thursday February 11, 2016 @09:57AM (#11080451)
What exactly did not work? Have you filed a bug?
Re:Amplifying C (2010) by dang on Sunday February 07, 2016 @07:32PM (#11055775)
That's clever.
Re:Amplifying C (2010) by pcwalton on Sunday February 07, 2016 @03:43PM (#11054726)
LLVM has a great tutorial (Kaleidoscope): http://llvm.org/docs/tutorial/

It walks you through basic expression generation, control flow, memory, etc. for a simple language. The learning curve isn't zero, to be sure, but I think the time saved by being able to work with IR as a tree instead of as a flat series of bytes makes it easily worth it.