Exemplo 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;
			}
		}
Exemplo 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;
		}
Exemplo n.º 3
0
	CharBuffer Manager::read(const char* path)	{
		FILE *const fi = fopen( modPath(path), "rb" );
		if(!fi)
			return CharBuffer();
		fseek(fi,0,SEEK_END);
		const int len = ftell(fi);
		fseek(fi,0,SEEK_SET);
		CharBuffer text = new Array<char>(len+1);
		fread( text->base, len,1,fi );
		text->base[len] = '\0';
		fclose(fi);
		return text;
	}
void CLIPSExtractValueInstructionBuilder::addFields(ExtractValueInst* inst, KnowledgeConstruction *kc, char* parent) {
   CLIPSUnaryInstructionBuilder::addFields((UnaryInstruction*)inst, kc, parent);
   addField("AggregateOperand", kc->route(inst->getAggregateOperand(), getNamer()));
   openField("Indices");
   for(ExtractValueInst::idx_iterator i = inst->idx_begin(), e = inst->idx_end();
         i != e; ++i) {
      char* buf = CharBuffer(32);
      sprintf(buf, "%d", *i);
      appendValue(buf);
      free(buf);
   }
   closeField();
}
Exemplo n.º 5
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;
		}
Exemplo n.º 6
0
 llvm::Module* LLVMIRCompiler::interpret() {
    void* theEnv = getEnvironment()->getEnvironment();
    DATA_OBJECT arg1;
    char* tmp;
    char* persist;
    if((EnvArgTypeCheck(theEnv, (char*)"rampancy-interpret", 2, 
                STRING, &arg1) == 0)) {
       EnvPrintRouter(theEnv, (char*)"werror",
             (char*)"\nInput was not a string!\n");
       return 0;
    }
    tmp = DOToString(arg1);
    persist = CharBuffer(strlen(tmp) + 1);
    sprintf(persist, "%s", tmp);
    llvm::StringRef code(persist);
    llvm::Module* result = interpret(code);
    free(persist);
    return result;
 }
Exemplo n.º 7
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;
		}
Exemplo n.º 8
0
 llvm::Module* LLVMIRCompiler::compile() {
    DATA_OBJECT arg1;
    char* persist;
    //this one is a little different we need to only extract a file name out
    void* theEnv = getEnvironment()->getEnvironment();
    if((EnvArgTypeCheck(theEnv, (char*)"rampancy-compile", 2,
                SYMBOL_OR_STRING, &arg1) == 0)) {
       EnvPrintRouter(theEnv, 
             (char*)"werror",
             (char*)"\nSecond argument to the IR parser is neither a string"
             " or symbol!\n");
       return 0;
    }
    char* tmp = DOToString(arg1);
    persist = CharBuffer(strlen(tmp) + 1);
    sprintf(persist, "%s", tmp);
    const std::string fileName (persist);
    llvm::SMDiagnostic err;
    llvm::Module* mod = compile(fileName, err);
    free(persist);
    return mod;
 }
Exemplo n.º 9
0
/* $ANTLR 2.7.4: "nexilang.g" -> "NexiLexer.cpp"$ */
#include "indri/NexiLexer.hpp"
#include <antlr/CharBuffer.hpp>
#include <antlr/TokenStreamException.hpp>
#include <antlr/TokenStreamIOException.hpp>
#include <antlr/TokenStreamRecognitionException.hpp>
#include <antlr/CharStreamException.hpp>
#include <antlr/CharStreamIOException.hpp>
#include <antlr/NoViableAltForCharException.hpp>

ANTLR_BEGIN_NAMESPACE(indri)
ANTLR_BEGIN_NAMESPACE(lang)
#line 1 "nexilang.g"
#line 13 "NexiLexer.cpp"
NexiLexer::NexiLexer(ANTLR_USE_NAMESPACE(std)istream& in)
	: ANTLR_USE_NAMESPACE(antlr)CharScanner(new ANTLR_USE_NAMESPACE(antlr)CharBuffer(in),true)
{
	initLiterals();
}

NexiLexer::NexiLexer(ANTLR_USE_NAMESPACE(antlr)InputBuffer& ib)
	: ANTLR_USE_NAMESPACE(antlr)CharScanner(ib,true)
{
	initLiterals();
}

NexiLexer::NexiLexer(const ANTLR_USE_NAMESPACE(antlr)LexerSharedInputState& state)
	: ANTLR_USE_NAMESPACE(antlr)CharScanner(state,true)
{
	initLiterals();
}