Esempio n. 1
0
Error Context::removeUnreachableCode() {
  PodList<Node*>::Link* link = _unreachableList.getFirst();
  Node* stop = getStop();

  while (link != NULL) {
    Node* node = link->getValue();
    if (node != NULL && node->getPrev() != NULL) {
      // Locate all unreachable nodes.
      Node* first = node;
      do {
        if (node->isFetched())
          break;
        node = node->getNext();
      } while (node != stop);

      // Remove.
      if (node != first) {
        Node* last = (node != NULL) ? node->getPrev() : getCompiler()->getLastNode();
        getCompiler()->removeNodes(first, last);
      }
    }

    link = link->getNext();
  }

  return kErrorOk;
}
Esempio n. 2
0
Error Context::compile(FuncNode* func) {
  Node* end = func->getEnd();
  Node* stop = end->getNext();

  _func = func;
  _stop = stop;
  _extraBlock = end;

  ASMJIT_PROPAGATE_ERROR(fetch());
  ASMJIT_PROPAGATE_ERROR(removeUnreachableCode());
  ASMJIT_PROPAGATE_ERROR(livenessAnalysis());

  Compiler* compiler = getCompiler();

#if !defined(ASMJIT_DISABLE_LOGGER)
  if (compiler->hasLogger())
    ASMJIT_PROPAGATE_ERROR(annotate());
#endif // !ASMJIT_DISABLE_LOGGER

  ASMJIT_PROPAGATE_ERROR(translate());

  if (compiler->hasFeature(kCodeGenEnableScheduler))
    ASMJIT_PROPAGATE_ERROR(schedule());

  // We alter the compiler cursor, because it doesn't make sense to reference
  // it after compilation - some nodes may disappear and it's forbidden to add
  // new code after the compilation is done.
  compiler->_setCursor(NULL);

  return kErrorOk;
}
  void printShortResults(const MatrixType& matrix, IterationType& iter, const SolverOptions& options)
  {
    const double elapsed = getTime() - startTime;
    const char d = ':';

    std::cout.precision(5);
    std::cout.setf(std::ios::fixed);
    std::cout << d;
    std::cout << "lib=desola" << d;
    std::cout << "mat=" << getLeaf(options.getFile()) << d;
    std::cout << "mat_n=" << num_cols(matrix) << d;
    std::cout << "compiler=" << getCompiler() << d;
    std::cout << "code_cache=" << getStatus(configManager.codeCachingEnabled()) << d;
    std::cout << "fusion=" << getStatus(configManager.loopFusionEnabled()) << d;
    std::cout << "contraction=" << getStatus(configManager.arrayContractionEnabled()) << d;
    std::cout << "liveness=" << getStatus(configManager.livenessAnalysisEnabled()) << d;
    std::cout << "iterations=" << iter.iterations() << d;
    std::cout << "compile_time=" << statsCollector.getCompileTime() << d;
    std::cout << "compile_count=" << statsCollector.getCompileCount() << d;
    std::cout << "total_time=" << elapsed << d;
    std::cout << "flop=" << statsCollector.getFlops() << d;
    std::cout << "high_level_fusion=" << getStatus(configManager.highLevelFusionEnabled()) << d;
    std::cout << "single_for_loop_sparse=" << getStatus(configManager.singleForLoopSparseIterationEnabled()) << d;
    std::cout << "specialise_sparse=" << getStatus(configManager.sparseSpecialisationEnabled()) << d;

    if (options.useSparse())
      std::cout << "nnz=" << nnz(matrix) << d;

    std::cout << std::endl;
  }
  void printLongResults(const MatrixType& matrix, IterationType& iter, const SolverOptions& options)
  {
    const double elapsed = getTime() - startTime;
    std::cout.precision(5);
    std::cout.setf(std::ios::fixed);
    std::cout << "Library: desola" << std::endl;
    std::cout << "Matrix: " << getLeaf(options.getFile()) << std::endl;
    std::cout << "Matrix Size: " << num_cols(matrix) << std::endl;
    std::cout << "Compiler: " << getCompiler() << std::endl;
    std::cout << "Code Caching: " << getStatus(configManager.codeCachingEnabled()) << std::endl;
    std::cout << "Loop Fusion: " << getStatus(configManager.loopFusionEnabled()) << std::endl;
    std::cout << "Array Contraction: " << getStatus(configManager.arrayContractionEnabled()) << std::endl;
    std::cout << "Iterations: " << iter.iterations() << std::endl;
    std::cout << "Liveness Analysis: " << getStatus(configManager.livenessAnalysisEnabled()) << std::endl;
    std::cout << "Time per Iteration: " << elapsed / iter.iterations() << " seconds" << std::endl;
    std::cout << "Compile Time: " << statsCollector.getCompileTime() << " seconds" << std::endl;
    std::cout << "Compile Count: " << statsCollector.getCompileCount() << std::endl;
    std::cout << "Total Time: " << elapsed << " seconds" << std::endl;
    std::cout << "FLOPs: " << statsCollector.getFlops() << std::endl;
    std::cout << "High-Level Fusion: " << getStatus(configManager.highLevelFusionEnabled()) << std::endl;
    std::cout << "Single For-Loop Sparse Iteration: " << getStatus(configManager.singleForLoopSparseIterationEnabled()) << std::endl;
    std::cout << "Sparse Row Length Specialisation: " << getStatus(configManager.sparseSpecialisationEnabled()) << std::endl;

    if (options.useSparse())
      std::cout << "NNZ: " << nnz(matrix) << std::endl;

    if (configManager.livenessAnalysisEnabled())
      std::cout << std::endl << "Warning: FLOPs figure may be misleading with liveness analysis enabled." << std::endl;
  }
