4 ms·
CIL: C Intermediate Language
- saagarjha 2y agoIs anyone using this? Perhaps for transpiring to a more limited compiler?
- nikki93 2y agoFrama-C uses CIL.
- KsassPeuk 2y agoWell, Frama-C uses a quite modified version of CIL.
- mingodad 2y agoSee also https://melt.cs.umn.edu/ableC/ https://melt.cs.umn.edu/ableC/ that has a similar goal.
- Tiberium 2y agoOne 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.
- HexDecOctBin 2y agoThis 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.
- tester756 2y agoIt seems like you're interested in frontend - Clang, not backend - LLVM.
- Gibbon1 2y agoI saw someones tool that allows you to embed python code to generate C code. https://nedbatchelder.com/code/cog/ https://nedbatchelder.com/code/cog/ Never used it.
- fuhsnn 2y agoIf 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 https://github.com/rui314/chibicc [1] https://github.com/fuhsnn/slimcc-defer/commits https://github.com/fuhsnn/slimcc-defer/commits
- metadat 2y agochibicc looks impressive, want to compliment on the clear and concise README. Thank you!
- neonsunset 2y agoA bit unfortunate choice of the name since there is another CIL too: https://ecma-international.org/publications-and-standards/standards/ecma-335/ https://ecma-international.org/publications-and-standards/st...
- someothherguyy 2y agoThat is CLI (Common Language Infrastructure)? https://en.wikipedia.org/wiki/Common_Language_Infrastructure https://en.wikipedia.org/wiki/Common_Language_Infrastructure
- tubs 2y agoPartition III: CIL Instruction Set – Describes the Common Intermediate Language (CIL) instruction set.
- almost 2y agoThere 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 2y agoI 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 2y agoPeople are more triggered by "this is improper in my culture" type of comments, those tend to actually derail the thread.
- PeterWhittaker 2y ago
- riperoni 2y agoCan someone explain to a C-noob how this differs from and compares to LLVM?
- Philpax 2y agoLLVM 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 2y agoHigh-level is good enough for me for the beginning, thanks!
- pizlonator 2y agoGreat 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.
- WalterBright 2y agoI 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.
- pipeline_peak 2y ago[flagged]
- junon 2y agoBecause the question is like asking why one wouldn't just substitute salt for oranges.
- pipeline_peak 2y agoHow so?
- Jtsummers 2y agoWhat 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 2y agoFrom 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 2y agoAI is slow, nondeterministic, imprecise, and often wrong. None of those are things you want in your compiler.
- ranger_danger 2y agoI 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 2y agoHave a look at http://ecere.org/ http://ecere.org/ they already have it working.