185static char SccsId[] =
"@(#)amasm.c 1.3 3/15/90";
191#include "YapCompile.h"
198#include "or.macros.h"
210 wamreg x1_arg, x2_arg;
217 int alloc_found, dealloc_found;
221static OPREG Var_Ref(
Ventry *,
int);
222static wamreg emit_xreg(CELL);
223static yslot emit_yreg(CELL);
224static wamreg emit_x(CELL);
225static yslot emit_y(
Ventry *);
226static yamop *emit_a(CELL);
230static CELL emit_c(CELL);
231static COUNT emit_count(CELL);
232static OPCODE emit_op(op_numbers);
235static yamop *a_ue(op_numbers, op_numbers,
yamop *,
int);
237static yamop *a_uv(
Ventry *, op_numbers, op_numbers, op_numbers, op_numbers,
239static yamop *a_vr(op_numbers, op_numbers,
yamop *,
int,
241static yamop *a_rv(op_numbers, op_numbers, OPREG,
yamop *,
int,
243static yamop *a_vv(op_numbers, op_numbers,
yamop *,
int,
247static yamop *a_f(CELL, op_numbers,
yamop *,
int);
248static yamop *a_c(CELL, op_numbers,
yamop *,
int);
249static yamop *a_uc(CELL, op_numbers, op_numbers,
yamop *,
int);
250static yamop *a_n(op_numbers,
int,
yamop *,
int);
251static yamop *a_un(op_numbers, op_numbers,
int,
yamop *,
int);
252static yamop *a_nc(CELL, op_numbers,
int,
yamop *,
int);
253static yamop *a_unc(CELL, op_numbers, op_numbers,
int,
yamop *,
int);
254static yamop *a_r(CELL, op_numbers,
yamop *,
int);
265static yamop *a_try(op_numbers, CELL, CELL,
int,
int,
yamop *,
int,
267static yamop *a_either(op_numbers, CELL, CELL,
int,
yamop *,
int,
270static yamop *a_try(op_numbers, CELL, CELL,
yamop *,
int,
272static yamop *a_either(op_numbers, CELL, CELL,
yamop *,
int,
277static COUNT compile_cmp_flags(
unsigned char *);
280static yamop *a_ucons(
int *, compiler_vm_op,
yamop *,
int,
287static void DumpOpCodes(
void);
290static void a_vsf(
int,
yamop *,
int,
struct PSEUDO *);
291static void a_asf(
int,
yamop *,
int,
struct PSEUDO *);
303 if (p->StatisticsForPred)
304 return p->StatisticsForPred;
309 INIT_LOCK(ptr->lock);
311 ptr->NOfHeadSuccesses = 0;
313 p->StatisticsForPred = ptr;
317#define GONEXT(TYPE) code_p = ((yamop *)(&(code_p->y_u.TYPE.next)))
319inline static yslot emit_y(
Ventry *ve) {
321 return (-FixedEnvSize - ((ve->NoOfVE) & MaskVarAdrs) - 1);
323 return (-FixedEnvSize - (((ve->NoOfVE) & MaskVarAdrs) * CELLSIZE) - CELLSIZE);
327inline static OPREG Var_Ref(
Ventry *ve,
int is_y_var) {
330 return -FixedEnvSize - ((ve->NoOfVE) & MaskVarAdrs) - 1;
332 return -FixedEnvSize - (((ve->NoOfVE) & MaskVarAdrs) * CELLSIZE) - CELLSIZE;
335#if PRECOMPUTE_REGADDRESS
336 return (CELL)(XREGS + ((ve->NoOfVE) & MaskVarAdrs));
339 return ((ve->NoOfVE) & MaskVarAdrs);
341 return CELLSIZE * ((ve->NoOfVE) & MaskVarAdrs);
347#define is_void_var() (((Ventry *)(cip->cpc->rnd1))->KindOfVE == VoidVar)
348#define is_a_void(X) (((Ventry *)(X))->KindOfVE == VoidVar)
350#define is_temp_var() (((Ventry *)(cip->cpc->rnd1))->KindOfVE == TempVar)
351#define is_atemp_var(p) (((Ventry *)(p->rnd1))->KindOfVE == TempVar)
353#define no_ref_var() (((Ventry *)(cip->cpc->rnd1))->NoOfVE == 1)
354#define no_ref(X) (((Ventry *)(X))->NoOfVE == 1)
356inline static yamop *fill_a(CELL a,
yamop *code_p,
int pass_no) {
357 CELL *ptr = ((CELL *)(code_p));
361 return (
yamop *)(++ptr);
364inline static wamreg emit_xreg(CELL w) {
return (wamreg)w; }
366inline static yslot emit_yreg(CELL w) {
return (yslot)w; }
368inline static wamreg emit_x(CELL
xarg) {
369#if PRECOMPUTE_REGADDRESS
370 return (emit_xreg((CELL)(XREGS +
xarg)));
373 return (emit_xreg(
xarg));
375 return (emit_xreg(CELLSIZE * (
xarg)));
380wamreg Yap_emit_x(CELL
xarg) {
return emit_x(
xarg); }
382inline static yamop *emit_a(CELL a) {
return ((
yamop *)(a)); }
386inline static yamop *emit_ilabel(
register CELL addr,
389 return (emit_a(Unsigned(cip->code_addr) + cip->label_offset[addr]));
391 return (emit_a(addr));
395inline static CELL *emit_bmlabel(
register CELL addr,
397 return (CELL *)(emit_a(Unsigned(cip->code_addr) + cip->label_offset[addr]));
402inline static CELL emit_c(CELL a) {
return a; }
404static inline COUNT emit_count(CELL count) {
return count; }
407inline static void DumpOpCodes(
void) {
411 for (j = i; j <= _std_top; j += 25)
412 fprintf(GLOBAL_stderr,
"%5d %6lx", j, absmadr(j));
413 fputc(
'\n', GLOBAL_stderr);
419static inline OPCODE emit_op(op_numbers op) {
return absmadr((Int)op); }
421static OPCODE opcode(op_numbers op) {
return (emit_op(op)); }
424Yap_opcode(op_numbers op) {
return opcode(op); }
426static void add_clref(CELL clause_code,
int pass_no) {
428 LogUpdClause *cl = ClauseCodeToLogUpdClause(clause_code);
433static void add_to_dbtermsl(
struct intermediates *cip, Term t) {
434 DBTerm *dbt = TermToDBTerm(t);
435 dbt->ag.NextDBT = cip->dbterml->dbterms;
436 cip->dbterml->dbterms = dbt;
439static yamop *a_lucl(op_numbers opcode,
yamop *code_p,
int pass_no,
443 code_p->opc = emit_op(opcode);
444 code_p->y_u.Illss.I = lcl;
445 cip->cpc->rnd4 = (CELL)code_p;
446 cip->current_try_lab = &code_p->y_u.Illss.l1;
447 cip->current_trust_lab = &code_p->y_u.Illss.l2;
448 code_p->y_u.Illss.l1 = NULL;
449 code_p->y_u.Illss.l2 = NULL;
450 code_p->y_u.Illss.s = cip->cpc->rnd3;
451 code_p->y_u.Illss.e = 0;
457static yamop *a_cle(op_numbers opcode,
yamop *code_p,
int pass_no,
462 code_p->opc = emit_op(opcode);
463 code_p->y_u.L.ClBase = cl;
465 cl->ClFlags |= LogUpdRuleMask;
471inline static yamop *a_e(op_numbers opcode,
yamop *code_p,
int pass_no) {
473 code_p->opc = emit_op(opcode);
479inline static yamop *a_p0(op_numbers opcode,
yamop *code_p,
int pass_no,
482 code_p->opc = emit_op(opcode);
483 code_p->y_u.p.p = p0;
489inline static yamop *a_lp(op_numbers opcode,
yamop *code_p,
int pass_no,
492 code_p->opc = emit_op(opcode);
493 code_p->y_u.lp.p = (
PredEntry *)cip->cpc->rnd1;
494 code_p->y_u.lp.l = (
yamop *)cip->cpc->rnd2;
500inline static yamop *a_ue(op_numbers opcode, op_numbers opcodew,
yamop *code_p,
503 code_p->opc = emit_op(opcode);
504 code_p->y_u.o.opcw = emit_op(opcodew);
511 if (cip->failure_handler) {
512 return emit_a(Unsigned(cip->code_addr) +
513 cip->label_offset[cip->failure_handler]);
519inline static yamop *a_v(op_numbers opcodex, op_numbers opcodey,
yamop *code_p,
520 int pass_no,
struct PSEUDO *cpc) {
523 int is_y_var = (ve->KindOfVE == PermVar);
525 var_offset = Var_Ref(ve, is_y_var);
528 code_p->opc = emit_op(opcodey);
529 code_p->y_u.y.y = emit_yreg(var_offset);
534 code_p->opc = emit_op(opcodex);
535 code_p->y_u.x.x = emit_xreg(var_offset);
542inline static yamop *a_vp(op_numbers opcodex, op_numbers opcodey,
yamop *code_p,
543 int pass_no,
struct PSEUDO *cpc,
547 int is_y_var = (ve->KindOfVE == PermVar);
549 var_offset = Var_Ref(ve, is_y_var);
552 code_p->opc = emit_op(opcodey);
553 code_p->y_u.yps.y = emit_yreg(var_offset);
554 code_p->y_u.yps.p0 = clinfo->CurrentPred;
555 code_p->y_u.yps.s = -Signed(RealEnvSize) - CELLSIZE * cpc->rnd2;
560 code_p->opc = emit_op(opcodex);
561 code_p->y_u.xps.x = emit_xreg(var_offset);
562 code_p->y_u.xps.p0 = clinfo->CurrentPred;
563 code_p->y_u.xps.s = -Signed(RealEnvSize) - CELLSIZE * cpc->rnd2;
570inline static yamop *a_uv(
Ventry *ve, op_numbers opcodex, op_numbers opcodexw,
571 op_numbers opcodey, op_numbers opcodeyw,
572 yamop *code_p,
int pass_no) {
574 int is_y_var = (ve->KindOfVE == PermVar);
576 var_offset = Var_Ref(ve, is_y_var);
579 code_p->opc = emit_op(opcodey);
580 code_p->y_u.oy.opcw = emit_op(opcodeyw);
581 code_p->y_u.oy.y = emit_yreg(var_offset);
586 code_p->opc = emit_op(opcodex);
587 code_p->y_u.ox.opcw = emit_op(opcodexw);
588 code_p->y_u.ox.x = emit_xreg(var_offset);
595inline static yamop *a_vv(op_numbers opcode, op_numbers opcodew,
yamop *code_p,
598 int is_y_var = (ve->KindOfVE == PermVar);
601 OPREG var_offset = Var_Ref(ve, is_y_var);
602 code_p->opc = emit_op(opcode);
603 code_p->y_u.oxx.opcw = emit_op(opcodew);
604 code_p->y_u.oxx.xl = emit_xreg(var_offset);
606 cip->cpc = cip->cpc->nextInst;
611 ve = (
Ventry *)cip->cpc->rnd1;
612 is_y_var = (ve->KindOfVE == PermVar);
613 var_offset = Var_Ref(ve, is_y_var);
614 code_p->y_u.oxx.xr = emit_xreg(var_offset);
620inline static yamop *a_vr(op_numbers opcodex, op_numbers opcodey,
yamop *code_p,
622 struct PSEUDO *cpc = cip->cpc;
624 int is_y_var = (ve->KindOfVE == PermVar);
627 if (opcodey == _put_y_val) {
628 struct PSEUDO *ncpc = cpc->nextInst;
629 if (ncpc->op == put_val_op &&
630 ((
Ventry *)ncpc->rnd1)->KindOfVE == PermVar) {
637 var_offset = Var_Ref(ve, is_y_var);
638 code_p->opc = emit_op(_put_y_vals);
639 code_p->y_u.yyxx.y1 = emit_yreg(var_offset);
640 code_p->y_u.yyxx.x1 = emit_x(cpc->rnd2);
641 var_offset2 = Var_Ref(ve2, is_y_var);
642 code_p->y_u.yyxx.y2 = emit_yreg(var_offset2);
643 code_p->y_u.yyxx.x2 = emit_x(ncpc->rnd2);
649 }
else if (FALSE && cpc->rnd2 == 0 && ncpc->op == get_var_op &&
651 ((
Ventry *)ncpc->rnd1)->KindOfVE != PermVar) {
657 code_p->opc = emit_op(_put_y_var);
658 var_offset = Var_Ref(ve, is_y_var);
659 var_offset2 = Var_Ref(ve2, !is_y_var);
660 code_p->y_u.yx.x = emit_xreg(var_offset2);
661 code_p->y_u.yx.y = emit_yreg(var_offset);
667 }
else if (opcodey == _get_y_var) {
668 struct PSEUDO *ncpc = cpc->nextInst;
669 if (ncpc->op == get_var_op &&
670 ((
Ventry *)ncpc->rnd1)->KindOfVE == PermVar) {
677 var_offset = Var_Ref(ve, is_y_var);
678 code_p->opc = emit_op(_get_yy_var);
679 code_p->y_u.yyxx.y1 = emit_yreg(var_offset);
680 code_p->y_u.yyxx.x1 = emit_x(cpc->rnd2);
681 var_offset2 = Var_Ref(ve2, is_y_var);
682 code_p->y_u.yyxx.y2 = emit_yreg(var_offset2);
683 code_p->y_u.yyxx.x2 = emit_x(ncpc->rnd2);
692 var_offset = Var_Ref(ve, is_y_var);
693 code_p->opc = emit_op(opcodey);
694 code_p->y_u.yx.y = emit_yreg(var_offset);
695 code_p->y_u.yx.x = emit_x(cpc->rnd2);
700 if (opcodex == _put_x_val && cpc->nextInst) {
701 if (cpc->nextInst->op == put_val_op &&
702 !(((
Ventry *)cpc->nextInst->rnd1)->KindOfVE == PermVar)) {
703 PInstr *ncpc = cpc->nextInst;
710 var_offset = Var_Ref(ve, is_y_var);
711 code_p->opc = emit_op(_put_xx_val);
712 code_p->y_u.xxxx.xl1 = emit_xreg(var_offset);
713 code_p->y_u.xxxx.xr1 = emit_x(cpc->rnd2);
714 var_offset2 = Var_Ref(ve2, is_y_var);
715 code_p->y_u.xxxx.xl2 = emit_xreg(var_offset2);
716 code_p->y_u.xxxx.xr2 = emit_x(ncpc->rnd2);
722 }
else if (cpc->rnd2 == 0 && cpc->nextInst->rnd2 == 0) {
729 ncpc = cpc->nextInst;
730 ve2 = (
Ventry *)ncpc->rnd1;
731 is_y_var2 = (ve2->KindOfVE == PermVar);
733 if (ncpc->op == get_var_op || ncpc->op == get_val_op) {
736 var_offset = Var_Ref(ve, is_y_var);
737 var_offset2 = Var_Ref(ve2, is_y_var2);
738 if (ncpc->op == get_var_op)
739 code_p->opc = emit_op(_get_y_var);
741 code_p->opc = emit_op(_get_y_val);
742 code_p->y_u.yx.x = emit_xreg(var_offset);
743 code_p->y_u.yx.y = emit_yreg(var_offset2);
750 var_offset = Var_Ref(ve, is_y_var);
751 var_offset2 = Var_Ref(ve2, is_y_var2);
752 code_p->y_u.xx.xl = emit_xreg(var_offset);
753 code_p->y_u.xx.xr = emit_xreg(var_offset2);
754 if (ncpc->op == get_var_op)
755 code_p->opc = emit_op(_put_x_val);
757 code_p->opc = emit_op(_get_x_val);
770 var_offset = Var_Ref(ve, is_y_var);
771 code_p->opc = emit_op(opcodex);
772 code_p->y_u.xx.xl = emit_xreg(var_offset);
773 code_p->y_u.xx.xr = emit_x(cpc->rnd2);
775 if (opcodex == _get_x_val && code_p->y_u.xx.xl > code_p->y_u.xx.xr) {
776 wamreg x1 = code_p->y_u.xx.xl;
777 code_p->y_u.xx.xl = code_p->y_u.xx.xr;
778 code_p->y_u.xx.xr = x1;
785inline static yamop *a_rv(op_numbers opcodex, op_numbers opcodey,
786 OPREG var_offset,
yamop *code_p,
int pass_no,
789 int is_y_var = (ve->KindOfVE == PermVar);
793 code_p->opc = emit_op(opcodey);
794 code_p->y_u.yx.x = emit_x(cpc->rnd2);
795 code_p->y_u.yx.y = emit_yreg(var_offset);
800 code_p->opc = emit_op(opcodex);
801 code_p->y_u.xx.xl = emit_x(cpc->rnd2);
802 code_p->y_u.xx.xr = emit_xreg(var_offset);
813inline static void a_vsf(
int opcode,
yamop *code_p,
int pass_no,
817 int is_y_var = (ve->KindOfVE == PermVar);
819 var_offset = Var_Ref(ve, is_y_var);
822 code_p->opc = emit_op((op_numbers)((
int)opcode + is_y_var));
823 code_p->y_u.fy.f = emit_f(cpc->rnd2);
824 code_p->y_u.fy.a = ArityOfFunctor(emit_f(cpc->rnd2));
825 code_p->y_u.fy.y = emit_yreg(var_offset);
830 code_p->opc = emit_op((op_numbers)((
int)opcode + is_y_var));
831 code_p->y_u.fx.f = emit_f(cpc->rnd2);
832 code_p->y_u.fx.a = ArityOfFunctor(emit_f(cpc->rnd2));
833 code_p->y_u.fx.x = emit_xreg(var_offset);
840inline static void a_asf(
int opcode,
yamop *code_p,
int pass_no,
843 code_p->opc = emit_op((op_numbers)((
int)opcode + is_y_var));
844 code_p->y_u.fn.f = emit_f(cpc->rnd2);
845 code_p->y_u.fn.a = ArityOfFunctor(emit_f(cpc->rnd2));
846 code_p->y_u.fn.n = emit_count(cpc->rnd1);
853inline static void a_pair(CELL *seq_ptr,
int pass_no,
856 CELL lab, lab0 = seq_ptr[1];
857 lab = (CELL)emit_ilabel(lab0, cip);
858 seq_ptr[0] = (CELL)emit_a(seq_ptr[0]);
863inline static yamop *a_n(op_numbers opcode,
int count,
yamop *code_p,
866 code_p->opc = emit_op(opcode);
867 code_p->y_u.s.s = count;
874inline static yamop *a_eam(op_numbers opcode,
int pred,
long cl,
yamop *code_p,
877 code_p->opc = emit_op(opcode);
878 code_p->y_u.os.opcw = cl;
879 code_p->y_u.os.s = pred;
886inline static yamop *a_un(op_numbers opcode, op_numbers opcodew,
int count,
887 yamop *code_p,
int pass_no) {
889 code_p->opc = emit_op(opcode);
890 code_p->y_u.os.opcw = emit_op(opcodew);
891 code_p->y_u.os.s = count;
897inline static yamop *a_f(CELL rnd1, op_numbers opcode,
yamop *code_p,
902 code_p->opc = emit_op(opcode);
903 code_p->y_u.fa.f = f;
904 code_p->y_u.fa.a = ArityOfFunctor(f);
910inline static yamop *a_uf(CELL rnd1, op_numbers opcode, op_numbers opcodew,
911 yamop *code_p,
int pass_no) {
915 code_p->opc = emit_op(opcode);
916 code_p->y_u.ofa.opcw = emit_op(opcodew);
917 code_p->y_u.ofa.f = f;
918 code_p->y_u.ofa.a = ArityOfFunctor(f);
924inline static yamop *a_c(CELL rnd1, op_numbers opcode,
yamop *code_p,
927 code_p->opc = emit_op(opcode);
928 code_p->y_u.c.c = emit_c(rnd1);
934inline static yamop *a_uc(CELL rnd1, op_numbers opcode, op_numbers opcode_w,
935 yamop *code_p,
int pass_no) {
937 code_p->opc = emit_op(opcode);
938 code_p->y_u.oc.opcw = emit_op(opcode_w);
939 code_p->y_u.oc.c = emit_c(rnd1);
945inline static yamop *a_wblob(CELL rnd1, op_numbers opcode,
946 int *clause_has_blobsp,
yamop *code_p,
int pass_no,
949 code_p->opc = emit_op(opcode);
951 AbsAppl((CELL *)(Unsigned(cip->code_addr) + cip->label_offset[rnd1]));
953 *clause_has_blobsp = TRUE;
958static yamop *a_ensure_space(op_numbers opcode,
yamop *code_p,
int pass_no,
960 if (cip->cpc->rnd1 > 4096) {
962 code_p->opc = emit_op(opcode);
963 code_p->y_u.Osbpa.i =
sizeof(CELL) * cip->cpc->rnd1;
964 code_p->y_u.Osbpa.p = clinfo->CurrentPred;
965 code_p->y_u.Osbpa.bmap = NULL;
966 code_p->y_u.Osbpa.s = emit_count(-Signed(RealEnvSize));
973inline static yamop *a_wdbt(CELL rnd1, op_numbers opcode,
974 int *clause_has_dbtermp,
yamop *code_p,
int pass_no,
977 code_p->opc = emit_op(opcode);
978 code_p->y_u.D.D = rnd1;
979 add_to_dbtermsl(cip, cip->cpc->rnd1);
981 *clause_has_dbtermp = TRUE;
986inline static yamop *a_ublob(CELL rnd1, op_numbers opcode, op_numbers opcode_w,
987 int *clause_has_blobsp,
yamop *code_p,
int pass_no,
990 code_p->opc = emit_op(opcode);
991 code_p->y_u.oN.opcw = emit_op(opcode_w);
993 AbsAppl((CELL *)(Unsigned(cip->code_addr) + cip->label_offset[rnd1]));
995 *clause_has_blobsp = TRUE;
1001inline static yamop *a_ustring(CELL rnd1, op_numbers opcode,
1002 op_numbers opcode_w,
int *clause_has_blobsp,
1003 yamop *code_p,
int pass_no,
1006 code_p->opc = emit_op(opcode);
1007 code_p->y_u.ou.opcw = emit_op(opcode_w);
1009 AbsAppl((CELL *)(Unsigned(cip->code_addr) + cip->label_offset[rnd1]));
1011 *clause_has_blobsp = TRUE;
1016inline static yamop *a_udbt(CELL rnd1, op_numbers opcode, op_numbers opcode_w,
1017 int *clause_has_dbtermp,
yamop *code_p,
int pass_no,
1020 code_p->opc = emit_op(opcode);
1021 code_p->y_u.oD.opcw = emit_op(opcode_w);
1022 code_p->y_u.oD.D = cip->cpc->rnd1;
1023 add_to_dbtermsl(cip, cip->cpc->rnd1);
1025 *clause_has_dbtermp = TRUE;
1030inline static yamop *a_ud(op_numbers opcode, op_numbers opcode_w,
yamop *code_p,
1031 int pass_no,
struct PSEUDO *cpc) {
1033 code_p->opc = emit_op(opcode);
1034 code_p->y_u.od.opcw = emit_op(opcode_w);
1035 code_p->y_u.od.d[0] = (CELL)FunctorDouble;
1036 code_p->y_u.od.d[1] = RepAppl(cpc->rnd1)[1];
1037#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
1038 code_p->y_u.od.d[2] = RepAppl(cpc->rnd1)[2];
1045inline static yamop *a_ui(op_numbers opcode, op_numbers opcode_w,
yamop *code_p,
1046 int pass_no,
struct PSEUDO *cpc) {
1048 code_p->opc = emit_op(opcode);
1049 code_p->y_u.oi.opcw = emit_op(opcode_w);
1050 code_p->y_u.oi.i[0] = (CELL)FunctorLongInt;
1051 code_p->y_u.oi.i[1] = RepAppl(cpc->rnd1)[1];
1057inline static yamop *a_wd(op_numbers opcode,
yamop *code_p,
int pass_no,
1060 code_p->opc = emit_op(opcode);
1061 code_p->y_u.d.d[0] = (CELL)FunctorDouble;
1062 code_p->y_u.d.d[1] = RepAppl(cpc->rnd1)[1];
1063#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
1064 code_p->y_u.d.d[2] = RepAppl(cpc->rnd1)[2];
1071inline static yamop *a_wi(op_numbers opcode,
yamop *code_p,
int pass_no,
1074 code_p->opc = emit_op(opcode);
1075 code_p->y_u.i.i[0] = (CELL)FunctorLongInt;
1076 code_p->y_u.i.i[1] = RepAppl(cpc->rnd1)[1];
1082inline static yamop *a_nc(CELL rnd1, op_numbers opcode,
int i,
yamop *code_p,
1085 code_p->opc = emit_op(opcode);
1086 code_p->y_u.sc.s = i;
1087 code_p->y_u.sc.c = emit_c(rnd1);
1093inline static yamop *a_unc(CELL rnd1, op_numbers opcode, op_numbers opcodew,
1094 int i,
yamop *code_p,
int pass_no) {
1096 code_p->opc = emit_op(opcode);
1097 code_p->y_u.osc.opcw = emit_op(opcodew);
1098 code_p->y_u.osc.s = i;
1099 code_p->y_u.osc.c = emit_c(rnd1);
1105inline static yamop *a_rf(op_numbers opcode,
yamop *code_p,
int pass_no,
1108 code_p->opc = emit_op(opcode);
1109 code_p->y_u.xfa.x = emit_x(cpc->rnd2);
1110 code_p->y_u.xfa.f = emit_f(cpc->rnd1);
1111 code_p->y_u.xfa.a = ArityOfFunctor(emit_f(cpc->rnd1));
1117inline static yamop *a_rd(op_numbers opcode,
yamop *code_p,
int pass_no,
1120 code_p->opc = emit_op(opcode);
1121 code_p->y_u.xd.x = emit_x(cpc->rnd2);
1122 code_p->y_u.xd.d[0] = (CELL)FunctorDouble;
1123 code_p->y_u.xd.d[1] = RepAppl(cpc->rnd1)[1];
1124#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
1125 code_p->y_u.xd.d[2] = RepAppl(cpc->rnd1)[2];
1132inline static yamop *a_ri(op_numbers opcode,
yamop *code_p,
int pass_no,
1135 code_p->opc = emit_op(opcode);
1136 code_p->y_u.xi.x = emit_x(cpc->rnd2);
1137 code_p->y_u.xi.i[0] = (CELL)FunctorLongInt;
1138 code_p->y_u.xi.i[1] = RepAppl(cpc->rnd1)[1];
1144static yamop *a_rc(op_numbers opcode,
yamop *code_p,
int pass_no,
1146 if (cip->cpc->rnd2 == 1 && cip->cpc->nextInst->rnd2 == 2 &&
1147 (cip->cpc->nextInst->op == get_atom_op ||
1148 cip->cpc->nextInst->op == get_num_op)) {
1150 next = cip->cpc->nextInst;
1151 if (next->nextInst->rnd2 == 3 && (next->nextInst->op == get_atom_op ||
1152 next->nextInst->op == get_num_op)) {
1153 struct PSEUDO *snext = next->nextInst;
1155 if (snext->nextInst->rnd2 == 4 && (snext->nextInst->op == get_atom_op ||
1156 snext->nextInst->op == get_num_op)) {
1157 struct PSEUDO *s2next = snext->nextInst;
1158 if (s2next->nextInst->rnd2 == 5 &&
1159 (s2next->nextInst->op == get_atom_op ||
1160 s2next->nextInst->op == get_num_op)) {
1161 struct PSEUDO *s3next = s2next->nextInst;
1162 if (s3next->nextInst->rnd2 == 6 &&
1163 (s3next->nextInst->op == get_atom_op ||
1164 s3next->nextInst->op == get_num_op)) {
1166 code_p->opc = emit_op(_get_6atoms);
1167 code_p->y_u.cccccc.c1 = emit_c(cip->cpc->rnd1);
1168 code_p->y_u.cccccc.c2 = emit_c(next->rnd1);
1169 code_p->y_u.cccccc.c3 = emit_c(snext->rnd1);
1170 code_p->y_u.cccccc.c4 = emit_c(s2next->rnd1);
1171 code_p->y_u.cccccc.c5 = emit_c(s3next->rnd1);
1172 code_p->y_u.cccccc.c6 = emit_c(s3next->nextInst->rnd1);
1174 cip->cpc = s3next->nextInst;
1178 code_p->opc = emit_op(_get_5atoms);
1179 code_p->y_u.ccccc.c1 = emit_c(cip->cpc->rnd1);
1180 code_p->y_u.ccccc.c2 = emit_c(next->rnd1);
1181 code_p->y_u.ccccc.c3 = emit_c(snext->rnd1);
1182 code_p->y_u.ccccc.c4 = emit_c(s2next->rnd1);
1183 code_p->y_u.ccccc.c5 = emit_c(s3next->rnd1);
1190 code_p->opc = emit_op(_get_4atoms);
1191 code_p->y_u.cccc.c1 = emit_c(cip->cpc->rnd1);
1192 code_p->y_u.cccc.c2 = emit_c(next->rnd1);
1193 code_p->y_u.cccc.c3 = emit_c(snext->rnd1);
1194 code_p->y_u.cccc.c4 = emit_c(s2next->rnd1);
1201 code_p->opc = emit_op(_get_3atoms);
1202 code_p->y_u.ccc.c1 = emit_c(cip->cpc->rnd1);
1203 code_p->y_u.ccc.c2 = emit_c(next->rnd1);
1204 code_p->y_u.ccc.c3 = emit_c(snext->rnd1);
1211 code_p->opc = emit_op(_get_2atoms);
1212 code_p->y_u.cc.c1 = emit_c(cip->cpc->rnd1);
1213 code_p->y_u.cc.c2 = emit_c(next->rnd1);
1220 code_p->opc = emit_op(opcode);
1221 code_p->y_u.xc.x = emit_x(cip->cpc->rnd2);
1222 code_p->y_u.xc.c = emit_c(cip->cpc->rnd1);
1229inline static yamop *a_rb(op_numbers opcode,
int *clause_has_blobsp,
1230 yamop *code_p,
int pass_no,
1233 code_p->opc = emit_op(opcode);
1234 code_p->y_u.xN.x = emit_x(cip->cpc->rnd2);
1235 code_p->y_u.xN.b = AbsAppl(
1236 (CELL *)(Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1]));
1238 *clause_has_blobsp = TRUE;
1243inline static yamop *a_rstring(op_numbers opcode,
int *clause_has_blobsp,
1244 yamop *code_p,
int pass_no,
1247 code_p->opc = emit_op(opcode);
1248 code_p->y_u.xu.x = emit_x(cip->cpc->rnd2);
1249 code_p->y_u.xu.ut = AbsAppl(
1250 (CELL *)(Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1]));
1252 *clause_has_blobsp = TRUE;
1257inline static yamop *a_dbt(op_numbers opcode,
int *clause_has_dbtermp,
1258 yamop *code_p,
int pass_no,
1261 code_p->opc = emit_op(opcode);
1262 code_p->y_u.xD.x = emit_x(cip->cpc->rnd2);
1263 code_p->y_u.xD.D = cip->cpc->rnd1;
1264 add_to_dbtermsl(cip, cip->cpc->rnd1);
1266 *clause_has_dbtermp = TRUE;
1271inline static yamop *a_r(CELL arnd2, op_numbers opcode,
yamop *code_p,
1274 code_p->opc = emit_op(opcode);
1275 code_p->y_u.x.x = emit_x(arnd2);
1283 if (clinfo->alloc_found == 2) {
1284 if (clinfo->CurrentPred->PredFlags & LogUpdatePredFlag)
1285 code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip);
1286 code_p = a_e(_allocate, code_p, pass_no);
1287 clinfo->alloc_found = 1;
1292static yamop *a_l(CELL rnd1, op_numbers opcode,
yamop *code_p,
int pass_no,
1295 code_p->opc = emit_op(opcode);
1297 emit_a(Unsigned(cip->code_addr) + cip->label_offset[rnd1]);
1303static yamop *a_il(CELL rnd1, op_numbers opcode,
yamop *code_p,
int pass_no,
1306 code_p->opc = emit_op(opcode);
1307 code_p->y_u.l.l = emit_ilabel(rnd1, cip);
1317 CELL Flags = RepPredProp(fe)->PredFlags;
1318 if (Flags & AsmPredFlag) {
1320 int is_test = FALSE;
1322 switch (Flags & 0x7f) {
1326#if INLINE_BIG_COMPARISONS
1337 code_p = check_alloc(clinfo, code_p, pass_no, cip);
1342 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
1343 "internal assembler error for built-in (%d)", (Flags & 0x7f));
1344 save_machine_regs();
1345 siglongjmp(cip->CompilerBotch, 1);
1350 if ((lab = cip->failure_handler)) {
1351 return a_l(lab, op, code_p, pass_no, cip);
1353 return a_il((CELL)FAILCODE, op, code_p, pass_no, cip);
1356 return a_e(op, code_p, pass_no);
1359 if (Flags & CPredFlag && opcode == _call) {
1360 code_p = check_alloc(clinfo, code_p, pass_no, cip);
1361 if (cip->failure_handler && (Flags & TestPredFlag)) {
1363 if (Flags & UserCPredFlag) {
1364 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
1365 "user defined predicate cannot be a test predicate");
1366 save_machine_regs();
1367 siglongjmp(cip->CompilerBotch, 1);
1369 code_p->opc = emit_op(_call_c_wfail);
1370 code_p->y_u.slpp.s =
1371 emit_count(-Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2);
1372 code_p->y_u.slpp.l = emit_fail(cip);
1373 code_p->y_u.slpp.p0 = clinfo->CurrentPred;
1374 code_p->y_u.slpp.p = emit_pe(RepPredProp(fe));
1379 code_p->y_u.Osbpp.p = RepPredProp(fe);
1380 if (Flags & UserCPredFlag) {
1381 code_p->opc = emit_op(_call_usercpred);
1383 if (RepPredProp(fe)->FunctorOfPred == FunctorExecuteInMod) {
1384 code_p->y_u.Osbmp.mod = cip->cpc->rnd4;
1385 code_p->opc = emit_op(_p_execute);
1386 }
else if (RepPredProp(fe)->FunctorOfPred == FunctorExecute2InMod) {
1387 code_p->opc = emit_op(_p_execute2);
1389 code_p->opc = emit_op(_call_cpred);
1392 code_p->y_u.Osbpp.s =
1393 emit_count(-Signed(RealEnvSize) - CELLSIZE * (cip->cpc->rnd2));
1394 code_p->y_u.Osbpp.p0 = clinfo->CurrentPred;
1395 if (cip->cpc->rnd2) {
1396 code_p->y_u.Osbpp.bmap = emit_bmlabel(cip->cpc->arnds[1], cip);
1399 code_p->y_u.Osbpp.bmap = NULL;
1407 if (opcode == _call && clinfo->alloc_found == 2) {
1408 if (clinfo->CurrentPred->PredFlags & LogUpdatePredFlag)
1409 code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip);
1411 code_p->opc = emit_op(_fcall);
1413 clinfo->alloc_found = 1;
1415 code_p = check_alloc(clinfo, code_p, pass_no, cip);
1417 code_p->opc = emit_op(opcode);
1419 if (opcode == _call) {
1421 code_p->y_u.Osbpp.s =
1422 emit_count(-Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2);
1423 code_p->y_u.Osbpp.p = RepPredProp(fe);
1424 code_p->y_u.Osbpp.p0 = clinfo->CurrentPred;
1426 code_p->y_u.Osbpp.bmap = emit_bmlabel(cip->cpc->arnds[1], cip);
1429 code_p->y_u.Osbpp.bmap = NULL;
1432 }
else if (opcode == _execute || opcode == _dexecute) {
1434 if (Flags & CPredFlag) {
1435 code_p->opc = emit_op(_execute_cpred);
1437 code_p->y_u.Osbpp.p = RepPredProp(fe);
1438 code_p->y_u.Osbpp.p0 = clinfo->CurrentPred;
1439 code_p->y_u.Osbpp.s = -Signed(RealEnvSize);
1440 code_p->y_u.Osbpp.bmap = NULL;
1445 code_p->y_u.p.p = RepPredProp(fe);
1457 if (clinfo->alloc_found == 1 && !clinfo->dealloc_found) {
1460 code_p->opc = emit_op(_call);
1464 code_p->opc = emit_op(_fcall);
1467 PredEntry *pe = RepPredProp(Yap_GetPredPropByAtom(AtomTrue, 0));
1468 code_p->y_u.Osbpp.s =
1469 emit_count(-Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2);
1470 code_p->y_u.Osbpp.p = pe;
1471 code_p->y_u.Osbpp.p0 = clinfo->CurrentPred;
1473 code_p->y_u.Osbpp.bmap = emit_bmlabel(cip->cpc->rnd1, cip);
1476 code_p->y_u.Osbpp.bmap = NULL;
1485 code_p->opc = emit_op(opcode);
1486 code_p->y_u.p.p = pred;
1494compile_cmp_flags(
unsigned char *s0) {
1495 char *s = (
char *)s0;
1496 if (strcmp(s,
"=<") == 0)
1497 return EQ_OK_IN_CMP | LT_OK_IN_CMP;
1498 if (strcmp(s,
"is") == 0)
1499 return EQ_OK_IN_CMP;
1500 if (strcmp(s,
"@=<") == 0)
1501 return EQ_OK_IN_CMP | LT_OK_IN_CMP;
1502 if (strcmp(s,
"<") == 0)
1503 return LT_OK_IN_CMP;
1504 if (strcmp(s,
"@<") == 0)
1505 return LT_OK_IN_CMP;
1506 if (strcmp(s,
">=") == 0)
1507 return EQ_OK_IN_CMP | GT_OK_IN_CMP;
1508 if (strcmp(s,
"@>=") == 0)
1509 return EQ_OK_IN_CMP | GT_OK_IN_CMP;
1510 if (strcmp(s,
">") == 0)
1511 return GT_OK_IN_CMP;
1512 if (strcmp(s,
"@>") == 0)
1513 return GT_OK_IN_CMP;
1514 if (strcmp(s,
"=:=") == 0)
1515 return EQ_OK_IN_CMP;
1516 if (strcmp(s,
"=\\=") == 0)
1517 return GT_OK_IN_CMP | LT_OK_IN_CMP;
1518 if (strcmp(s,
"\\==") == 0)
1519 return GT_OK_IN_CMP | LT_OK_IN_CMP;
1520 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
1521 "internal assembler error, %s/2 not recognised as binary op", s);
1527 return compile_cmp_flags(
1528 RepAtom(NameOfFunctor(pred->FunctorOfPred))->UStrOfAE);
1536 int is_y_var = (ve1->KindOfVE == PermVar);
1538 var_offset1 = Var_Ref(ve1, is_y_var);
1539 if (ve1->KindOfVE == PermVar) {
1540 yslot v1 = emit_yreg(var_offset1);
1541 bool is_y_var2 = (ve2->KindOfVE == PermVar);
1542 OPREG var_offset2 = Var_Ref(ve2, is_y_var2);
1545 code_p->opc = emit_op(_call_bfunc_yy);
1546 code_p->y_u.plyys.p = pred;
1547 code_p->y_u.plyys.f = emit_fail(cip);
1548 code_p->y_u.plyys.y1 = v1;
1549 code_p->y_u.plyys.y2 = emit_yreg(var_offset2);
1550 code_p->y_u.plyys.flags = compile_cmp_flags(
1551 RepAtom(NameOfFunctor(RepPredProp(((
Prop)pred))->FunctorOfPred))
1557 code_p->opc = emit_op(_call_bfunc_yx);
1558 code_p->y_u.plxys.p = pred;
1559 code_p->y_u.plxys.f = emit_fail(cip);
1560 code_p->y_u.plxys.x = emit_xreg(var_offset2);
1561 code_p->y_u.plxys.y = v1;
1562 code_p->y_u.plxys.flags = compile_cmp_flags(
1563 RepAtom(NameOfFunctor(RepPredProp(((
Prop)pred))->FunctorOfPred))
1569 wamreg x1 = emit_xreg(var_offset1);
1572 bool is_y_var2 = (ve2->KindOfVE == PermVar);
1573 var_offset2 = Var_Ref(ve2, is_y_var2);
1576 code_p->opc = emit_op(_call_bfunc_xy);
1577 code_p->y_u.plxys.p = pred;
1578 code_p->y_u.plxys.f = emit_fail(cip);
1579 code_p->y_u.plxys.x = x1;
1580 code_p->y_u.plxys.y = emit_yreg(var_offset2);
1581 code_p->y_u.plxys.flags = compile_cmp_flags(
1582 RepAtom(NameOfFunctor(RepPredProp(((
Prop)pred))->FunctorOfPred))
1589 code_p->opc = emit_op(_call_bfunc_xx);
1590 code_p->y_u.plxxs.p = pred;
1591 code_p->y_u.plxxs.f = emit_fail(cip);
1592 code_p->y_u.plxxs.x1 = x1;
1593 code_p->y_u.plxxs.x2 = emit_xreg(var_offset2);
1594 code_p->y_u.plxxs.flags = compile_cmp_flags(
1595 RepAtom(NameOfFunctor(RepPredProp(((
Prop)pred))->FunctorOfPred))
1604static yamop *a_igl(CELL rnd1, op_numbers opcode,
yamop *code_p,
int pass_no,
1607 code_p->opc = emit_op(opcode);
1608 code_p->y_u.l.l = emit_ilabel(rnd1, cip);
1614static yamop *a_xigl(op_numbers opcode,
yamop *code_p,
int pass_no,
1617 code_p->opc = emit_op(opcode);
1618 code_p->y_u.xll.x = emit_x(cpc->rnd2);
1619 code_p->y_u.xll.l1 = emit_a(cpc->rnd1);
1620 code_p->y_u.xll.l2 = NEXTOP(code_p, xll);
1627static int is_switch_on_list(op_numbers opcode,
struct intermediates *cip) {
1628 struct PSEUDO *cpc = cip->cpc, *ncpc, *n2cpc;
1632 if (cip->CurrentPred->PredFlags & LogUpdatePredFlag)
1635 if (opcode != _switch_on_type)
1638 if ((ncpc = cpc->nextInst) == NULL || (n2cpc = ncpc->nextInst) == NULL)
1641 if (ncpc->op != label_op || n2cpc->op != if_c_op)
1645 if (cpc->arnds[1] != ncpc->rnd1)
1647 if_table = (CELL *)(n2cpc->rnd2);
1649 if (n2cpc->rnd1 != 1 || if_table[0] != TermNil)
1656 if (cpc->arnds[0] & 1 ||
1657 (
yamop *)(cpc->arnds[0]) ==
1658 (
yamop *)(&(cip->CurrentPred->cs.p_code.ExpandCode)))
1662 if (if_table[3] != cpc->arnds[2])
1668static yamop *a_4sw(op_numbers opcode,
yamop *code_p,
int pass_no,
1672 if (is_switch_on_list(opcode, cip)) {
1674 CELL *ars = (CELL *)(cip->cpc->nextInst->nextInst->rnd2);
1675 code_p->opc = emit_op(_switch_list_nl);
1676 seq_ptr = cip->cpc->arnds;
1677 code_p->y_u.ollll.pop = ((
yamop *)(seq_ptr[0]))->opc;
1678 code_p->y_u.ollll.l1 = emit_ilabel(seq_ptr[0], cip);
1679 code_p->y_u.ollll.l2 = emit_ilabel(ars[1], cip);
1680 code_p->y_u.ollll.l3 = emit_ilabel(seq_ptr[2], cip);
1681 code_p->y_u.ollll.l4 = emit_ilabel(seq_ptr[3], cip);
1682 if (cip->CurrentPred->PredFlags & LogUpdatePredFlag) {
1685 Yap_LUIndexSpace_Tree -= icl->ClSize;
1686 Yap_FreeCodeSpace((
char *)icl);
1690 Yap_IndexSpace_Tree -= icl->ClSize;
1691 Yap_FreeCodeSpace((
char *)icl);
1696 cip->cpc = cip->cpc->nextInst->nextInst;
1699 code_p->opc = emit_op(opcode);
1700 seq_ptr = cip->cpc->arnds;
1701 code_p->y_u.llll.l1 = emit_ilabel(seq_ptr[0], cip);
1702 code_p->y_u.llll.l2 = emit_ilabel(seq_ptr[1], cip);
1703 code_p->y_u.llll.l3 = emit_ilabel(seq_ptr[2], cip);
1704 code_p->y_u.llll.l4 = emit_ilabel(seq_ptr[3], cip);
1711static yamop *a_4sw_x(op_numbers opcode,
yamop *code_p,
int pass_no,
1716 code_p->opc = emit_op(opcode);
1717 code_p->y_u.xllll.x = emit_x(cip->cpc->rnd2);
1718 cip->cpc = cip->cpc->nextInst;
1719 seq_ptr = cip->cpc->arnds;
1720 code_p->y_u.xllll.l1 = emit_ilabel(seq_ptr[0], cip);
1721 code_p->y_u.xllll.l2 = emit_ilabel(seq_ptr[1], cip);
1722 code_p->y_u.xllll.l3 = emit_ilabel(seq_ptr[2], cip);
1723 code_p->y_u.xllll.l4 = emit_ilabel(seq_ptr[3], cip);
1726 cip->cpc = cip->cpc->nextInst;
1732static yamop *a_4sw_s(op_numbers opcode,
yamop *code_p,
int pass_no,
1737 code_p->opc = emit_op(opcode);
1738 code_p->y_u.sllll.s = cip->cpc->rnd2;
1739 cip->cpc = cip->cpc->nextInst;
1740 seq_ptr = cip->cpc->arnds;
1741 code_p->y_u.sllll.l1 = emit_ilabel(seq_ptr[0], cip);
1742 code_p->y_u.sllll.l2 = emit_ilabel(seq_ptr[1], cip);
1743 code_p->y_u.sllll.l3 = emit_ilabel(seq_ptr[2], cip);
1744 code_p->y_u.sllll.l4 = emit_ilabel(seq_ptr[3], cip);
1747 cip->cpc = cip->cpc->nextInst;
1755 ic->SiblingIndex = cl_u->lui.ChildIndex;
1756 if (ic->SiblingIndex) {
1757 ic->SiblingIndex->PrevSiblingIndex = ic;
1759 cl_u->lui.ChildIndex = ic;
1760 ic->PrevSiblingIndex = NULL;
1761 ic->ChildIndex = NULL;
1765 cl_u->lui.ChildIndex = ic;
1766 cl_u->lui.ClRefCount++;
1771 ic->SiblingIndex = cl_u->si.ChildIndex;
1772 ic->ChildIndex = NULL;
1773 cl_u->si.ChildIndex = ic;
1776static yamop *a_hx(op_numbers opcode,
union clause_obj *cl_u,
int log_update,
1778 register CELL i, imax;
1779 register CELL *seq_ptr = (CELL *)cip->cpc->rnd2;
1782 imax = cip->cpc->rnd1;
1784 code_p->opc = emit_op(opcode);
1785 code_p->y_u.sssl.s = emit_c(imax);
1786 code_p->y_u.sssl.l = emit_a(cip->cpc->rnd2);
1788 init_log_upd_table(ClauseCodeToLogUpdIndex(cip->cpc->rnd2), cl_u);
1790 init_static_table(ClauseCodeToStaticIndex(cip->cpc->rnd2), cl_u);
1794 for (i = 0; i < imax; i++) {
1796 a_pair(seq_ptr, pass_no, cip);
1797 if (ipc != FAILCODE) {
1802 code_p->y_u.sssl.e = j;
1803 code_p->y_u.sssl.w = 0;
1809static yamop *a_if(op_numbers opcode,
union clause_obj *cl_u,
int log_update,
1811 register CELL i, imax;
1812 register CELL *seq_ptr = (CELL *)cip->cpc->rnd2;
1814 imax = cip->cpc->rnd1;
1816 code_p->opc = emit_op(opcode);
1817 code_p->y_u.sssl.s = code_p->y_u.sssl.e = emit_count(imax);
1818 code_p->y_u.sssl.w = 0;
1819 code_p->y_u.sssl.l = emit_a(cip->cpc->rnd2);
1821 init_log_upd_table(ClauseCodeToLogUpdIndex(cip->cpc->rnd2), cl_u);
1823 init_static_table(ClauseCodeToStaticIndex(cip->cpc->rnd2), cl_u);
1829 for (i = 0; i < imax; i++) {
1830 a_pair(seq_ptr, pass_no, cip);
1834 lab = (CELL)emit_ilabel(lab0, cip);
1840static yamop *a_ifnot(op_numbers opcode,
yamop *code_p,
int pass_no,
1842 CELL *seq_ptr = cip->cpc->arnds;
1844 code_p->opc = emit_op(opcode);
1845 code_p->y_u.clll.c = seq_ptr[0];
1846 code_p->y_u.clll.l1 = emit_ilabel(seq_ptr[1], cip);
1847 code_p->y_u.clll.l2 = emit_ilabel(seq_ptr[2], cip);
1848 code_p->y_u.clll.l3 = emit_ilabel(seq_ptr[3], cip);
1856 cip->clause_has_cut = TRUE;
1857 code_p = check_alloc(clinfo, code_p, pass_no, cip);
1858 if (clinfo->dealloc_found) {
1859 return a_n(_cut_e, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2, code_p,
1861 }
else if (clinfo->alloc_found == 1) {
1862 return a_n(_cut, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2, code_p,
1865 return a_n(_cut_t, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2, code_p,
1872a_try(op_numbers opcode, CELL lab, CELL opr,
int nofalts,
int hascut,
1875a_try(op_numbers opcode, CELL lab, CELL opr,
yamop *code_p,
int pass_no,
1882 if (ap->PredFlags & LogUpdatePredFlag) {
1886 UInt size = (UInt)NEXTOP((
yamop *)NULL, OtaLl);
1887 if ((newcp = (
yamop *)Yap_AllocCodeSpace(size)) == NULL) {
1889 save_machine_regs();
1890 siglongjmp(cip->CompilerBotch, 2);
1892 Yap_inform_profiler_of_clause(newcp, (
char *)(newcp) + size, ap,
1894 Yap_LUIndexSpace_CP += size;
1899 newcp->y_u.OtaLl.n = NULL;
1900 *cip->current_try_lab = newcp;
1901 if (opcode == _try_clause) {
1902 newcp->opc = emit_op(_try_logical);
1903 newcp->y_u.OtaLl.s = emit_count(opr);
1904 }
else if (opcode == _retry) {
1905 if (ap->PredFlags & CountPredFlag)
1906 newcp->opc = emit_op(_count_retry_logical);
1907 else if (ap->PredFlags & ProfiledPredFlag) {
1908 if (!Yap_initProfiler(ap)) {
1911 newcp->opc = emit_op(_profiled_retry_logical);
1913 newcp->opc = emit_op(_retry_logical);
1914 newcp->y_u.OtaLl.s = emit_count(opr);
1917 if (ap->PredFlags & CountPredFlag) {
1918 newcp->opc = emit_op(_count_trust_logical);
1919 }
else if (ap->PredFlags & ProfiledPredFlag) {
1920 if (!Yap_initProfiler(ap)) {
1923 newcp->opc = emit_op(_profiled_trust_logical);
1925 newcp->opc = emit_op(_trust_logical);
1927 newcp->y_u.OtILl.block = (
LogUpdIndex *)(cip->code_addr);
1928 *cip->current_trust_lab = newcp;
1930 newcp->y_u.OtaLl.d = ClauseCodeToLogUpdClause(emit_a(lab));
1931 cip->current_try_lab = &(newcp->y_u.OtaLl.n);
1938 if (opcode == _try_clause) {
1940 code_p->opc = emit_op(_try_clause2);
1941 code_p->y_u.l.l = emit_a(lab);
1945 }
else if (opcode == _retry) {
1947 code_p->opc = emit_op(_retry2);
1948 code_p->y_u.l.l = emit_a(lab);
1954 if (opcode == _try_clause) {
1956 code_p->opc = emit_op(_try_clause3);
1957 code_p->y_u.l.l = emit_a(lab);
1961 }
else if (opcode == _retry) {
1963 code_p->opc = emit_op(_retry3);
1964 code_p->y_u.l.l = emit_a(lab);
1970 if (opcode == _try_clause) {
1972 code_p->opc = emit_op(_try_clause4);
1973 code_p->y_u.l.l = emit_a(lab);
1977 }
else if (opcode == _retry) {
1979 code_p->opc = emit_op(_retry4);
1980 code_p->y_u.l.l = emit_a(lab);
1988 code_p->opc = emit_op(opcode);
1989 code_p->y_u.Otapl.d = emit_a(lab);
1990 code_p->y_u.Otapl.s = emit_count(opr);
1991 code_p->y_u.Otapl.p = ap;
1993 code_p->y_u.Otapl.te = ap->TableOfPred;
1996 INIT_YAMOP_LTT(code_p, nofalts);
1997 if (cip->clause_has_cut)
1998 PUT_YAMOP_CUT(code_p);
1999 if (ap->PredFlags & SequentialPredFlag)
2000 PUT_YAMOP_SEQ(code_p);
2009a_either(op_numbers opcode, CELL opr, CELL lab,
int nofalts,
yamop *code_p,
2012a_either(op_numbers opcode, CELL opr, CELL lab,
yamop *code_p,
int pass_no,
2017 code_p->opc = emit_op(opcode);
2018 code_p->y_u.Osblp.s = emit_count(opr);
2019 code_p->y_u.Osblp.l = emit_a(lab);
2020 code_p->y_u.Osblp.p0 = cip->CurrentPred;
2022 INIT_YAMOP_LTT(code_p, nofalts);
2023 if (cip->clause_has_cut)
2024 PUT_YAMOP_CUT(code_p);
2025 if (cip->CurrentPred->PredFlags & SequentialPredFlag)
2026 PUT_YAMOP_SEQ(code_p);
2027 if (opcode != _or_last) {
2028 code_p->y_u.Osblp.bmap = emit_bmlabel(cip->cpc->arnds[1], cip);
2031 code_p->y_u.Osblp.bmap = emit_bmlabel(cip->cpc->arnds[1], cip);
2038static yamop *a_gl(op_numbers opcode,
yamop *code_p,
int pass_no,
2041 return a_try(opcode, cpc->rnd1, LOCAL_IPredArity, cpc->rnd2 >> 1,
2042 cpc->rnd2 & 1, code_p, pass_no, cip);
2044 return a_try(opcode, cpc->rnd1, LOCAL_IPredArity, code_p, pass_no, cip);
2052static yamop *a_ucons(
int *do_not_optimise_uatomp, compiler_vm_op opcode,
2055 PInstr *np = cip->cpc->nextInst;
2057 CELL my_cons = cip->cpc->rnd1;
2059 if (*do_not_optimise_uatomp) {
2060 *do_not_optimise_uatomp = FALSE;
2061 if (opcode == unify_atom_op)
2062 return a_uc(cip->cpc->rnd1, _unify_atom, _unify_atom_write, code_p,
2065 return a_c(cip->cpc->rnd1, _write_atom, code_p, pass_no);
2067 while (np->op == opcode && np->rnd1 == my_cons) {
2073 if (opcode == unify_atom_op)
2074 return a_uc(cip->cpc->rnd1, _unify_atom, _unify_atom_write, code_p,
2077 return a_c(cip->cpc->rnd1, _write_atom, code_p, pass_no);
2079 if (opcode == unify_atom_op)
2080 return a_unc(cip->cpc->rnd1, _unify_n_atoms, _unify_n_atoms_write,
2081 i + 1, code_p, pass_no);
2083 return a_nc(cip->cpc->rnd1, _write_n_atoms, i + 1, code_p, pass_no);
2087 *do_not_optimise_uatomp = FALSE;
2088 if (opcode == unify_atom_op)
2089 return a_uc(cip->cpc->rnd1, _unify_atom, _unify_atom_write, code_p);
2091 return a_c(cip->cpc->rnd1, _write_atom, code_p);
2096 if (!is_void_var()) {
2098 if (is_temp_var()) {
2099 PInstr *np = cip->cpc->nextInst;
2101 if (np->op == unify_var_op && is_atemp_var(np)) {
2102 return a_vv(_unify_x_var2, _unify_x_var2_write, code_p, pass_no, cip);
2103 }
else if (np->op == unify_last_var_op && is_atemp_var(np)) {
2104 return a_vv(_unify_l_x_var2, _unify_l_x_var2_write, code_p, pass_no,
2109 return a_uv((
Ventry *)cip->cpc->rnd1, _unify_x_var, _unify_x_var_write,
2110 _unify_y_var, _unify_y_var_write, code_p, pass_no);
2114 PInstr *np = cip->cpc->nextInst;
2117 while (np->op == unify_var_op && is_a_void(np->rnd1)) {
2122 if (np->op == unify_last_var_op && is_a_void(np->rnd1)) {
2124 code_p = a_ue(_unify_l_void, _unify_l_void_write, code_p, pass_no);
2126 code_p = a_un(_unify_l_n_voids, _unify_l_n_voids_write, i + 1, code_p,
2130 return a_ue(_unify_void, _unify_void_write, code_p, pass_no);
2132 return a_un(_unify_n_voids, _unify_n_voids_write, i, code_p, pass_no);
2135 return a_ue(_unify_void, _unify_void_write);
2143 return a_v(_write_x_var, _write_y_var, code_p, pass_no, cip->cpc);
2147 PInstr *np = cip->cpc->nextInst;
2149 while (np->op == write_var_op && no_ref(np->rnd1)) {
2155 return a_e(_write_void, code_p, pass_no);
2157 return a_n(_write_n_voids, i + 1, code_p, pass_no);
2160 return a_e(_write_void, pass_no);
2165static yamop *a_glist(
int *do_not_optimise_uatomp,
yamop *code_p,
int pass_no,
2168 PInstr *pnext = cip->cpc->nextInst;
2170 if (cip->cpc->rnd2 != 1 && pnext->op == unify_val_op) {
2175 pnext->rnd2 = cip->cpc->rnd2;
2177 is_y_var = (ve->KindOfVE == PermVar);
2178 var_offset = Var_Ref(ve, is_y_var);
2179 return a_rv(_glist_valx, _glist_valy, var_offset, code_p, pass_no,
2181 }
else if (cip->cpc->rnd2 == 1 && pnext->op == unify_atom_op) {
2182 *do_not_optimise_uatomp = TRUE;
2183 return a_r(cip->cpc->rnd2, _get_list, code_p, pass_no);
2184 }
else if (cip->cpc->rnd2 != 1 && pnext->op == unify_var_op &&
2185 is_a_void(pnext->rnd1)) {
2186 PInstr *ppnext = pnext->nextInst;
2189 (ppnext->op == unify_last_var_op || ppnext->op == unify_last_val_op)) {
2191 int is_y_var = (ve->KindOfVE == PermVar);
2194 ppnext->rnd2 = cip->cpc->rnd2;
2196 var_offset = Var_Ref(ve, is_y_var);
2197 if (cip->cpc->op == unify_last_var_op)
2198 return a_rv(_gl_void_varx, _gl_void_vary, var_offset, code_p, pass_no,
2201 return a_rv(_gl_void_valx, _gl_void_valy, var_offset, code_p, pass_no,
2204 return a_r(cip->cpc->rnd2, _get_list, code_p, pass_no);
2208 return a_r(cip->cpc->rnd2, _get_list, code_p, pass_no);
2211#define NEXTOPC (cip->cpc->nextInst->op)
2215 if (clinfo->alloc_found == 1) {
2216 if (NEXTOPC == execute_op &&
2217 !(RepPredProp((
Prop)(cip->cpc->nextInst->rnd1))->PredFlags &
2219 cip->cpc = cip->cpc->nextInst;
2220 code_p = a_p(_dexecute, clinfo, code_p, pass_no, cip);
2222 code_p = a_p0(_deallocate, code_p, pass_no, cip->CurrentPred);
2223 clinfo->dealloc_found = TRUE;
2230 int i, max = (cpc->rnd1) / (8 *
sizeof(CELL));
2231 for (i = 0; i <= max; i++)
2232 code_p = fill_a(cpc->arnds[i], code_p, pass_no);
2238 int i, max = (cpc->rnd1) / (8 *
sizeof(CELL));
2239 code_p = fill_a(cpc->rnd1, code_p, pass_no);
2240 for (i = 0; i <= max; i++)
2241 code_p = fill_a(cpc->arnds[i], code_p, pass_no);
2247 int max = cpc->rnd1, i;
2248 for (i = 0; i < max; i++)
2249 code_p = fill_a(cpc->arnds[i], code_p, pass_no);
2255 int max = cpc->rnd1, i;
2256 for (i = 0; i < max; i++)
2257 code_p = fill_a(cpc->arnds[i], code_p, pass_no);
2261static void a_fetch_vv(
cmp_op_info *cmp_info,
int pass_no,
2265 PInstr *p = cip->cpc->nextInst;
2268 if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
2269 p->rnd2 = ve->NoOfVE & MaskVarAdrs;
2274 if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
2275 p->rnd2 = ve->NoOfVE & MaskVarAdrs;
2279 PInstr *p = cip->cpc->nextInst;
2281 cmp_info->c_type = TYPE_XX;
2283 cmp_info->x1_arg = emit_x(p->rnd2);
2285 cmp_info->x2_arg = emit_x(p->rnd2);
2289static void a_fetch_vc(
cmp_op_info *cmp_info,
int pass_no,
2293 PInstr *p = cip->cpc->nextInst;
2296 if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
2297 p->rnd2 = ve->NoOfVE & MaskVarAdrs;
2301 PInstr *p = cip->cpc->nextInst;
2303 cmp_info->c_type = TYPE_XC;
2304 cmp_info->c_arg = cip->cpc->rnd1;
2305 cmp_info->x1_arg = emit_x(p->rnd2);
2309static void a_fetch_cv(
cmp_op_info *cmp_info,
int pass_no,
2313 PInstr *p = cip->cpc->nextInst;
2316 if (ve->KindOfVE != PermVar && p->op != nop_op && p->op != put_var_op) {
2317 p->rnd2 = ve->NoOfVE & MaskVarAdrs;
2321 PInstr *p = cip->cpc->nextInst;
2323 cmp_info->c_type = TYPE_CX;
2324 cmp_info->c_arg = cip->cpc->rnd1;
2325 cmp_info->x1_arg = emit_x(p->rnd2);
2331 Int opc = cip->cpc->rnd2;
2333 int is_y_var = FALSE;
2337 is_y_var = (ve->KindOfVE == PermVar);
2338 xpos = ve->NoOfVE & MaskVarAdrs;
2341 if (opc <= _primitive) {
2344 code_p->y_u.yl.y = emit_y(ve);
2347 code_p->opc = opcode(_p_atom_y);
2350 code_p->opc = opcode(_p_atomic_y);
2353 code_p->opc = opcode(_p_compound_y);
2356 code_p->opc = opcode(_p_float_y);
2359 code_p->opc = opcode(_p_integer_y);
2362 code_p->opc = opcode(_p_nonvar_y);
2365 code_p->opc = opcode(_p_number_y);
2368 code_p->opc = opcode(_p_var_y);
2371 code_p->opc = opcode(_p_db_ref_y);
2374 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
2375 "internal assembler error: cut_by should be handled as ->");
2378 code_p->opc = opcode(_p_primitive_y);
2381 code_p->y_u.yl.F = emit_fail(cip);
2387 code_p->y_u.xl.x = emit_x(xpos);
2390 code_p->opc = opcode(_p_atom_x);
2393 code_p->opc = opcode(_p_atomic_x);
2396 code_p->opc = opcode(_p_compound_x);
2399 code_p->opc = opcode(_p_float_x);
2402 code_p->opc = opcode(_p_integer_x);
2405 code_p->opc = opcode(_p_nonvar_x);
2408 code_p->opc = opcode(_p_number_x);
2411 code_p->opc = opcode(_p_var_x);
2414 code_p->opc = opcode(_p_db_ref_x);
2417 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
2418 "internal assembler error: cut_by should be handled as ->");
2421 code_p->opc = opcode(_p_primitive_x);
2424 code_p->y_u.xl.F = emit_fail(cip);
2430 if (opc == _functor && (cip->cpc->nextInst->op == f_var_op ||
2431 cip->cpc->nextInst->op == f_0_op)) {
2433 int is_y_nvar = FALSE;
2436 cip->cpc = cip->cpc->nextInst;
2437 nve = (
Ventry *)(cip->cpc->rnd1);
2439 is_y_nvar = (nve->KindOfVE == PermVar);
2440 nxpos = nve->NoOfVE & MaskVarAdrs;
2445 code_p->opc = emit_op(_p_func2f_yy);
2446 code_p->y_u.yyx.y1 = emit_y(ve);
2447 code_p->y_u.yyx.y2 = emit_y(nve);
2448 code_p->y_u.yyx.x = cmp_info->x1_arg;
2454 code_p->opc = emit_op(_p_func2f_yx);
2455 code_p->y_u.yxx.y = emit_y(ve);
2456 code_p->y_u.yxx.x1 = emit_x(nxpos);
2457 code_p->y_u.yxx.x2 = cmp_info->x1_arg;
2465 code_p->opc = emit_op(_p_func2f_xy);
2466 code_p->y_u.xxy.x1 = emit_x(xpos);
2467 code_p->y_u.xxy.y2 = emit_y(nve);
2468 code_p->y_u.xxy.x = cmp_info->x1_arg;
2474 code_p->opc = emit_op(_p_func2f_xx);
2475 code_p->y_u.xxx.x1 = emit_x(xpos);
2476 code_p->y_u.xxx.x2 = emit_x(nxpos);
2477 code_p->y_u.xxx.x = cmp_info->x1_arg;
2485 switch (cmp_info->c_type) {
2490 code_p->opc = emit_op(_p_plus_y_vv);
2493 code_p->opc = emit_op(_p_minus_y_vv);
2496 code_p->opc = emit_op(_p_times_y_vv);
2499 code_p->opc = emit_op(_p_div_y_vv);
2502 code_p->opc = emit_op(_p_and_y_vv);
2505 code_p->opc = emit_op(_p_or_y_vv);
2508 code_p->opc = emit_op(_p_sll_y_vv);
2511 code_p->opc = emit_op(_p_slr_y_vv);
2514 code_p->opc = emit_op(_p_arg_y_vv);
2517 code_p->opc = emit_op(_p_func2s_y_vv);
2520 code_p->y_u.yxx.y = emit_y(ve);
2521 code_p->y_u.yxx.x1 = cmp_info->x1_arg;
2522 code_p->y_u.yxx.x2 = cmp_info->x2_arg;
2530 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2531 "internal assembler error CX for +/2 (should be XC)");
2532 save_machine_regs();
2533 siglongjmp(cip->CompilerBotch, 1);
2536 code_p->opc = emit_op(_p_minus_y_cv);
2539 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2540 "internal assembler error CX for */2 (should be XC)");
2541 save_machine_regs();
2542 siglongjmp(cip->CompilerBotch, 1);
2545 code_p->opc = emit_op(_p_div_y_cv);
2548 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2549 "internal assembler error CX for /\\/2 (should be XC)");
2550 save_machine_regs();
2551 siglongjmp(cip->CompilerBotch, 1);
2554 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2555 "internal assembler error CX for \\//2 (should be XC)");
2556 save_machine_regs();
2557 siglongjmp(cip->CompilerBotch, 1);
2560 code_p->opc = emit_op(_p_sll_y_cv);
2563 code_p->opc = emit_op(_p_slr_y_cv);
2566 code_p->opc = emit_op(_p_arg_y_cv);
2569 code_p->opc = emit_op(_p_func2s_y_cv);
2572 code_p->y_u.yxn.y = emit_y(ve);
2573 code_p->y_u.yxn.c = cmp_info->c_arg;
2574 code_p->y_u.yxn.xi = cmp_info->x1_arg;
2582 code_p->opc = emit_op(_p_plus_y_vc);
2585 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x2_arg,
2586 "internal assembler error XC for -/2");
2587 save_machine_regs();
2588 siglongjmp(cip->CompilerBotch, 1);
2591 code_p->opc = emit_op(_p_times_y_vc);
2594 code_p->opc = emit_op(_p_div_y_vc);
2597 code_p->opc = emit_op(_p_and_y_vc);
2600 code_p->opc = emit_op(_p_or_y_vc);
2603 if ((Int)cmp_info->c_arg < 0) {
2604 code_p->opc = emit_op(_p_slr_y_vc);
2605 cmp_info->c_arg = -(Int)cmp_info->c_arg;
2607 code_p->opc = emit_op(_p_sll_y_vc);
2611 if ((Int)cmp_info->c_arg < 0) {
2612 code_p->opc = emit_op(_p_sll_y_vc);
2613 cmp_info->c_arg = -(Int)cmp_info->c_arg;
2615 code_p->opc = emit_op(_p_slr_y_vc);
2619 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x2_arg,
2620 "internal assembler error for arg/3");
2621 save_machine_regs();
2622 siglongjmp(cip->CompilerBotch, 1);
2625 code_p->opc = emit_op(_p_func2s_y_vc);
2628 code_p->y_u.yxn.y = emit_y(ve);
2629 code_p->y_u.yxn.c = cmp_info->c_arg;
2630 code_p->y_u.yxn.xi = cmp_info->x1_arg;
2636 switch (cmp_info->c_type) {
2641 code_p->opc = emit_op(_p_plus_vv);
2644 code_p->opc = emit_op(_p_minus_vv);
2647 code_p->opc = emit_op(_p_times_vv);
2650 code_p->opc = emit_op(_p_div_vv);
2653 code_p->opc = emit_op(_p_and_vv);
2656 code_p->opc = emit_op(_p_or_vv);
2659 code_p->opc = emit_op(_p_sll_vv);
2662 code_p->opc = emit_op(_p_slr_vv);
2665 code_p->opc = emit_op(_p_arg_vv);
2668 code_p->opc = emit_op(_p_func2s_vv);
2671 code_p->y_u.xxx.x = emit_x(xpos);
2672 code_p->y_u.xxx.x1 = cmp_info->x1_arg;
2673 code_p->y_u.xxx.x2 = cmp_info->x2_arg;
2681 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2682 "internal assembler error CX for +/2");
2683 save_machine_regs();
2684 siglongjmp(cip->CompilerBotch, 1);
2687 code_p->opc = emit_op(_p_minus_cv);
2690 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2691 "internal assembler error CX for */2");
2692 save_machine_regs();
2693 siglongjmp(cip->CompilerBotch, 1);
2696 code_p->opc = emit_op(_p_div_cv);
2699 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2700 "internal assembler error CX for /\\/2");
2701 save_machine_regs();
2702 siglongjmp(cip->CompilerBotch, 1);
2705 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x1_arg,
2706 "internal assembler error CX for \\//2");
2707 save_machine_regs();
2708 siglongjmp(cip->CompilerBotch, 1);
2711 code_p->opc = emit_op(_p_sll_cv);
2714 code_p->opc = emit_op(_p_slr_cv);
2717 code_p->opc = emit_op(_p_arg_cv);
2720 code_p->opc = emit_op(_p_func2s_cv);
2723 code_p->y_u.xxn.x = emit_x(xpos);
2724 code_p->y_u.xxn.c = cmp_info->c_arg;
2725 code_p->y_u.xxn.xi = cmp_info->x1_arg;
2733 code_p->opc = emit_op(_p_plus_vc);
2736 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x2_arg,
2737 "internal assembler error XC for -/2");
2738 save_machine_regs();
2739 siglongjmp(cip->CompilerBotch, 1);
2742 code_p->opc = emit_op(_p_times_vc);
2745 code_p->opc = emit_op(_p_div_vc);
2748 code_p->opc = emit_op(_p_and_vc);
2751 code_p->opc = emit_op(_p_or_vc);
2754 if ((Int)cmp_info->c_arg < 0) {
2755 code_p->opc = emit_op(_p_slr_vc);
2756 cmp_info->c_arg = -(Int)cmp_info->c_arg;
2758 code_p->opc = emit_op(_p_sll_vc);
2762 if ((Int)cmp_info->c_arg < 0) {
2763 code_p->opc = emit_op(_p_sll_vc);
2764 cmp_info->c_arg = -(Int)cmp_info->c_arg;
2766 code_p->opc = emit_op(_p_slr_vc);
2770 Yap_ThrowError(SYSTEM_ERROR_COMPILER, cmp_info->x2_arg,
2771 "internal assembler error for arg/3");
2772 save_machine_regs();
2773 siglongjmp(cip->CompilerBotch, 1);
2776 code_p->opc = emit_op(_p_func2s_vc);
2779 code_p->y_u.xxn.x = emit_x(xpos);
2780 code_p->y_u.xxn.c = cmp_info->c_arg;
2781 code_p->y_u.xxn.xi = cmp_info->x1_arg;
2790static yamop *a_special_label(
yamop *code_p,
int pass_no,
2792 special_label_op lab_op = cip->cpc->rnd1;
2793 special_label_id lab_id = cip->cpc->rnd2;
2794 UInt lab_val = cip->cpc->rnd3;
2797 case SPECIAL_LABEL_INIT:
2799 case SPECIAL_LABEL_EXCEPTION:
2800 cip->exception_handler = lab_val;
2802 case SPECIAL_LABEL_SUCCESS:
2803 cip->success_handler = lab_val;
2805 case SPECIAL_LABEL_FAILURE:
2806 cip->failure_handler = lab_val;
2809 case SPECIAL_LABEL_SET:
2811 case SPECIAL_LABEL_CLEAR:
2813 case SPECIAL_LABEL_EXCEPTION:
2814 cip->exception_handler = 0;
2816 case SPECIAL_LABEL_SUCCESS:
2817 cip->success_handler = 0;
2819 case SPECIAL_LABEL_FAILURE:
2820 cip->failure_handler = 0;
2828#define TRYCODE(G, P) \
2829 a_try((G), Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1], \
2830 LOCAL_IPredArity, cip->cpc->rnd2 >> 1, cip->cpc->rnd2 & 1, code_p, \
2832#define TABLE_TRYCODE(G) \
2833 a_try((G), (CELL)emit_ilabel(cip->cpc->rnd1, cip), LOCAL_IPredArity, \
2834 cip->cpc->rnd2 >> 1, cip->cpc->rnd2 & 1, code_p, pass_no, cip)
2836#define TRYCODE(G, P) \
2837 a_try((G), Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1], \
2838 LOCAL_IPredArity, code_p, pass_no, cip)
2839#define TABLE_TRYCODE(G) \
2840 a_try((G), (CELL)emit_ilabel(cip->cpc->rnd1, cip), LOCAL_IPredArity, code_p, \
2844static yamop *do_pass(
int pass_no,
yamop **entry_codep,
int assembling,
2845 int *clause_has_blobsp,
int *clause_has_dbtermp,
2848#define MAX_DISJ_BRANCHES 256
2849 yamop *either_inst[MAX_DISJ_BRANCHES];
2850 int either_cont = 0;
2855 int ystop_found = FALSE;
2860 int do_not_optimise_uatom;
2862 code_p = cip->code_addr;
2864 cip->cpc = cip->CodeStart;
2865 clinfo.alloc_found = 0;
2866 clinfo.dealloc_found = FALSE;
2867 clinfo.CurrentPred = cip->CurrentPred;
2868 cip->current_try_lab = NULL;
2869 cip->exception_handler = 0;
2870 cip->success_handler = 0;
2871 cip->failure_handler = 0;
2872 cip->try_instructions = NULL;
2873 cmp_info.c_type = TYPE_XX;
2874 cmp_info.cl_info = &clinfo;
2875 do_not_optimise_uatom = FALSE;
2878 log_update = cip->CurrentPred->PredFlags & LogUpdatePredFlag;
2879 dynamic = cip->CurrentPred->PredFlags & DynamicPredFlag;
2880 tabled = cip->CurrentPred->PredFlags & TabledPredFlag;
2881 if (assembling == ASSEMBLING_CLAUSE) {
2884 cl_u->luc.Id = FunctorDBRef;
2885 cl_u->luc.ClFlags = LogUpdMask;
2886 if (cip->clause_has_cut)
2887 cl_u->luc.ClFlags |= HasCutMask;
2888 cl_u->luc.ClRefCount = 0;
2889 cl_u->luc.ClPred = cip->CurrentPred;
2891 if (cip->CurrentPred->LastCallOfPred != LUCALL_ASSERT) {
2892 if (cip->CurrentPred->TimeStampOfPred >= TIMESTAMP_RESET)
2893 Yap_UpdateTimestamps(cip->CurrentPred);
2894 ++cip->CurrentPred->TimeStampOfPred;
2897 cip->CurrentPred->LastCallOfPred = LUCALL_ASSERT;
2899 cl_u->luc.ClTimeStart = cip->CurrentPred->TimeStampOfPred;
2900 cl_u->luc.ClTimeEnd = TIMESTAMP_EOT;
2901 if (*clause_has_blobsp) {
2902 cl_u->luc.ClFlags |= HasBlobsMask;
2904 if (*clause_has_dbtermp) {
2905 cl_u->luc.ClFlags |= HasDBTMask;
2907 cl_u->luc.ClExt = NULL;
2908 cl_u->luc.ClPrev = cl_u->luc.ClNext = NULL;
2911 INIT_CLREF_COUNT(&(cl_u->luc));
2914 code_p = cl_u->luc.ClCode;
2915 }
else if (dynamic) {
2917 cl_u->ic.ClFlags = DynamicMask;
2918 if (*clause_has_blobsp) {
2919 cl_u->ic.ClFlags |= HasBlobsMask;
2921 if (*clause_has_dbtermp) {
2922 cl_u->ic.ClFlags |= HasDBTMask;
2924 cl_u->ic.ClSize = size;
2925 cl_u->ic.ClRefCount = 0;
2926#if defined(YAPOR) || defined(THREADS)
2927 INIT_LOCK(cl_u->ic.ClLock);
2929#ifdef MULTIPLE_STACKS
2930 INIT_CLREF_COUNT(&(cl_u->ic));
2933 code_p = cl_u->ic.ClCode;
2937 cl_u->sc.ClFlags = StaticMask;
2938 if (cip->clause_has_cut)
2939 cl_u->sc.ClFlags |= HasCutMask;
2940 cl_u->sc.ClNext = NULL;
2941 cl_u->sc.ClSize = size;
2942 cl_u->sc.usc.ClLine = Yap_source_line_no();
2943 if (*clause_has_blobsp) {
2944 cl_u->sc.ClFlags |= HasBlobsMask;
2946 if (*clause_has_dbtermp) {
2947 cl_u->sc.ClFlags |= HasDBTMask;
2950 code_p = cl_u->sc.ClCode;
2952 LOCAL_IPredArity = cip->CurrentPred->ArityOfPE;
2953 *entry_codep = code_p;
2957 code_p = a_try(_table_try_single, (CELL)NEXTOP(code_p, Otapl),
2958 LOCAL_IPredArity, 1, 0, code_p, pass_no, cip);
2960 code_p = a_try(_table_try_single, (CELL)NEXTOP(code_p, Otapl),
2961 LOCAL_IPredArity, code_p, pass_no, cip);
2967 code_p = a_try(_try_me, 0, LOCAL_IPredArity, 1, 0, code_p, pass_no, cip);
2969 code_p = a_try(_try_me, 0, LOCAL_IPredArity, code_p, pass_no, cip);
2976 code_p = a_e(_unlock_lu, code_p, pass_no);
2984 LogUpdMask | IndexedPredFlag | IndexMask | SwitchRootMask;
2985 cl_u->lui.ChildIndex = NULL;
2986 cl_u->lui.SiblingIndex = NULL;
2987 cl_u->lui.PrevSiblingIndex = NULL;
2988 cl_u->lui.ClPred = cip->CurrentPred;
2989 cl_u->lui.ParentIndex = NULL;
2990 cl_u->lui.ClSize = size;
2991 cl_u->lui.ClRefCount = 0;
2994 INIT_CLREF_COUNT(&(cl_u->lui));
2997 code_p = cl_u->lui.ClCode;
2998 *entry_codep = code_p;
3001 cl_u->si.ClSize = size;
3002 cl_u->si.ClFlags = IndexMask;
3003 cl_u->si.ChildIndex = NULL;
3004 cl_u->si.SiblingIndex = NULL;
3005 cl_u->si.ClPred = cip->CurrentPred;
3007 code_p = cl_u->si.ClCode;
3008 *entry_codep = code_p;
3012 switch ((
int)cip->cpc->op) {
3015 code_p = a_try(_sync, cip->cpc->rnd1, cip->cpc->rnd2, 1, Zero, code_p,
3020 case table_new_answer_op:
3021 code_p = a_n(_table_new_answer, (
int)cip->cpc->rnd2, code_p, pass_no);
3023 case table_try_single_op:
3025 a_gl(_table_try_single, code_p, pass_no, cip->cpc, cip PASS_REGS);
3028#ifdef TABLING_INNER_CUTS
3029 case clause_with_cut_op:
3030 code_p = a_e(_clause_with_cut, code_p, pass_no);
3035 code_p = a_rf(_get_s_f, code_p, cip->cpc);
3038 code_p = a_rf(_put_s_f, code_p, cip->cpc);
3041 code_p = a_d(_unify_s_f, code_p);
3044 code_p = a_f(cip->cpc->rnd1, _write_s_f);
3046 case unify_s_var_op:
3047 code_p = a_vsf(_unify_s_xvar);
3049 case write_s_var_op:
3050 code_p = a_vsf(_write_s_xvar);
3052 case unify_s_val_op:
3053 code_p = a_vsf(_unify_s_xval);
3055 case write_s_val_op:
3056 code_p = a_vsf(_write_s_xval);
3059 code_p = a_asf(_unify_s_a);
3062 code_p = a_asf(_write_s_a);
3065 code_p = a_n(_get_s_end, Unsigned(0));
3068 code_p = a_n(_put_s_end, Unsigned(0));
3070 case unify_s_end_op:
3071 code_p = a_n(_write_s_end, Unsigned(0));
3073 case write_s_end_op:
3074 code_p = a_n(_write_s_end, Unsigned(0));
3078 code_p = a_vr(_get_x_var, _get_y_var, code_p, pass_no, cip);
3081 code_p = a_vr(_put_x_var, _put_y_var, code_p, pass_no, cip);
3084 code_p = a_vr(_get_x_val, _get_y_val, code_p, pass_no, cip);
3087 code_p = a_vr(_put_x_val, _put_y_val, code_p, pass_no, cip);
3091 code_p = a_rc(_get_atom, code_p, pass_no, cip);
3094 *clause_has_blobsp = TRUE;
3095 code_p = a_rd(_get_float, code_p, pass_no, cip->cpc);
3098 code_p = a_special_label(code_p, pass_no, cip);
3100 case get_longint_op:
3101 *clause_has_blobsp = TRUE;
3102 code_p = a_ri(_get_longint, code_p, pass_no, cip->cpc);
3105 code_p = a_rb(_get_bigint, clause_has_blobsp, code_p, pass_no, cip);
3108 code_p = a_rstring(_get_string, clause_has_blobsp, code_p, pass_no, cip);
3111 code_p = a_dbt(_get_dbterm, clause_has_dbtermp, code_p, pass_no, cip);
3115 code_p = a_rc(_put_atom, code_p, pass_no, cip);
3118 *clause_has_blobsp = TRUE;
3119 code_p = a_rd(_put_float, code_p, pass_no, cip->cpc);
3121 case put_longint_op:
3122 *clause_has_blobsp = TRUE;
3123 code_p = a_ri(_put_longint, code_p, pass_no, cip->cpc);
3126 code_p = a_rb(_put_bigint, clause_has_blobsp, code_p, pass_no, cip);
3129 code_p = a_rstring(_put_bigint, clause_has_blobsp, code_p, pass_no, cip);
3132 code_p = a_dbt(_put_dbterm, clause_has_dbtermp, code_p, pass_no, cip);
3135 code_p = a_glist(&do_not_optimise_uatom, code_p, pass_no, cip);
3138 code_p = a_r(cip->cpc->rnd2, _put_list, code_p, pass_no);
3141 code_p = a_rf(_get_struct, code_p, pass_no, cip->cpc);
3144 code_p = a_rf(_put_struct, code_p, pass_no, cip->cpc);
3147 code_p = a_vr(_put_unsafe, _put_unsafe, code_p, pass_no, cip);
3150 code_p = a_uvar(code_p, pass_no, cip);
3152 case unify_last_var_op:
3154 a_uv((
Ventry *)cip->cpc->rnd1, _unify_l_x_var, _unify_l_x_var_write,
3155 _unify_l_y_var, _unify_l_y_var_write, code_p, pass_no);
3158 code_p = a_wvar(code_p, pass_no, cip);
3160 case unify_local_op:
3161 code_p = a_uv((
Ventry *)cip->cpc->rnd1, _unify_x_loc, _unify_x_loc_write,
3162 _unify_y_loc, _unify_y_loc_write, code_p, pass_no);
3165 code_p = a_uv((
Ventry *)cip->cpc->rnd1, _unify_x_val, _unify_x_val_write,
3166 _unify_y_val, _unify_y_val_write, code_p, pass_no);
3168 case unify_last_local_op:
3170 a_uv((
Ventry *)cip->cpc->rnd1, _unify_l_x_loc, _unify_l_x_loc_write,
3171 _unify_l_y_loc, _unify_l_y_loc_write, code_p, pass_no);
3173 case unify_last_val_op:
3175 a_uv((
Ventry *)cip->cpc->rnd1, _unify_l_x_val, _unify_l_x_val_write,
3176 _unify_l_y_val, _unify_l_y_val_write, code_p, pass_no);
3178 case write_local_op:
3179 code_p = a_v(_write_x_loc, _write_y_loc, code_p, pass_no, cip->cpc);
3182 code_p = a_v(_write_x_val, _write_y_val, code_p, pass_no, cip->cpc);
3187 a_ucons(&do_not_optimise_uatom, unify_atom_op, code_p, pass_no, cip);
3189 case unify_float_op:
3190 *clause_has_blobsp = TRUE;
3192 a_ud(_unify_float, _unify_float_write, code_p, pass_no, cip->cpc);
3194 case unify_longint_op:
3195 *clause_has_blobsp = TRUE;
3197 a_ui(_unify_longint, _unify_longint_write, code_p, pass_no, cip->cpc);
3199 case unify_bigint_op:
3200 code_p = a_ublob(cip->cpc->rnd1, _unify_bigint, _unify_atom_write,
3201 clause_has_blobsp, code_p, pass_no, cip);
3203 case unify_string_op:
3204 code_p = a_ustring(cip->cpc->rnd1, _unify_string, _unify_atom_write,
3205 clause_has_blobsp, code_p, pass_no, cip);
3207 case unify_dbterm_op:
3208 code_p = a_udbt(cip->cpc->rnd1, _unify_dbterm, _unify_atom_write,
3209 clause_has_dbtermp, code_p, pass_no, cip);
3211 case unify_last_num_op:
3212 case unify_last_atom_op:
3213 code_p = a_uc(cip->cpc->rnd1, _unify_l_atom, _unify_l_atom_write, code_p,
3216 case unify_last_float_op:
3217 *clause_has_blobsp = TRUE;
3219 a_ud(_unify_l_float, _unify_l_float_write, code_p, pass_no, cip->cpc);
3221 case unify_last_longint_op:
3222 *clause_has_blobsp = TRUE;
3223 code_p = a_ui(_unify_l_longint, _unify_l_longint_write, code_p, pass_no,
3226 case unify_last_bigint_op:
3227 code_p = a_ublob(cip->cpc->rnd1, _unify_l_bigint, _unify_l_atom_write,
3228 clause_has_blobsp, code_p, pass_no, cip);
3230 case unify_last_string_op:
3231 code_p = a_ustring(cip->cpc->rnd1, _unify_l_bigint, _unify_l_atom_write,
3232 clause_has_blobsp, code_p, pass_no, cip);
3234 case unify_last_dbterm_op:
3235 code_p = a_udbt(cip->cpc->rnd1, _unify_l_dbterm, _unify_l_atom_write,
3236 clause_has_dbtermp, code_p, pass_no, cip);
3241 a_ucons(&do_not_optimise_uatom, write_atom_op, code_p, pass_no, cip);
3243 case write_float_op:
3244 *clause_has_blobsp = TRUE;
3245 code_p = a_wd(_write_float, code_p, pass_no, cip->cpc);
3247 case write_longint_op:
3248 *clause_has_blobsp = TRUE;
3249 code_p = a_wi(_write_longint, code_p, pass_no, cip->cpc);
3251 case write_bigint_op:
3252 code_p = a_wblob(cip->cpc->rnd1, _write_bigint, clause_has_blobsp, code_p,
3255 case write_string_op:
3256 code_p = a_wblob(cip->cpc->rnd1, _write_bigint, clause_has_blobsp, code_p,
3259 case write_dbterm_op:
3260 code_p = a_wdbt(cip->cpc->rnd1, _write_dbterm, clause_has_dbtermp, code_p,
3264 code_p = a_ue(_unify_list, _unify_list_write, code_p, pass_no);
3266 case unify_last_list_op:
3267 code_p = a_ue(_unify_l_list, _unify_l_list_write, code_p, pass_no);
3270 code_p = a_e(_write_list, code_p, pass_no);
3272 case write_last_list_op:
3273 code_p = a_e(_write_l_list, code_p, pass_no);
3275 case unify_struct_op:
3276 code_p = a_uf(cip->cpc->rnd1, _unify_struct, _unify_struct_write, code_p,
3279 case unify_last_struct_op:
3280 code_p = a_uf(cip->cpc->rnd1, _unify_l_struc, _unify_l_struc_write,
3283 case write_struct_op:
3284 code_p = a_f(cip->cpc->rnd1, _write_struct, code_p, pass_no);
3286 case write_last_struct_op:
3287 code_p = a_f(cip->cpc->rnd1, _write_l_struc, code_p, pass_no);
3291 code_p = a_v(_save_b_x, _save_b_y, code_p, pass_no, cip->cpc);
3294 cip->clause_has_cut = TRUE;
3296 a_vp(_commit_b_x, _commit_b_y, code_p, pass_no, cip->cpc, &clinfo);
3299 cip->clause_has_cut = TRUE;
3301 a_vp(_soft_cut_b_x, _soft_cut_b_y, code_p, pass_no, cip->cpc, &clinfo);
3304 code_p = a_uv((
Ventry *)cip->cpc->rnd1, _save_pair_x, _save_pair_x_write,
3305 _save_pair_y, _save_pair_y_write, code_p, pass_no);
3308 code_p = a_uv((
Ventry *)cip->cpc->rnd1, _save_appl_x, _save_appl_x_write,
3309 _save_appl_y, _save_appl_y_write, code_p, pass_no);
3312 code_p = a_e(_op_fail, code_p, pass_no);
3313 code_p = a_pl(_procceed, cip->CurrentPred, code_p, pass_no);
3316 code_p = a_cut(&clinfo, code_p, pass_no, cip);
3319 cip->clause_has_cut = TRUE;
3320 if (cip->CurrentPred->PredFlags & LogUpdatePredFlag &&
3321 (*clause_has_blobsp || *clause_has_dbtermp) && !clinfo.alloc_found)
3322 code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip);
3323 code_p = a_cut(&clinfo, code_p, pass_no, cip);
3326 clinfo.alloc_found = 2;
3329 code_p = a_deallocate(&clinfo, code_p, pass_no, cip);
3334 code_p = TABLE_TRYCODE(_table_try_me);
3337 code_p = TRYCODE(_try_me, _try_me0);
3342 code_p = TABLE_TRYCODE(_table_retry_me);
3345 code_p = TRYCODE(_retry_me, _retry_me0);
3350 code_p = TABLE_TRYCODE(_table_trust_me);
3353 code_p = TRYCODE(_trust_me, _trust_me0);
3356 code_p = a_lucl(_enter_lu_pred, code_p, pass_no, cip, &clinfo);
3360 add_clref(cip->cpc->rnd1, pass_no);
3364 code_p = a_gl(_table_try, code_p, pass_no, cip->cpc, cip PASS_REGS);
3367 code_p = a_gl(_try_clause, code_p, pass_no, cip->cpc, cip PASS_REGS);
3371 add_clref(cip->cpc->rnd1, pass_no);
3375 code_p = a_gl(_table_retry, code_p, pass_no, cip->cpc, cip PASS_REGS);
3378 code_p = a_gl(_retry, code_p, pass_no, cip->cpc, cip PASS_REGS);
3382 add_clref(cip->cpc->rnd1, pass_no);
3386 code_p = a_gl(_table_trust, code_p, pass_no, cip->cpc, cip PASS_REGS);
3389 code_p = a_gl(_trust, code_p, pass_no, cip->cpc, cip PASS_REGS);
3392 code_p = a_il(cip->cpc->rnd1, _try_in, code_p, pass_no, cip);
3396 if (cip->cpc->nextInst == NULL || cip->cpc->nextInst->op != label_op ||
3397 cip->cpc->rnd1 != cip->cpc->nextInst->rnd1) {
3398 code_p = a_l(cip->cpc->rnd1, _jump, code_p, pass_no, cip);
3402 code_p = a_il(cip->cpc->rnd1, _jump, code_p, pass_no, cip);
3404 case restore_tmps_op:
3405 code_p = a_l(cip->cpc->rnd1, _move_back, code_p, pass_no, cip);
3407 case restore_tmps_and_skip_op:
3408 code_p = a_l(cip->cpc->rnd1, _skip, code_p, pass_no, cip);
3411 if (cip->CurrentPred->PredFlags & LogUpdatePredFlag &&
3412 (*clause_has_blobsp || *clause_has_dbtermp) && !clinfo.alloc_found)
3413 code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip);
3414 code_p = a_pl(_procceed, cip->CurrentPred, code_p, pass_no);
3417 code_p = a_p(_call, &clinfo, code_p, pass_no, cip);
3420 code_p = a_p(_execute, &clinfo, code_p, pass_no, cip);
3423 code_p = a_p(_call, &clinfo, code_p, pass_no, cip);
3426 if (!ystop_found && cip->cpc->nextInst != NULL &&
3427 (cip->cpc->nextInst->op == mark_initialized_pvars_op ||
3428 cip->cpc->nextInst->op == mark_live_regs_op ||
3429 cip->cpc->nextInst->op == blob_op ||
3430 cip->cpc->nextInst->op == string_op)) {
3432 code_p = a_il((CELL)*entry_codep, _Ystop, code_p, pass_no, cip);
3435#if !USE_SYSTEM_MALLOC
3436 if (CellPtr(cip->label_offset + cip->cpc->rnd1) > ASP - 256) {
3437 LOCAL_ThrowError_Size =
3438 256 + ((
char *)(cip->label_offset + cip->cpc->rnd1) - (
char *)HR);
3439 save_machine_regs();
3440 siglongjmp(cip->CompilerBotch, 3);
3442 if ((
char *)(cip->label_offset + cip->cpc->rnd1) >= cip->freep)
3443 cip->freep = (
char *)(cip->label_offset + (cip->cpc->rnd1 + 1));
3446 cip->label_offset[cip->cpc->rnd1] = (CELL)code_p;
3449 clinfo.dealloc_found = FALSE;
3451 case ensure_space_op:
3452 code_p = a_ensure_space(_ensure_space, code_p, pass_no, cip, &clinfo);
3455 if (cip->cpc->rnd1 == 1)
3456 code_p = a_e(_pop, code_p, pass_no);
3459 a_n(_pop_n, 2 * CELLSIZE * (cip->cpc->rnd1 - 1), code_p, pass_no);
3463 code_p = check_alloc(&clinfo, code_p, pass_no, cip);
3466 either_inst[either_cont++] = code_p;
3467 if (either_cont == MAX_DISJ_BRANCHES) {
3468 Yap_ThrowError(SYSTEM_ERROR_FATAL, TermNil,
3469 "Too Many Branches in disjunction: please increase "
3470 "MAX_DISJ_BRANCHES in amasm.c\n");
3474 a_either(_either, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2,
3475 Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1],
3476 0, code_p, pass_no, cip);
3479 a_either(_either, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2,
3480 Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1],
3481 code_p, pass_no, cip);
3487 either_inst[either_cont++] = code_p;
3489 a_either(_or_else, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2,
3490 Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1],
3491 0, code_p, pass_no, cip);
3494 a_either(_or_else, -Signed(RealEnvSize) - CELLSIZE * cip->cpc->rnd2,
3495 Unsigned(cip->code_addr) + cip->label_offset[cip->cpc->rnd1],
3496 code_p, pass_no, cip);
3498 clinfo.dealloc_found = FALSE;
3503 either_inst[either_cont++] = code_p;
3504 code_p = a_either(_or_last, 0, 0, 0, code_p, pass_no, cip);
3509 PUT_YAMOP_LTT(either_inst[either_cont],
cont++);
3510 }
while (either_inst[either_cont]->opc != opcode(_either));
3513 code_p = a_pl(_or_last, cip->CurrentPred, code_p, pass_no);
3515 clinfo.dealloc_found = FALSE;
3518 code_p = a_4sw_x(_switch_on_arg_type, code_p, pass_no, cip);
3520 case cache_sub_arg_op:
3521 code_p = a_4sw_s(_switch_on_sub_arg_type, code_p, pass_no, cip);
3524 code_p = a_igl(cip->cpc->rnd1, _jump_if_var, code_p, pass_no, cip);
3527 code_p = a_xigl(_jump_if_nonvar, code_p, pass_no, cip->cpc);
3529 case user_switch_op:
3530 code_p = a_lp(_user_switch, code_p, pass_no, cip);
3532 case switch_on_type_op:
3533 code_p = a_4sw(_switch_on_type, code_p, pass_no, cip);
3536 code_p = a_hx(_switch_on_cons, cl_u, log_update, code_p, pass_no, cip);
3539 code_p = a_hx(_switch_on_func, cl_u, log_update, code_p, pass_no, cip);
3542 if (cip->cpc->rnd1 == 1) {
3543 code_p = a_if(_go_on_cons, cl_u, log_update, code_p, pass_no, cip);
3545 code_p = a_if(_if_cons, cl_u, log_update, code_p, pass_no, cip);
3549 if (cip->cpc->rnd1 == 1) {
3550 code_p = a_if(_go_on_func, cl_u, log_update, code_p, pass_no, cip);
3552 code_p = a_if(_if_func, cl_u, log_update, code_p, pass_no, cip);
3556 code_p = a_ifnot(_if_not_then, code_p, pass_no, cip);
3558 case index_dbref_op:
3559 code_p = a_e(_index_dbref, code_p, pass_no);
3562 code_p = a_e(_index_blob, code_p, pass_no);
3565 code_p = a_e(_index_long, code_p, pass_no);
3567 case mark_initialized_pvars_op:
3569 code_p = a_il((CELL)*entry_codep, _Ystop, code_p, pass_no, cip);
3572 code_p = a_bmap(code_p, pass_no, cip->cpc);
3574 case mark_live_regs_op:
3576 code_p = a_il((CELL)*entry_codep, _Ystop, code_p, pass_no, cip);
3577 printf(
"-> %p\n", code_p->y_u.l.l);
3580 code_p = a_bregs(code_p, pass_no, cip->cpc);
3582 case fetch_args_vv_op:
3583 a_fetch_vv(&cmp_info, pass_no, cip);
3585 case fetch_args_vc_op:
3586 case fetch_args_vi_op:
3587 a_fetch_vc(&cmp_info, pass_no, cip);
3589 case fetch_args_cv_op:
3590 case fetch_args_iv_op:
3591 a_fetch_cv(&cmp_info, pass_no, cip);
3594 code_p = a_f2(&cmp_info, code_p, pass_no, cip);
3597 code_p = a_f2(&cmp_info, code_p, pass_no, cip);
3600 code_p = a_f2(&cmp_info, code_p, pass_no, cip);
3602 case enter_profiling_op: {
3604 if ((pe->PredFlags & (CPredFlag | UserCPredFlag | AsmPredFlag)) ||
3605 !pe->ModuleOfPred) {
3606 code_p = a_pl(_enter_profiling, pe, code_p, pass_no);
3607 Yap_initProfiler(pe);
3610 case retry_profiled_op:
3611 if (!Yap_initProfiler(cip->CurrentPred)) {
3615 a_pl(_retry_profiled, (
PredEntry *)(cip->cpc->rnd1), code_p, pass_no);
3617 case count_call_op: {
3619 if ((pe->PredFlags & (CPredFlag | UserCPredFlag | AsmPredFlag)) ||
3620 !pe->ModuleOfPred) {
3622 a_pl(_count_call, (
PredEntry *)(cip->cpc->rnd1), code_p, pass_no);
3625 case count_retry_op:
3627 a_pl(_count_retry, (
PredEntry *)(cip->cpc->rnd1), code_p, pass_no);
3631 a_bfunc(cip->cpc->rnd1, cip->cpc->rnd3, (
PredEntry *)(cip->cpc->rnd5),
3632 &clinfo, code_p, pass_no, cip);
3634 case align_float_op:
3636#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
3637 if (!((CELL)code_p & 0x4))
3643 code_p = copy_blob(code_p, pass_no, cip->cpc);
3647 code_p = copy_string(code_p, pass_no, cip->cpc);
3651 code_p = a_empty_call(&clinfo, code_p, pass_no, cip);
3657 code_p = check_alloc(&clinfo, code_p, pass_no, cip);
3668 code_p = a_eam(_run_eam, cip->cpc->rnd2,
3669 (
long)((
PredEntry *)cip->cpc->rnd2)->beamTable->last,
3674 Yap_ThrowError(SYSTEM_ERROR_COMPILER, TermNil,
3675 "instruction %d found while assembling", (
int)cip->cpc->op);
3676 save_machine_regs();
3677 siglongjmp(cip->CompilerBotch, 1);
3679 cip->cpc = cip->cpc->nextInst;
3682 code_p = a_il((CELL)*entry_codep, _Ystop, code_p, pass_no, cip);
3686static DBTerm *fetch_clause_space(Term *tp, UInt size,
3688 UInt *osizep USES_REGS) {
3694 HR = (CELL *)cip->freep;
3695 while ((x = Yap_StoreTermInDBPlusExtraSpace(*tp, size, osizep)) == NULL) {
3698 switch (LOCAL_Error_TYPE) {
3699 case RESOURCE_ERROR_STACK:
3700 LOCAL_Error_Size = 256 + ((
char *)cip->freep - (
char *)HR);
3701 save_machine_regs();
3702 siglongjmp(cip->CompilerBotch, 3);
3703 case RESOURCE_ERROR_TRAIL:
3706 if (!Yap_growtrail(K64, FALSE)) {
3709 LOCAL_Error_TYPE = YAP_NO_ERROR;
3712 case RESOURCE_ERROR_AUXILIARY_STACK:
3714 if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, (
void *)cip, TRUE)) {
3717 LOCAL_Error_TYPE = YAP_NO_ERROR;
3720 case RESOURCE_ERROR_HEAP:
3723 if (!Yap_growheap(TRUE, size, cip)) {
3726 LOCAL_Error_TYPE = YAP_NO_ERROR;
3733 HR = (CELL *)cip->freep;
3744 new->dbterms = NULL;
3745 new->clause_code = code_p;
3747 LOCK(DBTermsListLock);
3748 new->next_dbl = DBTermsList;
3750 UNLOCK(DBTermsListLock);
3754#define DEFAULT_NLABELS 4096
3767 int clause_has_blobs = FALSE;
3768 int clause_has_dbterm = FALSE;
3770#if USE_SYSTEM_MALLOC
3771 if (!cip->label_offset) {
3772 if (!LOCAL_LabelFirstArray && max_label <= DEFAULT_NLABELS) {
3773 LOCAL_LabelFirstArray =
3774 (Int *)Yap_AllocCodeSpace(
sizeof(Int) * DEFAULT_NLABELS);
3775 LOCAL_LabelFirstArraySz = DEFAULT_NLABELS;
3776 if (!LOCAL_LabelFirstArray) {
3777 save_machine_regs();
3778 siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
3781 if (LOCAL_LabelFirstArray && max_label <= LOCAL_LabelFirstArraySz) {
3782 cip->label_offset = LOCAL_LabelFirstArray;
3784 cip->label_offset = (Int *)Yap_AllocCodeSpace(
sizeof(Int) * max_label);
3785 if (!cip->label_offset) {
3786 save_machine_regs();
3787 siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
3792 cip->label_offset = (Int *)cip->freep;
3794 cip->clause_has_cut = FALSE;
3795 cip->code_addr = NULL;
3796 code_p = do_pass(0, &entry_code, mode, &clause_has_blobs, &clause_has_dbterm,
3797 cip, size PASS_REGS);
3798 if (clause_has_dbterm) {
3799 cip->dbterml = init_dbterms_list(code_p, ap);
3801 if (ap->PredFlags & DynamicPredFlag) {
3802 size = (CELL)NEXTOP(
3807 if ((CELL)code_p > size)
3808 size = (CELL)code_p;
3809 if (mode == ASSEMBLING_CLAUSE && ap->PredFlags & LogUpdatePredFlag &&
3815 if (!(x = fetch_clause_space(&t, size, cip, &osize PASS_REGS))) {
3819 cl->lusl.ClSource = x;
3820 cl->ClFlags |= SrcMask;
3821 x->ag.line_number = Yap_source_line_no();
3823 cip->code_addr = (
yamop *)cl;
3824 }
else if (mode == ASSEMBLING_CLAUSE &&
3825 (ap->PredFlags & MultiFileFlag ||
3826 (ap->cs.p_code.NOfClauses == 0 &&
3827 trueGlobalPrologFlag(SOURCE_FLAG)) ||
3828 (ap->cs.p_code.NOfClauses > 0 &&
3829 (ap->PredFlags & SourcePredFlag))) &&
3835 if (!(x = fetch_clause_space(&t, size, cip, &osize PASS_REGS))) {
3839 cip->code_addr = (
yamop *)cl;
3840 code_p = do_pass(1, &entry_code, mode, &clause_has_blobs,
3841 &clause_has_dbterm, cip, size PASS_REGS);
3843 cl->usc.ClSource = x;
3844 cl->ClFlags |= SrcMask;
3845 x->ag.line_number = Yap_source_line_no();
3847 LOCAL_ProfEnd = code_p;
3848 Yap_inform_profiler_of_clause(cl, LOCAL_ProfEnd, ap, GPROF_CLAUSE);
3851 while ((cip->code_addr = (
yamop *)Yap_AllocCodeSpace(size)) == NULL) {
3853 if (!Yap_growheap(TRUE, size, cip)) {
3854 LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
3855 LOCAL_Error_Size = size;
3859 Yap_inform_profiler_of_clause(
3860 cip->code_addr, (
char *)(cip->code_addr) + size, ap,
3861 (mode == ASSEMBLING_INDEX ? GPROF_INDEX : GPROF_CLAUSE));
3862 if (mode == ASSEMBLING_CLAUSE) {
3863 if (ap->PredFlags & LogUpdatePredFlag) {
3865 Yap_LUClauseSpace += size;
3868 cl->usc.ClSource = NULL;
3871 Yap_ClauseSpace += size;
3874 if (ap->PredFlags & LogUpdatePredFlag) {
3875 Yap_LUIndexSpace_Tree += size;
3877 Yap_IndexSpace_Tree += size;
3880 do_pass(1, &entry_code, mode, &clause_has_blobs, &clause_has_dbterm, cip,
3885void Yap_InitComma(
void) {
3886 yamop *code_p = COMMA_CODE;
3887 code_p->opc = opcode(_call);
3888 code_p->y_u.Osbpp.s = emit_count(-Signed(RealEnvSize) -
sizeof(CELL) * 3);
3889 code_p->y_u.Osbpp.p = code_p->y_u.Osbpp.p0 =
3890 RepPredProp(PredPropByFunc(FunctorComma, 0));
3891 code_p->y_u.Osbpp.bmap = NULL;
3893 code_p->opc = opcode(_p_execute_tail);
3894 code_p->y_u.Osbmp.s = emit_count(-Signed(RealEnvSize) - 3 *
sizeof(CELL));
3895 code_p->y_u.Osbmp.bmap = NULL;
3896 code_p->y_u.Osbmp.mod = MkAtomTerm(AtomUser);
3897 code_p->y_u.Osbmp.p0 = RepPredProp(PredPropByFunc(FunctorComma, 0));
3899 code_p->opc = emit_op(_deallocate);
3900 code_p->y_u.p.p = PredMetaCall;
3902 code_p->opc = emit_op(_procceed);
3903 code_p->y_u.p.p = PredMetaCall;
3908 arity_t arity = pe->ArityOfPE, i;
3909 yamop *code_p = NULL;
3912 for (i = 0; i < arity; i++)
3915pe->MetaEntryOfPred = code_p =
3916Yap_AllocCodeSpace((
size_t)code_p);
3917 code_p->opc = opcode(_call);
3918 code_p->y_u.Osbpp.s = emit_count(-Signed(RealEnvSize) -
sizeof(CELL) * pe->ArityOfPE);
3919 code_p->y_u.Osbpp.p =
3920 code_p->y_u.Osbpp.p0 = PredMetaCall;
3921 code_p->y_u.Osbpp.bmap = NULL;
3923 for (i = 0; i < arity; i++) {
3924 code_p->opc = opcode(_put_y_var);
3925 code_p->y_u.yx.y = -i - Signed(RealEnvSize) /
sizeof(CELL);
3926 code_p->y_u.yx.x = emit_xreg(i + 1);
3929 code_p->opc = opcode(_dexecute);
3930 code_p->y_u.Osbpp.p0 = PredMetaCall;
3931 code_p->y_u.Osbpp.s = -Signed(RealEnvSize);
3932 code_p->y_u.Osbpp.p = pe;
3934 return pe->MetaEntryOfPred;