Esempio n. 5
0
	TranslationUnit::TranslationUnit(NodeManager& mgr, const path& file, const ConversionSetup& setup)
	    : mMgr(mgr), mFileName(file), setup(setup), mClang(setup, file), mSema(mPragmaList, mClang.getPreprocessor(), mClang.getASTContext(), emptyCons, true) {
		// check for frontend extensions pragma handlers
		// and add user provided pragmas to be handled
		// by insieme
		std::map<std::string, clang::PragmaNamespace*> pragmaNamespaces;
		for(auto extension : setup.getExtensions()) {
			for(auto ph : extension->getPragmaHandlers()) {
				std::string name = ph->getName();
				// if the pragma namespace is not registered already
				// create and register it and store it in the map of pragma namespaces
				if(pragmaNamespaces.find(name) == pragmaNamespaces.end()) {
					pragmaNamespaces[name] = new clang::PragmaNamespace(name);
					mClang.getPreprocessor().AddPragmaHandler(pragmaNamespaces[name]);
				}
				// add the user provided pragma handler
				pragmaNamespaces[name]->AddPragma(pragma::PragmaHandlerFactory::CreatePragmaHandler<pragma::Pragma>(
				    mClang.getPreprocessor().getIdentifierInfo(ph->getKeyword()), *ph->getToken(), ph->getName(), ph->getFunction()));
			}
		}

		parseClangAST(mClang, &emptyCons, mSema);

		// all pragmas should now have either a decl or a stmt attached.
		// it can be the case that a pragma is at the end of a file
		// and therefore not attached to anything. Find these cases
		// and attach the pragmas to the translation unit declaration.
		for(auto cur : mPragmaList) {
			if(!cur->isStatement() && !cur->isDecl()) { cur->setDecl(getCompiler().getASTContext().getTranslationUnitDecl()); }
		}

		if(mClang.getDiagnostics().hasErrorOccurred()) {
			// errors are always fatal
			throw ClangParsingError(mFileName);
		}

		if(setup.hasOption(ConversionSetup::DumpClangAST)) {
			const std::string filter = setup.getClangASTDumpFilter();
			auto tuDecl = getASTContext().getTranslationUnitDecl();
			// if nothing defined print the whole context
			if(filter.empty()) {
				tuDecl->dumpColor();
			} else {
				// else filter out the right function decls
				auto declCtx = clang::TranslationUnitDecl::castToDeclContext(tuDecl);
				// iterate through the declarations inside and print (maybe)
				for(auto it = declCtx->decls_begin(); it != declCtx->decls_end(); ++it) {
					if(const clang::FunctionDecl* funDecl = llvm::dyn_cast<clang::FunctionDecl>(*it)) {
						if(boost::regex_match(funDecl->getNameAsString(), boost::regex(filter))) { funDecl->dumpColor(); }
					}
				}
			}
		}
	}
