d3dcompiler: Generalize message reporting function.
This commit is contained in:
parent
555f634912
commit
e2866d6fa1
|
@ -26,49 +26,17 @@
|
||||||
|
|
||||||
#include "d3dcompiler_private.h"
|
#include "d3dcompiler_private.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
|
WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
|
||||||
|
|
||||||
struct asm_parser asm_ctx;
|
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;
|
va_list args;
|
||||||
char* newbuffer;
|
|
||||||
int rc, newsize;
|
|
||||||
|
|
||||||
if(ctx->messagecapacity == 0) {
|
va_start(args, fmt);
|
||||||
ctx->messages = asm_alloc(MESSAGEBUFFER_INITIAL_SIZE);
|
compilation_message(&ctx->messages, fmt, args);
|
||||||
if(ctx->messages == NULL) {
|
va_end(args);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void asmshader_error(char const *s) {
|
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;
|
struct bwriter_shader *ret = NULL;
|
||||||
|
|
||||||
asm_ctx.shader = NULL;
|
asm_ctx.shader = NULL;
|
||||||
asm_ctx.status = PARSE_SUCCESS;
|
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;
|
asm_ctx.line_no = 1;
|
||||||
|
|
||||||
asmshader_parse();
|
asmshader_parse();
|
||||||
|
|
||||||
if(asm_ctx.status != PARSE_ERR) ret = asm_ctx.shader;
|
if (asm_ctx.status != PARSE_ERR)
|
||||||
else if(asm_ctx.shader) SlDeleteShader(asm_ctx.shader);
|
ret = asm_ctx.shader;
|
||||||
|
else if (asm_ctx.shader)
|
||||||
|
SlDeleteShader(asm_ctx.shader);
|
||||||
|
|
||||||
if(messages) {
|
if (messages)
|
||||||
if(asm_ctx.messagesize) {
|
{
|
||||||
|
if (asm_ctx.messages.size)
|
||||||
|
{
|
||||||
/* Shrink the buffer to the used 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) {
|
if(!*messages) {
|
||||||
ERR("Out of memory, no messages reported\n");
|
ERR("Out of memory, no messages reported\n");
|
||||||
asm_free(asm_ctx.messages);
|
asm_free(asm_ctx.messages.string);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*messages = NULL;
|
*messages = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(asm_ctx.messagecapacity) asm_free(asm_ctx.messages);
|
if(asm_ctx.messages.capacity) asm_free(asm_ctx.messages.string);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -216,7 +216,15 @@ enum parse_status
|
||||||
PARSE_ERR = 2
|
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 */
|
/* The function table of the parser implementation */
|
||||||
const struct asmparser_backend *funcs;
|
const struct asmparser_backend *funcs;
|
||||||
|
|
||||||
|
@ -225,9 +233,7 @@ struct asm_parser {
|
||||||
unsigned int m3x3pad_count;
|
unsigned int m3x3pad_count;
|
||||||
|
|
||||||
enum parse_status status;
|
enum parse_status status;
|
||||||
char *messages;
|
struct compilation_messages messages;
|
||||||
unsigned int messagesize;
|
|
||||||
unsigned int messagecapacity;
|
|
||||||
unsigned int line_no;
|
unsigned int line_no;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -255,6 +261,7 @@ struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
|
||||||
#define PRINTF_ATTR(fmt,args)
|
#define PRINTF_ATTR(fmt,args)
|
||||||
#endif
|
#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;
|
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)
|
static inline void set_parse_status(enum parse_status *current, enum parse_status update)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "d3dcompiler_private.h"
|
#include "d3dcompiler_private.h"
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
|
||||||
|
@ -715,3 +717,44 @@ HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob)
|
||||||
|
|
||||||
return S_OK;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue