Пример #1
0
/*-------------------------------------------------------------------------*/
int external_send_raw(char* buf)
{
	ir_cmd_t cmd;
	int ret=1; // default: cmd failed

	DDD("SEND CMD '%s'",buf);

	if (!strcasecmp(buf,"Startup")) {
		// start vdr
		standby(0);
		ret=0;
	}
	else {
		if (!strcasecmp(buf,"Standby")) {
		    if (power_state) {
			standby(1);
			strcpy(cmd.name,"Power");
		    }
		    else {
		        DDD("already in standby. nothing to do.");
		        ret=0;
		    }
		}
		else if (!strcasecmp(buf,"Poweroff")) {
			poweroff();
			strcpy(cmd.name,"Power");
		}
		else if (!strcasecmp(buf,"Eject") && !power_state) {
			cdeject();
			strcpy(cmd.name,"Eject");
			ret=0; // works also in standby
		}
		else {
			strcpy(cmd.name,buf);
		}
		int shifted=0;
		kbdx_t * kbdx=find_named_key(cmd.name, &shifted);
		if (!kbdx)
			return 0;
		cmd.kbdx=kbdx;
		cmd.source=0;
		cmd.cmd=0;        // dummy
		cmd.device=0;
		cmd.shift=shifted;
		cmd.flags=0;
		cmd.repeat=0;
		cmd.timestamp=get_timestamp();

		cmd.flags=0;
		cmd.state=REEL_IR_STATE_REEL;
		put_code(cmd);
		if (power_state)
			ret=0;
	}
	return ret;
}
Пример #2
0
int
main(int argc, char **argv)
{
    char *endptr;
    unsigned long nsteps = 1000000;
    VMState *state;
    bool hit_bp = false;
#ifdef WITH_DIFF
    VMStateDiff *diff;
#endif
    
    if (argc <= 1) {
        printf("Using a default of %lu steps\n", nsteps);
    } else {
        nsteps = strtoul(argv[1], &endptr, 0);
        
        if (errno) {
            perror("Invalid command line argument.");
            return 1;
        }
        
        if (*endptr)
            fprintf(stderr, "Warning: junk at end of number.\n");
    }
    

    check_error(state = vm_newstate_no_code(VM_POLICY_INTERRUPT_ALWAYS));
    
    put_code(state);
    
#ifdef WITH_DIFF
    check_error(diff = vm_newdiff());
    if (!vm_step(state, nsteps, diff, &hit_bp))
        goto error;
#else
    if (!vm_step(state, nsteps, NULL, &hit_bp))
        goto error;
#endif
    
    return EXIT_SUCCESS;
error:
    fputs(vm_strerror(-1), stderr);
    fputc('\n', stderr);
    return EXIT_FAILURE;
}
Пример #3
0
/*

 * output all code and labels in the peep list.
 */
void flush_peep P1 (unsigned, level)
{
    register CODE *ip;
    SWITCH *sw;
    EXPR   *ep2;
    LABEL   i;

    opt3 (level);		/* do the peephole optimizations */
    for (ip = peep_head; ip != NIL_CODE; ip = ip->fwd) {
	if (ip->opcode == op_label) {
	    put_label (ip->oper1->u.offset->v.l);
	} else
	    put_code (ip);
    }
    peep_head = NIL_CODE;
    for (sw = swtables; sw; sw = sw->next) {
	put_kseg (alignment_of_type (tp_pointer));
	put_label (sw->tablab);
	ep2 = mk_lcon (UNDEF_LABEL);
	/* generate the switch jump table as a series of 2-byte offsets
	 * This limits the amount of code that can be generated in a
	 * function to less then 32K.  I believe that this is a reasonable
	 * restriction.
	 */
	{
	    EXPR   *ep, *ep1;

	    ep1 = mk_lcon (sw->beglab);
	    ep = mk_node (en_sub, ep2, ep1, tp_void);
	    for (i = 0; i < sw->numlabs; i++) {
		ep2->v.l = sw->labels[i];
		put_short (ep);
	    }
	}
    }
    swtables = NIL_SWITCH;
}
Пример #4
0
/*
 *      output the instruction passed.
 */
void put_ocode(struct ocode *p)
{
	put_code(p);
//	put_code(p->opcode,p->length,p->oper1,p->oper2,p->oper3,p->oper4);
}
Пример #5
0
int CALLBACK _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
	int argc = 0;
	LPWSTR * argv = CommandLineToArgvW( GetCommandLineW(), &argc );

	if ( argv == NULL || argc != 3 ) return 1;

	wchar_t * end_char = 0;
	unsigned in_sum = wcstoul( argv[ 2 ], &end_char, 16 );
	if ( end_char == argv[ 2 ] || *end_char ) return 2;

	unsigned test_sum = 0;
	end_char = argv[ 1 ];
	while ( *end_char )
	{
		test_sum += (TCHAR)( *end_char++ * 820109 );
	}

#ifdef NDEBUG
	if ( test_sum != in_sum ) return 3;
