JuliaHubOSS/llvm-cbe

Version of C?

trapexit opened this issue · 6 comments

What version of C does llvm-cbe target? Is it selectable?

Generally C89 (so that any old compiler would work), though if you use atomics or threads, those were not defined until C11, so that instead is required.

I tried a minimal program and it includes stdint.h which was introduced in C99 as I recall.

int main() { return 0; }

resulted in

/* Provide Declarations */
#include <stdint.h>
#ifndef __cplusplus
typedef unsigned char bool;
#endif

#if defined(__GNUC__)
#define  __ATTRIBUTELIST__(x) __attribute__(x)
#else
#define  __ATTRIBUTELIST__(x)
#endif

#ifdef _MSC_VER  /* Can only support "linkonce" vars with GCC */
#define __attribute__(X)
#endif



/* Global Declarations */

/* Types Declarations */

/* Function definitions */

/* Types Definitions */

/* Function Declarations */
int main(void) __ATTRIBUTELIST__((noinline, nothrow));


/* LLVM Intrinsic Builtin Function Bodies */


/* Function Bodies */

int main(void) {
  uint32_t _1;    /* Address-exposed local */

  _1 = 0;
  return 0;
}

That is true. It is targeting a C89 parser, that has C99 stdint.h headers, and C11 atomic functions. It is not quite a clear target, but then C has been missing many essential features until quite recently.

I added a command-line option to switch between C89 and C99 variable declarations a little while ago. That's so far the only configuration option for the language compatibility.

This project will probably always use stdint because LLVM IR uses explicit integer sizes, and stdint is the best way to get those in C. If you need to target a C89 compiler, then it shouldn't be too difficult to write your own header providing the stdint types, assuming the target actually has types of the right sizes.

It is even probably possible to teach CBE to handle targets without the required type sizes, since we know how to round non-power-of-two operations up to the next largest supported size.

That is true, though I think the LLVM IR being consumed is going to assume things about pointer arithmetic that might limit its practical utility.