aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-06-23 18:18:57 +0200
committerAndrea Corallo2020-01-01 11:33:44 +0100
commitdbf05d0d22b1274898a9c545962abeef465d4119 (patch)
tree279c94b9aa9775a23b0f87ae55b21272ccb2dd8c /src/comp.c
parentd9e125793c36a06f0aca984473a911a92d1bbd7f (diff)
downloademacs-dbf05d0d22b1274898a9c545962abeef465d4119.tar.gz
emacs-dbf05d0d22b1274898a9c545962abeef465d4119.zip
add format_string
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c74
1 files changed, 35 insertions, 39 deletions
diff --git a/src/comp.c b/src/comp.c
index 0261cccc381..f2e7c2d1021 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -243,6 +243,19 @@ void emacs_native_compile (const char *lisp_f_name, const char *c_f_name,
243 Lisp_Object func, int opt_level, bool dump_asm); 243 Lisp_Object func, int opt_level, bool dump_asm);
244 244
245 245
246static char * ATTRIBUTE_FORMAT_PRINTF (1, 2)
247format_string (const char *format, ...)
248{
249 static char scratch_area[512];
250 va_list va;
251 va_start (va, format);
252 int res = vsnprintf (scratch_area, sizeof (scratch_area), format, va);
253 if (res >= sizeof (scratch_area))
254 error ("Truncating string");
255 va_end (va);
256 return scratch_area;
257}
258
246static void 259static void
247bcall0 (Lisp_Object f) 260bcall0 (Lisp_Object f)
248{ 261{
@@ -683,30 +696,23 @@ static gcc_jit_rvalue *
683emit_lisp_obj_from_ptr (basic_block_t *bblock, void *p) 696emit_lisp_obj_from_ptr (basic_block_t *bblock, void *p)
684{ 697{
685 static unsigned i; 698 static unsigned i;
686 char scratch[256];
687
688 int res = snprintf (scratch, sizeof (scratch),
689 "lisp_obj_from_ptr_%u", i++);
690 if (res >= sizeof (scratch))
691 error ("Internal error, truncating temporary variable");
692 699
693 gcc_jit_lvalue *lisp_obj = gcc_jit_function_new_local (comp.func, 700 gcc_jit_lvalue *lisp_obj =
694 NULL, 701 gcc_jit_function_new_local (comp.func,
695 comp.lisp_obj_type, 702 NULL,
696 scratch); 703 comp.lisp_obj_type,
704 format_string ("lisp_obj_from_ptr_%u", i++));
697 gcc_jit_rvalue *void_ptr = 705 gcc_jit_rvalue *void_ptr =
698 gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 706 gcc_jit_context_new_rvalue_from_ptr(comp.ctxt,
699 comp.void_ptr_type, 707 comp.void_ptr_type,
700 p); 708 p);
701 709
702 if (SYMBOLP (p)) 710 if (SYMBOLP (p))
703 { 711 gcc_jit_block_add_comment (
704 snprintf (scratch, sizeof (scratch), 712 bblock->gcc_bb,
705 "Symbol %s", (char *) SDATA (SYMBOL_NAME (p))); 713 NULL,
706 gcc_jit_block_add_comment (bblock->gcc_bb, 714 format_string ("Symbol %s",
707 NULL, 715 (char *) SDATA (SYMBOL_NAME (p))));
708 scratch);
709 }
710 716
711 gcc_jit_block_add_assignment (bblock->gcc_bb, 717 gcc_jit_block_add_assignment (bblock->gcc_bb,
712 NULL, 718 NULL,
@@ -718,8 +724,6 @@ emit_lisp_obj_from_ptr (basic_block_t *bblock, void *p)
718static gcc_jit_rvalue * 724static gcc_jit_rvalue *
719emit_scratch_callN (const char *f_name, unsigned nargs, gcc_jit_rvalue **args) 725emit_scratch_callN (const char *f_name, unsigned nargs, gcc_jit_rvalue **args)
720{ 726{
721 char tmp_str[256];
722
723 /* Here we set all the pointers into the scratch call area. */ 727 /* Here we set all the pointers into the scratch call area. */
724 /* TODO: distinguish primitives for faster calling convention. */ 728 /* TODO: distinguish primitives for faster calling convention. */
725 729
@@ -735,11 +739,9 @@ emit_scratch_callN (const char *f_name, unsigned nargs, gcc_jit_rvalue **args)
735 p[n] = 0x...; 739 p[n] = 0x...;
736 */ 740 */
737 741
738 snprintf (tmp_str, sizeof (tmp_str), "calling %s", f_name);
739
740 gcc_jit_block_add_comment (comp.bblock->gcc_bb, 742 gcc_jit_block_add_comment (comp.bblock->gcc_bb,
741 NULL, 743 NULL,
742 tmp_str); 744 format_string ("calling %s", f_name));
743 745
744 gcc_jit_lvalue *p = 746 gcc_jit_lvalue *p =
745 gcc_jit_function_new_local(comp.func, 747 gcc_jit_function_new_local(comp.func,
@@ -1115,14 +1117,13 @@ compute_bblocks (ptrdiff_t bytestr_length, unsigned char *bytestr_data)
1115 } 1117 }
1116 1118
1117 basic_block_t curr_bb; 1119 basic_block_t curr_bb;
1118 char block_name[256];
1119 for (int i = 0, pc = 0; pc < bytestr_length; pc++) 1120 for (int i = 0, pc = 0; pc < bytestr_length; pc++)
1120 { 1121 {
1121 if (i < bb_n && pc == bb_start_pc[i]) 1122 if (i < bb_n && pc == bb_start_pc[i])
1122 { 1123 {
1123 ++i; 1124 ++i;
1124 snprintf (block_name, sizeof (block_name), "bb_%d", i); 1125 curr_bb.gcc_bb =
1125 curr_bb.gcc_bb = gcc_jit_function_new_block (comp.func, block_name); 1126 gcc_jit_function_new_block (comp.func, format_string ("bb_%d", i));
1126 curr_bb.top = NULL; 1127 curr_bb.top = NULL;
1127 curr_bb.terminated = false; 1128 curr_bb.terminated = false;
1128 } 1129 }
@@ -1331,7 +1332,6 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1331 ptrdiff_t pc = 0; 1332 ptrdiff_t pc = 0;
1332 gcc_jit_rvalue *args[4]; 1333 gcc_jit_rvalue *args[4];
1333 unsigned op; 1334 unsigned op;
1334 char scratch_name[256];
1335 unsigned pushhandler_n = 0; 1335 unsigned pushhandler_n = 0;
1336 1336
1337 /* Meta-stack we use to flat the bytecode written for push and pop 1337 /* Meta-stack we use to flat the bytecode written for push and pop
@@ -1368,13 +1368,10 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1368 NULL, GCC_JIT_FUNCTION_EXPORTED, false); 1368 NULL, GCC_JIT_FUNCTION_EXPORTED, false);
1369 1369
1370 for (int i = 0; i < stack_depth; ++i) 1370 for (int i = 0; i < stack_depth; ++i)
1371 { 1371 stack[i] = gcc_jit_function_new_local (comp.func,
1372 snprintf (scratch_name, sizeof (scratch_name), "local_%d", i); 1372 NULL,
1373 stack[i] = gcc_jit_function_new_local (comp.func, 1373 comp.lisp_obj_type,
1374 NULL, 1374 format_string ("local_%d", i));
1375 comp.lisp_obj_type,
1376 scratch_name);
1377 }
1378 1375
1379 gcc_jit_block *prologue_bb = 1376 gcc_jit_block *prologue_bb =
1380 gcc_jit_function_new_block (comp.func, "prologue"); 1377 gcc_jit_function_new_block (comp.func, "prologue");
@@ -1615,13 +1612,12 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1615 { 1612 {
1616 /* struct handler *c = push_handler (POP, type); */ 1613 /* struct handler *c = push_handler (POP, type); */
1617 int handler_pc = FETCH2; 1614 int handler_pc = FETCH2;
1618 snprintf (scratch_name, sizeof (scratch_name), "c_%u",
1619 pushhandler_n);
1620 gcc_jit_lvalue *c = 1615 gcc_jit_lvalue *c =
1621 gcc_jit_function_new_local (comp.func, 1616 gcc_jit_function_new_local (comp.func,
1622 NULL, 1617 NULL,
1623 comp.handler_ptr_type, 1618 comp.handler_ptr_type,
1624 scratch_name); 1619 format_string ("c_%u",
1620 pushhandler_n));
1625 POP1; 1621 POP1;
1626 args[1] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, 1622 args[1] = gcc_jit_context_new_rvalue_from_int (comp.ctxt,
1627 comp.int_type, 1623 comp.int_type,
@@ -1644,10 +1640,10 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1644#else 1640#else
1645 res = emit_call ("setjmp", comp.int_type, 1, args); 1641 res = emit_call ("setjmp", comp.int_type, 1, args);
1646#endif 1642#endif
1647 snprintf (scratch_name, sizeof (scratch_name), "push_h_val_%u",
1648 pushhandler_n);
1649 gcc_jit_block *push_h_val_block = 1643 gcc_jit_block *push_h_val_block =
1650 gcc_jit_function_new_block (comp.func, scratch_name); 1644 gcc_jit_function_new_block (comp.func,
1645 format_string ("push_h_val_%u",
1646 pushhandler_n));
1651 emit_cond_jump ( 1647 emit_cond_jump (
1652 /* This negation is just to have a bool. */ 1648 /* This negation is just to have a bool. */
1653 gcc_jit_context_new_unary_op (comp.ctxt, 1649 gcc_jit_context_new_unary_op (comp.ctxt,