Example #1
0
void 
callopt(void)
{
	register int i, *p, j, k, *q;

	ggreed = malloc(sizeof (int) * size);
	pgo = malloc(sizeof (int) * size);
	yypgo = &nontrst[0].tvalue;

	/* read the arrays from tempfile and set parameters */

	if ((finput = fopen(TEMPNAME, "r")) == NULL)
		error("optimizer cannot open tempfile");

	optimmem = tracemem;
	pgo[0] = 0;
	temp1[0] = 0;
	nstate = 0;
	nnonter = 0;
	for (;;) {
		switch (gtnm()) {

		case L'\n':
			temp1[++nstate] = (--optimmem) - tracemem;
			/* FALLTHRU */

		case L',':
			continue;

		case L'$':
			break;

		default:
			error("bad tempfile");
		}
		break;
	}

	temp1[nstate] = yypgo[0] = (--optimmem) - tracemem;

	for (;;) {
		switch (gtnm()) {

		case L'\n':
			yypgo[++nnonter] = optimmem-tracemem;
			/* FALLTHRU */
		case L',':
			continue;

		case EOF:
			break;

		default:
			error("bad tempfile");
		}
		break;
	}

	yypgo[nnonter--] = (--optimmem) - tracemem;

	for (i = 0; i < nstate; ++i) {
		k = 32000000;
		j = 0;
		q = tracemem + temp1[i+1];
		for (p = tracemem + temp1[i]; p < q; p += 2) {
			if (*p > j)
				j = *p;
			if (*p < k)
				k = *p;
		}
		if (k <= j) {
			/*
			 * nontrivial situation
			 * temporarily, kill this for compatibility
			 */
			/* j -= k;  j is now the range */
			if (k > maxoff)
				maxoff = k;
		}
		tystate[i] = (temp1[i+1] - temp1[i]) + 2*j;
		if (j > maxspr)
			maxspr = j;
	}

	/* initialize ggreed table */
	for (i = 1; i <= nnonter; ++i) {
		ggreed[i] = 1;
		j = 0;
		/* minimum entry index is always 0 */
		q = tracemem + yypgo[i+1] -1;
		for (p = tracemem + yypgo[i]; p < q; p += 2) {
			ggreed[i] += 2;
			if (*p > j)
				j = *p;
		}
		ggreed[i] = ggreed[i] + 2*j;
		if (j > maxoff)
			maxoff = j;
	}

	/* now, prepare to put the shift actions into the amem array */
	for (i = 0; i < new_actsize; ++i)
		amem[i] = 0;
	maxa = amem;

	for (i = 0; i < nstate; ++i) {
		if (tystate[i] == 0 && adb > 1)
			fprintf(ftable, "State %d: null\n", i);
		indgo[i] = YYFLAG1;
	}

	while ((i = nxti()) != NOMORE) {
		if (i >= 0)
			stin(i);
		else
			gin(-i);
	}

	if (adb > 2) { /* print a array */
		for (p = amem; p <= maxa; p += 10) {
			fprintf(ftable, "%4d  ", p-amem);
			for (i = 0; i < 10; ++i)
				fprintf(ftable, "%4d  ", p[i]);
			fprintf(ftable, "\n");
		}
	}
	/* write out the output appropriate to the language */
	aoutput();
	osummary();
	ZAPFILE(TEMPNAME);
}
Example #2
0
File: y4.c Project: timburrow/ovj3
callopt(){

	register i, *p, j, k, *q;

	/* read the arrays from tempfile and set parameters */

	if( (finput=fopen(TEMPNAME,"r")) == NULL ) error( "optimizer cannot open tempfile" );

	pgo[0] = 0;
	yypact[0] = 0;
	nstate = 0;
	nnonter = 0;
	for(;;){
		switch( gtnm() ){

		case '\n':
			yypact[++nstate] = (--pmem) - mem;
		case ',':
			continue;

		case '$':
			break;

		default:
			error( "bad tempfile" );
			}
		break;
		}

	yypact[nstate] = yypgo[0] = (--pmem) - mem;

	for(;;){
		switch( gtnm() ){

		case '\n':
			yypgo[++nnonter]= pmem-mem;
		case ',':
			continue;

		case EOF:
			break;

		default:
			error( "bad tempfile" );
			}
		break;
		}

	yypgo[nnonter--] = (--pmem) - mem;



	for( i=0; i<nstate; ++i ){

		k = 32000;
		j = 0;
		q = mem + yypact[i+1];
		for( p = mem + yypact[i]; p<q ; p += 2 ){
			if( *p > j ) j = *p;
			if( *p < k ) k = *p;
			}
		if( k <= j ){ /* nontrivial situation */
			/* temporarily, kill this for compatibility
			j -= k;  /* j is now the range */
			if( k > maxoff ) maxoff = k;
			}
		greed[i] = (yypact[i+1]-yypact[i]) + 2*j;
		if( j > maxspr ) maxspr = j;
		}

	/* initialize ggreed table */

	for( i=1; i<=nnonter; ++i ){
		ggreed[i] = 1;
		j = 0;
		/* minimum entry index is always 0 */
		q = mem + yypgo[i+1] -1;
		for( p = mem+yypgo[i]; p<q ; p += 2 ) {
			ggreed[i] += 2;
			if( *p > j ) j = *p;
			}
		ggreed[i] = ggreed[i] + 2*j;
		if( j > maxoff ) maxoff = j;
		}


	/* now, prepare to put the shift actions into the a array */

	for( i=0; i<ACTSIZE; ++i ) a[i] = 0;
	maxa = a;

	for( i=0; i<nstate; ++i ) {
		if( greed[i]==0 && adb>1 ) fprintf( ftable, "State %d: null\n", i );
		pa[i] = YYFLAG1;
		}

	while( (i = nxti()) != NOMORE ) {
		if( i >= 0 ) stin(i);
		else gin(-i);

		}

	if( adb>2 ){ /* print a array */
		for( p=a; p <= maxa; p += 10){
			fprintf( ftable, "%4d  ", p-a );
			for( i=0; i<10; ++i ) fprintf( ftable, "%4d  ", p[i] );
			fprintf( ftable, "\n" );
			}
		}
	/* write out the output appropriate to the language */

	aoutput();

	osummary();
	ZAPFILE(TEMPNAME);
	}
