Skip to content

Commit b391653

Browse files
Set the correct gimple output format
1 parent e39f3a2 commit b391653

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

doc/gimple.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ also add the calls we need to generate the GIMPLE:
3333
```C
3434
int main() {
3535
gcc_jit_context *ctxt = gcc_jit_context_acquire();
36+
// To set `-O3`, update it depending on your needs.
37+
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
38+
// Very important option to generate the gimple format.
39+
gcc_jit_context_add_command_line_option(ctxt, "-fdump-tree-gimple");
3640
create_code(ctxt, NULL);
41+
3742
gcc_jit_context_compile(ctxt);
38-
gcc_jit_context_dump_to_file(ctxt, "tmp.gimple", 1);
43+
// If you want to compile to assembly (or any other format) directly, you can
44+
// use the following call instead:
45+
// gcc_jit_context_compile_to_file(ctxt, GCC_JIT_OUTPUT_KIND_ASSEMBLER, "out.s");
46+
3947
return 0;
4048
}
4149
```
@@ -46,13 +54,21 @@ Then we can compile it by using:
4654
gcc local.c -I `pwd`/gcc/gcc/jit/ -L `pwd`/gcc-build/gcc -lgccjit -o out
4755
```
4856

57+
Before running it, I recommend running:
58+
59+
```console
60+
rm -rf /tmp/libgccjit-*
61+
```
62+
63+
to make it easier for you to know which folder to look into.
64+
4965
And finally when you run it:
5066

5167
```console
5268
LD_LIBRARY_PATH=`pwd`/gcc-build/gcc LIBRARY_PATH=`pwd`/gcc-build/gcc ./out
5369
```
5470

55-
You should now have a file named `tmp.gimple` which contains:
71+
You should now have a file named with path looking like `/tmp/libgccjit-9OFqkD/fake.c.006t.gimple` which contains:
5672

5773
```c
5874
__attribute__((const))

0 commit comments

Comments
 (0)