| 1 |
/* { dg-do compile { target x86_64-*-* } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#include "libgccjit.h" |
| 7 |
|
| 8 |
/* We don't want set_options() in harness.h to set -O3 so our little local |
| 9 |
is optimized away. */ |
| 10 |
#define TEST_ESCHEWS_SET_OPTIONS |
| 11 |
static void set_options (gcc_jit_context *ctxt, const char *argv0) |
| 12 |
{ |
| 13 |
} |
| 14 |
|
| 15 |
#define TEST_COMPILING_TO_FILE |
| 16 |
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER |
| 17 |
#define OUTPUT_FILENAME "output-of-test-link-section-assembler.c.s" |
| 18 |
#include "harness.h" |
| 19 |
|
| 20 |
void |
| 21 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 22 |
{ |
| 23 |
/* Let's try to inject the equivalent of: |
| 24 |
register int global_variable asm ("r13"); |
| 25 |
int main() { |
| 26 |
register int variable asm ("r12"); |
| 27 |
return 0; |
| 28 |
} |
| 29 |
*/ |
| 30 |
gcc_jit_type *int_type = |
| 31 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 32 |
gcc_jit_lvalue *global_variable = |
| 33 |
gcc_jit_context_new_global ( |
| 34 |
ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "global_variable"); |
| 35 |
gcc_jit_lvalue_set_register_name(global_variable, "r13"); |
| 36 |
|
| 37 |
gcc_jit_function *func_main = |
| 38 |
gcc_jit_context_new_function (ctxt, NULL, |
| 39 |
GCC_JIT_FUNCTION_EXPORTED, |
| 40 |
int_type, |
| 41 |
"main", |
| 42 |
0, NULL, |
| 43 |
0); |
| 44 |
gcc_jit_lvalue *variable = gcc_jit_function_new_local(func_main, NULL, int_type, "variable"); |
| 45 |
gcc_jit_lvalue_set_register_name(variable, "r12"); |
| 46 |
gcc_jit_rvalue *two = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2); |
| 47 |
gcc_jit_rvalue *one = gcc_jit_context_one (ctxt, int_type); |
| 48 |
gcc_jit_block *block = gcc_jit_function_new_block (func_main, NULL); |
| 49 |
gcc_jit_block_add_assignment(block, NULL, variable, one); |
| 50 |
gcc_jit_block_add_assignment(block, NULL, global_variable, two); |
| 51 |
gcc_jit_block_end_with_return (block, NULL, gcc_jit_lvalue_as_rvalue(variable)); |
| 52 |
} |
| 53 |
|
| 54 |
/* { dg-final { jit-verify-output-file-was-created "" } } */ |
| 55 |
/* { dg-final { jit-verify-assembler-output "movl \\\$1, %r12d" } } */ |
| 56 |
/* { dg-final { jit-verify-assembler-output "movl \\\$2, %r13d" } } */ |