Example #3
0
static int falcon_handler(request_rec *request)
{
   Falcon::String path;
   bool phand = false;
   bool force_ftd = false;

   // should we handle this as a special path?
   if ( strcmp( request->handler, FALCON_PROGRAM_HANDLER) == 0 )
   {
      phand = true;
   }
   else if ( strcmp( request->handler, FALCON_PROGRAM_FTD) == 0 )
   {
      phand = true;
      force_ftd = true;
   }
   else if ( strcmp(request->handler, FALCON_FAM_TYPE) != 0 &&
        strcmp(request->handler, FALCON_FAL_TYPE) != 0 &&
        strcmp(request->handler, FALCON_FTD_TYPE) != 0)
   {
      return DECLINED;
   }

   // first time in this process?
   if( s_core == 0 )
   {
      module_startup();
   }

   Falcon::numeric startedAt = Falcon::Sys::Time::seconds();

   // verify that the file exists; decline otherwise
   const char *script_name = 0;
   const char *load_path = 0;
   falcon_dir_config* dircfg = (falcon_dir_config*)ap_get_module_config(request->per_dir_config, &falcon_module ) ;
   
   if ( phand )
   {
      // do we have a request configuration?
      if( dircfg->falconHandler[0] != '\0' )
      {
         script_name = dircfg->falconHandler;
      }
      else if( the_falcon_config->loaded != -1 )
      {
         script_name = the_falcon_config->falconHandler;
      }

      // else, go to the next the_falcon_config->loaded != -1 check
   }
   else
   {
      script_name = request->filename;
      Falcon::FileStat::e_fileType st;
      if ( ! Falcon::Sys::fal_fileType( script_name, st ) )
      {
         // sorry, the file do not exists, or we cannot access it.
         return DECLINED;
      }
   }

  
   // we accepted. but are we working?
   if( the_falcon_config->loaded == -1 )
   {
      falcon_mod_write_errorstring( request, "<HTML>\n<BODY>\n<H1>FALCON module error</H1>\n"
         "<p>Couldn't load Falcon configuration file. See the error log of this server "
         "for further details.</p>\n"
         "</BODY>\n"
         "</HTML>\n"
         );
      return OK;
   }

   // Set the load path
   if( dircfg->loadPath[0] != '\0' )
   {
      load_path = dircfg->loadPath;
   }
   else if( the_falcon_config->loaded != -1 )
   {
      load_path = the_falcon_config->loadPath;
   }

 
   // prepare the session manager for this process.
   if ( s_session == 0 )
   {
      if ( the_falcon_config->sessionMode == FM_DEFAULT_SESSION_MODE )
      {
         s_session = new Falcon::WOPI::FileSessionManager( the_falcon_config->uploadDir );
      }
      else
      {
         s_session = new Falcon::WOPI::MemSessionManager;
      }

      s_session->timeout( the_falcon_config->sessionTimeout );
      s_session->startup();
   }

   // we need some random data
   // for sure, the request address is unique within a time constraint.
   s_entropy += (((long)(startedAt * 1000))%0xFFFFFFFF + ((long) request));
   srand( s_entropy );

   //it's a Falcon module.
   ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, request,
      "Accepting a request from falcon %s", request->filename );

   // first of all, we need a module loader to load the script.
   // The parameter is the search path for where to search our module
   Falcon::ModuleLoader theLoader;

   // As we want to use standard Falcon installation,
   // tell the loader that is safe to search module in system path
   if( load_path != 0 && load_path[0] != '\0' )
   {
      theLoader.setSearchPath( load_path );
   }
   else
   {
      theLoader.setSearchPath( "" );
      theLoader.addFalconPath();
   }

   // also, instruct the module loader to take the script path as added search path
   Falcon::Path scriptPath( request->canonical_filename );

   if ( scriptPath.isValid() )
   {
      Falcon::String spath;
      scriptPath.getLocation( spath );
      theLoader.addDirectoryFront( spath );
   }

   // broadcast the same path to the application.
   Falcon::Engine::setSearchPath( theLoader.getSearchPath() );
   
   path = theLoader.getSearchPath();
   // for now, let's say we're utf-8
   theLoader.sourceEncoding( "utf-8" );
   Falcon::Engine::setEncodings( "utf-8", "utf-8" );

   if( force_ftd )
      theLoader.compileTemplate( true );

   // Now we need our error handler to manage possible problems in the next steps.
   // First, create the output brigade we'll need to deal with output.
   ApacheOutput aoutput( request );

   // then create an error handler that may use this output structure.
   ApacheErrorHandler errhand( the_falcon_config->errorMode, &aoutput );

   // Allow the script to load iteratively other resources it may need.
   ApacheRequest* ar = 0;
   Falcon::uint32 nSessionToken = 0;

   // We are ready to go. Let's create our VM and link in minimal stuff
   // we'll handle errors here
   ApacheVMachine* vm = new ApacheVMachine();

   // perform link of standard modules.
   vm->link( s_core );  // add the core module
   vm->link( s_ext );

   // prepare the request class.
   Falcon::Item* i_req = vm->findGlobalItem( "Request" );
   fassert( i_req != 0 );
   Falcon::Item* i_upld = vm->findGlobalItem( "Uploaded" );
   fassert( i_upld != 0 );
   Falcon::Item* i_reply = vm->findGlobalItem( "Reply" );
   fassert( i_reply != 0 );
   Falcon::Item* i_wopi = vm->findGlobalItem( "Wopi" );
   fassert( i_wopi != 0 );

   // Configure the Apache Request
   ar = Falcon::dyncast<ApacheRequest*>( i_req->asObject() );

   // And the reply here
   ApacheReply* reply = Falcon::dyncast<ApacheReply*>( i_reply->asObject() );
   reply->init( request, &aoutput );

   // init and configure
   ar->init( request, i_upld->asClass(), reply, s_session );
   ar->base()->startedAt( startedAt );
   // record the session token for automatic close at end.
   nSessionToken = ar->base()->sessionToken();

   vm->stdOut( new Falcon::WOPI::ReplyStream( reply ) );
   vm->stdErr( new Falcon::WOPI::ReplyStream( reply ) );

   // sets the options
   ar->base()->setMaxMemUpload( the_falcon_config->maxMemUpload );
   if( the_falcon_config->uploadDir[0] != 0 )
      ar->base()->setUploadPath( the_falcon_config->uploadDir );
   ar->configFromModule( vm->mainModule()->module() );

   // configure the WOPI persistent object
   if ( the_falcon_config->pdataDir[0] != 0 )
      Falcon::dyncast<Falcon::WOPI::CoreWopi*>(i_wopi->asObject())->wopi()->dataLocation( the_falcon_config->pdataDir );
   Falcon::dyncast<Falcon::WOPI::CoreWopi*>(i_wopi->asObject())->configFromModule( vm->mainModule()->module() );


   // ok start processing of the input request.
   ar->process();

   // ok; now prepare the scriptName and scriptPath variables, and set the current working directory
   // so that the script is ready.
   if ( scriptPath.isValid() )
   {
      Falcon::CoreString *spath = new Falcon::CoreString;
      Falcon::CoreString *sfile = new Falcon::CoreString;

      scriptPath.getLocation( *spath );
      scriptPath.getFilename( *sfile );
      Falcon::Item *i_scriptPath = vm->findGlobalItem( "scriptPath" );
      fassert( i_scriptPath != 0 );
      *i_scriptPath = spath;
      Falcon::Item *i_scriptName = vm->findGlobalItem( "scriptName" );
      fassert( i_scriptName != 0 );
      *i_scriptName = sfile;

      int fs;
      Falcon::Sys::fal_chdir( *spath, fs );
   }
   
   FALCON_WATCHDOG_TOKEN* wdt = 0;
   try {
      Falcon::Runtime rt( &theLoader );
      rt.loadFile( script_name );

      // tell the watchdog we're going to 
      if( the_falcon_config->runTimeout > 0 )
      {
         // approximate good size.
         int cbloops = the_falcon_config->runTimeout * 1000;
         vm->callbackLoops( cbloops > 10000 ? 10000 : cbloops );

         wdt = watchdog_push_vm( request, vm, the_falcon_config->runTimeout, reply );
      }
      // try to link our module and its dependencies.
      // -- It may fail if there are some undefined symbols
      vm->link( &rt );
      vm->launch();

      // close our stream
      aoutput.close();
   }
   catch( Falcon::Error* error )
   {
      reply->commit();
      errhand.handleError( error );
      aoutput.close();
   }
   
   if ( wdt != 0 ) {
      watchdog_vm_is_done( wdt );
   }

   // release all our sessions
   s_session->releaseSessions( nSessionToken );

   if( vm != 0 )
   {      
      void *temp_files = ar->base()->getTempFiles();
      vm->finalize();
      Falcon::memPool->start();
      //Falcon::memPool->performGC();

      if ( temp_files != 0 )
         Falcon::WOPI::Request::removeTempFiles( temp_files, request, ap_log_error_cb );
   }

   return OK;
}