Пример #1
0
		bool CLIPSFunctionPass::runOnFunction(llvm::Function& function) {
			if(!function.isDeclaration()) {
				void* env = getEnvironment();
				CLIPSEnvironment* clEnv = new CLIPSEnvironment(env);
				EnvReset(env);
				CLIPSPassHeader* header = (CLIPSPassHeader*)getIndirectPassHeader();
				char* passes = CharBuffer(strlen(header->getPasses()) + 64);
				sprintf(passes,"(passes %s)", header->getPasses());
				EnvAssertString(env, passes);
				free(passes);
				KnowledgeConstructor tmp;
				if(header->needsLoops() && header->needsRegions()) {
					llvm::LoopInfo& li = getAnalysis<LoopInfo>();
					llvm::RegionInfo& ri = getAnalysis<RegionInfo>();
					tmp.route(function, li, ri);
				} else if(header->needsLoops() && !header->needsRegions()) {
					llvm::LoopInfo& li = getAnalysis<LoopInfo>();
					tmp.route(function, li);
				} else if(header->needsRegions() && !header->needsLoops()) {
					llvm::RegionInfo& ri = getAnalysis<RegionInfo>();
					tmp.route(function, ri);
				} else {
					tmp.route(function);
				}
				clEnv->makeInstances((char*)tmp.getInstancesAsString().c_str());
				//TODO: put in the line to build the actual knowledge
				EnvRun(env, -1L);
				//it's up to the code in the expert system to make changes
				EnvReset(env);
				return true;
			} else {
				return false;
			}
		}
Пример #2
0
		bool CLIPSModulePass::runOnModule(llvm::Module& module) {
			//assume the environment has already been setup in one way or another.
			void* env = getEnvironment();		
			CLIPSEnvironment* clEnv = new CLIPSEnvironment(env);
			EnvReset(env);
			CLIPSPassHeader* header = (CLIPSPassHeader*)getIndirectPassHeader();
			char* passes = CharBuffer(strlen(header->getPasses()) + 64);
			sprintf(passes,"(passes %s)", header->getPasses());
			EnvAssertString(env, passes);
			free(passes);

			KnowledgeConstructor tmp;
			tmp.route(&module);
			clEnv->makeInstances((char*)tmp.getInstancesAsString().c_str());
			llvm::PassRegistry* registry = llvm::PassRegistry::getPassRegistry();
			llvm::PassManager manager;
			const llvm::PassInfo* ci = registry->getPassInfo(
					llvm::StringRef("function-to-knowledge"));
			ExpertSystem::FunctionKnowledgeConversionPass* copy = 
				(ExpertSystem::FunctionKnowledgeConversionPass*)ci->createPass();
			copy->setEnvironment(clEnv);
			copy->setSkipLoops(!header->needsLoops());
			copy->setSkipRegions(!header->needsRegions());
			manager.add(copy);
			//need to have the conversion code
			manager.run(module);
			//TODO: put in the line to build the actual knowledge
			EnvRun(env, -1L);
			//it's up to the code in the expert system to make changes
			EnvReset(env);
			return true;
		}
Пример #3
0
globle void ResetCommand(
  void *theEnv)
  {
   if (EnvArgCountCheck(theEnv,"reset",EXACTLY,0) == -1) return;
   EnvReset(theEnv);
   return;
  }
Пример #4
0
void ResetCommand(
  UDFContext *context,
  CLIPSValue *returnValue)
  {
   EnvReset(UDFContextEnvironment(context));
   return;
  }
Пример #5
0
bool ClipsRuleMgr::initialize(void *env, string sessionID)
{
		cout<<"ClipsRuleMgr::initialize 0"<<endl;
		getUserTemplateFiles();
		cout<<"ClipsRuleMgr::initialize 1"<<endl;
		m_theEnv = env;
		m_sessionID = sessionID;

		//rule files should use defmodule to group  T.B.D
				
		m_ruleFilesItor = m_ruleFiles.begin();
		while(m_ruleFilesItor!=m_ruleFiles.end())
		{
			EnvLoad(m_theEnv,string("./clp/" + *m_ruleFilesItor).c_str());
			cout<<"Rule Engine Initialize::load clp file:" <<*m_ruleFilesItor<<endl;
			m_ruleFilesItor++;
		}
		
		EnvReset(m_theEnv);
		
		getAllTemplatesFromClips();
		
		getTemplateFields();
		
		return true;
		
}
Пример #6
0
Common::Error AdventureEngineEngine::run() {
  _console = new Console(this);
  _timer->installTimerProc(interruptExpertSystem, 1000000 / 60, this, "clipsSlowDown"); 
  EnvReset(clipsEnv);
  EnvRun(clipsEnv, -1L);
  _timer->removeTimerProc(interruptExpertSystem);
  return Common::kNoError;
}
Пример #7
0
globle void ResetCommand(
  void *theEnv,
  EXEC_STATUS)
  {
   if (EnvArgCountCheck(theEnv,execStatus,"reset",EXACTLY,0) == -1) return;
   EnvReset(theEnv,execStatus);
   return;
  }
Пример #8
0
void ClipsSession::initialize(int argc,char *argv, string sessionID, RouterInterface *router)
#endif
{
	cout<<"ClipsSession::initialize 0 sessionID:"<<sessionID<<endl;
	m_sessionID = sessionID;
		cout<<"ClipsSession::initialize 1"<<endl;
	m_theEnv = CreateEnvironment();
	cout<<"ClipsSession::initialize 2"<<endl;
#ifdef _DEBUG_CLIPS_
    cout<<"ClipsSession::initialize 3"<<endl;

	if (ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").length() > 0)
	{
		fw.open(ConfigUtil::GetInstance()->GetConfigStr("CLIPSログ出力パス").c_str(), ios::out);
#if 1
		EnvWatch(m_theEnv,"globals");
		EnvWatch(m_theEnv, "rules");
		EnvWatch(m_theEnv, "facts");
		EnvWatch(m_theEnv,"activations");
		EnvWatch(m_theEnv,"focus");
		EnvWatch(m_theEnv,"deffunctions");
		EnvWatch(m_theEnv,"compilations");
#endif
		EnvAddRouter(m_theEnv,"DEBUG",999,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvAddRouter(m_theEnv,"wtrace",1000,queryFunction,printFunction,NULL,NULL,NULL);
		//EnvActivateRouter(m_theEnv,"wdialog");
		EnvActivateRouter(m_theEnv,"DEBUG");
#endif
#ifdef _PERFORMANCE_
		//for performance
		//EnvWatch(m_theEnv,"statistics");
#endif
	}

 #if 0
	char *tmp[1];
	tmp[0] = argv;
	RerouteStdin(m_theEnv,1,tmp);
#else
    if (router != NULL)
    {
        m_router = router;
        //const char *routerName=m_router->getRouterName().c_str();
        string routerName = m_router->getRouterName();
		EnvAddRouter(m_theEnv,routerName.c_str(),30,queryFunction,printFunction,NULL,NULL,NULL);
		EnvActivateRouter(m_theEnv, routerName.c_str());
    }
#endif	
	cout<<"ClipsSession::initialize 4"<<endl;	
	EnvReset(m_theEnv);

	
	cout<<"ClipsSession::initialize 5"<<endl;
	m_ruleMgr = new ClipsRuleMgr();
	if (m_ruleMgr != NULL) 
		m_ruleMgr->initialize(m_theEnv, m_sessionID);
}
Пример #9
0
		bool CLIPSBasicBlockPass::runOnBasicBlock(llvm::BasicBlock& bb) {
			void* env = getEnvironment();
			CLIPSEnvironment* clEnv = new CLIPSEnvironment(env);
			EnvReset(env);
			CLIPSPassHeader* header = (CLIPSPassHeader*)getIndirectPassHeader();
			char* passes = CharBuffer(strlen(header->getPasses()) + 64);
			sprintf(passes,"(passes %s)", header->getPasses());
			EnvAssertString(env, passes);
			free(passes);
			KnowledgeConstructor tmp;
			FunctionNamer namer;
			tmp.route(&bb, namer, (char*)"");
			clEnv->makeInstances((char*)tmp.getInstancesAsString().c_str());
			EnvRun(env, -1L);
			//it's up to the code in the expert system to make changes
			EnvReset(env);
			return true;
		}
Пример #10
0
		bool CLIPSRegionPass::runOnRegion(llvm::Region* region, llvm::RGPassManager& rg) {
			void* env = getEnvironment();
			CLIPSEnvironment* clEnv = new CLIPSEnvironment(env);
			EnvReset(env);
			CLIPSPassHeader* header = (CLIPSPassHeader*)getIndirectPassHeader();
			char* passes = CharBuffer(strlen(header->getPasses()) + 64);
			sprintf(passes,"(passes %s)", header->getPasses());
			EnvAssertString(env, passes);
			free(passes);
			KnowledgeConstructor tmp;
			FunctionNamer namer;
			tmp.route(region, namer, (char*)"");
			clEnv->makeInstances((char*)tmp.getInstancesAsString().c_str());
			//TODO: put in code to allow us to manipulate the RGPassManager
			EnvRun(env, -1L);
			//it's up to the code in the expert system to make changes
			EnvReset(env);
			return true;
		}
Пример #11
0
void EnvTrigger(Envelope *env) {

  if (env == NULL)
    return;

  if (env->envConfig == NULL)
    return;

  if (!env->envConfig->enabled)
    return;

  EnvReset(env);
  env->triggered = TRUE;
  env->hold = TRUE;
}
Пример #12
0
globle void Reset()
  {
   EnvReset(GetCurrentEnvironment());
  }  
Пример #13
0
globle void EnvClear(
  void *theEnv)
  {
   struct callFunctionItem *theFunction;
   
   /*==========================================*/
   /* Activate the watch router which captures */
   /* trace output so that it is not displayed */
   /* during a clear.                          */
   /*==========================================*/

#if DEBUGGING_FUNCTIONS
   EnvActivateRouter(theEnv,WTRACE);
#endif

   /*===================================*/
   /* Determine if a clear is possible. */
   /*===================================*/

   ConstructData(theEnv)->ClearReadyInProgress = TRUE;
   if ((ConstructData(theEnv)->ClearReadyLocks > 0) ||
       (ConstructData(theEnv)->DanglingConstructs > 0) ||
       (ClearReady(theEnv) == FALSE))
     {
      PrintErrorID(theEnv,"CONSTRCT",1,FALSE);
      EnvPrintRouter(theEnv,WERROR,"Some constructs are still in use. Clear cannot continue.\n");
#if DEBUGGING_FUNCTIONS
      EnvDeactivateRouter(theEnv,WTRACE);
#endif
      ConstructData(theEnv)->ClearReadyInProgress = FALSE;
      return;
     }
   ConstructData(theEnv)->ClearReadyInProgress = FALSE;

   /*===========================*/
   /* Call all clear functions. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = TRUE;

   for (theFunction = ConstructData(theEnv)->ListOfClearFunctions;
        theFunction != NULL;
        theFunction = theFunction->next)
     { 
      if (theFunction->environmentAware)
        { (*theFunction->func)(theEnv); }
      else            
        { (* (void (*)(void)) theFunction->func)(); }
     }

   /*=============================*/
   /* Deactivate the watch router */
   /* for capturing output.       */
   /*=============================*/

#if DEBUGGING_FUNCTIONS
   EnvDeactivateRouter(theEnv,WTRACE);
#endif

   /*===========================================*/
   /* Perform periodic cleanup if the clear was */
   /* issued from an embedded controller.       */
   /*===========================================*/

   if ((UtilityData(theEnv)->CurrentGarbageFrame->topLevel) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
       (EvaluationData(theEnv)->CurrentExpression == NULL) && (UtilityData(theEnv)->GarbageCollectionLocks == 0))
     {
      CleanCurrentGarbageFrame(theEnv,NULL);
      CallPeriodicTasks(theEnv);
     }

   /*===========================*/
   /* Clear has been completed. */
   /*===========================*/

   ConstructData(theEnv)->ClearInProgress = FALSE;
   
#if DEFRULE_CONSTRUCT
   if ((DefruleData(theEnv)->RightPrimeJoins != NULL) ||
       (DefruleData(theEnv)->LeftPrimeJoins != NULL))
     { SystemError(theEnv,"CONSTRCT",1); }
#endif

   /*============================*/
   /* Perform reset after clear. */
   /*============================*/
   
   EnvReset(theEnv);
  }
Пример #14
0
void __declspec(dllexport) CALL_CONV __EnvReset(
  void *theEnv)
  {
   EnvReset(theEnv);
  }
Пример #15
0
globle void Reset(EXEC_STATUS)
  {
   EnvReset(GetCurrentEnvironment(),GetCurrentExecutionStatus());
  }