aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-06-08 15:45:27 +0200
committerAndrea Corallo2020-01-01 11:33:40 +0100
commitb8aeb2e35d99e14970d15561fcf161ce78fd2426 (patch)
tree5698147f9e9016e7f90b013c186fdd081fa70e5e /src/comp.c
parent16b2a5471eaa7ae2514398720696b3da12514e84 (diff)
downloademacs-b8aeb2e35d99e14970d15561fcf161ce78fd2426.tar.gz
emacs-b8aeb2e35d99e14970d15561fcf161ce78fd2426.zip
move to lispobj as union
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c133
1 files changed, 85 insertions, 48 deletions
diff --git a/src/comp.c b/src/comp.c
index 8a88e5819c7..ddc0bd067f3 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -151,11 +151,13 @@ typedef struct {
151 gcc_jit_type *void_type; 151 gcc_jit_type *void_type;
152 gcc_jit_type *int_type; 152 gcc_jit_type *int_type;
153 gcc_jit_type *long_type; 153 gcc_jit_type *long_type;
154 gcc_jit_type *long_long_type;
154 gcc_jit_type *void_ptr_type; 155 gcc_jit_type *void_ptr_type;
155 gcc_jit_type *ptrdiff_type; 156 gcc_jit_type *ptrdiff_type;
156 gcc_jit_type *lisp_obj_type; 157 gcc_jit_type *lisp_obj_type;
158 gcc_jit_field *lisp_obj_as_ptr;
159 gcc_jit_field *lisp_obj_as_num;
157 gcc_jit_function *func; /* Current function being compiled */ 160 gcc_jit_function *func; /* Current function being compiled */
158 gcc_jit_rvalue *nil;
159 gcc_jit_rvalue *scratch; /* Will point to scratch_call_area */ 161 gcc_jit_rvalue *scratch; /* Will point to scratch_call_area */
160 gcc_jit_rvalue *most_positive_fixnum; 162 gcc_jit_rvalue *most_positive_fixnum;
161 gcc_jit_rvalue *most_negative_fixnum; 163 gcc_jit_rvalue *most_negative_fixnum;
@@ -207,6 +209,32 @@ pop (unsigned n, gcc_jit_lvalue ***stack_ref, gcc_jit_rvalue *args[])
207 *stack_ref = stack; 209 *stack_ref = stack;
208} 210}
209 211
212/* Construct fill and return a lisp object form a raw pointer. */
213
214INLINE static gcc_jit_rvalue *
215gcc_lisp_obj_as_ptr_from_ptr (basic_block_t *bblock, void *p)
216{
217 gcc_jit_lvalue *lisp_obj = gcc_jit_function_new_local (comp.func,
218 NULL,
219 comp.lisp_obj_type,
220 "lisp_obj");
221 gcc_jit_lvalue *lisp_obj_as_ptr =
222 gcc_jit_lvalue_access_field (lisp_obj,
223 NULL,
224 comp.lisp_obj_as_ptr);
225
226 gcc_jit_rvalue *void_ptr =
227 gcc_jit_context_new_rvalue_from_ptr(comp.ctxt,
228 comp.void_ptr_type,
229 p);
230
231 gcc_jit_block_add_assignment (bblock->gcc_bb,
232 NULL,
233 lisp_obj_as_ptr,
234 void_ptr);
235 return gcc_jit_lvalue_as_rvalue (lisp_obj);
236}
237
210static gcc_jit_function * 238static gcc_jit_function *
211gcc_func_declare (const char *f_name, gcc_jit_type *ret_type, 239gcc_func_declare (const char *f_name, gcc_jit_type *ret_type,
212 unsigned nargs, gcc_jit_rvalue **args, 240 unsigned nargs, gcc_jit_rvalue **args,
@@ -564,11 +592,12 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
564 } 592 }
565 593
566 basic_block_t *bb_map = compute_bblocks (bytestr_length, bytestr_data); 594 basic_block_t *bb_map = compute_bblocks (bytestr_length, bytestr_data);
567 /* basic_block_t *nil_ret_bb = NULL; */
568 595
569 for (ptrdiff_t i = 0; i < comp_res.max_args; ++i) 596 for (ptrdiff_t i = 0; i < comp_res.max_args; ++i)
570 PUSH_PARAM (gcc_jit_function_get_param (comp.func, i)); 597 PUSH_PARAM (gcc_jit_function_get_param (comp.func, i));
571 598
599 gcc_jit_rvalue *nil = gcc_lisp_obj_as_ptr_from_ptr (&bb_map[0], Qnil);
600
572 comp.bblock = NULL; 601 comp.bblock = NULL;
573 602
574 while (pc < bytestr_length) 603 while (pc < bytestr_length)
@@ -623,9 +652,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
623 op = FETCH; 652 op = FETCH;
624 varref: 653 varref:
625 { 654 {
626 args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 655 args[0] = gcc_lisp_obj_as_ptr_from_ptr (comp.bblock, vectorp[op]);
627 comp.lisp_obj_type,
628 vectorp[op]);
629 res = gcc_emit_call ("Fsymbol_value", comp.lisp_obj_type, 1, args); 656 res = gcc_emit_call ("Fsymbol_value", comp.lisp_obj_type, 1, args);
630 PUSH_LVAL (res); 657 PUSH_LVAL (res);
631 break; 658 break;
@@ -650,10 +677,8 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
650 { 677 {
651 POP1; 678 POP1;
652 args[1] = args[0]; 679 args[1] = args[0];
653 args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 680 args[0] = gcc_lisp_obj_as_ptr_from_ptr (comp.bblock, vectorp[op]);
654 comp.lisp_obj_type, 681 args[2] = nil;
655 vectorp[op]);
656 args[2] = comp.nil;
657 args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, 682 args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt,
658 comp.int_type, 683 comp.int_type,
659 SET_INTERNAL_SET); 684 SET_INTERNAL_SET);
@@ -679,9 +704,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
679 op -= Bvarbind; 704 op -= Bvarbind;
680 varbind: 705 varbind:
681 { 706 {
682 args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 707 args[0] = gcc_lisp_obj_as_ptr_from_ptr (comp.bblock, vectorp[op]);
683 comp.lisp_obj_type,
684 vectorp[op]);
685 pop (1, &stack, &args[1]); 708 pop (1, &stack, &args[1]);
686 res = gcc_emit_call ("specbind", comp.lisp_obj_type, 2, args); 709 res = gcc_emit_call ("specbind", comp.lisp_obj_type, 2, args);
687 PUSH_LVAL (res); 710 PUSH_LVAL (res);
@@ -770,9 +793,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
770 make_list: 793 make_list:
771 { 794 {
772 POP1; 795 POP1;
773 args[1] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 796 args[1] = nil;
774 comp.lisp_obj_type,
775 Qnil);
776 res = gcc_emit_call ("Fcons", comp.lisp_obj_type, 2, args); 797 res = gcc_emit_call ("Fcons", comp.lisp_obj_type, 2, args);
777 PUSH_LVAL (res); 798 PUSH_LVAL (res);
778 for (int i = 0; i < op; ++i) 799 for (int i = 0; i < op; ++i)
@@ -876,7 +897,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
876 897
877 case Bindent_to: 898 case Bindent_to:
878 POP1; 899 POP1;
879 args[1] = comp.nil; 900 args[1] = nil;
880 res = gcc_emit_call ("Findent_to", comp.lisp_obj_type, 2, args); 901 res = gcc_emit_call ("Findent_to", comp.lisp_obj_type, 2, args);
881 PUSH_LVAL (res); 902 PUSH_LVAL (res);
882 break; 903 break;
@@ -903,9 +924,8 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
903 break; 924 break;
904 925
905 case Binteractive_p: /* Obsolete since 24.1. */ 926 case Binteractive_p: /* Obsolete since 24.1. */
906 PUSH_RVAL (gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, 927 PUSH_RVAL (gcc_lisp_obj_as_ptr_from_ptr (comp.bblock,
907 comp.lisp_obj_type, 928 intern ("interactive-p")));
908 intern ("interactive-p")));
909 res = gcc_emit_call ("call0", comp.lisp_obj_type, 1, args); 929 res = gcc_emit_call ("call0", comp.lisp_obj_type, 1, args);
910 PUSH_LVAL (res); 930 PUSH_LVAL (res);
911 break; 931 break;
@@ -937,14 +957,14 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
937 case Bgotoifnil: 957 case Bgotoifnil:
938 op = FETCH2; 958 op = FETCH2;
939 POP1; 959 POP1;
940 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], comp.nil, 960 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], nil,
941 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 961 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
942 break; 962 break;
943 963
944 case Bgotoifnonnil: 964 case Bgotoifnonnil:
945 op = FETCH2; 965 op = FETCH2;
946 POP1; 966 POP1;
947 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], comp.nil, 967 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], nil,
948 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 968 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
949 break; 969 break;
950 970
@@ -952,7 +972,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
952 op = FETCH2; 972 op = FETCH2;
953 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, 973 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ,
954 gcc_jit_lvalue_as_rvalue (TOS), 974 gcc_jit_lvalue_as_rvalue (TOS),
955 comp.nil, 975 nil,
956 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 976 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
957 POP1; 977 POP1;
958 break; 978 break;
@@ -961,7 +981,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
961 op = FETCH2; 981 op = FETCH2;
962 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, 982 gcc_emit_conditional (GCC_JIT_COMPARISON_NE,
963 gcc_jit_lvalue_as_rvalue (TOS), 983 gcc_jit_lvalue_as_rvalue (TOS),
964 comp.nil, 984 nil,
965 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 985 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
966 POP1; 986 POP1;
967 break; 987 break;
@@ -995,9 +1015,8 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
995 break; 1015 break;
996 1016
997 case Bsave_restriction: 1017 case Bsave_restriction:
998 args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 1018 args[0] = gcc_lisp_obj_as_ptr_from_ptr (comp.bblock,
999 comp.void_ptr_type, 1019 save_restriction_restore);
1000 save_restriction_restore);
1001 args[1] = 1020 args[1] =
1002 gcc_jit_lvalue_as_rvalue (gcc_emit_call ("save_restriction_save", 1021 gcc_jit_lvalue_as_rvalue (gcc_emit_call ("save_restriction_save",
1003 comp.lisp_obj_type, 1022 comp.lisp_obj_type,
@@ -1009,9 +1028,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1009 case Bcatch: /* Obsolete since 24.4. */ 1028 case Bcatch: /* Obsolete since 24.4. */
1010 POP2; 1029 POP2;
1011 args[2] = args[1]; 1030 args[2] = args[1];
1012 args[1] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 1031 args[1] = gcc_lisp_obj_as_ptr_from_ptr (comp.bblock, eval_sub);
1013 comp.void_ptr_type,
1014 eval_sub);
1015 gcc_emit_call ("internal_catch", comp.void_ptr_type, 3, args); 1032 gcc_emit_call ("internal_catch", comp.void_ptr_type, 3, args);
1016 break; 1033 break;
1017 1034
@@ -1126,7 +1143,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1126 op = FETCH - 128; 1143 op = FETCH - 128;
1127 op += pc; 1144 op += pc;
1128 POP1; 1145 POP1;
1129 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], comp.nil, 1146 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], nil,
1130 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1147 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1131 break; 1148 break;
1132 1149
@@ -1134,7 +1151,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1134 op = FETCH - 128; 1151 op = FETCH - 128;
1135 op += pc; 1152 op += pc;
1136 POP1; 1153 POP1;
1137 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], comp.nil, 1154 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], nil,
1138 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1155 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1139 break; 1156 break;
1140 1157
@@ -1143,7 +1160,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1143 op += pc; 1160 op += pc;
1144 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ, 1161 gcc_emit_conditional (GCC_JIT_COMPARISON_EQ,
1145 gcc_jit_lvalue_as_rvalue (TOS), 1162 gcc_jit_lvalue_as_rvalue (TOS),
1146 comp.nil, 1163 nil,
1147 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1164 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1148 POP1; 1165 POP1;
1149 break; 1166 break;
@@ -1153,7 +1170,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1153 op += pc; 1170 op += pc;
1154 gcc_emit_conditional (GCC_JIT_COMPARISON_NE, 1171 gcc_emit_conditional (GCC_JIT_COMPARISON_NE,
1155 gcc_jit_lvalue_as_rvalue (TOS), 1172 gcc_jit_lvalue_as_rvalue (TOS),
1156 comp.nil, 1173 nil,
1157 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1174 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1158 POP1; 1175 POP1;
1159 break; 1176 break;
@@ -1192,9 +1209,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1192 if (pc >= bytestr_length || bytestr_data[pc] != Bswitch) 1209 if (pc >= bytestr_length || bytestr_data[pc] != Bswitch)
1193 { 1210 {
1194 gcc_jit_rvalue *c = 1211 gcc_jit_rvalue *c =
1195 gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, 1212 gcc_lisp_obj_as_ptr_from_ptr (comp.bblock, vectorp[op]);
1196 comp.lisp_obj_type,
1197 vectorp[op]);
1198 PUSH_RVAL (c); 1213 PUSH_RVAL (c);
1199 /* Fprint(vectorp[op], Qnil); */ 1214 /* Fprint(vectorp[op], Qnil); */
1200 break; 1215 break;
@@ -1342,19 +1357,44 @@ init_comp (void)
1342{ 1357{
1343 comp.ctxt = gcc_jit_context_acquire(); 1358 comp.ctxt = gcc_jit_context_acquire();
1344 1359
1360 comp.void_type = gcc_jit_context_get_type (comp.ctxt, GCC_JIT_TYPE_VOID);
1361 comp.void_ptr_type =
1362 gcc_jit_context_get_type (comp.ctxt, GCC_JIT_TYPE_VOID_PTR);
1363 comp.int_type = gcc_jit_context_get_type (comp.ctxt, GCC_JIT_TYPE_INT);
1364 comp.long_type = gcc_jit_context_get_type (comp.ctxt, GCC_JIT_TYPE_LONG);
1365 comp.long_long_type = gcc_jit_context_get_type (comp.ctxt,
1366 GCC_JIT_TYPE_LONG_LONG);
1367
1345#if EMACS_INT_MAX <= LONG_MAX 1368#if EMACS_INT_MAX <= LONG_MAX
1346 /* 32-bit builds without wide ints, 64-bit builds on Posix hosts. */ 1369 /* 32-bit builds without wide ints, 64-bit builds on Posix hosts. */
1347 comp.lisp_obj_type = gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_VOID_PTR); 1370 comp.lisp_obj_as_ptr = gcc_jit_context_new_field (comp.ctxt,
1371 NULL,
1372 comp.void_ptr_type,
1373 "obj");
1374 comp.lisp_obj_as_num = gcc_jit_context_new_field (comp.ctxt,
1375 NULL,
1376 comp.long_long_type,
1377 "num");
1378
1348#else 1379#else
1349 /* 64-bit builds on MS-Windows, 32-bit builds with wide ints. */ 1380 /* 64-bit builds on MS-Windows, 32-bit builds with wide ints. */
1350 comp.lisp_obj_type = gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_LONG_LONG); 1381 comp.lisp_obj_as_ptr = gcc_jit_context_new_field (comp.ctxt,
1382 NULL,
1383 comp.long_long_type,
1384 "obj");
1385 comp.lisp_obj_as_num = gcc_jit_context_new_field (comp.ctxt,
1386 NULL,
1387 comp.long_long_type,
1388 "num");
1351#endif 1389#endif
1352 1390
1353 comp.void_type = gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_VOID); 1391 gcc_jit_field *lisp_obj_fields[2] = { comp.lisp_obj_as_ptr,
1354 comp.int_type = gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_INT); 1392 comp.lisp_obj_as_num };
1355 comp.long_type = gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_LONG); 1393 comp.lisp_obj_type = gcc_jit_context_new_union_type (comp.ctxt,
1356 comp.void_ptr_type = 1394 NULL,
1357 gcc_jit_context_get_type(comp.ctxt, GCC_JIT_TYPE_VOID_PTR); 1395 "LispObj",
1396 2,
1397 lisp_obj_fields);
1358 comp.most_positive_fixnum = 1398 comp.most_positive_fixnum =
1359 gcc_jit_context_new_rvalue_from_long (comp.ctxt, 1399 gcc_jit_context_new_rvalue_from_long (comp.ctxt,
1360 comp.long_type, /* FIXME? */ 1400 comp.long_type, /* FIXME? */
@@ -1365,8 +1405,9 @@ init_comp (void)
1365 MOST_NEGATIVE_FIXNUM); 1405 MOST_NEGATIVE_FIXNUM);
1366 comp.one = 1406 comp.one =
1367 gcc_jit_context_new_rvalue_from_int (comp.ctxt, 1407 gcc_jit_context_new_rvalue_from_int (comp.ctxt,
1368 comp.lisp_obj_type, 1408 comp.int_type,
1369 1); 1409 1);
1410
1370 enum gcc_jit_types ptrdiff_t_gcc; 1411 enum gcc_jit_types ptrdiff_t_gcc;
1371 if (sizeof (ptrdiff_t) == sizeof (int)) 1412 if (sizeof (ptrdiff_t) == sizeof (int))
1372 ptrdiff_t_gcc = GCC_JIT_TYPE_INT; 1413 ptrdiff_t_gcc = GCC_JIT_TYPE_INT;
@@ -1379,10 +1420,6 @@ init_comp (void)
1379 1420
1380 comp.ptrdiff_type = gcc_jit_context_get_type(comp.ctxt, ptrdiff_t_gcc); 1421 comp.ptrdiff_type = gcc_jit_context_get_type(comp.ctxt, ptrdiff_t_gcc);
1381 1422
1382 comp.nil = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt,
1383 comp.lisp_obj_type,
1384 Qnil);
1385
1386 comp.scratch = 1423 comp.scratch =
1387 gcc_jit_lvalue_get_address( 1424 gcc_jit_lvalue_get_address(
1388 gcc_jit_context_new_global (comp.ctxt, NULL, 1425 gcc_jit_context_new_global (comp.ctxt, NULL,