unsigned int shader_type;
unsigned int parsing_builtin;
+
+ char error[256];
};
}
+static void
+_error(struct parse_context *ctx,
+ char *msg)
+{
+ if (ctx->error[0] == '\0') {
+ strcpy(ctx->error, msg);
+ }
+}
+
+
static int
_parse_token(struct parse_context *ctx,
enum sl_pp_token token,
return 0;
}
if (_parse_constant_expression(ctx, &p)) {
- return 0;
+ _error(ctx, "expected constant integral expression");
+ return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
- return 0;
+ _error(ctx, "expected `]'");
+ return -1;
}
_update(ctx, e, FIELD_ARRAY);
*ps = p;
_emit(ctx, &p.out, '\0');
}
if (_parse_token(ctx, SL_PP_LBRACE, &p)) {
+ _error(ctx, "expected `{'");
return -1;
}
if (_parse_struct_declaration_list(ctx, &p)) {
return -1;
}
if (_parse_constant_expression(ctx, &p)) {
+ _error(ctx, "expected constant integral expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
+ _error(ctx, "expected `]'");
return -1;
}
*ps = p;
return 0;
}
if (_parse_constant_expression(ctx, &p)) {
- return 0;
+ _error(ctx, "expected constant integral expression");
+ return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
- return 0;
+ _error(ctx, "expected `]'");
+ return -1;
}
_update(ctx, e, FUNCTION_CALL_ARRAY);
*ps = p;
*ps = p;
return 0;
}
+ _error(ctx, "expected `)'");
+ return -1;
}
p = *ps;
*ps = p;
return 0;
}
+ _error(ctx, "expected `)'");
+ return -1;
}
return -1;
_emit(ctx, &p.out, OP_POSTDECREMENT);
} else if (_parse_token(ctx, SL_PP_LBRACKET, &p) == 0) {
if (_parse_expression(ctx, &p)) {
- return 0;
+ _error(ctx, "expected an integral expression");
+ return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
- return 0;
+ _error(ctx, "expected `]'");
+ return -1;
}
_emit(ctx, &p.out, OP_SUBSCRIPT);
} else if (_parse_token(ctx, SL_PP_DOT, &p) == 0) {
return -1;
}
if (_parse_constant_expression(ctx, &p)) {
+ _error(ctx, "expected constant integral expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
+ _error(ctx, "expected `]'");
return -1;
}
*ps = p;
return -1;
}
if (_parse_constant_expression(ctx, &p)) {
+ _error(ctx, "expected constant integral expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RBRACKET, &p)) {
+ _error(ctx, "expected `]'");
return -1;
}
*ps = p;
*ps = p;
return 0;
}
+ _error(ctx, "expected `)'");
+ return -1;
}
}
*ps = p;
return 0;
}
+ _error(ctx, "expected `)'");
+ return -1;
}
return -1;
return -1;
}
if (_parse_token(ctx, SL_PP_LPAREN, &p)) {
+ _error(ctx, "expected `('");
return -1;
}
if (_parse_expression(ctx, &p)) {
+ _error(ctx, "expected an expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RPAREN, &p)) {
+ _error(ctx, "expected `)'");
return -1;
}
_emit(ctx, &p.out, OP_END);
return -1;
}
if (_parse_token(ctx, SL_PP_ASSIGN, &p)) {
+ _error(ctx, "expected `='");
return -1;
}
_emit(ctx, &p.out, VARIABLE_INITIALIZER);
if (_parse_initializer(ctx, &p)) {
+ _error(ctx, "expected an initialiser");
return -1;
}
_emit(ctx, &p.out, DECLARATOR_NONE);
if (_parse_id(ctx, ctx->dict._while, &p) == 0) {
_emit(ctx, &p.out, OP_WHILE);
if (_parse_token(ctx, SL_PP_LPAREN, &p)) {
+ _error(ctx, "expected `('");
return -1;
}
if (_parse_condition(ctx, &p)) {
+ _error(ctx, "expected an expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RPAREN, &p)) {
+ _error(ctx, "expected `)'");
return -1;
}
if (_parse_statement(ctx, &p)) {
return -1;
}
if (_parse_token(ctx, SL_PP_LPAREN, &p)) {
+ _error(ctx, "expected `('");
return -1;
}
if (_parse_expression(ctx, &p)) {
+ _error(ctx, "expected an expression");
return -1;
}
if (_parse_token(ctx, SL_PP_RPAREN, &p)) {
+ _error(ctx, "expected `)'");
return -1;
}
_emit(ctx, &p.out, OP_END);
if (_parse_token(ctx, SL_PP_SEMICOLON, &p)) {
+ _error(ctx, "expected `;'");
return -1;
}
*ps = p;
if (_parse_id(ctx, ctx->dict._for, &p) == 0) {
_emit(ctx, &p.out, OP_FOR);
if (_parse_token(ctx, SL_PP_LPAREN, &p)) {
+ _error(ctx, "expected `('");
return -1;
}
if (_parse_for_init_statement(ctx, &p)) {
return -1;
}
if (_parse_token(ctx, SL_PP_RPAREN, &p)) {
+ _error(ctx, "expected `)'");
return -1;
}
if (_parse_statement(ctx, &p)) {
*ps = p;
return 0;
}
+ _error(ctx, "expected an initialiser");
+ return -1;
}
p = *ps;
*ps = p;
return 0;
}
+ _error(ctx, "expected `]'");
+ return -1;
}
return 0;
}
*ps = p;
continue;
}
+ _error(ctx, "expected an initialiser");
+ break;
}
p = *ps;
*ps = p;
continue;
}
+ _error(ctx, "expected `]'");
+ break;
}
p = *ps;
}
_update(ctx, e, DECLARATION_INIT_DECLARATOR_LIST);
}
if (_parse_token(ctx, SL_PP_SEMICOLON, &p)) {
+ _error(ctx, "expected `;'");
return -1;
}
*ps = p;
return 0;
}
+ _error(ctx, "expected an identifier");
return -1;
}
sl_cl_compile(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
unsigned int shader_type,
+ unsigned int parsing_builtin,
unsigned char **output,
- unsigned int *cboutput)
+ unsigned int *cboutput,
+ char *error,
+ unsigned int cberror)
{
struct parse_context ctx;
struct parse_state ps;
ctx.shader_type = shader_type;
ctx.parsing_builtin = 1;
+ ctx.error[0] = '\0';
+
ps.in = 0;
ps.out = 0;
if (_parse_translation_unit(&ctx, &ps)) {
+ strncpy(error, ctx.error, cberror);
return -1;
}