Ejemplo n.º 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;
			}
		}
Ejemplo n.º 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;
		}
Ejemplo n.º 3
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;
		}
Ejemplo n.º 4
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;
		}
Ejemplo n.º 5
0
globle void AssertStringFunction(
    void *theEnv,
    DATA_OBJECT_PTR returnValue)
{
    DATA_OBJECT argPtr;
    struct fact *theFact;

    /*===================================================*/
    /* Set the default return value to the symbol FALSE. */
    /*===================================================*/

    SetpType(returnValue,SYMBOL);
    SetpValue(returnValue,EnvFalseSymbol(theEnv));

    /*=====================================================*/
    /* Check for the correct number and type of arguments. */
    /*=====================================================*/

    if (EnvArgCountCheck(theEnv,"assert-string",EXACTLY,1) == -1) return;

    if (EnvArgTypeCheck(theEnv,"assert-string",1,STRING,&argPtr) == FALSE)
    {
        return;
    }

    /*==========================================*/
    /* Call the driver routine for converting a */
    /* string to a fact and then assert it.     */
    /*==========================================*/

    theFact = (struct fact *) EnvAssertString(theEnv,DOToString(argPtr));
    if (theFact != NULL)
    {
        SetpType(returnValue,FACT_ADDRESS);
        SetpValue(returnValue,(void *) theFact);
    }

    return;
}