mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-09-10 23:49:54 -04:00
This PR adds [CO2](https://github.com/hkalbasi/co2) which is a language backward compatible with C, with some Rust interop features that compiles to Rust's MIR. I added two compiler `co2rustc` and `co2cc`, and a tool `co2miri` which is Miri for CO2. I added `co2cc` under C compilers, to make it possible to view diff of assembly for a C code compiled with CO2 and clang or gcc. `co2cc` is a CO2 frontend which accepts gcc-like flags, and can (or at least should) compile almost every ISO compatible C23 code. `co2rustc` accepts Rust like flags, and added under a new `CO2` language. Tested locally and it seems to work. I need some help in setting up artifacts (which, if I understand correctly, needs to happen in `infra` or `compiler-workflows`). I make an artifact `co2-multicall` in my CI, which needs to get symlinked in `co2cc`, `co2rustc` and `co2miri`, and it needs to run a simple project with miri to create the miri sysroot. If you show me a similar project, I will do the job. Disclaimer: Written partially by LLM. --------- Co-authored-by: Matt Godbolt <matt@godbolt.org>
21 lines
682 B
Plaintext
21 lines
682 B
Plaintext
// Type your code here, or load an example.
|
|
|
|
#include <stdio.h>
|
|
|
|
// Similar to Rust, small functions are automatically
|
|
// marked as `#[inline]` so they will not show up in
|
|
// the output when compiling with optimisations. Use
|
|
// `#[no_mangle]` or `#[inline(never)]` to
|
|
// work around this issue. C style functions are
|
|
// automatically `#[no_mangle]` and do not need attribute.
|
|
// See https://github.com/compiler-explorer/compiler-explorer/issues/5939
|
|
#[no_mangle]
|
|
pub fn square(num: i32) -> i32 {
|
|
i32 result = num * num;
|
|
printf("square of %d is %d", num, result);
|
|
return result;
|
|
}
|
|
|
|
// If you use `main()`, declare it as `pub` to see it in the output:
|
|
// pub fn main() {}
|