about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-09-07 14:03:56 +0200
committerGitHub <noreply@github.com>2023-09-07 14:03:56 +0200
commitb3916539dd56c52a9d8e62a7b06bf9449aa8a23d (patch)
treefb1751464dcffef4e832c0bf3f10859e16cde311
parente39f3a24847ecea0542c8a3b9c776913c6e7be83 (diff)
downloadrust-b3916539dd56c52a9d8e62a7b06bf9449aa8a23d.tar.gz
rust-b3916539dd56c52a9d8e62a7b06bf9449aa8a23d.zip
Set the correct gimple output format
-rw-r--r--doc/gimple.md20
1 files changed, 18 insertions, 2 deletions
diff --git a/doc/gimple.md b/doc/gimple.md
index e2ae93cf20d..f97e50c32cb 100644
--- a/doc/gimple.md
+++ b/doc/gimple.md
@@ -33,9 +33,17 @@ also add the calls we need to generate the GIMPLE:
 ```C
 int main() {
     gcc_jit_context *ctxt = gcc_jit_context_acquire();
+    // To set `-O3`, update it depending on your needs.
+    gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
+    // Very important option to generate the gimple format.
+    gcc_jit_context_add_command_line_option(ctxt, "-fdump-tree-gimple");
     create_code(ctxt, NULL);
+
     gcc_jit_context_compile(ctxt);
-    gcc_jit_context_dump_to_file(ctxt, "tmp.gimple", 1);
+    // If you want to compile to assembly (or any other format) directly, you can
+    // use the following call instead:
+    // gcc_jit_context_compile_to_file(ctxt, GCC_JIT_OUTPUT_KIND_ASSEMBLER, "out.s");
+
     return 0;
 }
 ```
@@ -46,13 +54,21 @@ Then we can compile it by using:
 gcc local.c -I `pwd`/gcc/gcc/jit/ -L `pwd`/gcc-build/gcc -lgccjit -o out
 ```
 
+Before running it, I recommend running:
+
+```console
+rm -rf /tmp/libgccjit-*
+```
+
+to make it easier for you to know which folder to look into.
+
 And finally when you run it:
 
 ```console
 LD_LIBRARY_PATH=`pwd`/gcc-build/gcc LIBRARY_PATH=`pwd`/gcc-build/gcc ./out
 ```
 
-You should now have a file named `tmp.gimple` which contains:
+You should now have a file named with path looking like `/tmp/libgccjit-9OFqkD/fake.c.006t.gimple` which contains:
 
 ```c
 __attribute__((const))