Esempio n. 6
0
Error Context::removeUnreachableCode() {
  Compiler* compiler = getCompiler();

  PodList<HLNode*>::Link* link = _unreachableList.getFirst();
  HLNode* stop = getStop();

  while (link != nullptr) {
    HLNode* node = link->getValue();
    if (node != nullptr && node->getPrev() != nullptr && node != stop) {
      // Locate all unreachable nodes.
      HLNode* first = node;
      do {
        if (node->isFetched())
          break;
        node = node->getNext();
      } while (node != stop);

      // Remove unreachable nodes that are neither informative nor directives.
      if (node != first) {
        HLNode* end = node;
        node = first;

        // NOTE: The strategy is as follows:
        // 1. The algorithm removes everything until it finds a first label.
        // 2. After the first label is found it removes only removable nodes.
        bool removeEverything = true;
        do {
          HLNode* next = node->getNext();
          bool remove = node->isRemovable();

          if (!remove) {
            if (node->isLabel())
              removeEverything = false;
            remove = removeEverything;
          }

          if (remove) {
            ASMJIT_TSEC({
              this->_traceNode(this, node, "[REMOVED UNREACHABLE] ");
            });
            compiler->removeNode(node);
          }

          node = next;
        } while (node != end);
      }
Esempio n. 7
0
TranslationUnit::TranslationUnit(NodeManager& mgr, const path& file,  const ConversionSetup& setup)
	: mMgr(mgr), mFileName(file), setup(setup), mClang(setup, file),  
		mSema(mPragmaList, mClang.getPreprocessor(), mClang.getASTContext(), emptyCons, true) 
	{

	// check for frontend extensions pragma handlers
	// and add user provided pragmas to be handled
	// by insieme
	std::map<std::string,clang::PragmaNamespace *> pragmaNamespaces;
	for(auto extension : setup.getExtensions()) {
		for(auto ph : extension->getPragmaHandlers()) {
			std::string name = ph->getName();
			// if the pragma namespace is not registered already
			// create and register it and store it in the map of pragma namespaces
			if(pragmaNamespaces.find(name) == pragmaNamespaces.end()) {
				pragmaNamespaces[name] = new clang::PragmaNamespace(name);
				mClang.getPreprocessor().AddPragmaHandler(pragmaNamespaces[name]);
			}
			// add the user provided pragma handler
			pragmaNamespaces[name]->AddPragma(pragma::PragmaHandlerFactory::CreatePragmaHandler<pragma::Pragma>(
														mClang.getPreprocessor().getIdentifierInfo(ph->getKeyword()),
														*ph->getToken(), ph->getName(), ph->getFunction()));

		}
	}

	parseClangAST(mClang, &emptyCons, mSema);

    // all pragmas should now have either a decl or a stmt attached.
    // it can be the case that a pragma is at the end of a file
    // and therefore not attached to anything. Find these cases
    // and attach the pragmas to the translation unit declaration.
    for(auto cur : mPragmaList) {
        if(!cur->isStatement() && !cur->isDecl()) {
            cur->setDecl(getCompiler().getASTContext().getTranslationUnitDecl());
        }
    }

	if(mClang.getDiagnostics().hasErrorOccurred()) {
		// errors are always fatal
		throw ClangParsingError(mFileName);
	}
}
Esempio n. 8
0
bool ShaderD3D::compile(const std::string &source)
{
    uncompile();

    void *compiler = getCompiler();

    compileToHLSL(compiler, source);

    if (mType == GL_VERTEX_SHADER)
    {
        parseAttributes(compiler);
    }

    parseVaryings(compiler);

    if (mType == GL_FRAGMENT_SHADER)
    {
        std::sort(mVaryings.begin(), mVaryings.end(), compareVarying);

        const std::string &hlsl = getTranslatedSource();
        if (!hlsl.empty())
        {
            mActiveOutputVariables = *GetShaderVariables(ShGetOutputVariables(compiler));
            FilterInactiveVariables(&mActiveOutputVariables);
        }
    }

#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
    mDebugInfo += std::string("// ") + GetShaderTypeString(mType) + " SHADER BEGIN\n";
    mDebugInfo += "\n// GLSL BEGIN\n\n" + source + "\n\n// GLSL END\n\n\n";
    mDebugInfo += "// INITIAL HLSL BEGIN\n\n" + getTranslatedSource() + "\n// INITIAL HLSL END\n\n\n";
    // Successive steps will append more info
#else
    mDebugInfo += getTranslatedSource();
#endif

    return !getTranslatedSource().empty();
}
Esempio n. 9
0
Error Context::removeUnreachableCode() {
  Compiler* compiler = getCompiler();

  PodList<HLNode*>::Link* link = _unreachableList.getFirst();
  HLNode* stop = getStop();

  while (link != NULL) {
    HLNode* node = link->getValue();
    if (node != NULL && node->getPrev() != NULL && node != stop) {
      // Locate all unreachable nodes.
      HLNode* first = node;
      do {
        if (node->isFetched())
          break;
        node = node->getNext();
      } while (node != stop);

      // Remove unreachable nodes that are neither informative nor directives.
      if (node != first) {
        HLNode* end = node;
        node = first;
        do {
          HLNode* next = node->getNext();
          if (!node->isInformative() && node->getType() != kHLNodeTypeAlign) {
            ASMJIT_TLOG("[%05d] Unreachable\n", node->getFlowId());
            compiler->removeNode(node);
          }
          node = next;
        } while (node != end);
      }
    }

    link = link->getNext();
  }

  return kErrorOk;
}
Esempio n. 10
0
/*
 * This method will initialize the JVM. If there is already an active JVM
 * running, it will just attach to it. If there isn't an active JVM, it will
 * create and start a new one
 */
void Runtime::initializeJVM() throw( HLA::RTIinternalError )
{
	logger->debug( "Initialize the JVM" );

	///////////////////////////////////////////
	// 1. get the classpath and library path //
	///////////////////////////////////////////
	pair<string,string> paths = this->generatePaths();
	logger->debug( "Using Classpath   : %s", paths.first.c_str() );
	logger->debug( "Using Library Path: %s", paths.second.c_str() );

	/////////////////////////////////////////////
	// 2. check to see if a JVM already exists //
	/////////////////////////////////////////////
	// other jvm options - remember to increment the option array size
	// if you are going to add more
	string stackSize( "-Xss8m" );
	string mode = getMode();
	string compiler = getCompiler();
	string hlaVersion = getHlaVersion();
	string architecture = getArch();
	
	// before we can create or connect to the JVM, we need to specify its environment
	JavaVMInitArgs vmargs;
	JavaVMOption options[7];
	options[0].optionString = const_cast<char*>(paths.first.c_str());
	options[1].optionString = const_cast<char*>(paths.second.c_str());
	options[2].optionString = const_cast<char*>(mode.c_str());         // build mode
	options[3].optionString = const_cast<char*>(compiler.c_str());     // compiler version
	options[4].optionString = const_cast<char*>(hlaVersion.c_str());   // hla interface version
	options[5].optionString = const_cast<char*>(architecture.c_str()); // architecture
	options[6].optionString = const_cast<char*>(stackSize.c_str());
	vmargs.nOptions = 7;
	vmargs.version = JNI_VERSION_1_6;
	vmargs.options = options;
	vmargs.ignoreUnrecognized = JNI_TRUE;

	// Before we create the JVM, we will check to see if one already exists or
	// not. If there is an existing one, we will just attach to it rather than
	// creating a separate one.
	jint result;
	jsize jvmCount = 0;
	result = JNI_GetCreatedJavaVMs( &jvm, 1, &jvmCount );
	if( this->jvm != NULL && jvmCount > 0 && result == JNI_OK )
	{
		///////////////////////////////////////////////////////////////
		// JVM already exists, just attach to the existing reference //
		///////////////////////////////////////////////////////////////
		logger->debug( "[check] JVM already exists, attaching to it" );
		result = jvm->AttachCurrentThread( (void**)&jvmenv, &vmargs );
		// check the result
		if( result < 0 )
		{
			logger->fatal( "*** JVM already existed, but we failed to attach ***" );
			logger->fatal( "    result=%d", result );
			throw HLA::RTIinternalError( "*** JVM already existed, but we failed to attach ***" );
		}

		// we're all attached just fine, so let's get out of here
		this->attached = true;
		return;
	}

	//////////////////////////////////
	// 3. create a new JVM instance //
	//////////////////////////////////
	// JVM doesn't exist yet, create a new one to work with
	logger->debug( "[check] JVM doesn't exist, creating a new one" );
	result = JNI_CreateJavaVM( &jvm, (void**)&jvmenv, &vmargs );

	if( result < 0 )
	{
		logger->fatal( "*** Couldn't create a new JVM! *** result=%d", result );
		throw HLA::RTIinternalError( "*** Couldn't create a new JVM! ***" );
	}

	logger->info( "New JVM has been created" );
}
Esempio n. 11
0
void EasySFML::install(){

    if (checkConfig()){

        SetColor(DARKGREEN);

        string version;
        bool ok=true;
        string finalpath;
        string command = "";

        // Final Path
        if(ok){

            SetColor(DARKGREEN);
            cout << "# Enter where you want to install sfml:" << endl;
            cout << "# ex: C:/" << endl;
            SetColor(WHITE);
            cout << "SFML path >> " ;
            getline(cin, finalpath);
            cout << endl;

            if (finalpath != ""){
                finalpath = clean_path(finalpath);
                if (!dirExist(finalpath)){
                    SetColor(RED);
                    cout << "ERROR: Impossible to find folder '" << finalpath << "' ."<< endl << endl;
                    SetColor(WHITE);
                    ok = false;
                }
            }
            else{
                SetColor(RED);
                cout << "ERROR: Impossible to find folder '" << finalpath << "' ."<< endl << endl;
                SetColor(WHITE);
                ok = false;
            }
        }

        if (ok){
            SetColor(DARKGREEN);
            cout << "# Enter the sfml version to install." << endl;
            cout << "# ex: 1" << endl;

            XMLNode xMainNode=XMLNode::openFileHelper("conf/version.xml","PMML");
            XMLNode xversions=xMainNode.getChildNode("versions");
            int n=xversions.nChildNode("version");
            for (int i = 0; i < n;i++ ){
                XMLNode xversion =xversions.getChildNode("version",i);
                cout << i << " : " << xversion.getChildNode("name").getText() << endl;
            }

            SetColor(WHITE);
            cout << "Version >> " ;
            getline(cin, version);
            cout << endl;

            int i = atoi(version.c_str());
            if (!(i >= 0 && i < n) || version == ""){
                ok = false;
                SetColor(RED);
                cout << "ERROR: Impossible to choose version '" << version << "' ."<< endl << endl;
                SetColor(WHITE);
            }
            else{
               // _compilertype = version;
               int i = atoi(version.c_str());
                XMLNode xversion =xversions.getChildNode("version",i);
                string sfmlPath = xversion.getChildNode("path").getText();
                if (!dirExist(sfmlPath)){
                    cout << "Create new dir: '"<< sfmlPath <<"'" << endl;
                    if (!dirExist("download/versions/")) mkdir("download/versions/");
                    mkdir(sfmlPath.c_str());

                }

                if (!fileExist(xversion.getChildNode("zip").getText())){
                    cout << "Download: "<< xversion.getChildNode("url").getText() << "..." << endl;
                    get_http_data(xversion.getChildNode("url").getText(),xversion.getChildNode("zip").getText());
                }



                cout << "Delete: "<< xversion.getChildNode("src").getText() << "..." << endl;
                command = xversion.getChildNode("src").getText();
                command = "rd /s /q \""+command+"\"";
                system( command.c_str() );
                cout << "Unzip: "<< xversion.getChildNode("zip").getText() << "..." << endl;
                extract_zip(xversion.getChildNode("path").getText(),xversion.getChildNode("zip").getText());

                // Compilation
                string mainpath = GetPath();
                string compiler = getCompiler();
                string src_sfml = xversion.getChildNode("src").getText();

                command = "";
                command += "cd " + src_sfml + " && ";
                command += "set PATH=\""+_compilerpath +"bin/\";%PATH%" + " && ";
                command += "set PATH=\""+_cmakepath +"bin/\";%PATH%" + " && ";
                command += "cmake -G \""+compiler+"\" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=TRUE \"" + mainpath+"/"+src_sfml + "\" && ";
                command += "mingw32-make &&";
                command += "cmake -G \""+compiler+"\" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=TRUE \"" + mainpath+"/"+src_sfml + "\" && ";
                command += "mingw32-make && ";
                command += "cmake -G \""+compiler+"\" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=FALSE \"" + mainpath+"/"+src_sfml + "\" && ";
                command += "mingw32-make && ";
                command += "cmake -G \""+compiler+"\" -D CMAKE_BUILD_TYPE=Debug -D BUILD_SHARED_LIBS=FALSE \"" + mainpath+"/"+src_sfml + "\" && ";
                command += "mingw32-make";
                //cout << command << endl;
                int resCMD = system(command.c_str());

                if (resCMD == 0 && errno == 0)
                {
                    cout << "Finalize installation..." << endl;
                    command = xversion.getChildNode("name").getText();
                    command = "xcopy  \""+ mainpath+"/"+src_sfml +"\" \""+finalpath+"/"+command+"\" /s /e /y /i";
                    cout << command << endl;
                    system(command.c_str());

                    cout << endl << "Installation complete." << endl;
                }
                else{
                    SetColor(RED);
                    cout << "ERROR: Impossible to cmake or compile." << endl;
                    SetColor(WHITE);
                }



            }
        }

    }



}
Esempio n. 12
0
int main(int argc, char* arg[]){

	char* compiler;		/* the compiler - from enviroment flag "DMD" */
	char* cmd_arg_case;	/* additional arguments - from the testcase file */
	char* buffer;		/* general purpose buffer */
	size_t bufferLen;
	int index;
	int modus;		/* test modus: RUN NORUN COMPILE NOCOMPILE */
	char* case_file;
	int case_result;
	int torture_result[sizeof(torture)/sizeof(char*)];
	char* torture_block_global;
	char* torture_block_case;
	char* torture_require;
	char* error_file;	/* expected sourcefile containing the error */
	char* error_line;	/* expected error line */
	char* gdb;		/* the debugger - from environment flag "GDB" */
	char* gdb_script;	/* gdb command sequence */
	char* gdb_pattern_raw;	/* POSIX regexp expected in GDB's output */
#ifdef REG_EXTENDED
	regex_t* gdb_pattern;
#endif

	compiler	= NULL;
	cmd_arg_case	= NULL;
	buffer		= NULL;
	bufferLen 	= 0;
	modus 		= -1;
	case_file 	= NULL;
	torture_block_global	= NULL;
	torture_block_case	= NULL;
	torture_require	= NULL;
	error_file 	= NULL;
	error_line 	= NULL;
	gdb		= NULL;
	gdb_script	= NULL;
	gdb_pattern_raw = NULL;
#ifdef REG_EXTENDED
	gdb_pattern 	= NULL;
#endif

	/* check arguments */
	if(argc != 3){
err:
		fprintf(stderr, "DStress test executer (revision 1083)\n"
			"Copyright by Thomas Kuehne <*****@*****.**> 2005, 2006\n"
			"\n");

		if(argc!=0){
			fprintf(stderr,
				"%s <run|norun|compile|nocompile> <source>\n",
				arg[0]);
		}else{
			fprintf(stderr,
				"dstress <run|norun|compile|nocompile>"
				" <source>\n");
		}

		fprintf(stderr, "\n"
		"== eniroment settings (usually $NAME or %%NAME%%)  ==\n"
		"* DMD                - compiler (including standard arguments)\n"
		"* GDB                - debugger (including standard arguments)\n");
		fprintf(stderr, "\n"
		"== case setting (line in the case source) ==\n"
		"* __DSTRESS_DFLAGS__ - additional compiler arguments\n"
		"only evaluated if it is a \"nocompile\" or \"norun\" test:\n"
		"* __DSTRESS_ELINE__  - expected source line to throw an error message\n"
		"* __DSTRESS_EFILE__  - expected source file to throw an error message\n"
		"                       (defaults to the case file)\n");
		fprintf(stderr,
		"only evaluated if it is a \"run\" or \"norun\" test:\n"
		"* __GDB_SCRIPT__     - command sequence to feed to the debugger\n"
		"                       (use \\n to encode a line break)\n"
		"* __GDB_PATTERN__    - expected regular expression in the debugger's\n"
		"                       output\n");
		fprintf(stderr, "\n"
		"== note ==\n"
		"* the current directory is required to contain the sub-directory \"obj\"\n"
		"  (used for temporary files)\n"
		);
		exit(EXIT_FAILURE);
	}

	modus = 0;
	if(0==strncmp(arg[1], TORTURE_PREFIX, strlen(TORTURE_PREFIX))){
		modus |= MODE_TORTURE;
		arg[1] += strlen(TORTURE_PREFIX);
	}
	if(0==strcmp(arg[1], "run")){
		modus |= MODE_RUN;
	}else if(0==strcmp(arg[1], "norun")){
		modus |= MODE_NORUN;
	}else if(0==strcmp(arg[1], "compile")){
		modus |= MODE_COMPILE;
	}else if(0==strcmp(arg[1], "nocompile")){
		modus |= MODE_NOCOMPILE;
	}else{
		goto err;
	}

	/* gen flags */
	case_file = cleanPathSeperator(arg[2]);
	compiler = getCompiler();
	gdb = getGDB();
	torture_block_global = getTortureBlock();
	buffer = loadFile(case_file, &bufferLen);
	bufferLen = 0;

	cmd_arg_case =  cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_DFLAGS__"));
	error_line = getCaseFlag(buffer, "__DSTRESS_ELINE__");
	error_file =  cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_EFILE__"));
	gdb_script = getCaseFlag(buffer, "__GDB_SCRIPT__");
	gdb_pattern_raw = getCaseFlag(buffer, "__GDB_PATTERN__");
	torture_block_case = getCaseFlag(buffer, "__DSTRESS_TORTURE_BLOCK__");
	torture_require = getCaseFlag(buffer, "__DSTRESS_TORTURE_REQUIRE__");

	free(buffer);

	/* tmp_dir */
	if(!cmd_arg_case || !cmd_arg_case[0]){
		tmp_dir = TMP_DIR;
	}else{
		pid_t pid;
		pid = getpid();
		bufferLen = strlen(TMP_DIR) + 4 + sizeof(pid_t) * 4;
		buffer = (char*) malloc(bufferLen);
		snprintf(buffer, bufferLen, "%s/_%X", TMP_DIR, pid);
		tmp_dir = cleanPathSeperator(buffer);
		if(mkdir(tmp_dir, 0770)){
			fprintf(stderr, "failed to create tmp dir: %s (%d, %s)\n",
					tmp_dir, errno, strerror(errno));
			return EXIT_FAILURE;
		}
	}

	/* set implicit source file */
	if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){
		error_file=case_file;
	}

	/* gdb pattern */
#ifdef REG_EXTENDED
	if(gdb_pattern_raw!=NULL && gdb_pattern_raw[0]!='\x00'){

		gdb_pattern = (regex_t*) malloc(sizeof(regex_t));
		if(regcomp(gdb_pattern, gdb_pattern_raw, REG_EXTENDED | REG_NOSUB)){
			fprintf(stderr, "failed to compile regular expression:"
				"\n\t%s\n", gdb_pattern_raw);
			exit(EXIT_FAILURE);
		}else if(gdb_script==NULL){
			fprintf(stderr, "GDB pattern without GDB script\n");
			exit(EXIT_FAILURE);
		}
	}else{
		gdb_pattern = NULL;
	}

	/* gdb script */
	if(gdb_script!=NULL && gdb_script[0]!='\x00'){
		if(gdb_pattern==NULL){
			fprintf(stderr, "GDB script without GDB pattern\n");
			exit(EXIT_FAILURE);
		}
		buffer=gdb_script;
		for(; *buffer; buffer++){
			if(buffer[0]=='\\'){
				if(buffer[1]=='n'){
					buffer[0]=' ';
					buffer[1]='\n';
				}
				buffer++;
			}
		}

		bufferLen = strlen(gdb_script)+11;
		buffer = (char*) malloc(bufferLen);
		snprintf(buffer, bufferLen, "%s\n\nquit\ny\n\n", gdb_script);
		gdb_script=buffer;
	}else if(gdb_script){
		free(gdb_script);
		gdb_script = NULL;
	}

#else

	if(gdb_script && strlen(gdb_script)){
		if(gdb_pattern_raw && strlen(gdb_pattern_raw)){
			fprintf(stderr, "WARNING: GDB/regex support inactive\n");
		}else{
			fprintf(stderr, "GDB script without GDB pattern\n");
			exit(EXIT_FAILURE);
		}
	}else if(gdb_pattern_raw && strlen(gdb_pattern_raw)){
		fprintf(stderr, "GDB pattern without GDB script\n");
		exit(EXIT_FAILURE);
	}

#endif /* REG_EXTENDED else */

#ifdef DEBUG
	fprintf(stderr, "case    : \"%s\"\n", case_file);
	fprintf(stderr, "compiler: \"%s\"\n", compiler);
	fprintf(stderr, "DFLAGS C: \"%s\"\n", cmd_arg_case);
	fprintf(stderr, "ELINE   : \"%s\"\n", error_line);
	fprintf(stderr, "EFILE   : \"%s\"\n", error_file);
#ifdef REG_EXTENDED
	fprintf(stderr, "GDB Scri: \"%s\"\n", gdb_script);
	fprintf(stderr, "GDB Patt: \"%s\"\n", gdb_pattern_raw);
#endif
	fprintf(stderr, "block G : \"%s\"\n", torture_block_global);
	fprintf(stderr, "block C : \"%s\"\n", torture_block_case);
	fprintf(stderr, "modus   : %x\n", modus);
#endif


	/* let's get serious */
#ifdef USE_WINDOWS
	originalStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	originalStderr = GetStdHandle(STD_ERROR_HANDLE);
#endif

	if(modus & MODE_TORTURE){
		if((modus & (MODE_COMPILE | MODE_NOCOMPILE))
			&& (modus & (MODE_RUN | MODE_NORUN)))
		{
			fprintf(stderr, "BUG: unhandled torture modus %x\n", modus);
			exit(EXIT_FAILURE);
		}else if(!(modus & (MODE_COMPILE | MODE_NOCOMPILE | MODE_RUN | MODE_NORUN))){
			fprintf(stderr, "BUG: unhandled torture modus %x\n", modus);
			exit(EXIT_FAILURE);
		}

		bufferLen = strlen(torture[(sizeof(torture) / sizeof(char*))-1])
			+ 128 + strlen(cmd_arg_case) + 3;

		if(torture_block_case!=NULL && strlen(torture_block_case)<1){
			torture_block_case=NULL;
		}

		buffer = (char*) malloc(bufferLen);
		for(index=0; index < sizeof(torture)/sizeof(char*); index++){
			if((torture_block_global && strstr(torture[index], torture_block_global))
				|| (torture_block_case && strstr(torture[index], torture_block_case))
				|| (torture_require && !strstr(torture[index], torture_require)))
			{
				torture_result[index]=RES_UNTESTED;
				continue;
			}

			buffer[0]=0;
			snprintf(buffer, bufferLen, "%s %s", torture[index], cmd_arg_case);

			if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){
				torture_result[index] = target_compile(modus,
					compiler, buffer, case_file,
					error_file, error_line);
			}else if(modus & (MODE_RUN | MODE_NORUN)){
				torture_result[index] = target_run(modus,
					compiler, buffer, case_file,
					error_file, error_line
#ifdef REG_EXTENDED
					, gdb, gdb_script, gdb_pattern
#endif
				);
			}

			printf("Torture-Sub-%i/" ZU "-", index+1,
					sizeof(torture)/sizeof(char*));
			printResult(torture_result[index], modus, case_file,
					stdout);
			printf("--------\n");
		}
	}else{
		if(torture_require && torture_require[0]){
			if(!cmd_arg_case || !cmd_arg_case[0]){
				cmd_arg_case = torture_require;
			}else{
				bufferLen = strlen(cmd_arg_case);
				bufferLen += strlen(torture_require);
				bufferLen += 2;
				buffer = (char*) malloc(bufferLen);
				snprintf(buffer, bufferLen, "%s %s", cmd_arg_case, torture_require);
				cmd_arg_case = buffer;
			}
		}
		if(modus & (MODE_RUN | MODE_NORUN)){
			case_result = target_run(modus, compiler, cmd_arg_case,
					case_file, error_file, error_line
#ifdef REG_EXTENDED
					, gdb, gdb_script, gdb_pattern
#endif
					);
		}else if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){
			case_result = target_compile(modus, compiler,
					cmd_arg_case, case_file, error_file,
					error_line);
		}else{
			fprintf(stderr, "BUG: unhandled non-torture modus %x\n", modus);
			exit(EXIT_FAILURE);
		}

		printf("Torture-Sub-1/" ZU "-",
			sizeof(torture)/sizeof(char*));
		printResult(case_result, modus, case_file, stdout);
	}

	if(strcmp(TMP_DIR, tmp_dir)){
		bufferLen = strlen(tmp_dir);
		bufferLen += strlen(RM_DIR);
		bufferLen += 2;
		buffer = (char*) malloc(bufferLen);
		snprintf(buffer, bufferLen, "%s %s", RM_DIR, tmp_dir);
		system(buffer);
	}
	exit(EXIT_SUCCESS);
}