#endif

	unsigned code = 0;

	HMODULE hDll = NULL;
	main_func pMain = NULL;
	AEffect * pEffect[3] = {0, 0, 0};

	audioMasterData effectData[3] = { { 0 }, { 1 }, { 2 } };

	std::vector<uint8_t> blState;

	uint32_t max_num_outputs = 2;
	uint32_t sample_rate = 44100;

	std::vector<uint8_t> chunk;
	std::vector<float> sample_buffer;

	null_file = CreateFile( _T("NUL"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );

	pipe_in = GetStdHandle( STD_INPUT_HANDLE );
	pipe_out = GetStdHandle( STD_OUTPUT_HANDLE );

	SetStdHandle( STD_INPUT_HANDLE, null_file );
	SetStdHandle( STD_OUTPUT_HANDLE, null_file );

	{
		INITCOMMONCONTROLSEX icc;
		icc.dwSize = sizeof(icc);
		icc.dwICC = ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_STANDARD_CLASSES;
		if ( !InitCommonControlsEx( &icc ) ) return 4;
	}

	if ( FAILED( CoInitialize( NULL ) ) ) return 5;

#ifndef _DEBUG
	SetUnhandledExceptionFilter( myExceptFilterProc );
#endif

	size_t dll_name_len = wcslen( argv[ 1 ] );
	dll_dir = ( char * ) malloc( dll_name_len + 1 );
	wcstombs( dll_dir, argv[ 1 ], dll_name_len );
	dll_dir[ dll_name_len ] = '\0';
	char * slash = strrchr( dll_dir, '\\' );
	*slash = '\0';

	hDll = LoadLibraryW( argv[ 1 ] );
	if ( !hDll )
	{
		code = 6;
		goto exit;
	}

	pMain = (main_func) GetProcAddress( hDll, "main" );
	if ( !pMain )
	{
		code = 7;
		goto exit;
	}

#if 0
	MessageBox( GetDesktopWindow(), argv[ 1 ], _T("HUUUURRRRRR"), 0 );
#endif

	pEffect[ 0 ] = pMain( &audioMaster );
	if ( !pEffect[ 0 ] || pEffect[ 0 ]->magic != kEffectMagic )
	{
		code = 8;
		goto exit;
	}

	pEffect[ 0 ]->user = &effectData[ 0 ];

	pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effOpen, 0, 0, 0, 0 );

	if ( pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effGetPlugCategory, 0, 0, 0, 0 ) != kPlugCategSynth ||
		pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effCanDo, 0, 0, "sendVstMidiEvent", 0 ) == 0 )
	{
		code = 9;
		goto exit;
	}

	max_num_outputs = min( pEffect[ 0 ]->numOutputs, 2 );

	{
		char name_string[256] = { 0 };
		char vendor_string[256] = { 0 };
		char product_string[256] = { 0 };
		uint32_t name_string_length;
		uint32_t vendor_string_length;
		uint32_t product_string_length;
		uint32_t vendor_version;
		uint32_t unique_id;

		pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effGetEffectName, 0, 0, &name_string, 0 );
		pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effGetVendorString, 0, 0, &vendor_string, 0 );
		pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effGetProductString, 0, 0, &product_string, 0 );
		name_string_length = strlen( name_string );
		vendor_string_length = strlen( vendor_string );
		product_string_length = strlen( product_string );
		vendor_version = pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effGetVendorVersion, 0, 0, 0, 0 );
		unique_id = pEffect[ 0 ]->uniqueID;

		put_code( 0 );
		put_code( name_string_length );
		put_code( vendor_string_length );
		put_code( product_string_length );
		put_code( vendor_version );
		put_code( unique_id );
		put_code( max_num_outputs );
		if ( name_string_length ) put_bytes( name_string, name_string_length );
		if ( vendor_string_length ) put_bytes( vendor_string, vendor_string_length );
		if ( product_string_length ) put_bytes( product_string, product_string_length );
	}

	float     ** float_list_in;
	float     ** float_list_out;
	float      * float_null;
	float      * float_out;

	for (;;)
	{
		uint32_t command = get_code();
		if ( !command ) break;

		switch ( command )
		{
		case 1: // Get Chunk
			getChunk( pEffect[ 0 ], chunk );

			put_code( 0 );
			put_code( chunk.size() );
			put_bytes( chunk.data(), chunk.size() );
			break;

		case 2: // Set Chunk
			{
				uint32_t size = get_code();
				chunk.resize( size );
				if ( size ) get_bytes( chunk.data(), size );

				setChunk( pEffect[ 0 ], chunk );
				setChunk( pEffect[ 1 ], chunk );
				setChunk( pEffect[ 2 ], chunk );

				put_code( 0 );
			}
			break;

		case 3: // Has Editor
			{
				uint32_t has_editor = ( pEffect[ 0 ]->flags & effFlagsHasEditor ) ? 1 : 0;

				put_code( 0 );
				put_code( has_editor );
			}
			break;

		case 4: // Display Editor Modal
			{
				if ( pEffect[ 0 ]->flags & effFlagsHasEditor )
				{
					MyDLGTEMPLATE t;
					t.style = WS_POPUPWINDOW | WS_DLGFRAME | DS_MODALFRAME | DS_CENTER;
					DialogBoxIndirectParam ( 0, &t, GetDesktopWindow(), (DLGPROC)EditorProc, (LPARAM)( pEffect[ 0 ] ) );
					getChunk( pEffect[ 0 ], chunk );
					setChunk( pEffect[ 1 ], chunk );
					setChunk( pEffect[ 2 ], chunk );
				}

				put_code( 0 );
			}
			break;

		case 5: // Set Sample Rate
			{
				uint32_t size = get_code();
				if ( size != sizeof(sample_rate) )
				{
					code = 10;
					goto exit;
				}

				sample_rate = get_code();

				put_code( 0 );
			}
			break;

		case 6: // Reset
			{
				if ( pEffect[ 2 ] )
				{
					if ( blState.size() ) pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effStopProcess, 0, 0, 0, 0 );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effClose, 0, 0, 0, 0 );
					pEffect[ 2 ] = NULL;
				}
				if ( pEffect[ 1 ] )
				{
					if ( blState.size() ) pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effStopProcess, 0, 0, 0, 0 );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effClose, 0, 0, 0, 0 );
					pEffect[ 1 ] = NULL;
				}
				if ( blState.size() ) pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effStopProcess, 0, 0, 0, 0 );
				pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effClose, 0, 0, 0, 0 );

				blState.resize( 0 );

				freeChain();

				pEffect[ 0 ] = pMain( &audioMaster );
				if ( !pEffect[ 0 ] )
				{
					code = 8;
					goto exit;
				}
				pEffect[ 0 ]->user = &effectData[ 0 ];
				pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effOpen, 0, 0, 0, 0 );
				setChunk( pEffect[ 0 ], chunk );

				put_code( 0 );
			}
			break;

		case 7: // Send MIDI Event
			{
				myVstEvent * ev = ( myVstEvent * ) calloc( sizeof( myVstEvent ), 1 );
				if ( evTail ) evTail->next = ev;
				evTail = ev;
				if ( !evChain ) evChain = ev;

				uint32_t b = get_code();

				ev->port = (b & 0x7F000000) >> 24;
				if (ev->port > 2) ev->port = 2;
				ev->ev.midiEvent.type = kVstMidiType;
				ev->ev.midiEvent.byteSize = sizeof(ev->ev.midiEvent);
				memcpy(&ev->ev.midiEvent.midiData, &b, 3);

				put_code( 0 );
			}
			break;

		case 8: // Send System Exclusive Event
			{
				myVstEvent * ev = ( myVstEvent * ) calloc( sizeof( myVstEvent ), 1 );
				if ( evTail ) evTail->next = ev;
				evTail = ev;
				if ( !evChain ) evChain = ev;

				uint32_t size = get_code();
				uint32_t port = size >> 24;
				size &= 0xFFFFFF;

				ev->port = port;
				if (ev->port > 2) ev->port = 2;
				ev->ev.sysexEvent.type = kVstSysExType;
				ev->ev.sysexEvent.byteSize = sizeof(ev->ev.sysexEvent);
				ev->ev.sysexEvent.dumpBytes = size;
				ev->ev.sysexEvent.sysexDump = (char*) malloc( size );

				get_bytes( ev->ev.sysexEvent.sysexDump, size );

				put_code( 0 );
			}
			break;

		case 9: // Render Samples
			{
				if ( !pEffect[ 1 ] )
				{
					pEffect[ 1 ] = pMain( &audioMaster );
					if ( !pEffect[ 1 ] )
					{
						code = 11;
						goto exit;
					}
					pEffect[ 1 ]->user = &effectData[ 1 ];
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effOpen, 0, 0, 0, 0 );
					setChunk( pEffect[ 1 ], chunk );
				}
				if ( !pEffect[ 2 ] )
				{
					pEffect[ 2 ] = pMain( &audioMaster );
					if ( !pEffect[ 2 ] )
					{
						code = 11;
						goto exit;
					}
					pEffect[ 2 ]->user = &effectData[ 2 ];
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effOpen, 0, 0, 0, 0 );
					setChunk( pEffect[ 2 ], chunk );
				}

				if ( !blState.size() )
				{
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effSetSampleRate, 0, 0, 0, float(sample_rate) );
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effSetBlockSize, 0, BUFFER_SIZE, 0, 0 );
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effMainsChanged, 0, 1, 0, 0 );
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effStartProcess, 0, 0, 0, 0 );

					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effSetSampleRate, 0, 0, 0, float(sample_rate) );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effSetBlockSize, 0, BUFFER_SIZE, 0, 0 );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effMainsChanged, 0, 1, 0, 0 );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effStartProcess, 0, 0, 0, 0 );

					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effSetSampleRate, 0, 0, 0, float(sample_rate) );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effSetBlockSize, 0, BUFFER_SIZE, 0, 0 );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effMainsChanged, 0, 1, 0, 0 );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effStartProcess, 0, 0, 0, 0 );

					size_t buffer_size = sizeof(float*) * ( pEffect[ 0 ]->numInputs + pEffect[ 0 ]->numOutputs * 3 ); // float lists
					buffer_size += sizeof(float) * BUFFER_SIZE;                                // null input
					buffer_size += sizeof(float) * BUFFER_SIZE * pEffect[ 0 ]->numOutputs * 3;          // outputs

					blState.resize( buffer_size );

					float_list_in  = (float**) blState.data();
					float_list_out = float_list_in + pEffect[ 0 ]->numInputs;
					float_null     = (float*) ( float_list_out + pEffect[ 0 ]->numOutputs * 3 );
					float_out      = float_null + BUFFER_SIZE;

					for ( unsigned i = 0; i < pEffect[ 0 ]->numInputs; ++i )      float_list_in [ i ] = float_null;
					for ( unsigned i = 0; i < pEffect[ 0 ]->numOutputs * 3; ++i ) float_list_out[ i ] = float_out + BUFFER_SIZE * i;

					memset( float_null, 0, sizeof(float) * BUFFER_SIZE );

					sample_buffer.resize( BUFFER_SIZE * max_num_outputs );
				}

				if ( need_idle )
				{
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );

					if ( !idle_started )
					{
						unsigned idle_run = BUFFER_SIZE * 128;

						while ( idle_run )
						{
							unsigned count_to_do = min( idle_run, BUFFER_SIZE );
							unsigned num_outputs = pEffect[ 0 ]->numOutputs;

							pEffect[ 0 ]->processReplacing( pEffect[ 0 ], float_list_in, float_list_out, count_to_do );
							pEffect[ 1 ]->processReplacing( pEffect[ 1 ], float_list_in, float_list_out + num_outputs, count_to_do );
							pEffect[ 2 ]->processReplacing( pEffect[ 2 ], float_list_in, float_list_out + num_outputs * 2, count_to_do );

							pEffect[ 0 ]->dispatcher( pEffect[ 0 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
							pEffect[ 1 ]->dispatcher( pEffect[ 1 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
							pEffect[ 2 ]->dispatcher( pEffect[ 2 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );

							idle_run -= count_to_do;
						}
					}
				}

				VstEvents * events[ 3 ] = {0};

				if ( evChain )
				{
					unsigned event_count[ 3 ] = {0};
					myVstEvent * ev = evChain;
					while ( ev )
					{
						event_count[ ev->port ]++;
						ev = ev->next;
					}

					if ( event_count[ 0 ] )
					{
						events[ 0 ] = ( VstEvents * ) malloc( sizeof(long) + sizeof(long) + sizeof(VstEvent*) * event_count[ 0 ] );

						events[ 0 ]->numEvents = event_count[ 0 ];
						events[ 0 ]->reserved = 0;

						ev = evChain;

						for ( unsigned i = 0; ev; )
						{
							if ( !ev->port ) events[ 0 ]->events[ i++ ] = (VstEvent*) &ev->ev;
							ev = ev->next;
						}

						pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effProcessEvents, 0, 0, events[ 0 ], 0 );
					}

					if ( event_count[ 1 ] )
					{
						events[ 1 ] = ( VstEvents * ) malloc( sizeof(long) + sizeof(long) + sizeof(VstEvent*) * event_count[ 1 ] );

						events[ 1 ]->numEvents = event_count[ 1 ];
						events[ 1 ]->reserved = 0;

						ev = evChain;

						for ( unsigned i = 0; ev; )
						{
							if ( ev->port == 1 ) events[ 1 ]->events[ i++ ] = (VstEvent*) &ev->ev;
							ev = ev->next;
						}

						pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effProcessEvents, 0, 0, events[ 1 ], 0 );
					}

					if ( event_count[ 2 ] )
					{
						events[ 2 ] = ( VstEvents * ) malloc( sizeof(long) + sizeof(long) + sizeof(VstEvent*) * event_count[ 2 ] );

						events[ 2 ]->numEvents = event_count[ 2 ];
						events[ 2 ]->reserved = 0;

						ev = evChain;

						for ( unsigned i = 0; ev; )
						{
							if ( ev->port == 2 ) events[ 2 ]->events[ i++ ] = (VstEvent*) &ev->ev;
							ev = ev->next;
						}

						pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effProcessEvents, 0, 0, events[ 2 ], 0 );
					}
				}

				if ( need_idle )
				{
					pEffect[ 0 ]->dispatcher( pEffect[ 0 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
					pEffect[ 1 ]->dispatcher( pEffect[ 1 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );
					pEffect[ 2 ]->dispatcher( pEffect[ 2 ], DECLARE_VST_DEPRECATED (effIdle), 0, 0, 0, 0 );

					if ( !idle_started )
					{
						if ( events[ 0 ] ) pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effProcessEvents, 0, 0, events[ 0 ], 0 );
						if ( events[ 1 ] ) pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effProcessEvents, 0, 0, events[ 1 ], 0 );
						if ( events[ 2 ] ) pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effProcessEvents, 0, 0, events[ 2 ], 0 );

						idle_started = true;
					}
				}

				uint32_t count = get_code();

				put_code( 0 );

				while( count )
				{
					unsigned count_to_do = min( count, BUFFER_SIZE );
					unsigned num_outputs = pEffect[ 0 ]->numOutputs;

					pEffect[ 0 ]->processReplacing( pEffect[ 0 ], float_list_in, float_list_out, count_to_do );
					pEffect[ 1 ]->processReplacing( pEffect[ 1 ], float_list_in, float_list_out + num_outputs, count_to_do );
					pEffect[ 2 ]->processReplacing( pEffect[ 2 ], float_list_in, float_list_out + num_outputs * 2, count_to_do );

					float * out = sample_buffer.data();

					if ( max_num_outputs == 2 )
					{
						for ( unsigned i = 0; i < count_to_do; ++i )
						{
							float sample = ( float_out[ i ] + float_out[ i + BUFFER_SIZE * num_outputs ] + float_out[ i + BUFFER_SIZE * num_outputs * 2 ] );
							out[ 0 ] = sample;
							sample = ( float_out[ i + BUFFER_SIZE ] + float_out[ i + BUFFER_SIZE + BUFFER_SIZE * num_outputs ] + float_out[ i + BUFFER_SIZE + BUFFER_SIZE * num_outputs * 2 ] );
							out[ 1 ] = sample;
							out += 2;
						}
					}
					else
					{
						for ( unsigned i = 0; i < count_to_do; ++i )
						{
							float sample = ( float_out[ i ] + float_out[ i + BUFFER_SIZE * num_outputs ] + float_out[ i + BUFFER_SIZE * num_outputs * 2 ] );
							out[ 0 ] = sample;
							out++;
						}
					}

					put_bytes( sample_buffer.data(), sizeof(float) * count_to_do * max_num_outputs );

					count -= count_to_do;
				}

				if ( events[ 0 ] ) free( events[ 0 ] );
				if ( events[ 1 ] ) free( events[ 1 ] );
				if ( events[ 2 ] ) free( events[ 2 ] );

				freeChain();
			}
			break;

		default:
			code = 12;
			goto exit;
			break;
		}
	}

