gallium/tgsi/text: Parse immediates of non-float data types.

This commit is contained in:
Francisco Jerez 2012-03-20 22:39:29 +01:00
parent e9072863b1
commit 40123dae43
1 changed files with 48 additions and 18 deletions

View File

@ -132,6 +132,23 @@ static boolean parse_uint( const char **pcur, uint *val )
return FALSE; return FALSE;
} }
static boolean parse_int( const char **pcur, int *val )
{
const char *cur = *pcur;
int sign = (*cur == '-' ? -1 : 1);
if (*cur == '+' || *cur == '-')
cur++;
if (parse_uint(&cur, (uint *)val)) {
*val *= sign;
*pcur = cur;
return TRUE;
}
return FALSE;
}
static boolean parse_identifier( const char **pcur, char *ret ) static boolean parse_identifier( const char **pcur, char *ret )
{ {
const char *cur = *pcur; const char *cur = *pcur;
@ -971,10 +988,11 @@ parse_instruction(
/* parses a 4-touple of the form {x, y, z, w} /* parses a 4-touple of the form {x, y, z, w}
* where x, y, z, w are numbers */ * where x, y, z, w are numbers */
static boolean parse_immediate_data(struct translate_ctx *ctx, static boolean parse_immediate_data(struct translate_ctx *ctx, unsigned type,
float *values) union tgsi_immediate_data *values)
{ {
unsigned i; unsigned i;
int ret;
eat_opt_white( &ctx->cur ); eat_opt_white( &ctx->cur );
if (*ctx->cur != '{') { if (*ctx->cur != '{') {
@ -992,8 +1010,21 @@ static boolean parse_immediate_data(struct translate_ctx *ctx,
ctx->cur++; ctx->cur++;
eat_opt_white( &ctx->cur ); eat_opt_white( &ctx->cur );
} }
if (!parse_float( &ctx->cur, &values[i] )) {
report_error( ctx, "Expected literal floating point" ); switch (type) {
case TGSI_IMM_FLOAT32:
ret = parse_float(&ctx->cur, &values[i].Float);
break;
case TGSI_IMM_UINT32:
ret = parse_uint(&ctx->cur, &values[i].Uint);
break;
case TGSI_IMM_INT32:
ret = parse_int(&ctx->cur, &values[i].Int);
break;
}
if (!ret) {
report_error( ctx, "Expected immediate constant" );
return FALSE; return FALSE;
} }
} }
@ -1210,7 +1241,7 @@ static boolean parse_declaration( struct translate_ctx *ctx )
} }
} else if (is_imm_array) { } else if (is_imm_array) {
unsigned i; unsigned i;
float *vals_itr; union tgsi_immediate_data *vals_itr;
/* we have our immediate data */ /* we have our immediate data */
if (*cur != '{') { if (*cur != '{') {
report_error( ctx, "Immediate array without data" ); report_error( ctx, "Immediate array without data" );
@ -1222,9 +1253,9 @@ static boolean parse_declaration( struct translate_ctx *ctx )
decl.ImmediateData.u = decl.ImmediateData.u =
MALLOC(sizeof(union tgsi_immediate_data) * 4 * MALLOC(sizeof(union tgsi_immediate_data) * 4 *
(decl.Range.Last + 1)); (decl.Range.Last + 1));
vals_itr = (float*)decl.ImmediateData.u; vals_itr = decl.ImmediateData.u;
for (i = 0; i <= decl.Range.Last; ++i) { for (i = 0; i <= decl.Range.Last; ++i) {
if (!parse_immediate_data(ctx, vals_itr)) { if (!parse_immediate_data(ctx, TGSI_IMM_FLOAT32, vals_itr)) {
FREE(decl.ImmediateData.u); FREE(decl.ImmediateData.u);
return FALSE; return FALSE;
} }
@ -1291,28 +1322,27 @@ static boolean parse_declaration( struct translate_ctx *ctx )
static boolean parse_immediate( struct translate_ctx *ctx ) static boolean parse_immediate( struct translate_ctx *ctx )
{ {
struct tgsi_full_immediate imm; struct tgsi_full_immediate imm;
float values[4];
uint advance; uint advance;
int type;
if (!eat_white( &ctx->cur )) { if (!eat_white( &ctx->cur )) {
report_error( ctx, "Syntax error" ); report_error( ctx, "Syntax error" );
return FALSE; return FALSE;
} }
if (!str_match_no_case( &ctx->cur, "FLT32" ) || for (type = 0; type < Elements(tgsi_immediate_type_names); ++type) {
is_digit_alpha_underscore( ctx->cur )) { if (str_match_no_case(&ctx->cur, tgsi_immediate_type_names[type]) &&
report_error( ctx, "Expected `FLT32'" ); !is_digit_alpha_underscore(ctx->cur))
break;
}
if (type == Elements(tgsi_immediate_type_names)) {
report_error( ctx, "Expected immediate type" );
return FALSE; return FALSE;
} }
parse_immediate_data(ctx, values);
imm = tgsi_default_full_immediate(); imm = tgsi_default_full_immediate();
imm.Immediate.NrTokens += 4; imm.Immediate.NrTokens += 4;
imm.Immediate.DataType = TGSI_IMM_FLOAT32; imm.Immediate.DataType = type;
imm.u[0].Float = values[0]; parse_immediate_data(ctx, type, imm.u);
imm.u[1].Float = values[1];
imm.u[2].Float = values[2];
imm.u[3].Float = values[3];
advance = tgsi_build_full_immediate( advance = tgsi_build_full_immediate(
&imm, &imm,