| 
									
										
										
										
											2001-04-09 19:54:03 +00: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			 * | 
					
						
							|  |  |  | *									 * | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  | * Last rev:     $Date: 2007-11-26 23:43:08 $							 * | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  | * $Log: not supported by cvs2svn $ | 
					
						
							| 
									
										
										
										
											2007-11-26 23:43:10 +00:00
										 |  |  | * Revision 1.31  2007/11/06 17:02:12  vsc | 
					
						
							|  |  |  | * compile ground terms away. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2007-11-06 17:02:13 +00:00
										 |  |  | * Revision 1.30  2006/09/20 20:03:51  vsc | 
					
						
							|  |  |  | * improve indexing on floats | 
					
						
							|  |  |  | * fix sending large lists to DB | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  | * Revision 1.29  2005/12/05 17:16:10  vsc | 
					
						
							|  |  |  | * write_depth/3 | 
					
						
							|  |  |  | * overflow handlings and garbage collection | 
					
						
							|  |  |  | * Several ipdates to CLPBN | 
					
						
							|  |  |  | * dif/2 could be broken in the presence of attributed variables. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | * Revision 1.28  2005/09/08 22:06:44  rslopes | 
					
						
							|  |  |  | * BEAM for YAP update... | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  | * Revision 1.27  2005/07/06 15:10:04  vsc | 
					
						
							|  |  |  | * improvements to compiler: merged instructions and fixes for -> | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-07-06 15:10:18 +00:00
										 |  |  | * Revision 1.26  2005/01/04 02:50:21  vsc | 
					
						
							|  |  |  | * - allow MegaClauses with blobs | 
					
						
							|  |  |  | * - change Diffs to be thread specific | 
					
						
							|  |  |  | * - include Christian's updates | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2005-01-04 02:50:23 +00:00
										 |  |  | * Revision 1.25  2004/11/19 17:14:13  vsc | 
					
						
							|  |  |  | * a few fixes for 64 bit compiling. | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-11-19 17:14:15 +00:00
										 |  |  | * Revision 1.24  2004/04/16 19:27:31  vsc | 
					
						
							|  |  |  | * more bug fixes | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00: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 19:54:03 +00: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"
 | 
					
						
							| 
									
										
										
										
											2009-10-23 14:22:17 +01:00
										 |  |  | #include "YapHeap.h"
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #include "compile.h"
 | 
					
						
							|  |  |  | #include "yapio.h"
 | 
					
						
							|  |  |  | #if HAVE_STRING_H
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  | static void ShowOp(const char *, struct PSEUDO *); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif /* DEBUG */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * The compiler creates an instruction chain which will be assembled after | 
					
						
							|  |  |  |  * afterwards  | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  | typedef struct mem_blk { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |   union { | 
					
						
							|  |  |  |     struct mem_blk *next; | 
					
						
							|  |  |  |     double fill; | 
					
						
							| 
									
										
										
										
											2014-02-18 09:44:01 +00:00
										 |  |  |   } ublock; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |   char contents[1]; | 
					
						
							|  |  |  | } MemBlk; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  | #define CMEM_BLK_SIZE (4*4096)
 | 
					
						
							|  |  |  | #define FIRST_CMEM_BLK_SIZE (16*4096)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | static char * | 
					
						
							| 
									
										
										
										
											2010-05-06 15:00:44 +01:00
										 |  |  | AllocCMem (UInt size, struct intermediates *cip) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if SIZEOF_INT_P==8
 | 
					
						
							| 
									
										
										
										
											2010-05-11 12:25:49 +01:00
										 |  |  |   size = (size + 7) & ((UInt)-8); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-05-11 12:25:49 +01:00
										 |  |  |   size = (size + 3) & ((UInt)0xfffffffc); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							|  |  |  |   if (!cip->blks || cip->blk_cur+size > cip->blk_top) { | 
					
						
							|  |  |  |     UInt blksz; | 
					
						
							|  |  |  |     struct mem_blk *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (size > CMEM_BLK_SIZE) | 
					
						
							|  |  |  |       blksz = size+sizeof(struct mem_blk); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       blksz = CMEM_BLK_SIZE; | 
					
						
							|  |  |  |     if (!cip->blks) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |       CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       if (LOCAL_CMemFirstBlock) { | 
					
						
							|  |  |  | 	p = LOCAL_CMemFirstBlock; | 
					
						
							|  |  |  | 	blksz = LOCAL_CMemFirstBlockSz; | 
					
						
							| 
									
										
										
										
											2014-02-18 09:44:01 +00:00
										 |  |  | 	p->ublock.next = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |       } else { | 
					
						
							|  |  |  | 	if (blksz < FIRST_CMEM_BLK_SIZE) | 
					
						
							|  |  |  | 	  blksz = FIRST_CMEM_BLK_SIZE; | 
					
						
							|  |  |  | 	p = (struct mem_blk *)Yap_AllocCodeSpace(blksz); | 
					
						
							|  |  |  | 	if (!p) { | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	  LOCAL_Error_Size = size; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  | 	  save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:31:19 +00:00
										 |  |  | 	  siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  | 	LOCAL_CMemFirstBlock = p; | 
					
						
							|  |  |  | 	LOCAL_CMemFirstBlockSz = blksz; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       p = (struct mem_blk *)Yap_AllocCodeSpace(blksz); | 
					
						
							|  |  |  |       if (!p) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  | 	CACHE_REGS | 
					
						
							| 
									
										
										
										
											2011-05-23 16:19:47 +01:00
										 |  |  | 	LOCAL_Error_Size = size; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  | 	save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:31:19 +00:00
										 |  |  | 	siglongjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-02-18 09:44:01 +00:00
										 |  |  |     p->ublock.next = cip->blks; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |     cip->blks = p; | 
					
						
							|  |  |  |     cip->blk_cur = p->contents; | 
					
						
							|  |  |  |     cip->blk_top = (char *)p+blksz; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     char *out = cip->blk_cur; | 
					
						
							|  |  |  |     cip->blk_cur += size; | 
					
						
							|  |  |  |     return out; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   char *p; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   if (ASP <= CellPtr (cip->freep) + 256) { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |     CACHE_REGS | 
					
						
							| 
									
										
										
										
											2014-01-19 21:57:02 +00:00
										 |  |  |     LOCAL_Error_Size = 256+((char *)cip->freep - (char *)HR); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     save_machine_regs(); | 
					
						
							| 
									
										
										
										
											2010-12-16 01:31:19 +00:00
										 |  |  |     siglongjmp(cip->CompilerBotch, OUT_OF_STACK_BOTCH); | 
					
						
							| 
									
										
										
										
											2013-07-22 10:40:47 -05:00
										 |  |  |   }  | 
					
						
							|  |  |  |   p = cip->freep; | 
					
						
							|  |  |  |   cip->freep += size; | 
					
						
							|  |  |  |   return p; | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | Yap_ReleaseCMem (struct intermediates *cip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if USE_SYSTEM_MALLOC
 | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |   struct mem_blk *p = cip->blks; | 
					
						
							|  |  |  |   while (p) { | 
					
						
							| 
									
										
										
										
											2014-02-18 09:44:01 +00:00
										 |  |  |     struct mem_blk *nextp = p->ublock.next; | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |     if (p != LOCAL_CMemFirstBlock) | 
					
						
							| 
									
										
										
										
											2010-04-15 22:23:54 +01:00
										 |  |  |       Yap_FreeCodeSpace((ADDR)p); | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |     p = nextp; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   cip->blks = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-15 22:49:25 +01:00
										 |  |  |   if (cip->label_offset && | 
					
						
							| 
									
										
										
										
											2011-05-04 10:11:41 +01:00
										 |  |  |       cip->label_offset != LOCAL_LabelFirstArray) { | 
					
						
							| 
									
										
										
										
											2010-04-15 22:49:25 +01:00
										 |  |  |     Yap_FreeCodeSpace((ADDR)cip->label_offset); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-04-15 22:49:25 +01:00
										 |  |  |   cip->label_offset = NULL; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | char * | 
					
						
							| 
									
										
										
										
											2010-05-06 15:00:44 +01:00
										 |  |  | Yap_AllocCMem (UInt size, struct intermediates *cip) | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-31 15:51:18 +01:00
										 |  |  |   return AllocCMem(size, cip); | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | is_a_test(Term arg, Term mod) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-10 14:59:55 +00:00
										 |  |  |   if (IsVarTerm (arg)) { | 
					
						
							| 
									
										
										
										
											2003-12-27 00:38:53 +00:00
										 |  |  |     return FALSE; | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (IsVarTerm (arg) || !IsAtomTerm(mod)) { | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (IsAtomTerm (arg)) { | 
					
						
							| 
									
										
										
										
											2001-10-03 13:39:16 +00: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; | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (IsApplTerm (arg)) { | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |     Functor f = FunctorOfTerm (arg); | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (f == FunctorModule) { | 
					
						
							|  |  |  |       return is_a_test(ArgOfTerm(2,arg), ArgOfTerm(1,arg)); | 
					
						
							|  |  |  |     } else if (f == FunctorComma) { | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  | 	is_a_test(ArgOfTerm(1,arg), mod) && | 
					
						
							|  |  |  | 	is_a_test(ArgOfTerm(2,arg), mod); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       PredEntry *pe = RepPredProp(PredPropByFunc(f, mod)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (EndOfPAEntr(pe)) | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							|  |  |  |       if (pe->PredFlags & AsmPredFlag) { | 
					
						
							|  |  |  | 	int op = pe->PredFlags & 0x7f; | 
					
						
							|  |  |  | 	if (op >= _atom && op <= _eq) { | 
					
						
							|  |  |  | 	  return TRUE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return FALSE; | 
					
						
							|  |  |  |       }       | 
					
						
							| 
									
										
										
										
											2009-02-09 21:56:40 +00:00
										 |  |  |       return pe->PredFlags & (TestPredFlag|BinaryPredFlag); | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-12-09 14:23:19 +00:00
										 |  |  |   return FALSE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | Yap_is_a_test_pred (Term arg, Term mod) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return is_a_test(arg, mod); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PInstr *p; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   p = (PInstr *) AllocCMem (sizeof (*p), cip); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   p->op = o; | 
					
						
							|  |  |  |   p->rnd1 = r1; | 
					
						
							|  |  |  |   p->rnd2 = r2; | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |   p->nextInst = NULL; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   if (cip->cpc == NIL) { | 
					
						
							|  |  |  |     cip->cpc = cip->CodeStart = p; | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |     cip->cpc->nextInst = p; | 
					
						
							|  |  |  |     cip->cpc = p; | 
					
						
							| 
									
										
										
										
											2003-05-19 13:04:09 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PInstr *p; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   p = (PInstr *) AllocCMem (sizeof (*p)+sizeof(CELL), cip); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |       cip->cpc->nextInst = p; | 
					
						
							|  |  |  |       cip->cpc = p; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00: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 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PInstr *p; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   p = (PInstr *) AllocCMem (sizeof (*p) + size - CellSize, cip); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |       cip->cpc->nextInst = p; | 
					
						
							|  |  |  |       cip->cpc = p; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-04-16 19:27:31 +00:00
										 |  |  |   return p->arnds; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-11 17:38:10 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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; | 
					
						
							| 
									
										
										
										
											2013-02-13 09:06:06 -06:00
										 |  |  |   case _save_by: | 
					
						
							|  |  |  |     strcpy(s,"save_by"); | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   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 15:48:04 +00:00
										 |  |  |   case _arg: | 
					
						
							|  |  |  |     strcpy(s,"arg"); | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | write_address(CELL address) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (address < (CELL)AtomBase) { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |     Yap_DebugErrorPutc('L'); | 
					
						
							| 
									
										
										
										
											2009-05-22 13:24:27 -05:00
										 |  |  |     Yap_DebugPlWrite(MkIntTerm (address)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |   } else if (address == (CELL) FAILCODE) { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |     Yap_DebugPlWrite (MkAtomTerm (AtomFail)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |   } 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 17:46:05 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-03-08 00:02:19 +00:00
										 |  |  |     sprintf(buf,"%p",(void *)address); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     p[31] = '\0'; /* so that I don't have to worry */ | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |     Yap_DebugErrorPutc('0'); | 
					
						
							|  |  |  |     Yap_DebugErrorPutc('x'); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |     while (*p != '\0') { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |       Yap_DebugErrorPutc(*p++); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | write_functor(Functor f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (IsExtensionFunctor(f)) { | 
					
						
							|  |  |  |     if (f == FunctorDBRef) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |       Yap_DebugPlWrite(MkAtomTerm(AtomDBREF)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |     } else if (f == FunctorLongInt) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |       Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT)); | 
					
						
							| 
									
										
										
										
											2011-11-01 17:25:59 -07:00
										 |  |  |     } else if (f == FunctorBigInt) { | 
					
						
							|  |  |  |       Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |     } else if (f == FunctorDouble) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  |       Yap_DebugPlWrite(MkAtomTerm(AtomDOUBLE)); | 
					
						
							| 
									
										
										
										
											2013-12-02 14:49:41 +00:00
										 |  |  |     } else if (f == FunctorString) { | 
					
						
							|  |  |  |       Yap_DebugPlWrite(MkAtomTerm(AtomSTRING)); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |     Yap_DebugPlWrite(MkAtomTerm(NameOfFunctor (f))); | 
					
						
							|  |  |  |     Yap_DebugErrorPutc ('/'); | 
					
						
							|  |  |  |     Yap_DebugPlWrite(MkIntTerm(ArityOfFunctor (f))); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  | ShowOp (const char *f, struct PSEUDO *cpc) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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 19:54:03 +00:00
										 |  |  |   while ((ch = *f++) != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (ch == '%') | 
					
						
							|  |  |  | 	switch (ch = *f++) | 
					
						
							|  |  |  | 	  { | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  | #ifdef BEAM
 | 
					
						
							|  |  |  | 	case '1': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite(MkIntTerm(rn)); | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case '4': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite(MkIntTerm(arg)); | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  case 'a': | 
					
						
							|  |  |  | 	  case 'n': | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  | 	  case 'S': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite ((Term) arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'b': | 
					
						
							|  |  |  | 	    /* write a variable bitmap for a call */ | 
					
						
							|  |  |  | 	    { | 
					
						
							| 
									
										
										
										
											2013-03-26 15:01:52 -05:00
										 |  |  | 	      CACHE_REGS | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	      int max = arg/(8*sizeof(CELL)), i; | 
					
						
							|  |  |  | 	      CELL *ptr = cptr; | 
					
						
							|  |  |  | 	      for (i = 0; i <= max; i++) { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite(MkIntegerTerm((Int)(*ptr++))); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	      } | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	    break;		 | 
					
						
							|  |  |  | 	  case 'l': | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	    write_address (arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'B': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      char s[32]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	      bip_name(rn,s); | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	      Yap_DebugPlWrite (MkAtomTerm(Yap_LookupAtom(s))); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'd': | 
					
						
							| 
									
										
										
										
											2013-03-26 15:01:52 -05:00
										 |  |  | 	    { | 
					
						
							|  |  |  | 	      CACHE_REGS | 
					
						
							|  |  |  | 	      Yap_DebugPlWrite (MkIntegerTerm (arg)); | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'z': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite (MkIntTerm (cpc->rnd3)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'v': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      Ventry *v = (Ventry *) arg; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	      Yap_DebugErrorPutc (v->KindOfVE == PermVar ? 'Y' : 'X'); | 
					
						
							|  |  |  | 	      Yap_DebugPlWrite (MkIntTerm ((v->NoOfVE) & MaskVarAdrs)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2005-07-06 15:10:18 +00:00
										 |  |  | 	    break;	 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  case 'N': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      Ventry *v; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	      cpc = cpc->nextInst; | 
					
						
							|  |  |  | 	      arg = cpc->rnd1; | 
					
						
							|  |  |  | 	      v = (Ventry *) arg; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	      Yap_DebugErrorPutc (v->KindOfVE == PermVar ? 'Y' : 'X'); | 
					
						
							|  |  |  | 	      Yap_DebugPlWrite (MkIntTerm ((v->NoOfVE) & MaskVarAdrs)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2009-02-16 21:04:30 +00:00
										 |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  case 'm': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite (MkAtomTerm ((Atom) arg)); | 
					
						
							|  |  |  | 	    Yap_DebugErrorPutc ('/'); | 
					
						
							|  |  |  | 	    Yap_DebugPlWrite (MkIntTerm (rn)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	      Yap_DebugPlWrite (mod); | 
					
						
							|  |  |  | 	      Yap_DebugErrorPutc (':'); | 
					
						
							| 
									
										
										
										
											2001-10-30 16:42:05 +00:00
										 |  |  | 	      if (arity == 0) | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite (MkAtomTerm ((Atom)f)); | 
					
						
							| 
									
										
										
										
											2001-10-30 16:42:05 +00:00
										 |  |  | 	      else | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite (MkAtomTerm (NameOfFunctor (f))); | 
					
						
							|  |  |  | 	      Yap_DebugErrorPutc ('/'); | 
					
						
							|  |  |  | 	      Yap_DebugPlWrite (MkIntTerm (arity)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00: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; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	      Yap_DebugPlWrite (mod); | 
					
						
							|  |  |  | 	      Yap_DebugErrorPutc (':'); | 
					
						
							| 
									
										
										
										
											2001-10-30 16:42:05 +00:00
										 |  |  | 	      if (arity == 0) | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite (MkAtomTerm ((Atom)f)); | 
					
						
							| 
									
										
										
										
											2001-10-30 16:42:05 +00:00
										 |  |  | 	      else | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite (MkAtomTerm (NameOfFunctor (f))); | 
					
						
							|  |  |  | 	      Yap_DebugErrorPutc ('/'); | 
					
						
							|  |  |  | 	      Yap_DebugPlWrite (MkIntTerm (arity)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'f': | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	    write_functor((Functor)arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'r': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugErrorPutc ('A'); | 
					
						
							|  |  |  | 	    Yap_DebugPlWrite (MkIntTerm (rn)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'h': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      CELL my_arg = *cptr++; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	      write_address(my_arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'g': | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	    write_address(arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'i': | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	    write_address (arg); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'j': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      Functor fun = (Functor)*cptr++; | 
					
						
							|  |  |  | 	      if (IsExtensionFunctor(fun)) { | 
					
						
							|  |  |  | 		if (fun == FunctorDBRef) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  | 		  Yap_DebugPlWrite(MkAtomTerm(AtomDBREF)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 		} else if (fun == FunctorLongInt) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  | 		  Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 		} else if (fun == FunctorDouble) { | 
					
						
							| 
									
										
										
										
											2008-12-23 01:53:52 +00:00
										 |  |  | 		  Yap_DebugPlWrite(MkAtomTerm(AtomDOUBLE)); | 
					
						
							| 
									
										
										
										
											2013-12-05 11:20:57 +00:00
										 |  |  | 		} else if (fun == FunctorString) { | 
					
						
							|  |  |  | 		  Yap_DebugPlWrite(MkAtomTerm(AtomSTRING)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	      } else { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugPlWrite (MkAtomTerm(NameOfFunctor(fun))); | 
					
						
							|  |  |  | 		Yap_DebugErrorPutc ('/'); | 
					
						
							|  |  |  | 		Yap_DebugPlWrite (MkIntTerm(ArityOfFunctor(fun))); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	      } | 
					
						
							|  |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'O': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite(AbsAppl(cptr)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'x': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite (MkIntTerm (rn >> 1)); | 
					
						
							|  |  |  | 	    Yap_DebugErrorPutc ('\t'); | 
					
						
							|  |  |  | 	    Yap_DebugPlWrite (MkIntTerm (rn & 1)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											2006-09-20 20:03:51 +00:00
										 |  |  | 	  case 'w': | 
					
						
							|  |  |  | 	    Yap_DebugPlWrite (arg); | 
					
						
							|  |  |  | 	    break; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  case 'o': | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugPlWrite ((Term) * cptr++); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  case 'c': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      int i; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 	      CELL *ptr = (CELL *)cptr[0]; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	      for (i = 0; i < arg; ++i) { | 
					
						
							|  |  |  | 		CELL my_arg; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugErrorPutc('\t'); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 		if (*ptr) { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		  Yap_DebugPlWrite ((Term) *ptr++); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		  Yap_DebugPlWrite (MkIntTerm (0)); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 		  ptr++; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugErrorPutc ('\t'); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 		my_arg = *ptr++; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 		write_address (my_arg); | 
					
						
							|  |  |  | 		if (i+1 < arg) | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		  Yap_DebugErrorPutc ('\n'); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	      } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  case 'e': | 
					
						
							|  |  |  | 	    { | 
					
						
							|  |  |  | 	      int i; | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 	      CELL *ptr = (CELL *)cptr[0]; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	      for (i = 0; i < arg; ++i)	{ | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 		CELL my_arg = ptr[0], lbl = ptr[1]; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugErrorPutc('\t'); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 		if (my_arg) { | 
					
						
							|  |  |  | 		  write_functor((Functor)my_arg); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		  Yap_DebugPlWrite(MkIntTerm (0)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		Yap_DebugErrorPutc('\t'); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 		write_address(lbl); | 
					
						
							| 
									
										
										
										
											2003-08-27 13:37:10 +00:00
										 |  |  | 		ptr += 2; | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 		if (i+1 < arg) | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 		  Yap_DebugErrorPutc('\n'); | 
					
						
							| 
									
										
										
										
											2003-04-30 17:46:05 +00:00
										 |  |  | 	      } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } | 
					
						
							|  |  |  | 	    break; | 
					
						
							|  |  |  | 	  default: | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	    Yap_DebugErrorPutc ('%'); | 
					
						
							|  |  |  | 	    Yap_DebugErrorPutc (ch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  } | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	Yap_DebugErrorPutc (ch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |   Yap_DebugErrorPutc ('\n'); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  | static const char * | 
					
						
							|  |  |  | getFormat(compiler_vm_op ic) { | 
					
						
							|  |  |  |   switch( ic ) { | 
					
						
							|  |  |  |   case nop_op: | 
					
						
							|  |  |  |     return "nop"; | 
					
						
							|  |  |  |   case get_var_op: | 
					
						
							|  |  |  |     return "get_var\t\t%v,%r"; | 
					
						
							|  |  |  |   case put_var_op: | 
					
						
							|  |  |  |     return  "put_var\t\t%v,%r"; | 
					
						
							|  |  |  |   case get_val_op: | 
					
						
							|  |  |  |     return "get_val\t\t%v,%r"; | 
					
						
							|  |  |  |   case put_val_op: | 
					
						
							|  |  |  |     return "put_val\t\t%v,%r"; | 
					
						
							|  |  |  |   case get_atom_op: | 
					
						
							|  |  |  |     return "get_atom\t%a,%r"; | 
					
						
							|  |  |  |   case put_atom_op: | 
					
						
							|  |  |  |     return "put_atom\t%a,%r"; | 
					
						
							|  |  |  |   case get_num_op: | 
					
						
							|  |  |  |     return "get_num\t\t%n,%r"; | 
					
						
							|  |  |  |   case put_num_op: | 
					
						
							|  |  |  |     return "put_num\t\t%n,%r"; | 
					
						
							|  |  |  |   case get_float_op: | 
					
						
							|  |  |  |     return "get_float\t\t%w,%r"; | 
					
						
							|  |  |  |   case put_float_op: | 
					
						
							|  |  |  |     return "put_float\t\t%w,%r"; | 
					
						
							|  |  |  |   case get_string_op: | 
					
						
							|  |  |  |     return "get_string\t\t%w,%S"; | 
					
						
							|  |  |  |   case put_string_op: | 
					
						
							|  |  |  |     return "put_string\t\t%w,%S"; | 
					
						
							|  |  |  |   case get_dbterm_op: | 
					
						
							|  |  |  |     return "get_dbterm\t%w,%r"; | 
					
						
							|  |  |  |   case put_dbterm_op: | 
					
						
							|  |  |  |     return "put_dbterm\t%w,%r"; | 
					
						
							|  |  |  |   case get_longint_op: | 
					
						
							|  |  |  |     return "get_longint\t\t%w,%r"; | 
					
						
							|  |  |  |   case put_longint_op: | 
					
						
							|  |  |  |     return "put_longint\t\t%w,%r"; | 
					
						
							|  |  |  |   case get_bigint_op: | 
					
						
							|  |  |  |     return "get_bigint\t\t%l,%r"; | 
					
						
							|  |  |  |   case put_bigint_op: | 
					
						
							|  |  |  |     return "put_bigint\t\t%l,%r"; | 
					
						
							|  |  |  |   case get_list_op: | 
					
						
							|  |  |  |     return "get_list\t%r"; | 
					
						
							|  |  |  |   case put_list_op: | 
					
						
							|  |  |  |     return "put_list\t%r"; | 
					
						
							|  |  |  |   case get_struct_op: | 
					
						
							|  |  |  |     return "get_struct\t%f,%r"; | 
					
						
							|  |  |  |   case put_struct_op: | 
					
						
							|  |  |  |     return "put_struct\t%f,%r"; | 
					
						
							|  |  |  |   case put_unsafe_op: | 
					
						
							|  |  |  |     return "put_unsafe\t%v,%r"; | 
					
						
							|  |  |  |   case unify_var_op: | 
					
						
							|  |  |  |     return "unify_var\t%v"; | 
					
						
							|  |  |  |   case write_var_op: | 
					
						
							|  |  |  |     return "write_var\t%v"; | 
					
						
							|  |  |  |   case unify_val_op: | 
					
						
							|  |  |  |     return "unify_val\t%v"; | 
					
						
							|  |  |  |   case write_val_op: | 
					
						
							|  |  |  |     return "write_val\t%v"; | 
					
						
							|  |  |  |   case unify_atom_op: | 
					
						
							|  |  |  |     return "unify_atom\t%a"; | 
					
						
							|  |  |  |   case write_atom_op: | 
					
						
							|  |  |  |     return "write_atom\t%a"; | 
					
						
							|  |  |  |   case unify_num_op: | 
					
						
							|  |  |  |     return "unify_num\t%n"; | 
					
						
							|  |  |  |   case write_num_op: | 
					
						
							|  |  |  |     return "write_num\t%n"; | 
					
						
							|  |  |  |   case unify_float_op: | 
					
						
							|  |  |  |     return "unify_float\t%w"; | 
					
						
							|  |  |  |   case write_float_op: | 
					
						
							|  |  |  |     return "write_float\t%w"; | 
					
						
							|  |  |  |   case unify_string_op: | 
					
						
							|  |  |  |     return "unify_string\t%S"; | 
					
						
							|  |  |  |   case write_string_op: | 
					
						
							|  |  |  |     return "write_string\t%S"; | 
					
						
							|  |  |  |   case unify_dbterm_op: | 
					
						
							|  |  |  |     return "unify_dbterm\t%w"; | 
					
						
							|  |  |  |   case write_dbterm_op: | 
					
						
							|  |  |  |     return "write_dbterm\t%w"; | 
					
						
							|  |  |  |   case unify_longint_op: | 
					
						
							|  |  |  |     return "unify_longint\t%w"; | 
					
						
							|  |  |  |   case write_longint_op: | 
					
						
							|  |  |  |     return "write_longint\t%w"; | 
					
						
							|  |  |  |   case unify_bigint_op: | 
					
						
							|  |  |  |     return "unify_bigint\t%l"; | 
					
						
							|  |  |  |   case write_bigint_op: | 
					
						
							|  |  |  |     return "write_bigint\t%l"; | 
					
						
							|  |  |  |   case unify_list_op: | 
					
						
							|  |  |  |     return "unify_list"; | 
					
						
							|  |  |  |   case write_list_op: | 
					
						
							|  |  |  |     return "write_list"; | 
					
						
							|  |  |  |   case unify_struct_op: | 
					
						
							|  |  |  |     return "unify_struct\t%f"; | 
					
						
							|  |  |  |   case write_struct_op: | 
					
						
							|  |  |  |     return "write_struct\t%f"; | 
					
						
							|  |  |  |   case write_unsafe_op: | 
					
						
							|  |  |  |     return "write_unsafe\t%v"; | 
					
						
							|  |  |  |   case unify_local_op: | 
					
						
							|  |  |  |     return "unify_local\t%v"; | 
					
						
							|  |  |  |   case write_local_op: | 
					
						
							|  |  |  |     return "write local\t%v"; | 
					
						
							|  |  |  |   case unify_last_list_op: | 
					
						
							|  |  |  |     return "unify_last_list"; | 
					
						
							|  |  |  |   case write_last_list_op: | 
					
						
							|  |  |  |     return "write_last_list"; | 
					
						
							|  |  |  |   case unify_last_struct_op: | 
					
						
							|  |  |  |     return "unify_last_struct\t%f"; | 
					
						
							|  |  |  |   case write_last_struct_op: | 
					
						
							|  |  |  |     return "write_last_struct\t%f"; | 
					
						
							|  |  |  |   case unify_last_var_op: | 
					
						
							|  |  |  |     return "unify_last_var\t%v"; | 
					
						
							|  |  |  |   case unify_last_val_op: | 
					
						
							|  |  |  |     return "unify_last_val\t%v"; | 
					
						
							|  |  |  |   case unify_last_local_op: | 
					
						
							|  |  |  |     return "unify_last_local\t%v"; | 
					
						
							|  |  |  |   case unify_last_atom_op: | 
					
						
							|  |  |  |     return "unify_last_atom\t%a"; | 
					
						
							|  |  |  |   case unify_last_num_op: | 
					
						
							|  |  |  |     return "unify_last_num\t%n"; | 
					
						
							|  |  |  |   case unify_last_float_op: | 
					
						
							|  |  |  |      return "unify_last_float\t%w"; | 
					
						
							|  |  |  |   case unify_last_string_op: | 
					
						
							|  |  |  |      return "unify_last_string\t%S"; | 
					
						
							|  |  |  |   case unify_last_dbterm_op: | 
					
						
							|  |  |  |     return "unify_last_dbterm\t%w"; | 
					
						
							|  |  |  |   case unify_last_longint_op: | 
					
						
							|  |  |  |     return "unify_last_longint\t%w"; | 
					
						
							|  |  |  |   case unify_last_bigint_op: | 
					
						
							|  |  |  |     return "unify_last_bigint\t%l"; | 
					
						
							|  |  |  |   case ensure_space_op: | 
					
						
							|  |  |  |     return "ensure_space"; | 
					
						
							|  |  |  |   case native_op: | 
					
						
							|  |  |  |     return "native_code"; | 
					
						
							|  |  |  |   case f_var_op: | 
					
						
							|  |  |  |     return "function_to_var\t%v,%B"; | 
					
						
							|  |  |  |   case f_val_op: | 
					
						
							|  |  |  |     return "function_to_val\t%v,%B"; | 
					
						
							|  |  |  |   case f_0_op: | 
					
						
							|  |  |  |     return "function_to_0\t%B"; | 
					
						
							|  |  |  |   case align_float_op: | 
					
						
							|  |  |  |     return "align_float"; | 
					
						
							|  |  |  |   case fail_op: | 
					
						
							|  |  |  |     return "fail"; | 
					
						
							|  |  |  |   case cut_op: | 
					
						
							|  |  |  |     return "cut"; | 
					
						
							|  |  |  |   case cutexit_op: | 
					
						
							|  |  |  |     return "cutexit"; | 
					
						
							|  |  |  |   case allocate_op: | 
					
						
							|  |  |  |     return "allocate"; | 
					
						
							|  |  |  |   case deallocate_op: | 
					
						
							|  |  |  |     return "deallocate"; | 
					
						
							|  |  |  |   case tryme_op: | 
					
						
							|  |  |  |     return "try_me_else\t\t%l\t%x"; | 
					
						
							|  |  |  |   case jump_op: | 
					
						
							|  |  |  |     return "jump\t\t%l"; | 
					
						
							|  |  |  |   case jumpi_op: | 
					
						
							|  |  |  |     return "jump_in_indexing\t\t%i"; | 
					
						
							|  |  |  |   case procceed_op: | 
					
						
							|  |  |  |     return "proceed"; | 
					
						
							|  |  |  |   case call_op: | 
					
						
							|  |  |  |     return "call\t\t%p,%d,%z"; | 
					
						
							|  |  |  |   case execute_op: | 
					
						
							|  |  |  |     return "execute\t\t%p"; | 
					
						
							|  |  |  |   case safe_call_op: | 
					
						
							|  |  |  |     return "sys\t\t%p"; | 
					
						
							|  |  |  |   case label_op: | 
					
						
							|  |  |  |     return "%l:"; | 
					
						
							|  |  |  |   case name_op: | 
					
						
							|  |  |  |     return "name\t\t%m,%d"; | 
					
						
							|  |  |  |   case pop_op: | 
					
						
							|  |  |  |     return "pop\t\t%l"; | 
					
						
							|  |  |  |   case retryme_op: | 
					
						
							|  |  |  |     return "retry_me_else\t\t%l\t%x"; | 
					
						
							|  |  |  |   case trustme_op: | 
					
						
							|  |  |  |     return "trust_me_else_fail\t%x"; | 
					
						
							|  |  |  |   case either_op: | 
					
						
							|  |  |  |     return "either_me\t\t%l,%d,%z"; | 
					
						
							|  |  |  |   case orelse_op: | 
					
						
							|  |  |  |     return "or_else\t\t%l,%z"; | 
					
						
							|  |  |  |   case orlast_op: | 
					
						
							|  |  |  |     return "or_last"; | 
					
						
							|  |  |  |   case push_or_op: | 
					
						
							|  |  |  |     return "push_or"; | 
					
						
							|  |  |  |   case pop_or_op: | 
					
						
							|  |  |  |     return "pop_or"; | 
					
						
							|  |  |  |   case pushpop_or_op: | 
					
						
							|  |  |  |     return "pushpop_or"; | 
					
						
							|  |  |  |   case save_b_op: | 
					
						
							|  |  |  |     return "save_by\t\t%v"; | 
					
						
							|  |  |  |   case commit_b_op: | 
					
						
							|  |  |  |     return "commit_by\t\t%v"; | 
					
						
							|  |  |  |   case patch_b_op: | 
					
						
							|  |  |  |     return "patch_by\t\t%v"; | 
					
						
							|  |  |  |   case try_op: | 
					
						
							|  |  |  |     return "try\t\t%g\t%x"; | 
					
						
							|  |  |  |   case retry_op: | 
					
						
							|  |  |  |     return "retry\t\t%g\t%x"; | 
					
						
							|  |  |  |   case trust_op: | 
					
						
							|  |  |  |     return "trust\t\t%g\t%x"; | 
					
						
							|  |  |  |   case try_in_op: | 
					
						
							|  |  |  |     return "try_in\t\t%g\t%x"; | 
					
						
							|  |  |  |   case jump_v_op: | 
					
						
							|  |  |  |     return "jump_if_var\t\t%g"; | 
					
						
							|  |  |  |   case jump_nv_op: | 
					
						
							|  |  |  |     return "jump_if_nonvar\t\t%g"; | 
					
						
							|  |  |  |   case cache_arg_op: | 
					
						
							|  |  |  |     return "cache_arg\t%r"; | 
					
						
							|  |  |  |   case cache_sub_arg_op: | 
					
						
							|  |  |  |     return "cache_sub_arg\t%d"; | 
					
						
							|  |  |  |   case user_switch_op: | 
					
						
							|  |  |  |     return "user_switch"; | 
					
						
							|  |  |  |   case switch_on_type_op: | 
					
						
							|  |  |  |     return "switch_on_type\t%h\t%h\t%h\t%h"; | 
					
						
							|  |  |  |   case switch_c_op: | 
					
						
							|  |  |  |     return "switch_on_constant\t%i\n%c"; | 
					
						
							|  |  |  |   case if_c_op: | 
					
						
							|  |  |  |     return "if_constant\t%i\n%c"; | 
					
						
							|  |  |  |   case switch_f_op: | 
					
						
							|  |  |  |     return "switch_on_functor\t%i\n%e"; | 
					
						
							|  |  |  |   case if_f_op: | 
					
						
							|  |  |  |     return "if_functor\t%i\n%e"; | 
					
						
							|  |  |  |   case if_not_op: | 
					
						
							|  |  |  |     return "if_not_then\t%i\t%h\t%h\t%h"; | 
					
						
							|  |  |  |   case index_dbref_op: | 
					
						
							|  |  |  |     return "index_on_dbref"; | 
					
						
							|  |  |  |   case index_blob_op: | 
					
						
							|  |  |  |     return "index_on_blob"; | 
					
						
							|  |  |  |   case index_long_op: | 
					
						
							|  |  |  |     return "index_on_blob"; | 
					
						
							|  |  |  |   case index_string_op: | 
					
						
							|  |  |  |     return "index_on_string"; | 
					
						
							|  |  |  |   case 	if_nonvar_op: | 
					
						
							|  |  |  |     return "check_var\t %r"; | 
					
						
							|  |  |  |   case save_pair_op: | 
					
						
							|  |  |  |     return "save_pair\t%v"; | 
					
						
							|  |  |  |   case save_appl_op: | 
					
						
							|  |  |  |     return "save_appl\t%v"; | 
					
						
							|  |  |  |   case mark_initialised_pvars_op: | 
					
						
							|  |  |  |     return "pvar_bitmap\t%l,%b"; | 
					
						
							|  |  |  |   case mark_live_regs_op: | 
					
						
							|  |  |  |     return "pvar_live_regs\t%l,%b"; | 
					
						
							|  |  |  |   case fetch_args_vv_op: | 
					
						
							|  |  |  |     return "fetch_reg1_reg2\t%N,%N"; | 
					
						
							|  |  |  |   case fetch_args_cv_op: | 
					
						
							|  |  |  |     return "fetch_constant_reg\t%l,%N"; | 
					
						
							|  |  |  |   case fetch_args_vc_op: | 
					
						
							|  |  |  |     return "fetch_reg_constant\t%l,%N"; | 
					
						
							|  |  |  |   case fetch_args_iv_op: | 
					
						
							|  |  |  |     return "fetch_integer_reg\t%d,%N"; | 
					
						
							|  |  |  |   case fetch_args_vi_op: | 
					
						
							|  |  |  |     return "fetch_reg_integer\t%d,%N"; | 
					
						
							|  |  |  |   case enter_profiling_op: | 
					
						
							|  |  |  |     return "enter_profiling\t\t%g"; | 
					
						
							|  |  |  |   case retry_profiled_op: | 
					
						
							|  |  |  |     return "retry_profiled\t\t%g"; | 
					
						
							|  |  |  |   case count_call_op: | 
					
						
							|  |  |  |     return "count_call_op\t\t%g"; | 
					
						
							|  |  |  |   case count_retry_op: | 
					
						
							|  |  |  |     return "count_retry_op\t\t%g"; | 
					
						
							|  |  |  |   case restore_tmps_op: | 
					
						
							|  |  |  |     return "restore_temps\t\t%l"; | 
					
						
							|  |  |  |   case restore_tmps_and_skip_op: | 
					
						
							|  |  |  |     return "restore_temps_and_skip\t\t%l"; | 
					
						
							|  |  |  |   case enter_lu_op: | 
					
						
							|  |  |  |     return "enter_lu"; | 
					
						
							|  |  |  |   case empty_call_op: | 
					
						
							|  |  |  |     return "empty_call\t\t%l,%d"; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef YAPOR
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |   case sync_op: | 
					
						
							|  |  |  |     return "sync"; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif /* YAPOR */
 | 
					
						
							| 
									
										
										
										
											2003-11-07 16:31:08 +00:00
										 |  |  | #ifdef TABLING
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |   case table_new_answer_op: | 
					
						
							|  |  |  |     return "table_new_answer"; | 
					
						
							|  |  |  |   case table_try_single_op: | 
					
						
							|  |  |  |     return "table_try_single\t%g\t%x"; | 
					
						
							| 
									
										
										
										
											2003-11-07 16:31:08 +00:00
										 |  |  | #endif /* TABLING */
 | 
					
						
							|  |  |  | #ifdef TABLING_INNER_CUTS
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |   case "clause_with_cut": | 
					
						
							|  |  |  |     return clause_with_cut_op; | 
					
						
							| 
									
										
										
										
											2003-11-07 16:31:08 +00:00
										 |  |  | #endif /* TABLING_INNER_CUTS */
 | 
					
						
							| 
									
										
										
										
											2005-09-08 22:06:45 +00:00
										 |  |  | #ifdef BEAM
 | 
					
						
							|  |  |  |   "run_op %1,%4", | 
					
						
							|  |  |  |   "body_op %1", | 
					
						
							|  |  |  |   "endgoal_op", | 
					
						
							|  |  |  |   "try_me_op %1,%4", | 
					
						
							|  |  |  |   "retry_me_op %1,%4", | 
					
						
							|  |  |  |   "trust_me_op %1,%4", | 
					
						
							|  |  |  |   "only_1_clause_op %1,%4", | 
					
						
							|  |  |  |   "create_first_box_op %1,%4", | 
					
						
							|  |  |  |   "create_box_op %1,%4", | 
					
						
							|  |  |  |   "create_last_box_op %1,%4", | 
					
						
							|  |  |  |   "remove_box_op %1,%4", | 
					
						
							|  |  |  |   "remove_last_box_op %1,%4", | 
					
						
							|  |  |  |   "prepare_tries", | 
					
						
							|  |  |  |   "std_base_op %1,%4", | 
					
						
							|  |  |  |   "direct_safe_call", | 
					
						
							|  |  |  |   "skip_while_var_op", | 
					
						
							|  |  |  |   "wait_while_var_op", | 
					
						
							|  |  |  |   "force_wait_op", | 
					
						
							|  |  |  |   "write_op", | 
					
						
							|  |  |  |   "is_op", | 
					
						
							|  |  |  |   "equal_op", | 
					
						
							|  |  |  |   "exit", | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |   case fetch_args_for_bccall_op: | 
					
						
							|  |  |  |     return "fetch_args_for_bccall\t%v"; | 
					
						
							|  |  |  |   case bccall_op: | 
					
						
							|  |  |  |     return "binary_cfunc\t\t%v,%P"; | 
					
						
							|  |  |  |   case blob_op: | 
					
						
							|  |  |  |     return "blob\t%O"; | 
					
						
							|  |  |  |   case string_op: | 
					
						
							|  |  |  |     return "string\t%O"; | 
					
						
							|  |  |  |   case label_ctl_op: | 
					
						
							|  |  |  |     return "label_control\t"; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #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
 | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-06-19 15:05:46 +01:00
										 |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  | Yap_ShowCode (struct intermediates *cint) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-07 16:02:55 +00:00
										 |  |  |   CACHE_REGS | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   struct PSEUDO *cpc; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   cpc = cint->CodeStart; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   /* MkIntTerm and friends may build terms in the global stack */ | 
					
						
							| 
									
										
										
										
											2014-01-19 21:57:02 +00:00
										 |  |  |   HR = (CELL *)cint->freep; | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |   while (cpc) { | 
					
						
							|  |  |  |     compiler_vm_op ic = cpc->op; | 
					
						
							|  |  |  |     if (ic != nop_op) { | 
					
						
							| 
									
										
										
										
											2014-05-22 21:57:54 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     ShowOp (getFormat(ic), cpc); | 
					
						
							| 
									
										
										
										
											2004-01-23 02:23:51 +00:00
										 |  |  |     cpc = cpc->nextInst; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |   Yap_DebugErrorPutc ('\n'); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* DEBUG */
 | 
					
						
							|  |  |  | 
 |