exit:
	if ( pEffect[ 2 ] )
	{
		if ( blState.size() ) pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effStopProcess, 0, 0, 0, 0 );
		pEffect[ 2 ]->dispatcher( pEffect[ 2 ], effClose, 0, 0, 0, 0 );
	}
	if ( pEffect[ 1 ] )
	{
		if ( blState.size() ) pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effStopProcess, 0, 0, 0, 0 );
		pEffect[ 1 ]->dispatcher( pEffect[ 1 ], effClose, 0, 0, 0, 0 );
	}
	if ( pEffect[ 0 ] )
	{
		if ( blState.size() ) pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effStopProcess, 0, 0, 0, 0 );
		pEffect[ 0 ]->dispatcher( pEffect[ 0 ], effClose, 0, 0, 0, 0 );
	}
	freeChain();
	if ( hDll ) FreeLibrary( hDll );
	CoUninitialize();
	if ( argv ) LocalFree( argv );

	put_code( code );

	if ( null_file )
	{
		CloseHandle( null_file );

		SetStdHandle( STD_INPUT_HANDLE, pipe_in );
		SetStdHandle( STD_OUTPUT_HANDLE, pipe_out );
	}

	return code;
}
Пример #6
0
/*
 *  Examines dataflow and checks if data is already in a register
 *  when read-accesses to external ram occurs
 *  needs multiple-passes to work
 */
