示例#1
0
//==============================
// ovrLexer::NextToken
ovrLexer::ovrResult ovrLexer::NextToken( char * token, size_t const maxTokenSize )
{
	int const BUFF_SIZE = 8192;
	char buffer[BUFF_SIZE];

	SkipWhitespace( p );

	bool inQuotes = false;
	uint32_t ch = UTF8Util::DecodeNextChar( &p );
	ptrdiff_t bufferOfs = 0;
	while( !IsWhitespace( ch ) || inQuotes )
	{
		if ( ch == '\0' )
		{
			UTF8Util::EncodeChar( buffer, &bufferOfs, '\0' );
			CopyResult( buffer, token, maxTokenSize );
			return ( bufferOfs <= 1 ) ? LEX_RESULT_EOF : LEX_RESULT_OK;
		} 
		else if ( IsQuote( ch ) )
		{
			if ( inQuotes )	// if we were in quotes, end the token at the closing quote
			{
				UTF8Util::EncodeChar( buffer, &bufferOfs, ch );
				UTF8Util::EncodeChar( buffer, &bufferOfs, '\0' );
				CopyResult( buffer, token, maxTokenSize );
				return LEX_RESULT_OK;
			}
			inQuotes = !inQuotes;
		}

		int encodeSize = UTF8Util::GetEncodeCharSize( ch );
		if ( bufferOfs + encodeSize >= BUFF_SIZE - 1 || bufferOfs + encodeSize + 1 >= (int32_t)maxTokenSize )
		{
			// truncation
			UTF8Util::EncodeChar( buffer, &bufferOfs, '\0' );
			CopyResult( buffer, token, maxTokenSize );
			return LEX_RESULT_ERROR;
		}
		UTF8Util::EncodeChar( buffer, &bufferOfs, ch );
		// decode next character and advance pointer
		ch = UTF8Util::DecodeNextChar( &p );
	}
	buffer[bufferOfs] = '\0';
	CopyResult( buffer, token, maxTokenSize );
	return LEX_RESULT_OK;
}
示例#2
0
static void my_decode(RESULT * result, int argc, RESULT * argv[])
{
    int index;

    if (argc < 2) {
	error("decode(): wrong number of parameters");
	SetResult(&result, R_STRING, "");
	return;
    }

    index = R2N(argv[0]);

    if (index < 0 || index >= argc - 1) {
	SetResult(&result, R_STRING, "");
	return;
    }

    CopyResult(&result, argv[index + 1]);
}
示例#3
0
GPASampleResult* DX12GPASample::PopulateSampleResult()
{
    size_t sampleDataBytes = 0u;

    // Validate result space
    sampleDataBytes = GetSampleResultLocation()->GetBufferBytes();

    if (0 != sampleDataBytes)
    {
        if (nullptr != GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer())
        {
            gpa_uint64* pResultBuffer = nullptr;
            gpa_uint64 timingData[2] = {};

            if (GetPass()->IsTimingPass())
            {
                pResultBuffer = timingData;
                sampleDataBytes = sizeof(timingData);
            }
            else
            {
                pResultBuffer = GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer();
            }

            if (CopyResult(sampleDataBytes, pResultBuffer))
            {
                if (GetPass()->IsTimingPass())
                {
                    const GPA_HardwareCounters* pHardwareCounters = GetPass()->GetSessionContextCounterAccessor()->GetHardwareCounters();

                    for (CounterCount i = 0; i < GetPass()->GetEnabledCounterCount(); ++i)
                    {
                        CounterIndex counterIndex;
                        GetPass()->GetCounterByIndexInPass(i, &counterIndex);

                        if (counterIndex == pHardwareCounters->m_gpuTimeBottomToBottomDurationCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[1] - timingData[0];
                        }
                        else if (counterIndex == pHardwareCounters->m_gpuTimeBottomToBottomStartCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[0];
                        }
                        else if (counterIndex == pHardwareCounters->m_gpuTimeBottomToBottomEndCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[1];
                        }
                        else if (counterIndex == pHardwareCounters->m_gpuTimeTopToBottomDurationCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[1] - timingData[0];
                        }
                        else if (counterIndex == pHardwareCounters->m_gpuTimeTopToBottomStartCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[0];
                        }
                        else if (counterIndex == pHardwareCounters->m_gpuTimeTopToBottomEndCounterIndex)
                        {
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = timingData[1];
                        }
                        else
                        {
                            GPA_LogError("Unknown timing counter.");
                            GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[i] = 0;
                        }
                    }
                }

                if (IsSampleContinuing())
                {
                    GPASampleResult* pSampleResult = reinterpret_cast<DX12GPASample*>(GetContinuingSample())->PopulateSampleResult();

                    for (size_t counterIter = 0; counterIter < GetPass()->GetEnabledCounterCount(); counterIter++)
                    {
                        GetSampleResultLocation()->GetAsCounterSampleResult()->GetResultBuffer()[counterIter] += pSampleResult->GetAsCounterSampleResult()->GetResultBuffer()[counterIter];
                    }
                }

                MarkAsCompleted();
            }
            else
            {
                GPA_LogError("Unable to get the result from the driver.");
            }
        }
        else
        {
            GPA_LogError("Incorrect space allocated for sample result.");
        }
    }

    return GetSampleResultLocation();
}