2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: computils.c *
|
|
|
|
* comments: some useful routines for YAP's compiler *
|
|
|
|
* *
|
2004-11-19 17:14:15 +00:00
|
|
|
* Last rev: $Date: 2004-11-19 17:14:13 $ *
|
2004-04-16 20:27:31 +01:00
|
|
|
* $Log: not supported by cvs2svn $
|
2004-11-19 17:14:15 +00:00
|
|
|
* Revision 1.24 2004/04/16 19:27:31 vsc
|
|
|
|
* more bug fixes
|
|
|
|
*
|
2004-04-16 20:27:31 +01:00
|
|
|
* Revision 1.23 2004/03/10 14:59:55 vsc
|
|
|
|
* optimise -> for type tests
|
|
|
|
* *
|
2004-03-10 14:59:55 +00:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file includes a set of utilities, useful to the several compilation
|
|
|
|
* modules
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "Yatom.h"
|
|
|
|
#include "Heap.h"
|
|
|
|
#include "compile.h"
|
|
|
|
#include "yapio.h"
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2004-01-23 02:23:51 +00:00
|
|
|
STATIC_PROTO (void ShowOp, (char *, struct PSEUDO *));
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The compiler creates an instruction chain which will be assembled after
|
|
|
|
* afterwards
|
|
|
|
*/
|
|
|
|
|
2002-11-12 19:53:52 +00:00
|
|
|
#ifdef DEBUG
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
char Yap_Option[20];
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
YP_FILE *Yap_logfile;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static char *
|
2004-01-23 02:23:51 +00:00
|
|
|
AllocCMem (int size, struct intermediates *cip)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
char *p;
|
2004-01-23 02:23:51 +00:00
|
|
|
p = cip->freep;
|
2001-04-09 20:54:03 +01:00
|
|
|
#if SIZEOF_INT_P==8
|
|
|
|
size = (size + 7) & 0xfffffffffffffff8L;
|
|
|
|
#else
|
|
|
|
size = (size + 3) & 0xfffffffcL;
|
|
|
|
#endif
|
2004-01-23 02:23:51 +00:00
|
|
|
cip->freep += size;
|
|
|
|
if (ASP <= CellPtr (cip->freep) + 256) {
|
|
|
|
Yap_Error_Size = 256+((char *)cip->freep - (char *)H);
|
2001-04-09 20:54:03 +01:00
|
|
|
save_machine_regs();
|
2004-01-23 02:23:51 +00:00
|
|
|
longjmp(cip->CompilerBotch,3);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
char *
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_AllocCMem (int size, struct intermediates *cip)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2004-01-23 02:23:51 +00:00
|
|
|
return(AllocCMem(size, cip));
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
int
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_is_a_test_pred (Term arg, Term mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-03-10 14:59:55 +00:00
|
|
|
if (IsVarTerm (arg)) {
|
2003-12-27 00:38:53 +00:00
|
|
|
return FALSE;
|
2004-03-10 14:59:55 +00:00
|
|
|
} else if (IsAtomTerm (arg)) {
|
2001-10-03 14:39:16 +01:00
|
|
|
Atom At = AtomOfTerm (arg);
|
2001-11-15 00:01:43 +00:00
|
|
|
PredEntry *pe = RepPredProp(PredPropByAtom(At, mod));
|
|
|
|
if (EndOfPAEntr(pe))
|
2003-12-27 00:38:53 +00:00
|
|
|
return FALSE;
|
|
|
|
return pe->PredFlags & TestPredFlag;
|
2003-05-19 14:04:09 +01:00
|
|
|
} else if (IsApplTerm (arg)) {
|
|
|
|
Functor f = FunctorOfTerm (arg);
|
2004-03-10 14:59:55 +00:00
|
|
|
PredEntry *pe = RepPredProp(PredPropByFunc(f, mod));
|
|
|
|
if (EndOfPAEntr(pe))
|
|
|
|
return FALSE;
|
|
|
|
if (pe->PredFlags & AsmPredFlag) {
|
|
|
|
int op = pe->PredFlags & 0x7f;
|
|
|
|
if (op >= _atom && op <= _primitive) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return pe->PredFlags & (TestPredFlag|BinaryTestPredFlag);
|
2003-05-19 14:04:09 +01:00
|
|
|
} else {
|
2003-12-27 00:38:53 +00:00
|
|
|
return FALSE;
|
2003-05-19 14:04:09 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_emit (compiler_vm_op o, Int r1, CELL r2, struct intermediates *cip)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
PInstr *p;
|
2004-01-23 02:23:51 +00:00
|
|
|
p = (PInstr *) AllocCMem (sizeof (*p), cip);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->op = o;
|
|
|
|
p->rnd1 = r1;
|
|
|
|
p->rnd2 = r2;
|
2003-05-19 14:04:09 +01:00
|
|
|
p->nextInst = NULL;
|
2004-01-23 02:23:51 +00:00
|
|
|
if (cip->cpc == NIL) {
|
|
|
|
cip->cpc = cip->CodeStart = p;
|
2003-05-19 14:04:09 +01:00
|
|
|
} else {
|
2004-01-23 02:23:51 +00:00
|
|
|
cip->cpc->nextInst = p;
|
|
|
|
cip->cpc = p;
|
2003-05-19 14:04:09 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_emit_3ops (compiler_vm_op o, CELL r1, CELL r2, CELL r3, struct intermediates *cip)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
PInstr *p;
|
2004-01-23 02:23:51 +00:00
|
|
|
p = (PInstr *) AllocCMem (sizeof (*p)+sizeof(CELL), cip);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->op = o;
|
|
|
|
p->rnd1 = r1;
|
|
|
|
p->rnd2 = r2;
|
|
|
|
p->rnd3 = r3;
|
|
|
|
p->nextInst = NIL;
|
2004-01-23 02:23:51 +00:00
|
|
|
if (cip->cpc == NIL)
|
|
|
|
cip->cpc = cip->CodeStart = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
|
|
|
{
|
2004-01-23 02:23:51 +00:00
|
|
|
cip->cpc->nextInst = p;
|
|
|
|
cip->cpc = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-29 14:47:17 +00:00
|
|
|
void
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_emit_4ops (compiler_vm_op o, CELL r1, CELL r2, CELL r3, CELL r4, struct intermediates *cip)
|
2003-01-29 14:47:17 +00:00
|
|
|
{
|
|
|
|
PInstr *p;
|
2004-01-23 02:23:51 +00:00
|
|
|
p = (PInstr *) AllocCMem (sizeof (*p)+2*sizeof(CELL), cip);
|
2003-01-29 14:47:17 +00:00
|
|
|
p->op = o;
|
|
|
|
p->rnd1 = r1;
|
|
|
|
p->rnd2 = r2;
|
|
|
|
p->rnd3 = r3;
|
|
|
|
p->rnd4 = r4;
|
|
|
|
p->nextInst = NIL;
|
2004-01-23 02:23:51 +00:00
|
|
|
if (cip->cpc == NIL)
|
|
|
|
cip->cpc = cip->CodeStart = p;
|
2003-01-29 14:47:17 +00:00
|
|
|
else
|
|
|
|
{
|
2004-01-23 02:23:51 +00:00
|
|
|
cip->cpc->nextInst = p;
|
|
|
|
cip->cpc = p;
|
2003-01-29 14:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_emit_extra_size (compiler_vm_op o, CELL r1, int size, struct intermediates *cip)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
PInstr *p;
|
2004-01-23 02:23:51 +00:00
|
|
|
p = (PInstr *) AllocCMem (sizeof (*p) + size - CellSize, cip);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->op = o;
|
|
|
|
p->rnd1 = r1;
|
|
|
|
p->nextInst = NIL;
|
2004-01-23 02:23:51 +00:00
|
|
|
if (cip->cpc == NIL)
|
|
|
|
cip->cpc = cip->CodeStart = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
|
|
|
{
|
2004-01-23 02:23:51 +00:00
|
|
|
cip->cpc->nextInst = p;
|
|
|
|
cip->cpc = p;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-04-16 20:27:31 +01:00
|
|
|
return p->arnds;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
bip_name(Int op, char *s)
|
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case _atom:
|
|
|
|
strcpy(s,"atom");
|
|
|
|
break;
|
|
|
|
case _atomic:
|
|
|
|
strcpy(s,"atomic");
|
|
|
|
break;
|
|
|
|
case _integer:
|
|
|
|
strcpy(s,"integer");
|
|
|
|
break;
|
|
|
|
case _nonvar:
|
|
|
|
strcpy(s,"nonvar");
|
|
|
|
break;
|
|
|
|
case _number:
|
|
|
|
strcpy(s,"number");
|
|
|
|
break;
|
|
|
|
case _var:
|
|
|
|
strcpy(s,"var");
|
|
|
|
break;
|
|
|
|
case _cut_by:
|
|
|
|
strcpy(s,"cut_by");
|
|
|
|
break;
|
|
|
|
case _db_ref:
|
|
|
|
strcpy(s,"db_ref");
|
|
|
|
break;
|
|
|
|
case _compound:
|
|
|
|
strcpy(s,"compound");
|
|
|
|
break;
|
|
|
|
case _float:
|
|
|
|
strcpy(s,"float");
|
|
|
|
break;
|
|
|
|
case _primitive:
|
|
|
|
strcpy(s,"primitive");
|
|
|
|
break;
|
|
|
|
case _equal:
|
|
|
|
strcpy(s,"equal");
|
|
|
|
break;
|
|
|
|
case _dif:
|
|
|
|
strcpy(s,"dif");
|
|
|
|
break;
|
|
|
|
case _eq:
|
|
|
|
strcpy(s,"eq");
|
|
|
|
break;
|
|
|
|
case _functor:
|
|
|
|
strcpy(s,"functor");
|
|
|
|
break;
|
|
|
|
case _plus:
|
|
|
|
strcpy(s,"plus");
|
|
|
|
break;
|
|
|
|
case _minus:
|
|
|
|
strcpy(s,"minus");
|
|
|
|
break;
|
|
|
|
case _times:
|
|
|
|
strcpy(s,"times");
|
|
|
|
break;
|
|
|
|
case _div:
|
|
|
|
strcpy(s,"div");
|
|
|
|
break;
|
|
|
|
case _and:
|
|
|
|
strcpy(s,"and");
|
|
|
|
break;
|
|
|
|
case _or:
|
|
|
|
strcpy(s,"or");
|
|
|
|
break;
|
|
|
|
case _sll:
|
|
|
|
strcpy(s,"sll");
|
|
|
|
break;
|
|
|
|
case _slr:
|
|
|
|
strcpy(s,"slr");
|
|
|
|
break;
|
2001-04-20 16:48:04 +01:00
|
|
|
case _arg:
|
|
|
|
strcpy(s,"arg");
|
|
|
|
break;
|
2001-04-09 20:54:03 +01:00
|
|
|
default:
|
|
|
|
strcpy(s,"");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_bip_name(Int op, char *s) {
|
2002-11-11 17:38:10 +00:00
|
|
|
bip_name(op,s);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
static void
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address(CELL address)
|
|
|
|
{
|
|
|
|
if (address < (CELL)AtomBase) {
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'L');
|
|
|
|
Yap_plwrite (MkIntTerm (address), Yap_DebugPutc, 0);
|
|
|
|
} else if (address == (CELL) FAILCODE) {
|
|
|
|
Yap_plwrite (MkAtomTerm (AtomFail), Yap_DebugPutc, 0);
|
|
|
|
} else {
|
|
|
|
char buf[32], *p = buf;
|
|
|
|
|
|
|
|
#if HAVE_SNPRINTF
|
2004-11-19 17:14:15 +00:00
|
|
|
snprintf(buf,32,"%p",(void *)address);
|
2003-04-30 18:46:05 +01:00
|
|
|
#else
|
2004-11-19 17:14:15 +00:00
|
|
|
snprintf(buf,"%p",(void *)address);
|
2003-04-30 18:46:05 +01:00
|
|
|
#endif
|
|
|
|
p[31] = '\0'; /* so that I don't have to worry */
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'0');
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'x');
|
|
|
|
while (*p != '\0') {
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,*p++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
write_functor(Functor f)
|
|
|
|
{
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
if (f == FunctorDBRef) {
|
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("DBRef")), Yap_DebugPutc, 0);
|
|
|
|
} else if (f == FunctorLongInt) {
|
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("LongInt")), Yap_DebugPutc, 0);
|
|
|
|
} else if (f == FunctorDouble) {
|
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("Double")), Yap_DebugPutc, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Yap_plwrite(MkAtomTerm(NameOfFunctor (f)), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite(MkIntTerm(ArityOfFunctor (f)), Yap_DebugPutc, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-01-23 02:23:51 +00:00
|
|
|
ShowOp (char *f, struct PSEUDO *cpc)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
char ch;
|
2004-01-23 02:23:51 +00:00
|
|
|
Int arg = cpc->rnd1;
|
|
|
|
Int rn = cpc->rnd2;
|
|
|
|
CELL *cptr = cpc->arnds;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
while ((ch = *f++) != 0)
|
|
|
|
{
|
|
|
|
if (ch == '%')
|
|
|
|
switch (ch = *f++)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
case 'n':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite ((Term) arg, Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
/* write a variable bitmap for a call */
|
|
|
|
{
|
|
|
|
int max = arg/(8*sizeof(CELL)), i;
|
|
|
|
CELL *ptr = cptr;
|
|
|
|
for (i = 0; i <= max; i++) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(MkIntegerTerm((Int)(*ptr++)), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address (arg);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
{
|
|
|
|
char s[32];
|
|
|
|
|
|
|
|
bip_name(rn,s);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm(Yap_LookupAtom(s)), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkIntTerm (rn), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'z':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkIntTerm (cpc->rnd3), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
{
|
|
|
|
Ventry *v = (Ventry *) arg;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,v->KindOfVE == PermVar ? 'Y' : 'X');
|
|
|
|
Yap_plwrite (MkIntTerm ((v->NoOfVE) & MaskVarAdrs), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
{
|
|
|
|
Ventry *v;
|
|
|
|
|
|
|
|
cpc = cpc->nextInst;
|
|
|
|
arg = cpc->rnd1;
|
|
|
|
v = (Ventry *) arg;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,v->KindOfVE == PermVar ? 'Y' : 'X');
|
|
|
|
Yap_plwrite (MkIntTerm ((v->NoOfVE) & MaskVarAdrs), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm ((Atom) arg), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite (MkIntTerm (rn), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
{
|
|
|
|
PredEntry *p = RepPredProp ((Prop) arg);
|
|
|
|
Functor f = p->FunctorOfPred;
|
2001-10-30 16:42:05 +00:00
|
|
|
UInt arity = p->ArityOfPE;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (p->ModuleOfPred)
|
|
|
|
mod = p->ModuleOfPred;
|
|
|
|
else
|
|
|
|
mod = TermProlog;
|
|
|
|
Yap_plwrite (mod, Yap_DebugPutc, 0);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,':');
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm ((Atom)f), Yap_DebugPutc, 0);
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm (NameOfFunctor (f)), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite (MkIntTerm (arity), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
PredEntry *p = RepPredProp((Prop) rn);
|
|
|
|
Functor f = p->FunctorOfPred;
|
2001-10-30 16:42:05 +00:00
|
|
|
UInt arity = p->ArityOfPE;
|
2004-02-12 12:37:12 +00:00
|
|
|
Term mod = TermProlog;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
if (p->ModuleOfPred) mod = p->ModuleOfPred;
|
|
|
|
Yap_plwrite (mod, Yap_DebugPutc, 0);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,':');
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm ((Atom)f), Yap_DebugPutc, 0);
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm (NameOfFunctor (f)), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite (MkIntTerm (arity), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'f':
|
2003-04-30 18:46:05 +01:00
|
|
|
write_functor((Functor)arg);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'r':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'A');
|
|
|
|
Yap_plwrite (MkIntTerm (rn), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
{
|
|
|
|
CELL my_arg = *cptr++;
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address(my_arg);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address(arg);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'i':
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address (arg);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
{
|
|
|
|
Functor fun = (Functor)*cptr++;
|
|
|
|
if (IsExtensionFunctor(fun)) {
|
|
|
|
if (fun == FunctorDBRef) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("DBRef")), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (fun == FunctorLongInt) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("LongInt")), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (fun == FunctorDouble) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(MkAtomTerm(Yap_LookupAtom("Double")), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkAtomTerm(NameOfFunctor(fun)), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'/');
|
|
|
|
Yap_plwrite (MkIntTerm(ArityOfFunctor(fun)), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'O':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite(AbsAppl(cptr), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'x':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite (MkIntTerm (rn >> 1), Yap_DebugPutc, 0);
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'\t');
|
|
|
|
Yap_plwrite (MkIntTerm (rn & 1), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case 'o':
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_plwrite ((Term) * cptr++, Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
case 'c':
|
|
|
|
{
|
|
|
|
int i;
|
2003-08-27 14:37:10 +01:00
|
|
|
CELL *ptr = (CELL *)cptr[0];
|
2003-04-30 18:46:05 +01:00
|
|
|
for (i = 0; i < arg; ++i) {
|
|
|
|
CELL my_arg;
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\t');
|
2003-08-27 14:37:10 +01:00
|
|
|
if (*ptr) {
|
|
|
|
Yap_plwrite ((Term) *ptr++, Yap_DebugPutc, 0);
|
2003-04-30 18:46:05 +01:00
|
|
|
} else {
|
|
|
|
Yap_plwrite (MkIntTerm (0), Yap_DebugPutc, 0);
|
2003-08-27 14:37:10 +01:00
|
|
|
ptr++;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'\t');
|
2003-08-27 14:37:10 +01:00
|
|
|
my_arg = *ptr++;
|
2003-04-30 18:46:05 +01:00
|
|
|
write_address (my_arg);
|
|
|
|
if (i+1 < arg)
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'\n');
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
{
|
|
|
|
int i;
|
2003-08-27 14:37:10 +01:00
|
|
|
CELL *ptr = (CELL *)cptr[0];
|
2003-04-30 18:46:05 +01:00
|
|
|
for (i = 0; i < arg; ++i) {
|
2003-08-27 14:37:10 +01:00
|
|
|
CELL my_arg = ptr[0], lbl = ptr[1];
|
2003-04-30 18:46:05 +01:00
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\t');
|
|
|
|
if (my_arg) {
|
|
|
|
write_functor((Functor)my_arg);
|
|
|
|
} else {
|
|
|
|
Yap_plwrite(MkIntTerm (0), Yap_DebugPutc, 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\t');
|
|
|
|
write_address(lbl);
|
2003-08-27 14:37:10 +01:00
|
|
|
ptr += 2;
|
2003-04-30 18:46:05 +01:00
|
|
|
if (i+1 < arg)
|
|
|
|
Yap_DebugPutc(Yap_c_error_stream,'\n');
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'%');
|
|
|
|
Yap_DebugPutc (Yap_c_error_stream,ch);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,ch);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *opformat[] =
|
|
|
|
{
|
|
|
|
"nop",
|
|
|
|
"get_var\t\t%v,%r",
|
|
|
|
"put_var\t\t%v,%r",
|
|
|
|
"get_val\t\t%v,%r",
|
|
|
|
"put_val\t\t%v,%r",
|
|
|
|
"get_atom\t%a,%r",
|
|
|
|
"put_atom\t%a,%r",
|
|
|
|
"get_num\t\t%n,%r",
|
|
|
|
"put_num\t\t%n,%r",
|
|
|
|
"get_float\t\t%l,%r",
|
|
|
|
"put_float\t\t%l,%r",
|
2003-12-27 00:38:53 +00:00
|
|
|
"align_float",
|
2001-04-09 20:54:03 +01:00
|
|
|
"get_longint\t\t%l,%r",
|
|
|
|
"put_longint\t\t%l,%r",
|
|
|
|
"get_bigint\t\t%l,%r",
|
|
|
|
"put_bigint\t\t%l,%r",
|
|
|
|
"get_list\t%r",
|
|
|
|
"put_list\t%r",
|
|
|
|
"get_struct\t%f,%r",
|
|
|
|
"put_struct\t%f,%r",
|
|
|
|
"put_unsafe\t%v,%r",
|
|
|
|
"unify_var\t%v",
|
|
|
|
"write_var\t%v",
|
|
|
|
"unify_val\t%v",
|
|
|
|
"write_val\t%v",
|
|
|
|
"unify_atom\t%a",
|
|
|
|
"write_atom\t%a",
|
|
|
|
"unify_num\t%n",
|
|
|
|
"write_num\t%n",
|
|
|
|
"unify_float\t%l",
|
|
|
|
"write_float\t%l",
|
|
|
|
"unify_longint\t%l",
|
|
|
|
"write_longint\t%l",
|
|
|
|
"unify_bigint\t%l",
|
|
|
|
"write_bigint\t%l",
|
|
|
|
"unify_list",
|
|
|
|
"write_list",
|
|
|
|
"unify_struct\t%f",
|
|
|
|
"write_struct\t%f",
|
|
|
|
"write_unsafe\t%v",
|
|
|
|
"fail",
|
|
|
|
"cut",
|
|
|
|
"cutexit",
|
|
|
|
"allocate",
|
|
|
|
"deallocate",
|
|
|
|
"try_me_else\t\t%l\t%x",
|
|
|
|
"jump\t\t%l",
|
2003-04-30 18:46:05 +01:00
|
|
|
"jump\t\t%l",
|
2003-09-24 15:51:42 +01:00
|
|
|
"proceed",
|
2001-04-09 20:54:03 +01:00
|
|
|
"call\t\t%p,%d,%z",
|
|
|
|
"execute\t\t%p",
|
|
|
|
"sys\t\t%p",
|
|
|
|
"%l:",
|
|
|
|
"name\t\t%m,%d",
|
|
|
|
"pop\t\t%l",
|
|
|
|
"retry_me_else\t\t%l\t%x",
|
|
|
|
"trust_me_else_fail\t%x",
|
|
|
|
"either_me\t\t%l,%d,%z",
|
|
|
|
"or_else\t\t%l,%z",
|
|
|
|
"or_last",
|
|
|
|
"push_or",
|
|
|
|
"pushpop_or",
|
|
|
|
"pop_or",
|
|
|
|
"save_by\t\t%v",
|
2003-12-27 00:38:53 +00:00
|
|
|
"commit_by\t\t%v",
|
2001-04-09 20:54:03 +01:00
|
|
|
"patch_by\t\t%v",
|
|
|
|
"try\t\t%g\t%x",
|
|
|
|
"retry\t\t%g\t%x",
|
|
|
|
"trust\t\t%g\t%x",
|
|
|
|
"try_in\t\t%g\t%x",
|
|
|
|
"jump_if_var\t\t%g",
|
2003-10-28 01:16:03 +00:00
|
|
|
"jump_if_nonvar\t\t%g",
|
2003-04-30 18:46:05 +01:00
|
|
|
"cache_arg\t%r",
|
|
|
|
"cache_sub_arg\t%d",
|
2001-04-09 20:54:03 +01:00
|
|
|
"switch_on_type\t%h\t%h\t%h\t%h",
|
|
|
|
"switch_on_constant\t%i\n%c",
|
2003-08-27 14:37:10 +01:00
|
|
|
"if_constant\t%i\n%c",
|
2001-04-09 20:54:03 +01:00
|
|
|
"switch_on_functor\t%i\n%e",
|
2003-08-27 14:37:10 +01:00
|
|
|
"if_functor\t%i\n%e",
|
2001-04-09 20:54:03 +01:00
|
|
|
"if_not_then\t%i\t%h\t%h\t%h",
|
2003-08-27 14:37:10 +01:00
|
|
|
"index_on_dbref",
|
|
|
|
"index_on_blob",
|
|
|
|
"check_var\t %r",
|
2001-04-09 20:54:03 +01:00
|
|
|
"save_pair\t%v",
|
|
|
|
"save_appl\t%v",
|
|
|
|
"fail_label\t%l",
|
|
|
|
"unify_local\t%v",
|
|
|
|
"write local\t%v",
|
|
|
|
"unify_last_list",
|
|
|
|
"write_last_list",
|
|
|
|
"unify_last_struct\t%f",
|
|
|
|
"write_last_struct\t%f",
|
|
|
|
"unify_last_var\t%v",
|
|
|
|
"unify_last_val\t%v",
|
|
|
|
"unify_last_local\t%v",
|
|
|
|
"unify_last_atom\t%a",
|
|
|
|
"unify_last_num\t%n",
|
|
|
|
"unify_last_float\t%l",
|
|
|
|
"unify_last_longint\t%l",
|
|
|
|
"unify_last_bigint\t%l",
|
|
|
|
"pvar_bitmap\t%l,%b",
|
|
|
|
"pvar_live_regs\t%l,%b",
|
|
|
|
"fetch_reg1_reg2\t%N,%N",
|
|
|
|
"fetch_constant_reg\t%l,%N",
|
|
|
|
"fetch_reg_constant\t%l,%N",
|
|
|
|
"function_to_var\t%v,%B",
|
|
|
|
"function_to_al\t%v,%B",
|
|
|
|
"enter_profiling\t\t%g",
|
|
|
|
"retry_profiled\t\t%g",
|
2002-09-03 15:28:09 +01:00
|
|
|
"count_call_op\t\t%g",
|
|
|
|
"count_retry_op\t\t%g",
|
2001-04-09 20:54:03 +01:00
|
|
|
"restore_temps\t\t%l",
|
|
|
|
"restore_temps_and_skip\t\t%l",
|
2003-09-15 02:25:29 +01:00
|
|
|
"enter_lu",
|
2001-04-09 20:54:03 +01:00
|
|
|
"empty_call\t\t%l,%d",
|
|
|
|
#ifdef YAPOR
|
|
|
|
"sync",
|
|
|
|
#endif /* YAPOR */
|
2003-11-07 16:31:08 +00:00
|
|
|
#ifdef TABLING
|
|
|
|
"table_new_answer",
|
2003-12-18 16:38:40 +00:00
|
|
|
"table_try_single\t%g\t%x",
|
2003-11-07 16:31:08 +00:00
|
|
|
#endif /* TABLING */
|
|
|
|
#ifdef TABLING_INNER_CUTS
|
|
|
|
"clause_with_cut",
|
|
|
|
#endif /* TABLING_INNER_CUTS */
|
2001-04-09 20:54:03 +01:00
|
|
|
"fetch_args_for_bccall\t%v",
|
|
|
|
"binary_cfunc\t\t%v,%P",
|
|
|
|
"blob\t%O"
|
|
|
|
#ifdef SFUNC
|
|
|
|
,
|
|
|
|
"get_s_f_op\t%f,%r",
|
|
|
|
"put_s_f_op\t%f,%r",
|
|
|
|
"unify_s_f_op\t%f",
|
|
|
|
"write_s_f_op\t%f",
|
|
|
|
"unify_s_var\t%v,%r",
|
|
|
|
"write_s_var\t%v,%r",
|
|
|
|
"unify_s_val\t%v,%r",
|
|
|
|
"write_s_val\t%v,%r",
|
|
|
|
"unify_s_a\t%a,%r",
|
|
|
|
"write_s_a\t%a,%r",
|
|
|
|
"get_s_end",
|
|
|
|
"put_s_end",
|
|
|
|
"unify_s_end",
|
|
|
|
"write_s_end"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_ShowCode (struct intermediates *cint)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
CELL *OldH = H;
|
2004-01-23 02:23:51 +00:00
|
|
|
struct PSEUDO *cpc;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
cpc = cint->CodeStart;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* MkIntTerm and friends may build terms in the global stack */
|
2004-01-23 02:23:51 +00:00
|
|
|
H = (CELL *)cint->freep;
|
|
|
|
while (cpc) {
|
|
|
|
compiler_vm_op ic = cpc->op;
|
|
|
|
if (ic != nop_op) {
|
|
|
|
ShowOp (opformat[ic], cpc);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-01-23 02:23:51 +00:00
|
|
|
cpc = cpc->nextInst;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_DebugPutc (Yap_c_error_stream,'\n');
|
2001-04-09 20:54:03 +01:00
|
|
|
H = OldH;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|