int flow_dataflow P2 (CODE *, peep_head, int, level)
{
    FLOWLISTENTRY *RegUsage[MAX_REG + 1];
    int     LabelChanges;
    BOOL    headless;		/* is true when currently no entrypoint for code was found 

				 * (after a jump before the first label is found 
				 */
    REG     reg;
    register CODE *ip;
    int     replacecount = 0;
    static int totreplace = 0;

#ifdef DEBUG
    int     Round = 1;

#endif /* DEBUG */

    do {
	DPRINTF ((DEBUG_FLOW, "Dataflow, round %d...", Round++));
	LabelChanges = 0;
	/* currently no entrypoint found */
	headless = FALSE;
	/* clear all lists to start analysis */
	clear_regusage (&(RegUsage[0]));
	for (ip = peep_head; ip != NIL_CODE; ip = ip->fwd) {
	    /*
	     * invalidate all entries with references to registers
	     * modified in this instruction
	     */
	    validate_regusage (ip, &(RegUsage[0]));

	    switch (ip->opcode) {
	    case op_ldi_ldi:
	    case op_ldf_ldf:
		/* destination now references to source */
		new_flow_list (&(RegUsage[ip->dst2->preg]), ip->dst2->preg,
			       ip->src21, ip->type);
		if (is_am_register (ip->src21)) {
		    /* dest references now to the same list of values as source */
		    add_list_to_flow_list (&(RegUsage[ip->dst2->preg]),
					   RegUsage[ip->src21->preg]);
		    /* source refers now also to destination */
		    add_flow_list (&(RegUsage[ip->src21->preg]),
				   ip->src21->preg, ip->dst2, ip->type);
		}
		/*FALLTHRU */
	    case op_ldi:
	    case op_ldf:
	    case op_ldiu:
	    case op_ldfu:
		/* destination now references to source */
		new_flow_list (&(RegUsage[ip->dst->preg]), ip->dst->preg,
			       ip->src1, ip->type);
		if (is_am_register (ip->src1)) {
		    /* dest references now to the same list of values as source */
		    add_list_to_flow_list (&(RegUsage[ip->dst->preg]),
					   RegUsage[ip->src1->preg]);
		    /* source refers now also to destination */
		    add_flow_list (&(RegUsage[ip->src1->preg]),
				   ip->src1->preg, ip->dst, ip->type);
		}
		break;

	    case op_ldi_sti:
	    case op_ldf_stf:
		/* destination now references to source */
		new_flow_list (&(RegUsage[ip->dst->preg]), ip->dst->preg,
			       ip->src1, ip->type);
		if (is_am_register (ip->src1)) {
		    /* dest references now to the same list of values as source */
		    add_list_to_flow_list (&(RegUsage[ip->dst->preg]),
					   RegUsage[ip->src1->preg]);
		    /* source refers now also to destination */
		    add_flow_list (&(RegUsage[ip->src1->preg]),
				   ip->src1->preg, ip->dst, ip->type);
		}
		/* source of sti refers now also to destination */
		add_flow_list (&(RegUsage[ip->src21->preg]), ip->src21->preg,
			       ip->dst2, ip->type);
		break;

	    case op_sti_sti:
	    case op_stf_stf:
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src2->preg]), ip->src2->preg,
			       ip->dst2, ip->type);
		/*FALLTHRU */
	    case op_sti:
	    case op_stf:
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			       ip->dst, ip->type);
		break;

	    case op_absf_stf:
	    case op_absi_sti:
	    case op_addf3_stf:
	    case op_addi3_sti:
	    case op_and3_sti:
	    case op_ash3_sti:
	    case op_fix_sti:
	    case op_float_stf:
	    case op_lsh3_sti:
	    case op_mpyf3_stf:
	    case op_mpyi3_sti:
	    case op_negf_stf:
	    case op_negi_sti:
	    case op_not_sti:
	    case op_or3_sti:
	    case op_subf3_stf:
	    case op_subi3_sti:
	    case op_xor3_sti:
		/* source of sti refers now also to destination */
		add_flow_list (&(RegUsage[ip->src2->preg]), ip->src2->preg,
			       ip->dst2, ip->type);
		if ((ip->dst != NULL) && (is_am_register (ip->dst))) {
		    /* destination of operation does not reference to anywhere now */
		    RegUsage[ip->dst->preg] = NULL;
		}
		break;

	    case op_blo:
	    case op_bls:
	    case op_bhi:
	    case op_bhs:
	    case op_beq:
	    case op_bne:
	    case op_blt:
	    case op_ble:
	    case op_bgt:
	    case op_bge:
	    case op_bz:
	    case op_bnz:
	    case op_bp:
	    case op_bn:
	    case op_bnn:
		/* attach aktual registerusageinfo to label of jumpdestination */
		LabelChanges +=
		    attach_regusage_to_label (ip, &(RegUsage[0]), level);
		break;

	    case op_label:
		if (headless == TRUE) {
		    /* first entrypoint of this piece of code, so use whole information from label */
		    copy_regusage_from_label (ip, &(RegUsage[0]), level);
		    headless = FALSE;
		} else {
		    /* not first entrypoint, so merge information from label */
		    LabelChanges +=
			merge_regusage_from_label (ip, &(RegUsage[0]), level);
		}
		break;

	    case op_bu:
	    case op_br:
		/* attach aktual registerusageinfo to label of jumpdestination */
		LabelChanges +=
		    attach_regusage_to_label (ip, &(RegUsage[0]), level);
		/* FALLTHRU */

	    case op_retsu:
	    case op_retiu:
		/* no information abaout registers availlable now */
		clear_regusage (&(RegUsage[0]));
		/* since no entrypoint found now (unconditional controltransfer) */
		headless = TRUE;
		break;

	    case op_asm:
		/* clear whole list, asm can do anything to registers and memory */
		clear_regusage (&(RegUsage[0]));
		break;

	    case op_rpts:
	    case op_rptb:
		/* remove all references to and from blockrepeatregisters */
		RegUsage[REG_RC] = NULL;
		RegUsage[REG_RS] = NULL;
		RegUsage[REG_RE] = NULL;
		remove_from_regusage (RegUsage, REG_RC);
		remove_from_regusage (RegUsage, REG_RS);
		remove_from_regusage (RegUsage, REG_RE);
		break;

	    case op_call:
	    case op_trapu:
	    case op_xcall:
	    case op_callu:
		/* remove all references to and from temporary registers */
		clear_tempreg_usage (&(RegUsage[0]));
		/*
		 * we do not know what called routine does
		 * with memory
		 */
		remove_from_regusage (RegUsage, REG_MEMORY);
		/* FALLTHRU */

	    case op_push:
	    case op_pop:
	    case op_pushf:
	    case op_popf:
	    case op_pushnopeep:
	    case op_pushfnopeep:
		/* references from SP are no longer valid */
		RegUsage[REG_SP] = NULL;
		/* FALLTHRU */

	    default:
		if ((ip->dst != NULL) && (is_am_register (ip->dst))) {
		    /* destination of operation does not reference to anywhere now */
		    RegUsage[ip->dst->preg] = NULL;
		}
		if ((ip->dst2 != NULL) && (is_am_register (ip->dst2))) {
		    /* destination of operation does not reference to anywhere now */
		    RegUsage[ip->dst2->preg] = NULL;
		}
		break;

	    }
	}
	DPRINTF ((DEBUG_FLOW, " %d changes \n", LabelChanges));
    } while (LabelChanges != 0);

    DPRINTF ((DEBUG_FLOW, "%s\n", "Dataflow, REPLACEMENT ROUND"));
    LabelChanges = 0;
    /* currently no entrypoint found */
    headless = FALSE;
    /* clear all lists to start analysis */
    clear_regusage (&(RegUsage[0]));
    for (ip = peep_head; ip != NIL_CODE; ip = ip->fwd) {
	/*
	 * invalidate all entries with references to registers
	 * modified in this instruction
	 */
#ifdef ENHANCED_FLOW
	validate_addressregusage (ip, &(RegUsage[0]));
#else
	validate_regusage (ip, &(RegUsage[0]));
#endif
	switch (ip->opcode) {
	case op_ldi_ldi:
	case op_ldf_ldf:
	    if (
		(reg =
		 search_in_regusage (&(RegUsage[0]), ip->src1,
				     ip->type)) >= 0) {
		DPRINTF (
			 (DEBUG_FLOW, "FoundReplacement for src1 %d",
			  (int) reg));
		if (is_exchangable (&(ip->src1), reg)) {
		    replacecount++;
		    totreplace++;
		    Update_Peep_Info (ip);
		}
	    }
	    if (
		(reg =
		 search_in_regusage (&(RegUsage[0]), ip->src21,
				     ip->type)) >= 0) {
		DPRINTF (
			 (DEBUG_FLOW, "FoundReplacement for src21 %d",
			  (int) reg));
		if (is_exchangable (&(ip->src21), reg)) {
		    replacecount++;
		    totreplace++;
		    Update_Peep_Info (ip);
		}
	    }
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* destination now references to source */
	    new_flow_list (&(RegUsage[ip->dst->preg]), ip->dst->preg,
			   ip->src1, ip->type);
	    if (is_am_register (ip->src1)) {
		/* dest references now to the same list of values as source */
		add_list_to_flow_list (&(RegUsage[ip->dst->preg]),
				       RegUsage[ip->src1->preg]);
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			       ip->dst, ip->type);
	    }
	    /* destination now references to source */
	    new_flow_list (&(RegUsage[ip->dst2->preg]), ip->dst2->preg,
			   ip->src21, ip->type);
	    if (is_am_register (ip->src21)) {
		/* dest references now to the same list of values as source */
		add_list_to_flow_list (&(RegUsage[ip->dst2->preg]),
				       RegUsage[ip->src21->preg]);
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src21->preg]), ip->src21->preg,
			       ip->dst2, ip->type);
	    }
	    break;

	case op_ldi:
	case op_ldf:
	case op_ldiu:
	case op_ldfu:
	    if (
		(reg =
		 search_in_regusage (&(RegUsage[0]), ip->src1,
				     ip->type)) >= 0) {
		DPRINTF (
			 (DEBUG_FLOW, "FoundReplacement for src1 %d",
			  (int) reg));
		if (is_exchangable (&(ip->src1), reg)) {
		    replacecount++;
		    totreplace++;
		    Update_Peep_Info (ip);
		}
	    }
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* destination now references to source */
	    new_flow_list (&(RegUsage[ip->dst->preg]), ip->dst->preg,
			   ip->src1, ip->type);
	    if (is_am_register (ip->src1)) {
		/* dest references now to the same list of values as source */
		add_list_to_flow_list (&(RegUsage[ip->dst->preg]),
				       RegUsage[ip->src1->preg]);
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			       ip->dst, ip->type);
	    }
	    break;

	case op_ldi_sti:
	case op_ldf_stf:
	    if (
		(reg =
		 search_in_regusage (&(RegUsage[0]), ip->src1,
				     ip->type)) >= 0) {
		DPRINTF (
			 (DEBUG_FLOW, "FoundReplacement for src1 %d",
			  (int) reg));
		if (is_exchangable (&(ip->src1), reg)) {
		    replacecount++;
		    totreplace++;
		    Update_Peep_Info (ip);
		}
	    }
	    if (
		(reg =
		 search_in_regusage (&(RegUsage[0]), ip->src21,
				     ip->type)) >= 0) {
		DPRINTF (
			 (DEBUG_FLOW, "FoundReplacement for src21 %d",
			  (int) reg));
		if (is_exchangable (&(ip->src21), reg)) {
		    replacecount++;
		    totreplace++;
		    Update_Peep_Info (ip);
		}
	    }
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* destination now references to source */
	    new_flow_list (&(RegUsage[ip->dst->preg]), ip->dst->preg,
			   ip->src1, ip->type);
	    if (is_am_register (ip->src1)) {
		/* dest references now to the same list of values as source */
		add_list_to_flow_list (&(RegUsage[ip->dst->preg]),
				       RegUsage[ip->src1->preg]);
		/* source refers now also to destination */
		add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			       ip->dst, ip->type);
	    }
	    /* source of sti refers now also to destination */
	    add_flow_list (&(RegUsage[ip->src21->preg]), ip->src21->preg,
			   ip->dst2, ip->type);
	    break;

	case op_sti_sti:
	case op_stf_stf:
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* source refers now also to destination */
	    add_flow_list (&(RegUsage[ip->src2->preg]), ip->src2->preg,
			   ip->dst2, ip->type);
	    /* source refers now also to destination */
	    add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			   ip->dst, ip->type);
	    break;

	case op_sti:
	case op_stf:
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* source refers now also to destination */
	    add_flow_list (&(RegUsage[ip->src1->preg]), ip->src1->preg,
			   ip->dst, ip->type);
	    break;


	case op_absf_stf:
	case op_absi_sti:
	case op_addf3_stf:
	case op_addi3_sti:
	case op_and3_sti:
	case op_ash3_sti:
	case op_fix_sti:
	case op_float_stf:
	case op_lsh3_sti:
	case op_mpyf3_stf:
	case op_mpyi3_sti:
	case op_negf_stf:
	case op_negi_sti:
	case op_not_sti:
	case op_or3_sti:
	case op_subf3_stf:
	case op_subi3_sti:
	case op_xor3_sti:
