Top
Best
New

Posted by tosh 10/28/2024

CIL: C Intermediate Language(github.com)
80 points | 32 comments
neonsunset 11/1/2024|
A bit unfortunate choice of the name since there is another CIL too: https://ecma-international.org/publications-and-standards/st...
pkhuong 11/1/2024||
https://github.com/goblint/cil/blob/develop/LICENSE Copyright (c) 2001-2020

(I first learned about CIL in https://people.eecs.berkeley.edu/~necula/Papers/cil_cc02.pdf)

I guess ECMA should have done better research.

fluoridation 11/1/2024||
https://en.wikipedia.org/wiki/Common_Language_Infrastructure

2012 is just the latest version. It was first published in 2001, and started in 2000. They're so close together that it's difficult to say if one would have been able to find the other.

PeterWhittaker 11/1/2024|||
Not to mention SELinux CIL, Common Intermediate Language, https://selinuxproject.org/page/PolicyLanguage
someothherguyy 11/1/2024|||
That is CLI (Common Language Infrastructure)?

https://en.wikipedia.org/wiki/Common_Language_Infrastructure

tubs 11/1/2024||
Partition III: CIL Instruction Set – Describes the Common Intermediate Language (CIL) instruction set.
almost 11/1/2024||
There are a finite number of names, and an even smaller number of good names. But apparently an infinite number of hacker news posters who comment on every new project to complain that the name has been used before for something else.

And even the fact that this is a fork of an earlier project and the name comes from that doesn't stop it!

(I'm aware I have chosen a very weird thing to be getting annoyed at over my breakfast crumpets this morning)

Philpax 11/1/2024|||
I would normally agree with you on this, but these projects are in the same realm (language compiler infrastructure), so it's a bit more unfortunate than in the usual case
fuhsnn 11/1/2024|||
People are more triggered by "this is improper in my culture" type of comments, those tend to actually derail the thread.
HexDecOctBin 11/1/2024||
This reminds me, is there any C compilers that allows injecting custom parsing rules? Say, if it is parsing or type checking and hits upon an error, it calls a callback instead of bailing. This would be very useful for adding simple extensions to the language. I tried to make LLVM do this but couldn't figure it out.
fuhsnn 11/1/2024||
If you are ok with unoptimized codegen, chibicc[0] is very easy to modify. For an example checkout the patch set for adding defer in my fork[1].

[0] https://github.com/rui314/chibicc [1] https://github.com/fuhsnn/slimcc-defer/commits

metadat 11/2/2024||
chibicc looks impressive, want to compliment on the clear and concise README. Thank you!
tester756 11/1/2024|||
It seems like you're interested in frontend - Clang, not backend - LLVM.
Gibbon1 11/1/2024||
I saw someones tool that allows you to embed python code to generate C code.

https://nedbatchelder.com/code/cog/

Never used it.

WalterBright 11/1/2024||
I considered developing such a language, but could not justify it. The intermediate code I developed works just fine for this, and would be trivial to convert to/from a text based form, but I couldn't see the point.
riperoni 11/1/2024||
Can someone explain to a C-noob how this differs from and compares to LLVM?
pizlonator 11/1/2024||
Great question.

First of all, llvm has clang, which means that llvm as a whole is equipped to understand C (and C++ and Objective-C) both at a high level (abstract syntax tree, all types as declared by the programmer) and low level (SSA form, only the types that are meaningful for sound analysis and optimization).

I think that CIL was a really big deal before llvm and clang. Back then, it was a more approachable alternative to trying to fiddle with C than using GCC, since GCC has a steep learning curve. But in the last 15 years or so, most of the research that would have been done in CIL before is now done in llvm. That’s because llvm is much more complete and it’s designed for ergonomics, specifically in the case where you just want to mess around and even if you’re a newcomer to the compiler. The docs are great and the APIs are top notch.

I think that LLVM’s SSA form is especially good for doing sophisticated analysis and instrumentation of C. I’ve used that a lot for my C experiments. Clang’s AST is really great, too - and it’s amazing for doing higher level stuff where you want to see the original C types and declarations before lowering.

I suspect that there is very little that CIL can do for you that can’t be done in llvm more straightforwardly. And llvm+clang support all of C, plus the adjacent languages (C++ and others).

So, it’s cool that CIL is still around (having alternatives is good, generally) but in my opinion as someone who does experimental work in C compilers, C language extensions, and static/dynamic analysis of C, llvm completely subsumes CIL.

pjmlp 11/2/2024||
Additional note that CIL isn't the first of its kind, there were a few around the 1990's.
Philpax 11/1/2024||
LLVM is a backend: it takes LLVM IR (intermediate representation) and generates machine code.

This is a frontend: it takes C and generates its own IR (a simplified version of C).

You could glue these together with an adapter from CIL to LLVM IR to get a complete C compiler.

Clang is both a frontend and a complete compiler in this respect: the Clang frontend compiles C to LLVM IR, and these are bundled together to produce the Clang compiler.

(Note: I'm simplifying things here. Clang and LLVM are more intertwined than these, and there are several nuances I'm not covering; I'm going for a high-level perspective here)

riperoni 11/1/2024||
High-level is good enough for me for the beginning, thanks!
saagarjha 11/1/2024||
Is anyone using this? Perhaps for transpiring to a more limited compiler?
nikki93 11/1/2024||
Frama-C uses CIL.
KsassPeuk 11/1/2024||
Well, Frama-C uses a quite modified version of CIL.
Tiberium 11/1/2024|||
One thing that CIL allows is creating amalgamations - converting the whole program into a single C file that can be then compiled by GCC or other compilers.
mingodad 11/1/2024||
See also https://melt.cs.umn.edu/ableC/ that has a similar goal.
ranger_danger 11/1/2024||
I just want a way to add simple inheritable classes to C without bringing in the entirety of C++ and all its differences and baggage. But I guess things like constructors/destructors are not possible to implement in a language standard-compliant way (not relying on compiler extensions).
mingodad 11/1/2024|
Have a look at http://ecere.org/ they already have it working.
pipeline_peak 11/1/2024|
[flagged]
junon 11/1/2024|
Because the question is like asking why one wouldn't just substitute salt for oranges.
pipeline_peak 11/1/2024||
How so?
Jtsummers 11/1/2024||
What would you use AI for and in what way that is equivalent to what this tool is designed to do?

Which "AI"? There are a million and one different subcategories of AI or specific techniques and tools which fall under the AI umbrella. Which AI tools or techniques are suitable replacement tools for CIL and how?

pipeline_peak 11/1/2024||
From the page description

“ CIL is a front-end for the C programming language that facilitates program analysis and transformation. CIL will parse and typecheck a program, and compile it into a simplified subset of C. “

To answer your question, I don’t know. I’m no expert in AI by any means. I just think that if there, as you put “a million and one different subcategories of AI or specific techniques and tools which fall under the AI umbrella”, it should be no surprise if something like this could be done with less effort with something that either already exists today or by designing an LLM to achieve the same goals.

And it would be far more enticing because users wouldn’t have to learn yet another language.

NobodyNada 11/2/2024||
AI is slow, nondeterministic, imprecise, and often wrong. None of those are things you want in your compiler.