CIR Playground
Load example...
CIR on GitHub
Input
Run
// When a compile-time function declares its argument(s) to take a code object // (CirCodeId), CIR will pass the raw code (in CIR IR form) into the function. // // In this example, we use this capability to examine if a pice of code calls // any function or not. #include <stdbool.h> #include <stdio.h> #include <cir.h> // Returns true if the code calls a function, otherwise returns false. static bool callsAFunction(CirCodeId codeId) { // Notice that a simple for loop is sufficient no matter how complex or // branchy the piece of code passed into a function is -- CIR's IR was // explicitly designed to be flat to make it easy to examine and manipulate // in C code. for (CirStmtId stmtId = CirCode_getFirstStmt(codeId); stmtId; stmtId = CirStmt_getNext(stmtId)) { if (CirStmt_isCall(stmtId)) return true; } return false; } int main(void) { // Evaluates to true bool code1_callsAFunction = @callsAFunction(puts("Hi")); // Evaluates to false bool code2_callsAFunction = @callsAFunction(42); // Evaluates to true bool code3_callsAFunction = @callsAFunction(({ int x = 3, y = 2; if (y > x) puts("y > x"); })); return 0; }
stdout
stderr
Load Example...
×
00 - Compile-time fibonacci
01 - Inline Repeat
02 - Compile-time strtok
03 - Does a code call a function
04 - C Preprocessor identifiers may be accidentally shadowed
05 - CIR identifiers won't be accidentally shadowed
06 - C Preprocessor accidental capture of symbols
07 - CIR won't accidentally capture symbols
08 - bf-to-C (low level ver)
09 - bf-to-C (with quote-antiquote)
10 - async-await
11 - Embed an external file
12 - zlib