#if 0
/* 
 * sorry, currently no replace possible, since
 * src1 must be r0-r7
 * src2 must be restricted indirect
 * src21 must be r0-r7
 */
	    if (ip->src1 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src1,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src1 %d",
			      reg));
		    if (is_exchangable (&(ip->src1), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    if (ip->src2 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src2,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src2 %d",
			      reg));
		    if (is_exchangable (&(ip->src2), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
#endif
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* source of sti refers now also to destination */
	    add_flow_list (&(RegUsage[ip->src21->preg]), ip->src21->preg,
			   ip->dst2, ip->type);
	    if ((ip->dst != NULL)
		&& (is_am_register (ip->dst))) {
		/* destination of operation does not reference to anywhere now */
		RegUsage[ip->dst->preg] = NULL;
	    }
	    break;
	case op_label:
	    if (headless == TRUE) {
		/* first entrypoint of this piece of code, so use whole information from label */
		copy_regusage_from_label (ip, &(RegUsage[0]), level);
		headless = FALSE;
	    } else {
		/* not first entrypoint, so merge information from label */
		LabelChanges +=
		    merge_regusage_from_label (ip, &(RegUsage[0]), level);
	    }
	    /*
	     *  Remove regusage-entry from label
	     */
	    ip->src21 = NULL;
	    break;

	case op_bu:
	    if ((ip->src1 != NULL) && (ip->src1->mode != am_immed)) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src1,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src1 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src1), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    /* FALLTHRU */
	case op_br:
	    /* FALLTHRU */
	case op_retsu:
	case op_retiu:
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* no information abaout registers availlable now */
	    clear_regusage (&(RegUsage[0]));
	    /* since no entrypoint found now (unconditional controltransfer) */
	    headless = TRUE;
	    break;

	case op_asm:
	    /* clear whole list, asm can do anything to registers and memory */
	    clear_regusage (&(RegUsage[0]));
	    break;

	case op_rpts:
	    if (ip->src1 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src1,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src1 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src1), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    /* FALLTHRU */

	case op_rptb:
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* remove all references to and from blockrepeatregisters */
	    RegUsage[REG_RC] = NULL;
	    RegUsage[REG_RS] = NULL;
	    RegUsage[REG_RE] = NULL;
	    remove_from_regusage (RegUsage, REG_RC);
	    remove_from_regusage (RegUsage, REG_RS);
	    remove_from_regusage (RegUsage, REG_RE);
	    break;

	case op_callu:
	    if ((ip->src1 != NULL) && (ip->src1->mode != am_immed)) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src1,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src1 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src1), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    /* FALLTHRU */
	case op_call:
	case op_trapu:
	case op_xcall:
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    /* remove all references to and from temporary registers */
	    clear_tempreg_usage (&(RegUsage[0]));
	    /*
	     * we do not know what called routine does
	     * with memory
	     */
	    remove_from_regusage (RegUsage, REG_MEMORY);
	    /* FALLTHRU */

	case op_push:
	case op_pop:
	case op_pushf:
	case op_popf:
	case op_pushnopeep:
	case op_pushfnopeep:
	    /* references from SP are no longer valid */
	    RegUsage[REG_SP] = NULL;
	    /* FALLTHRU */

	default:
	    if (ip->src1 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src1,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src1 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src1), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    if (ip->src2 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src2,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src2 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src2), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    if (ip->src21 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src21,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src21 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src21), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
	    if (ip->src22 != NULL) {
		if (
		    (reg =
		     search_in_regusage (&(RegUsage[0]), ip->src22,
					 ip->type)) >= 0) {
		    DPRINTF (
			     (DEBUG_FLOW, "FoundReplacement for src22 %d",
			      (int) reg));
		    if (is_exchangable (&(ip->src22), reg)) {
			replacecount++;
			totreplace++;
			Update_Peep_Info (ip);
		    }
		}
	    }
#ifdef USE_ALL_OPCODES
	    /* FALLTHRU */
	    /* do no replacements with parallel mul/add */
	case op_mpf3_adf3:
	case op_mpf3_sbf3:
	case op_mpi3_adi3:
	case op_mpi3_sbi3:
#endif /* USE_ALL_OPCODES */
#ifdef ENHANCED_FLOW
	    validate_regusage (ip, &(RegUsage[0]));
#endif
	    if ((ip->dst != NULL) && (is_am_register (ip->dst))) {
		/* destination of operation does not reference to anywhere now */
		RegUsage[ip->dst->preg] = NULL;
	    }
	    if ((ip->dst2 != NULL) && (is_am_register (ip->dst2))) {
		/* destination of operation does not reference to anywhere now */
		RegUsage[ip->dst2->preg] = NULL;
	    }
	    break;

	}
#ifdef DEBUG
	if (is_debugging (DEBUG_FLOW)) {
	    FHANDLE save = output;

	    output = debugfile;
	    if (ip->opcode == op_label) {
		put_label (ip->src1->u.offset->v.l);
	    } else {
		put_code (ip);
	    }
	    output = save;
	    print_regusage (&(RegUsage[0]));
	}
#endif /* DEBUG */
    }
    DPRINTF ((DEBUG_FLOW, "Replaced %d ", replacecount));
    DPRINTF ((DEBUG_FLOW, "Total %d \n", totreplace));
    return replacecount;
}