Commit e2866d6f authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

d3dcompiler: Generalize message reporting function.

parent 555f6349
......@@ -26,49 +26,17 @@
#include "d3dcompiler_private.h"
#include <stdio.h>
WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
struct asm_parser asm_ctx;
/* Error reporting function */
void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) {
void asmparser_message(struct asm_parser *ctx, const char *fmt, ...)
{
va_list args;
char* newbuffer;
int rc, newsize;
if(ctx->messagecapacity == 0) {
ctx->messages = asm_alloc(MESSAGEBUFFER_INITIAL_SIZE);
if(ctx->messages == NULL) {
ERR("Error allocating memory for parser messages\n");
return;
}
ctx->messagecapacity = MESSAGEBUFFER_INITIAL_SIZE;
}
while(1) {
va_start(args, fmt);
rc = vsnprintf(ctx->messages + ctx->messagesize,
ctx->messagecapacity - ctx->messagesize, fmt, args);
va_end(args);
if (rc < 0 || /* C89 */
rc >= ctx->messagecapacity - ctx->messagesize) { /* C99 */
/* Resize the buffer */
newsize = ctx->messagecapacity * 2;
newbuffer = asm_realloc(ctx->messages, newsize);
if(newbuffer == NULL){
ERR("Error reallocating memory for parser messages\n");
return;
}
ctx->messages = newbuffer;
ctx->messagecapacity = newsize;
} else {
ctx->messagesize += rc;
return;
}
}
va_start(args, fmt);
compilation_message(&ctx->messages, fmt, args);
va_end(args);
}
static void asmshader_error(char const *s) {
......@@ -1704,32 +1672,37 @@ predicate: '(' REG_PREDICATE swizzle ')'
%%
struct bwriter_shader *parse_asm_shader(char **messages) {
struct bwriter_shader *parse_asm_shader(char **messages)
{
struct bwriter_shader *ret = NULL;
asm_ctx.shader = NULL;
asm_ctx.status = PARSE_SUCCESS;
asm_ctx.messagesize = asm_ctx.messagecapacity = 0;
asm_ctx.messages.size = asm_ctx.messages.capacity = 0;
asm_ctx.line_no = 1;
asmshader_parse();
if(asm_ctx.status != PARSE_ERR) ret = asm_ctx.shader;
else if(asm_ctx.shader) SlDeleteShader(asm_ctx.shader);
if (asm_ctx.status != PARSE_ERR)
ret = asm_ctx.shader;
else if (asm_ctx.shader)
SlDeleteShader(asm_ctx.shader);
if(messages) {
if(asm_ctx.messagesize) {
if (messages)
{
if (asm_ctx.messages.size)
{
/* Shrink the buffer to the used size */
*messages = asm_realloc(asm_ctx.messages, asm_ctx.messagesize + 1);
*messages = asm_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1);
if(!*messages) {
ERR("Out of memory, no messages reported\n");
asm_free(asm_ctx.messages);
asm_free(asm_ctx.messages.string);
}
} else {
*messages = NULL;
}
} else {
if(asm_ctx.messagecapacity) asm_free(asm_ctx.messages);
if(asm_ctx.messages.capacity) asm_free(asm_ctx.messages.string);
}
return ret;
......
......@@ -216,7 +216,15 @@ enum parse_status
PARSE_ERR = 2
};
struct asm_parser {
struct compilation_messages
{
char *string;
unsigned int size;
unsigned int capacity;
};
struct asm_parser
{
/* The function table of the parser implementation */
const struct asmparser_backend *funcs;
......@@ -225,9 +233,7 @@ struct asm_parser {
unsigned int m3x3pad_count;
enum parse_status status;
char *messages;
unsigned int messagesize;
unsigned int messagecapacity;
struct compilation_messages messages;
unsigned int line_no;
};
......@@ -255,6 +261,7 @@ struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
#define PRINTF_ATTR(fmt,args)
#endif
void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN;
void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
static inline void set_parse_status(enum parse_status *current, enum parse_status update)
{
......
......@@ -23,6 +23,8 @@
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include "d3dcompiler_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
......@@ -715,3 +717,44 @@ HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob)
return S_OK;
}
void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args)
{
char* buffer;
int rc, size;
if (msg->capacity == 0)
{
msg->string = asm_alloc(MESSAGEBUFFER_INITIAL_SIZE);
if (msg->string == NULL)
{
ERR("Error allocating memory for parser messages\n");
return;
}
msg->capacity = MESSAGEBUFFER_INITIAL_SIZE;
}
while (1)
{
rc = vsnprintf(msg->string + msg->size,
msg->capacity - msg->size, fmt, args);
if (rc < 0 || rc >= msg->capacity - msg->size)
{
size = msg->capacity * 2;
buffer = asm_realloc(msg->string, size);
if (buffer == NULL)
{
ERR("Error reallocating memory for parser messages\n");
return;
}
msg->string = buffer;
msg->capacity = size;
}
else
{
msg->size += rc;
return;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment