/* * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign * code files and libraries and locates an initialization routine */ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc) { while (ofiles) { void *handle; /* mydlopen wants to follow the LD_CONFIG_PATH */ if (!Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE)) { strcpy(LOCAL_ErrorSay, "%% Trying to open unexisting file in LoadForeign"); return LOAD_FAILLED; } if((handle=mydlopen(LOCAL_FileNameBuf)) == 0) { fprintf(stderr,"calling dlopen with error %s\n", mydlerror()); /* strcpy(LOCAL_ErrorSay,dlerror());*/ return LOAD_FAILLED; } ofiles->handle = handle; ofiles = ofiles->next; } /* load libraries first so that their symbols are available to other routines */ while (libs) { char *s = AtomName(lib->name); if (ls[0] == '-') { strcpy(LOCAL_FileNameBuf,"lib"); strcat(LOCAL_FileNameBuf,s+2); strcat(LOCAL_FileNameBuf,".so"); } else { strcpy(LOCAL_FileNameBuf,s); } if((libs->handle=mydlopen(LOCAL_FileNameBuf)) == NULL) { strcpy(LOCAL_ErrorSay,mydlerror()); return LOAD_FAILLED; } libs = libs->next; } *init_proc = (YapInitProc) mydlsym(proc_name); if(! *init_proc) { strcpy(LOCAL_ErrorSay,"Could not locate initialization routine"); return LOAD_FAILLED; } return LOAD_SUCCEEDED; }
/* * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign * code files and libraries and locates an initialization routine */ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc) { while (ofiles) { HINSTANCE handle; if (Yap_TrueFileName(AtomName(ofiles->name), LOCAL_FileNameBuf, TRUE) && (handle=LoadLibrary(LOCAL_FileNameBuf)) != 0) { LOCAL_ErrorSay[0]=~'\0'; if (*init_proc == NULL) *init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name); } else { FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorSay, 256, NULL); } ofiles = ofiles->next; } /* load libraries first so that their symbols are available to other routines */ while (libs) { HINSTANCE handle; char * s = AtomName(libs->name); if (s[0] == '-') { strcat(LOCAL_FileNameBuf,s+2); strcat(LOCAL_FileNameBuf,".dll"); } else { strcpy(LOCAL_FileNameBuf,s); } if((handle=LoadLibrary(LOCAL_FileNameBuf)) == 0) { /* strcpy(LOCAL_ErrorSay,dlerror());*/ return LOAD_FAILLED; } if (*init_proc == NULL) *init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name); libs = libs->next; } if(*init_proc == NULL) { strcpy(LOCAL_ErrorSay,"Could not locate initialization routine"); return LOAD_FAILLED; } return LOAD_SUCCEEDED; }
/* * Here we initialize the arguments indexing */ YAP_Int p_udi_args_init(Term spec, int arity, UdiInfo blk) { int i; Term arg; Atom idxtype; UdiControlBlock *cb; struct udi_p_args p_arg; for (i = 1; i <= arity; i++) { arg = ArgOfTerm(i,spec); if (IsAtomTerm(arg)) { idxtype = AtomOfTerm(arg); if (idxtype == AtomMinus) //skip this argument continue; p_arg.control = NULL; cb = NULL; while ((cb = (UdiControlBlock *) utarray_next(indexing_structures, cb))) { if (idxtype == (*cb)->decl){ p_arg.arg = i; p_arg.control = *cb; p_arg.idxstr = (*cb)->init(spec, i, arity); utarray_push_back(blk->args, &p_arg); } } if (p_arg.control == NULL){ /* not "-" and not found */ fprintf(stderr, "Invalid Spec (%s)\n", AtomName(idxtype)); return FALSE; } } } return TRUE; }
static Int p_frequencyty1( USES_REGS1 ) { // this predicate works only 'SMART_JIT' and 'CONTINUOUS_COMPILATION' modes if (ExpEnv.config_struc.execution_mode == SMART_JIT || ExpEnv.config_struc.execution_mode == CONTINUOUS_COMPILATION) { Term t = Deref(ARG1); // valid value for ARG1 is just 'atom' if (IsAtomTerm(t)) { // ARG1 is atom int i = 0, j = 0; char *tmp; // gets string from atom and stores it on 'str' char *str = (char*)malloc(YAP_AtomNameLength(AtomOfTerm(t))*sizeof(char)); strcpy(str, AtomName(AtomOfTerm(t))); // Makes upper characters of 'str' (for comparison) UPPER_ENTRY(str); // Detectng frequency type according to 'str' if (strcmp(str, "COUNTER") == 0 || strcmp(str, "COUNT") == 0) { ExpEnv.config_struc.frequency_type = COUNTER; // setting frequency type to 'counter' ExpEnv.config_struc.frequency_bound = 1024.0; // if 'counter', frequency bound is '1024.0' return TRUE; } else if (strcmp(str, "TIME") == 0 || strcmp(str, "TIMING") == 0) { ExpEnv.config_struc.frequency_type = TIME; // setting frequency type to 'time' ExpEnv.config_struc.frequency_bound = 0.02; // if 'time', frequency bound is '0.02' return TRUE; } else { // value passed by argument is out of known range Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } } else { // ARG1 is not an atom Yap_NilError(INVALID_PARAMETER_TYPE_ERROR,"Frequency type"); return FALSE; } } else { // current execution mode differs of 'SMART_JIT' and 'CONTINUOUS_COMPILATION' Yap_NilError(INCOMPATIBLEMODE_WARNING,""); return FALSE; } }
/* * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign * code files and libraries and locates an initialization routine */ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc) { extern char *sys_errlist[ ]; /* load wants to follow the LIBRARY_PATH */ if (ofiles->next != NULL || libs != NULL) { strcpy(LOCAL_ErrorSay," Load Failed: in AIX you must load a single object file"); return LOAD_FAILLED; } if (!Yap_AbsoluteFileInBuffer(AtomName(ofiles->name), LOCAL_FileNameBuf, YAP_FILENAME_MAX, true)) { strcpy(LOCAL_ErrorSay, " Trying to open unexisting file in LoadForeign "); return LOAD_FAILLED; } /* In AIX, just call load and everything will go in */ if ((*init_proc=((YapInitProc *)load(LOCAL_FileNameBuf,0,NULL))) == NULL) { strcpy(LOCAL_ErrorSay,sys_errlist[errno]); return LOAD_FAILLED; } return LOAD_SUCCEEDED; }
/* Return a list of files for a directory */ static Int list_directory(USES_REGS1) { Term tf = MkAtomTerm(Yap_LookupAtom("[]")); yhandle_t sl = Yap_InitSlot(tf); VFS_t *vfsp; char *buf = (char *)AtomName(AtomOfTerm(ARG1)); if ((vfsp = vfs_owner(buf))) { void *de; const char *dp; if ((de = vfsp->opendir(vfsp, buf)) == NULL) { PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory", strerror(errno)); } while ((dp = vfsp->nextdir( de))) { YAP_Term ti = MkAtomTerm(Yap_LookupAtom(dp)); Yap_PutInHandle(sl, MkPairTerm(ti, Yap_GetFromHandle(sl))); } vfsp->closedir( de); } else { #if defined(__MINGW32__) || _MSC_VER struct _finddata_t c_file; char bs[BUF_SIZE]; long hFile; bs[0] = '\0'; #if HAVE_STRNCPY strncpy(bs, buf, BUF_SIZE); #else strcpy(bs, buf); #endif #if HAVE_STRNCAT strncat(bs, "/*", BUF_SIZE); #else strcat(bs, "/*"); #endif if ((hFile = _findfirst(bs, &c_file)) == -1L) { return (Yap_unify(ARG2, tf)); } Yap_PutInSlot(sl, MkPairTerm(MkAtomTerm(Yap_LookupAtom(c_file.name)), Yap_GetFromSlot(sl))); while (_findnext(hFile, &c_file) == 0) { Term ti = MkAtomTerm(Yap_LookupAtom(c_file.name)); Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl))); } _findclose(hFile); #elif HAVE_OPENDIR { DIR *de; struct dirent *dp; if ((de = opendir(buf)) == NULL) { PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory", strerror(errno)); return false; } while ((dp = readdir(de))) { Term ti = MkAtomTerm(Yap_LookupAtom(dp->d_name)); Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl))); } closedir(de); } #endif /* HAVE_OPENDIR */ } tf = Yap_GetFromSlot(sl); return Yap_unify(ARG2, tf); }
static Int p_table( USES_REGS1 ) { Term mod, t, list; PredEntry *pe; Atom at; int arity; tab_ent_ptr tab_ent; #ifdef MODE_DIRECTED_TABLING int* mode_directed = NULL; #endif /* MODE_DIRECTED_TABLING */ mod = Deref(ARG1); t = Deref(ARG2); list = Deref(ARG3); if (IsAtomTerm(t)) { at = AtomOfTerm(t); pe = RepPredProp(PredPropByAtom(at, mod)); arity = 0; } else if (IsApplTerm(t)) { at = NameOfFunctor(FunctorOfTerm(t)); pe = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod)); arity = ArityOfFunctor(FunctorOfTerm(t)); } else return (FALSE); if (list != TermNil) { /* non-empty list */ #ifndef MODE_DIRECTED_TABLING Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "invalid tabling declaration for %s/%d (mode directed tabling not enabled)", AtomName(at), arity); return(FALSE); #else /************************************************************************************* The mode operator declaration is reordered as follows: 1. arguments with mode 'index' (any number) 2. arguments with mode 'min' and 'max' (any number, following the original order) 3. arguments with mode 'all' (any number) 4. arguments with mode 'sum' or 'last' (only one of the two is allowed) 5. arguments with mode 'first' (any number) *************************************************************************************/ int pos_index = 0; int pos_min_max = 0; int pos_all = 0; int pos_sum_last = 0; int pos_first = 0; int i; int *aux_mode_directed; aux_mode_directed = malloc(arity * sizeof(int)); for (i = 0; i < arity; i++) { int mode = IntOfTerm(HeadOfTerm(list)); if (mode == MODE_DIRECTED_INDEX) pos_index++; else if (mode == MODE_DIRECTED_MIN || mode == MODE_DIRECTED_MAX) pos_min_max++; else if (mode == MODE_DIRECTED_ALL) pos_all++; else if (mode == MODE_DIRECTED_SUM || mode == MODE_DIRECTED_LAST) { if (pos_sum_last) { free(aux_mode_directed); Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "invalid tabling declaration for %s/%d (more than one argument with modes 'sum' and/or 'last')", AtomName(at), arity); return(FALSE); } else pos_sum_last = 1; } aux_mode_directed[i] = mode; list = TailOfTerm(list); } pos_first = pos_index + pos_min_max + pos_all + pos_sum_last; pos_sum_last = pos_index + pos_min_max + pos_all; pos_all = pos_index + pos_min_max; pos_min_max = pos_index; pos_index = 0; ALLOC_BLOCK(mode_directed, arity * sizeof(int), int); for (i = 0; i < arity; i++) { int aux_pos = 0; if (aux_mode_directed[i] == MODE_DIRECTED_INDEX) aux_pos = pos_index++; else if (aux_mode_directed[i] == MODE_DIRECTED_MIN || aux_mode_directed[i] == MODE_DIRECTED_MAX) aux_pos = pos_min_max++; else if (aux_mode_directed[i] == MODE_DIRECTED_ALL) aux_pos = pos_all++; else if (aux_mode_directed[i] == MODE_DIRECTED_SUM || aux_mode_directed[i] == MODE_DIRECTED_LAST) aux_pos = pos_sum_last++; else if(aux_mode_directed[i] == MODE_DIRECTED_FIRST) aux_pos = pos_first++; mode_directed[aux_pos] = MODE_DIRECTED_SET(i, aux_mode_directed[i]); } free(aux_mode_directed); #endif /* MODE_DIRECTED_TABLING */ }
static Int LoadForeign( StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc ) { /* *init_proc is initialized to NULL in load_foreign.c */ int init_missing = -1; int n, i; struct shl_symbol *p; while( ofiles ) { int valid_fname; /* shl_load wants to follow the LD_CONFIG_PATH */ const char *file = AtomName(ofiles->name); valid_fname = Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true); if( !valid_fname ) { strcpy( LOCAL_ErrorSay, "%% Trying to open non-existing file in LoadForeign" ); return LOAD_FAILLED; } ofiles->handle = Yap_AllocCodeSpace( sizeof(shl_t) ); *(shl_t *)ofiles->handle = shl_load( LOCAL_FileNameBuf, BIND_DEFERRED, 0 ); if( *(shl_t *)ofiles->handle == NULL ) { strncpy( LOCAL_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE ); return LOAD_FAILLED; } if( init_missing ) { init_missing = shl_findsym( ofiles->handle, proc_name, TYPE_PROCEDURE, init_proc ); } ofiles = ofiles->next; } if( init_missing ) { strcpy( LOCAL_ErrorSay, "Could not locate initialization routine" ); return LOAD_FAILLED; } while( libs ) { char *s = AtomName(lib->s); if( s[0] == '-' ) { strcpy( LOCAL_FileNameBuf, "lib" ); strcat( LOCAL_FileNameBuf, s+2 ); strcat( LOCAL_FileNameBuf, ".sl" ); } else { strcpy( LOCAL_FileNameBuf, s ); } *(shl_t *)libs->handle = shl_load( LOCAL_FileNameBuf, BIND_DEFERRED, 0 ); if( *(shl_t *)libs->handle == NULL ) { strncpy( LOCAL_ErrorSay, strerror(errno), MAX_ERROR_MSG_SIZE ); return LOAD_FAILLED; } libs = libs->next; } return LOAD_SUCCEEDED; }
/* * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign * code files and libraries and locates an initialization routine */ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, YapInitProc *init_proc) { char command[2*MAXPATHLEN]; char o_files[1024]; /* list of objects we want to load */ char l_files[1024]; /* list of libraries we want to load */ char tmp_buff[32] = "/tmp/YAP_TMP_XXXXXX"; /* used for mktemp */ char *tfile; /* name of temporary file */ int fildes; /* temp file descriptor */ struct aouthdr sysHeader; struct filehdr fileHeader; struct scnhdr sectionHeader[MAXSECTIONS]; struct exec header; /* header for loaded file */ unsigned long loadImageSize, firstloadImSz; /* size of image we will load */ char *FCodeBase; /* where we load foreign code */ /* * put in a string the names of the files you want to load and of any * libraries you want to use */ /* files first */ *o_files = '\0'; { StringList tmp = ofiles; while(tmp != NULL) { strcat(o_files," "); strcat(o_files,AtomName(tmp->name)); tmp = tmp->next; } } /* same_trick for libraries */ *l_files = '\0'; { StringList tmp = libs; while(tmp != NULL) { strcat(l_files," "); strcat(l_files,AtomName(tmp->name)); tmp = tmp->next; } } /* next, create a temp file to serve as loader output */ tfile = mktemp(tmp_buff); /* prepare the magic */ if (strlen(o_files) + strlen(l_files) + strlen(proc_name) + strlen(GLOBAL_Executable) > 2*MAXPATHLEN) { strcpy(LOCAL_ErrorSay, " too many parameters in load_foreign/3 "); return LOAD_FAILLED; } sprintf(command, "/usr/bin/ld -N -A %s -o %s %s %s -lc", GLOBAL_Executable, tfile, o_files, l_files); /* now, do the magic */ if (system(command) != 0) { unlink(tfile); strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files "); return LOAD_FAILLED; } /* now check the music has played */ if ((fildes = open(tfile, O_RDONLY)) < 0) { strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files "); return LOAD_FAILLED; } /* it did, get the mice */ /* first, get the header */ read(fildes, (char *) &fileHeader, sizeof(fileHeader)); read(fildes, (char *) &sysHeader, sizeof(sysHeader)); { int i; for (i = 0; i < fileHeader.f_nscns; i++) read(fildes, (char *) §ionHeader[i], sizeof(*sectionHeader)); } close(fildes); /* get the full size of what we need to load */ loadImageSize = sysHeader.tsize + sysHeader.dsize + sysHeader.bsize; #ifdef mips /* add an extra page in mips machines */ loadImageSize += 4095 + 16; #else /* add 16 just to play it safe */ loadImageSize += 16; #endif /* keep this copy */ firstloadImSz = loadImageSize; /* now fetch the space we need */ if (!(FCodeBase = Yap_AllocCodeSpace((int) loadImageSize)) #ifdef pyr || activate_code(ForeignCodeBase, u1) #endif /* pyr */ ) { strcpy(LOCAL_ErrorSay," unable to allocate space for external code "); return LOAD_FAILLED; } #ifdef mips FCodeBase = (char *) (Unsigned(FCodeBase + PAGESIZE - 1) & ~(PAGESIZE - 1)); #endif /* now, a new incantation to load the new foreign code */ #ifdef convex /* No -N flag in the Convex loader */ /* -T option does not want MallocBase bit set */ sprintf(command, "ld -x -A %s -T %lx -o %s -u %s %s %s -lc", ostabf, ((unsigned long) (((unsigned long) (ForeignCodeBase)) & ((unsigned long) (~Yap_HeapBase)) ) ), tfile, entry_point, o_files, l_files); #else #ifdef mips sprintf(command, "ld -systype bsd43 -N -A %s -T %lx -o %s -u %s %s %s -lc", ostabf, (unsigned long) ForeignCodeBase, tfile, entry_point, o_files, l_files); #else sprintf(command, "ld -N -A %s -T %lx -o %s -e %s -u _%s %s -lc", ostabf, (unsigned long) ForeignCodeBase, tfile, entry_point, o_files, l_files); #endif /* mips */ #endif /* convex */ /* and do it */ if (system(command) != 0) { unlink(tfile); strcpy(LOCAL_ErrorSay," ld returned error status in load_foreign_files "); return LOAD_FAILLED; } if ((fildes = open(tfile, O_RDONLY)) < 0) { strcpy(LOCAL_ErrorSay," unable to open temp file in load_foreign_files "); return LOAD_FAILLED; } read(fildes, (char *) &fileHeader, sizeof(fileHeader)); read(fildes, (char *) &sysHeader, sizeof(sysHeader)); { int i; for (i = 0; i < fileHeader.f_nscns; i++) read(fildes, (char *) §ionHeader[i], sizeof(*sectionHeader)); } loadImageSize = sysHeader.tsize + sysHeader.dsize + sysHeader.bsize; if (firstloadImSz < loadImageSize) { strcpy(LOCAL_ErrorSay," miscalculation in load_foreign/3 "); return LOAD_FAILLED; } /* now search for our init function */ { char entry_fun[256]; struct nlist func_info[2]; #if defined(mips) || defined(I386) char NAME1[128], NAME2[128]; func_info[0].n_name = NAME1; func_info[1].n_name = NAME2; #endif /* COFF */ sprintf(entry_fun, "_%s", proc_name); func_info[0].n_name = entry_fun; func_info[1].n_name = NULL; if (nlist(tfile, func_info) == -1) { strcpy(LOCAL_ErrorSay," in nlist(3) "); return LOAD_FAILLED; } if (func_info[0].n_type == 0) { strcpy(LOCAL_ErrorSay," in nlist(3) "); return LOAD_FAILLED; } *init_proc = (YapInitProc)(func_info[0].n_value); } /* ok, we got our init point */ /* now read our text */ lseek(fildes, (long)(N_TXTOFF(header)), 0); { unsigned int u1 = header.a_text + header.a_data; read(fildes, (char *) FCodeBase, u1); /* zero the BSS segment */ while (u1 < loadImageSize) FCodeBase[u1++] = 0; } close(fildes); unlink(tfile); return LOAD_SUCCEEDED; }
static Int p_execution_mode( USES_REGS1 ) { enumExecModes mode; // valid values for ARG1 are 'integer' and 'atom' Term t = Deref(ARG1); if (IsIntTerm(t)) { // ARG1 is integer Int v = IntOfTerm(t); if (v < 0 || v > 3) { // value passed by argument is out of known range (valid values are: 0 -- interpreted; 1 -- smart jit; 2 -- continuous compilation; 3 -- just compiled) Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } // storing mode mode = (enumExecModes)v; } else if (IsAtomTerm(t)) { // ARG1 is atom int i = 0, j = 0; char *tmp; // gets string from atom and stores it on 'str' char *str = (char*)malloc(YAP_AtomNameLength(AtomOfTerm(t))*sizeof(char)); strcpy(str, AtomName(AtomOfTerm(t))); // Makes upper characters of 'str' (for comparison) UPPER_ENTRY(str); // Detecting mode according to 'str' if (strcmp(str, "INTERPRETED") == 0) mode = JUST_INTERPRETED; else if (strcmp(str, "SMARTJIT") == 0) mode = SMART_JIT; else if (strcmp(str, "CONTINUOUSCOMPILATION") == 0) mode = CONTINUOUS_COMPILATION; else if (strcmp(str, "JUSTCOMPILED") == 0) mode = JUST_COMPILED; else { // value passed by argument is out of known range Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } } else { // ARG1 is not an integer or atom Yap_NilError(INVALID_PARAMETER_TYPE_ERROR,"Execution mode"); return FALSE; } // setting execution mode ExpEnv.config_struc.execution_mode = mode; /* setting execution mode parameters */ switch (mode) { case JUST_INTERPRETED: { if (Yap_ExecutionMode == INTERPRETED) { // execution mode only can be 'JUST_INTERPRETED' if 'Yap_ExecutionMode == INTERPRETED' (passing -J0 on command line) // 'JUST_INTERPRETED' does not use these parameters ExpEnv.config_struc.frequency_type = NO_FREQ; ExpEnv.config_struc.frequency_bound = 0.0; ExpEnv.config_struc.profiling_startp = 0.0; ExpEnv.config_struc.mainclause_ty = UNUSED; ExpEnv.config_struc.compilation_threads = 0; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," YAP Execution mode changed to INTERPRETED!!\n"); #endif } else { // 'Yap_ExecutionMode' is not compatible Yap_NilError(INCOMPATIBLE_CODEMODE_WARNING,"INTERPRETED"); return FALSE; } } break; case SMART_JIT: { if (Yap_ExecutionMode == MIXED_MODE) { // execution mode only can be 'SMART_JIT' if 'Yap_ExecutionMode == MIXED_MODE' (passing -J1 on command line) ExpEnv.config_struc.frequency_type = COUNTER; ExpEnv.config_struc.frequency_bound = 1024.0; ExpEnv.config_struc.profiling_startp = 0.72; ExpEnv.config_struc.mainclause_ty = HOT_AND_CALLEE; ExpEnv.config_struc.compilation_threads = 0; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," YAP Execution mode changed to SMART JIT!!\n"); #endif } else { // 'Yap_ExecutionMode' is not compatible Yap_NilError(INCOMPATIBLE_CODEMODE_WARNING,"SMART JIT"); return FALSE; } } break; case CONTINUOUS_COMPILATION: { if (Yap_ExecutionMode == MIXED_MODE) { // execution mode only can be 'CONTINUOUS_COMPILATION' if 'Yap_ExecutionMode == MIXED_MODE' (passing -J1 on command line) ExpEnv.config_struc.frequency_type = COUNTER; ExpEnv.config_struc.frequency_bound = 1024.0; ExpEnv.config_struc.profiling_startp = 0.72; ExpEnv.config_struc.mainclause_ty = HOT_AND_CALLEE; ExpEnv.config_struc.compilation_threads = ExpEnv.config_struc.ncores-1; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," YAP Execution mode changed to CONTINUOUS COMPILATION!!\n"); #endif } else { // 'Yap_ExecutionMode' is not compatible Yap_NilError(INCOMPATIBLE_CODEMODE_WARNING,"CONTINUOUS COMPILATION"); return FALSE; } } break; case JUST_COMPILED: { if (Yap_ExecutionMode == COMPILED) { // execution mode only can be 'JUST_COMPILED' if 'Yap_ExecutionMode == COMPILED' (passing -J2 on command line) // 'JUST_COMPILED' does not use these parameters ExpEnv.config_struc.frequency_type = NO_FREQ; ExpEnv.config_struc.frequency_bound = 0.0; ExpEnv.config_struc.profiling_startp = 0.0; ExpEnv.config_struc.mainclause_ty = UNUSED; ExpEnv.config_struc.compilation_threads = 0; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," YAP Execution mode changed to JUST COMPILED!!\n"); #endif } else { // 'Yap_ExecutionMode' is not compatible Yap_NilError(INCOMPATIBLE_CODEMODE_WARNING,"JUST COMPILED"); return FALSE; } } break; } /***/ return TRUE; }
static Int p_main_clause_ty( USES_REGS1 ) { // this predicate works only 'SMART_JIT' and 'CONTINUOUS_COMPILATION' modes if (ExpEnv.config_struc.execution_mode == SMART_JIT || ExpEnv.config_struc.execution_mode == CONTINUOUS_COMPILATION) { Term t = Deref(ARG1); // valid values for ARG1 are 'integer' and 'atom' if (IsIntTerm(t)) { // ARG1 is integer Int v; v = IntOfTerm(t); if (v < 0 || v > 3) { // value passed by argument is out of known range Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) { switch(v) { case 0: fprintf(stderr," Type of main clause was changed to JUST HOT!!\n"); break; case 1: fprintf(stderr," Type of main clause was changed to HOT AND CALLEE!!\n"); break; case 2: fprintf(stderr," Type of main clause was changed to HOT AND GREATER!!\n"); break; case 3: fprintf(stderr," Type of main clause was changed to HOT AND FEWER!!\n"); break; } } #endif // setting 'mainclause_ty' -- I should de add '1' because the first enum of 'enumMainClauseType' is 'UNUSED', used just for control ExpEnv.config_struc.mainclause_ty = (enumMainClauseType)(v+1); return TRUE; } else if (IsAtomTerm(t)) { // ARG1 is atom enumMainClauseType v; int i = 0, j = 0; char *tmp; // gets string from atom and stores it on 'str' char *str = (char*)malloc(YAP_AtomNameLength(AtomOfTerm(t))*sizeof(char)); strcpy(str, AtomName(AtomOfTerm(t))); // Makes upper characters of 'str' (for comparison) UPPER_ENTRY(str); // Detecting mainclause type chosen by user according to 'str' if (strcmp(str, "JUSTHOT") == 0) { v = JUST_HOT; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," Type of main clause was changed to JUST HOT!!\n"); #endif } else if (strcmp(str, "HOTANDCALLEE") == 0) { v = HOT_AND_CALLEE; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," Type of main clause was changed to HOT AND CALLEE!!\n"); #endif } else if (strcmp(str, "HOTANDGREATER") == 0) { v = HOT_AND_GREATER; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," Type of main clause was changed to HOT AND GREATER!!\n"); #endif } else if (strcmp(str, "HOTANDFEWER") == 0) { v = HOT_AND_FEWER; #if YAP_DBG_PREDS if (ExpEnv.debug_struc.act_predicate_msgs.success_msgs) fprintf(stderr," Type of main clause was changed to HOT AND FEWER!!\n"); #endif } else { // value passed by argument is out of known range Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } ExpEnv.config_struc.mainclause_ty = v; return TRUE; } else { // ARG1 is not an integer or atom Yap_NilError(INVALID_PARAMETER_TYPE_ERROR,"main_clause_ty/1 (1st arg)"); return FALSE; } } else { // current execution mode differs of 'SMART_JIT' and 'CONTINUOUS_COMPILATION' Yap_NilError(INCOMPATIBLEMODE_WARNING,""); return FALSE; } }
static Int p_frequencyty2( USES_REGS1 ) { // this predicate works only 'SMART_JIT' and 'CONTINUOUS_COMPILATION' modes if (ExpEnv.config_struc.execution_mode == SMART_JIT || ExpEnv.config_struc.execution_mode == CONTINUOUS_COMPILATION) { Term t = Deref(ARG1); // valid value for ARG1 is just 'atom' if (IsAtomTerm(t)) { Term u = Deref(ARG2); // valid values for ARG2 are 'integer' and 'float' if (IsIntTerm(u) || IsFloatTerm(u)) { // ARG1 is atom and ARG2 is integer or float int i = 0, j = 0; char *tmp; // getting string from atom and stores it on 'str' char *str = (char*)malloc(YAP_AtomNameLength(AtomOfTerm(t))*sizeof(char)); strcpy(str, AtomName(AtomOfTerm(t))); // Making upper characters of 'str' (for comparison) UPPER_ENTRY(str); // getting ARG2 value Float v; if (IsIntTerm(u)) v = (Float)IntOfTerm(u); if (IsFloatTerm(u)) v = FloatOfTerm(u); // setting 'frequency type' and 'frequency bound' if 'COUNTER' if (strcmp(str, "COUNTER") == 0 || strcmp(str, "COUNT") == 0) { if (v < 20.0) { // Very low frequency bound to apply on 'COUNTER' fprintf(stderr,"%.2f is a very low value for the active frequency type. Reconsider its value...\n", v); return FALSE; } ExpEnv.config_struc.frequency_type = COUNTER; ExpEnv.config_struc.frequency_bound = roundf(v); return TRUE; } // setting 'frequency type' and 'frequency bound' if 'TIME' else if (strcmp(str, "TIME") == 0 || strcmp(str, "TIMING") == 0) { if (v <= 0.0 || v > 0.49) { // Very low frequency bound to apply on 'COUNTER' fprintf(stderr,"%.2f is an invalid or a very high value for the active frequency type. Reconsider its value...\n", v); return FALSE; } ExpEnv.config_struc.frequency_type = TIME; ExpEnv.config_struc.frequency_bound = v; return TRUE; } else { // value passed by argument (ARG1) is out of known range Yap_Error(OUT_OF_KNOWNRANGE_ERROR,t,""); return FALSE; } } else { // ARG2 is not an 'integer' or 'float' Yap_NilError(INVALID_PARAMETER_TYPE_ERROR,"frequencyty/2 (2nd arg)"); return FALSE; } } else { // ARG1 is not an atom Yap_NilError(INVALID_PARAMETER_TYPE_ERROR,"frequencyty/2 (1st arg)"); return FALSE; } } else { // current execution mode differs of 'SMART_JIT' and 'CONTINUOUS_COMPILATION' Yap_NilError(INCOMPATIBLEMODE_WARNING,""); return FALSE; } }