3.2.8.2 Adding top-level assembler statements

In addition to creating extended asm instructions within a function, there is support for creating “top-level” assembler statements, outside of any function.

C++ Function: void gccjit::context::add_top_level_asm (const char *asm_stmts, gccjit::location loc = location())

Create a set of top-level asm statements, analogous to those created by GCC’s “basic” asm syntax in C at file scope.

For example, to create the equivalent of:

     asm ("\t.pushsection .text\n"
          "\t.globl add_asm\n"
          "\t.type add_asm, @function\n"
          "add_asm:\n"
          "\tmovq %rdi, %rax\n"
          "\tadd %rsi, %rax\n"
          "\tret\n"
          "\t.popsection\n");

the following API calls could be used:

  ctxt.add_top_level_asm ("\t.pushsection .text\n"
                          "\t.globl add_asm\n"
                          "\t.type add_asm, @function\n"
                          "add_asm:\n"
                          "\tmovq %rdi, %rax\n"
                          "\tadd %rsi, %rax\n"
                          "\tret\n"
                          "\t# some asm here\n"
                          "\t.popsection\n");