d3dcompiler: Always use vkd3d-shader's preprocessor.
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
8956862e0a
commit
9400874e3c
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_33.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=33
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_34.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=34
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_35.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=35
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_36.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=36
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_37.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=37
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_38.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=38
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_39.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=39
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_40.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=40
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_41.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=41
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
MODULE = d3dcompiler_42.dll
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=42
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -11,16 +11,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "wine/debug.h"
|
||||
|
||||
#include "d3dcompiler_private.h"
|
||||
#include "wpp_private.h"
|
||||
|
||||
#include <vkd3d_shader.h>
|
||||
|
||||
|
@ -55,49 +54,8 @@ static HRESULT hresult_from_vkd3d_result(int vkd3d_result)
|
|||
|
||||
#define D3DXERR_INVALIDDATA 0x88760b59
|
||||
|
||||
#define BUFFER_INITIAL_CAPACITY 256
|
||||
|
||||
struct mem_file_desc
|
||||
{
|
||||
const char *buffer;
|
||||
unsigned int size;
|
||||
unsigned int pos;
|
||||
};
|
||||
|
||||
static struct mem_file_desc current_shader;
|
||||
static ID3DInclude *current_include;
|
||||
static const char *initial_filename;
|
||||
|
||||
#define INCLUDES_INITIAL_CAPACITY 4
|
||||
|
||||
struct loaded_include
|
||||
{
|
||||
const char *name;
|
||||
const char *data;
|
||||
};
|
||||
|
||||
static struct loaded_include *includes;
|
||||
static int includes_capacity, includes_size;
|
||||
static const char *parent_include;
|
||||
|
||||
static char *wpp_output;
|
||||
static int wpp_output_capacity, wpp_output_size;
|
||||
|
||||
static char *wpp_messages;
|
||||
static int wpp_messages_capacity, wpp_messages_size;
|
||||
|
||||
struct define
|
||||
{
|
||||
struct define *next;
|
||||
char *name;
|
||||
char *value;
|
||||
};
|
||||
|
||||
static struct define *cmdline_defines;
|
||||
|
||||
/* Mutex used to guarantee a single invocation
|
||||
of the D3DXAssembleShader function (or its variants) at a time.
|
||||
This is needed as wpp isn't thread-safe */
|
||||
/* Mutex used to guarantee a single invocation of the D3DAssemble function at
|
||||
* a time. This is needed as the assembler isn't thread-safe. */
|
||||
static CRITICAL_SECTION wpp_mutex;
|
||||
static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
|
||||
{
|
||||
|
@ -108,409 +66,21 @@ static CRITICAL_SECTION_DEBUG wpp_mutex_debug =
|
|||
};
|
||||
static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 };
|
||||
|
||||
/* Preprocessor error reporting functions */
|
||||
static void wpp_write_message(const char *fmt, va_list args)
|
||||
struct d3dcompiler_include_from_file
|
||||
{
|
||||
char* newbuffer;
|
||||
int rc, newsize;
|
||||
ID3DInclude ID3DInclude_iface;
|
||||
const char *initial_filename;
|
||||
};
|
||||
|
||||
if(wpp_messages_capacity == 0)
|
||||
{
|
||||
wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE);
|
||||
if(wpp_messages == NULL)
|
||||
return;
|
||||
|
||||
wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
rc = vsnprintf(wpp_messages + wpp_messages_size,
|
||||
wpp_messages_capacity - wpp_messages_size, fmt, args);
|
||||
|
||||
if (rc < 0 || /* C89 */
|
||||
rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */
|
||||
/* Resize the buffer */
|
||||
newsize = wpp_messages_capacity * 2;
|
||||
newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize);
|
||||
if(newbuffer == NULL)
|
||||
{
|
||||
ERR("Error reallocating memory for parser messages\n");
|
||||
return;
|
||||
}
|
||||
wpp_messages = newbuffer;
|
||||
wpp_messages_capacity = newsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
wpp_messages_size += rc;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WINAPIV PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
|
||||
static inline struct d3dcompiler_include_from_file *impl_from_ID3DInclude(ID3DInclude *iface)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
wpp_write_message(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int WINAPIV ppy_error(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
wpp_write_message_var("%s:%d:%d: %s: ",
|
||||
pp_status.input ? pp_status.input : "'main file'",
|
||||
pp_status.line_number, pp_status.char_number, "Error");
|
||||
wpp_write_message(msg, ap);
|
||||
wpp_write_message_var("\n");
|
||||
va_end(ap);
|
||||
pp_status.state = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WINAPIV ppy_warning(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
wpp_write_message_var("%s:%d:%d: %s: ",
|
||||
pp_status.input ? pp_status.input : "'main file'",
|
||||
pp_status.line_number, pp_status.char_number, "Warning");
|
||||
wpp_write_message(msg, ap);
|
||||
wpp_write_message_var("\n");
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *wpp_lookup(const char *filename, int type, const char *parent_name)
|
||||
{
|
||||
/* We don't check for file existence here. We will potentially fail on
|
||||
* the following wpp_open_mem(). */
|
||||
char *path;
|
||||
int i;
|
||||
|
||||
TRACE("Looking for include %s, parent %s.\n", debugstr_a(filename), debugstr_a(parent_name));
|
||||
|
||||
parent_include = NULL;
|
||||
if (strcmp(parent_name, initial_filename))
|
||||
{
|
||||
for(i = 0; i < includes_size; i++)
|
||||
{
|
||||
if(!strcmp(parent_name, includes[i].name))
|
||||
{
|
||||
parent_include = includes[i].data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(parent_include == NULL)
|
||||
{
|
||||
ERR("Parent include %s missing.\n", debugstr_a(parent_name));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
path = malloc(strlen(filename) + 1);
|
||||
if(path)
|
||||
memcpy(path, filename, strlen(filename) + 1);
|
||||
return path;
|
||||
}
|
||||
|
||||
void *wpp_open(const char *filename, int type)
|
||||
{
|
||||
struct mem_file_desc *desc;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("Opening include %s.\n", debugstr_a(filename));
|
||||
|
||||
if(!strcmp(filename, initial_filename))
|
||||
{
|
||||
current_shader.pos = 0;
|
||||
return ¤t_shader;
|
||||
}
|
||||
|
||||
if(current_include == NULL) return NULL;
|
||||
desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
|
||||
if(!desc)
|
||||
return NULL;
|
||||
|
||||
if (FAILED(hr = ID3DInclude_Open(current_include, type ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
|
||||
filename, parent_include, (const void **)&desc->buffer, &desc->size)))
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, desc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(includes_capacity == includes_size)
|
||||
{
|
||||
if(includes_capacity == 0)
|
||||
{
|
||||
includes = HeapAlloc(GetProcessHeap(), 0, INCLUDES_INITIAL_CAPACITY * sizeof(*includes));
|
||||
if(includes == NULL)
|
||||
{
|
||||
ERR("Error allocating memory for the loaded includes structure\n");
|
||||
goto error;
|
||||
}
|
||||
includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes);
|
||||
}
|
||||
else
|
||||
{
|
||||
int newcapacity = includes_capacity * 2;
|
||||
struct loaded_include *newincludes =
|
||||
HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity);
|
||||
if(newincludes == NULL)
|
||||
{
|
||||
ERR("Error reallocating memory for the loaded includes structure\n");
|
||||
goto error;
|
||||
}
|
||||
includes = newincludes;
|
||||
includes_capacity = newcapacity;
|
||||
}
|
||||
}
|
||||
includes[includes_size].name = filename;
|
||||
includes[includes_size++].data = desc->buffer;
|
||||
|
||||
desc->pos = 0;
|
||||
return desc;
|
||||
|
||||
error:
|
||||
ID3DInclude_Close(current_include, desc->buffer);
|
||||
HeapFree(GetProcessHeap(), 0, desc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wpp_close(void *file)
|
||||
{
|
||||
struct mem_file_desc *desc = file;
|
||||
|
||||
if(desc != ¤t_shader)
|
||||
{
|
||||
if(current_include)
|
||||
ID3DInclude_Close(current_include, desc->buffer);
|
||||
else
|
||||
ERR("current_include == NULL, desc == %p, buffer = %s\n",
|
||||
desc, desc->buffer);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, desc);
|
||||
}
|
||||
}
|
||||
|
||||
int wpp_read(void *file, char *buffer, unsigned int len)
|
||||
{
|
||||
struct mem_file_desc *desc = file;
|
||||
|
||||
len = min(len, desc->size - desc->pos);
|
||||
memcpy(buffer, desc->buffer + desc->pos, len);
|
||||
desc->pos += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
void wpp_write(const char *buffer, unsigned int len)
|
||||
{
|
||||
char *new_wpp_output;
|
||||
|
||||
if(wpp_output_capacity == 0)
|
||||
{
|
||||
wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY);
|
||||
if(!wpp_output)
|
||||
return;
|
||||
|
||||
wpp_output_capacity = BUFFER_INITIAL_CAPACITY;
|
||||
}
|
||||
if(len > wpp_output_capacity - wpp_output_size)
|
||||
{
|
||||
while(len > wpp_output_capacity - wpp_output_size)
|
||||
{
|
||||
wpp_output_capacity *= 2;
|
||||
}
|
||||
new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
|
||||
wpp_output_capacity);
|
||||
if(!new_wpp_output)
|
||||
{
|
||||
ERR("Error allocating memory\n");
|
||||
return;
|
||||
}
|
||||
wpp_output = new_wpp_output;
|
||||
}
|
||||
memcpy(wpp_output + wpp_output_size, buffer, len);
|
||||
wpp_output_size += len;
|
||||
}
|
||||
|
||||
static int wpp_close_output(void)
|
||||
{
|
||||
char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output,
|
||||
wpp_output_size + 1);
|
||||
if(!new_wpp_output) return 0;
|
||||
wpp_output = new_wpp_output;
|
||||
wpp_output[wpp_output_size]='\0';
|
||||
wpp_output_size++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void add_cmdline_defines(void)
|
||||
{
|
||||
struct define *def;
|
||||
|
||||
for (def = cmdline_defines; def; def = def->next)
|
||||
{
|
||||
if (def->value) pp_add_define( def->name, def->value );
|
||||
}
|
||||
}
|
||||
|
||||
static void del_cmdline_defines(void)
|
||||
{
|
||||
struct define *def;
|
||||
|
||||
for (def = cmdline_defines; def; def = def->next)
|
||||
{
|
||||
if (def->value) pp_del_define( def->name );
|
||||
}
|
||||
}
|
||||
|
||||
static void add_special_defines(void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
pp_entry_t *ppp;
|
||||
char buf[32];
|
||||
|
||||
strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
|
||||
pp_add_define( "__DATE__", buf );
|
||||
|
||||
strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
|
||||
pp_add_define( "__TIME__", buf );
|
||||
|
||||
ppp = pp_add_define( "__FILE__", "" );
|
||||
if(ppp)
|
||||
ppp->type = def_special;
|
||||
|
||||
ppp = pp_add_define( "__LINE__", "" );
|
||||
if(ppp)
|
||||
ppp->type = def_special;
|
||||
}
|
||||
|
||||
static void del_special_defines(void)
|
||||
{
|
||||
pp_del_define( "__DATE__" );
|
||||
pp_del_define( "__TIME__" );
|
||||
pp_del_define( "__FILE__" );
|
||||
pp_del_define( "__LINE__" );
|
||||
}
|
||||
|
||||
|
||||
/* add a define to the preprocessor list */
|
||||
int wpp_add_define( const char *name, const char *value )
|
||||
{
|
||||
struct define *def;
|
||||
|
||||
if (!value) value = "";
|
||||
|
||||
for (def = cmdline_defines; def; def = def->next)
|
||||
{
|
||||
if (!strcmp( def->name, name ))
|
||||
{
|
||||
char *new_value = pp_xstrdup(value);
|
||||
if(!new_value)
|
||||
return 1;
|
||||
free( def->value );
|
||||
def->value = new_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
def = pp_xmalloc( sizeof(*def) );
|
||||
if(!def)
|
||||
return 1;
|
||||
def->next = cmdline_defines;
|
||||
def->name = pp_xstrdup(name);
|
||||
if(!def->name)
|
||||
{
|
||||
free(def);
|
||||
return 1;
|
||||
}
|
||||
def->value = pp_xstrdup(value);
|
||||
if(!def->value)
|
||||
{
|
||||
free(def->name);
|
||||
free(def);
|
||||
return 1;
|
||||
}
|
||||
cmdline_defines = def;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* undefine a previously added definition */
|
||||
void wpp_del_define( const char *name )
|
||||
{
|
||||
struct define *def;
|
||||
|
||||
for (def = cmdline_defines; def; def = def->next)
|
||||
{
|
||||
if (!strcmp( def->name, name ))
|
||||
{
|
||||
free( def->value );
|
||||
def->value = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* the main preprocessor parsing loop */
|
||||
int wpp_parse( const char *input, FILE *output )
|
||||
{
|
||||
int ret;
|
||||
|
||||
pp_status.input = NULL;
|
||||
pp_status.line_number = 1;
|
||||
pp_status.char_number = 1;
|
||||
pp_status.state = 0;
|
||||
|
||||
ret = pp_push_define_state();
|
||||
if(ret)
|
||||
return ret;
|
||||
add_cmdline_defines();
|
||||
add_special_defines();
|
||||
|
||||
if (!input) pp_status.file = stdin;
|
||||
else if (!(pp_status.file = wpp_open(input, 1)))
|
||||
{
|
||||
ppy_error("Could not open %s\n", input);
|
||||
del_special_defines();
|
||||
del_cmdline_defines();
|
||||
pp_pop_define_state();
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp_status.input = input ? pp_xstrdup(input) : NULL;
|
||||
|
||||
ppy_out = output;
|
||||
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
|
||||
|
||||
ret = ppy_parse();
|
||||
/* If there were errors during processing, return an error code */
|
||||
if (!ret && pp_status.state) ret = pp_status.state;
|
||||
|
||||
if (input)
|
||||
{
|
||||
wpp_close(pp_status.file);
|
||||
free(pp_status.input);
|
||||
}
|
||||
/* Clean if_stack, it could remain dirty on errors */
|
||||
while (pp_get_if_depth()) pp_pop_if();
|
||||
ppy_lex_destroy();
|
||||
del_special_defines();
|
||||
del_cmdline_defines();
|
||||
pp_pop_define_state();
|
||||
return ret;
|
||||
return CONTAINING_RECORD(iface, struct d3dcompiler_include_from_file, ID3DInclude_iface);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type,
|
||||
const char *filename, const void *parent_data, const void **data, UINT *bytes)
|
||||
{
|
||||
struct d3dcompiler_include_from_file *include = impl_from_ID3DInclude(iface);
|
||||
char *fullpath, *buffer = NULL, current_dir[MAX_PATH + 1];
|
||||
const char *initial_dir;
|
||||
SIZE_T size;
|
||||
|
@ -518,10 +88,10 @@ static HRESULT WINAPI d3dcompiler_include_from_file_open(ID3DInclude *iface, D3D
|
|||
ULONG read;
|
||||
DWORD len;
|
||||
|
||||
if ((initial_dir = strrchr(initial_filename, '\\')))
|
||||
if ((initial_dir = strrchr(include->initial_filename, '\\')))
|
||||
{
|
||||
len = initial_dir - initial_filename + 1;
|
||||
initial_dir = initial_filename;
|
||||
len = initial_dir - include->initial_filename + 1;
|
||||
initial_dir = include->initial_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -578,85 +148,106 @@ const struct ID3DIncludeVtbl d3dcompiler_include_from_file_vtbl =
|
|||
d3dcompiler_include_from_file_close
|
||||
};
|
||||
|
||||
struct d3dcompiler_include_from_file
|
||||
static int open_include(const char *filename, bool local, const char *parent_data, void *context,
|
||||
struct vkd3d_shader_code *code)
|
||||
{
|
||||
ID3DInclude ID3DInclude_iface;
|
||||
};
|
||||
ID3DInclude *iface = context;
|
||||
unsigned int size = 0;
|
||||
|
||||
if (!iface)
|
||||
return VKD3D_ERROR;
|
||||
|
||||
memset(code, 0, sizeof(*code));
|
||||
if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
|
||||
filename, parent_data, &code->code, &size)))
|
||||
return VKD3D_ERROR;
|
||||
|
||||
code->size = size;
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static void close_include(const struct vkd3d_shader_code *code, void *context)
|
||||
{
|
||||
ID3DInclude *iface = context;
|
||||
|
||||
ID3DInclude_Close(iface, code->code);
|
||||
}
|
||||
|
||||
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename,
|
||||
const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
|
||||
const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **shader_blob,
|
||||
ID3DBlob **messages_blob)
|
||||
{
|
||||
struct d3dcompiler_include_from_file include_from_file;
|
||||
int ret;
|
||||
HRESULT hr = S_OK;
|
||||
struct vkd3d_shader_preprocess_info preprocess_info;
|
||||
struct vkd3d_shader_compile_info compile_info;
|
||||
const D3D_SHADER_MACRO *def = defines;
|
||||
struct vkd3d_shader_code byte_code;
|
||||
char *messages;
|
||||
HRESULT hr;
|
||||
int ret;
|
||||
|
||||
if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE)
|
||||
{
|
||||
include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
|
||||
include_from_file.initial_filename = filename ? filename : "";
|
||||
include = &include_from_file.ID3DInclude_iface;
|
||||
}
|
||||
|
||||
if (def != NULL)
|
||||
compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
|
||||
compile_info.next = &preprocess_info;
|
||||
compile_info.source.code = data;
|
||||
compile_info.source.size = data_size;
|
||||
compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
|
||||
compile_info.target_type = VKD3D_SHADER_TARGET_NONE;
|
||||
compile_info.options = NULL;
|
||||
compile_info.option_count = 0;
|
||||
compile_info.log_level = VKD3D_SHADER_LOG_INFO;
|
||||
compile_info.source_name = filename;
|
||||
|
||||
preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
|
||||
preprocess_info.next = NULL;
|
||||
preprocess_info.macros = (const struct vkd3d_shader_macro *)defines;
|
||||
preprocess_info.macro_count = 0;
|
||||
if (defines)
|
||||
{
|
||||
while (def->Name != NULL)
|
||||
{
|
||||
wpp_add_define(def->Name, def->Definition);
|
||||
def++;
|
||||
}
|
||||
for (def = defines; def->Name; ++def)
|
||||
++preprocess_info.macro_count;
|
||||
}
|
||||
current_include = include;
|
||||
includes_size = 0;
|
||||
preprocess_info.pfn_open_include = open_include;
|
||||
preprocess_info.pfn_close_include = close_include;
|
||||
preprocess_info.include_context = include;
|
||||
|
||||
wpp_output_size = wpp_output_capacity = 0;
|
||||
wpp_output = NULL;
|
||||
|
||||
wpp_messages_size = wpp_messages_capacity = 0;
|
||||
wpp_messages = NULL;
|
||||
current_shader.buffer = data;
|
||||
current_shader.size = data_size;
|
||||
initial_filename = filename ? filename : "";
|
||||
|
||||
ret = wpp_parse(initial_filename, NULL);
|
||||
if (!wpp_close_output())
|
||||
ret = 1;
|
||||
if (ret)
|
||||
ret = vkd3d_shader_preprocess(&compile_info, &byte_code, &messages);
|
||||
if (messages)
|
||||
{
|
||||
TRACE("Error during shader preprocessing\n");
|
||||
if (wpp_messages)
|
||||
if (messages_blob)
|
||||
{
|
||||
int size;
|
||||
ID3DBlob *buffer;
|
||||
|
||||
TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages));
|
||||
|
||||
if (error_messages)
|
||||
size_t size = strlen(messages);
|
||||
if (FAILED(hr = D3DCreateBlob(size, messages_blob)))
|
||||
{
|
||||
size = strlen(wpp_messages) + 1;
|
||||
hr = D3DCreateBlob(size, &buffer);
|
||||
if (FAILED(hr))
|
||||
goto cleanup;
|
||||
CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size);
|
||||
*error_messages = buffer;
|
||||
vkd3d_shader_free_messages(messages);
|
||||
vkd3d_shader_free_shader_code(&byte_code);
|
||||
return hr;
|
||||
}
|
||||
memcpy(ID3D10Blob_GetBufferPointer(*messages_blob), messages, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkd3d_shader_free_messages(messages);
|
||||
}
|
||||
if (data)
|
||||
TRACE("Shader source:\n%s\n", debugstr_an(data, data_size));
|
||||
hr = E_FAIL;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
/* Remove the previously added defines */
|
||||
if (defines != NULL)
|
||||
if (!ret)
|
||||
{
|
||||
while (defines->Name != NULL)
|
||||
if (FAILED(hr = D3DCreateBlob(byte_code.size, shader_blob)))
|
||||
{
|
||||
wpp_del_define(defines->Name);
|
||||
defines++;
|
||||
vkd3d_shader_free_shader_code(&byte_code);
|
||||
return hr;
|
||||
}
|
||||
memcpy(ID3D10Blob_GetBufferPointer(*shader_blob), byte_code.code, byte_code.size);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, wpp_messages);
|
||||
return hr;
|
||||
|
||||
return hresult_from_vkd3d_result(ret);
|
||||
}
|
||||
|
||||
static HRESULT assemble_shader(const char *preproc_shader, ID3DBlob **shader_blob, ID3DBlob **error_messages)
|
||||
|
@ -739,6 +330,9 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
|
|||
const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags,
|
||||
ID3DBlob **shader, ID3DBlob **error_messages)
|
||||
{
|
||||
unsigned int preproc_size;
|
||||
ID3DBlob *preproc_shader;
|
||||
char *preproc_terminated;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, sflags %#x, "
|
||||
|
@ -753,40 +347,24 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
|
|||
if (shader) *shader = NULL;
|
||||
if (error_messages) *error_messages = NULL;
|
||||
|
||||
hr = preprocess_shader(data, datasize, filename, defines, include, error_messages);
|
||||
hr = preprocess_shader(data, datasize, filename, defines, include, &preproc_shader, error_messages);
|
||||
if (SUCCEEDED(hr))
|
||||
hr = assemble_shader(wpp_output, shader, error_messages);
|
||||
{
|
||||
preproc_size = ID3D10Blob_GetBufferSize(preproc_shader);
|
||||
if ((preproc_terminated = malloc(preproc_size + 1)))
|
||||
{
|
||||
memcpy(preproc_terminated, ID3D10Blob_GetBufferPointer(preproc_shader), preproc_size);
|
||||
ID3D10Blob_Release(preproc_shader);
|
||||
preproc_terminated[preproc_size] = 0;
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, wpp_output);
|
||||
hr = assemble_shader(preproc_terminated, shader, error_messages);
|
||||
free(preproc_terminated);
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&wpp_mutex);
|
||||
return hr;
|
||||
}
|
||||
|
||||
static int open_include(const char *filename, bool local, const char *parent_data, void *context,
|
||||
struct vkd3d_shader_code *code)
|
||||
{
|
||||
ID3DInclude *iface = context;
|
||||
unsigned int size = 0;
|
||||
|
||||
if (!iface)
|
||||
return VKD3D_ERROR;
|
||||
|
||||
memset(code, 0, sizeof(*code));
|
||||
if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
|
||||
filename, parent_data, &code->code, &size)))
|
||||
return VKD3D_ERROR;
|
||||
|
||||
code->size = size;
|
||||
return VKD3D_OK;
|
||||
}
|
||||
|
||||
static void close_include(const struct vkd3d_shader_code *code, void *context)
|
||||
{
|
||||
ID3DInclude *iface = context;
|
||||
|
||||
ID3DInclude_Close(iface, code->code);
|
||||
}
|
||||
|
||||
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
|
||||
const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
|
||||
const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
|
||||
|
@ -839,6 +417,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen
|
|||
if (include == D3D_COMPILE_STANDARD_FILE_INCLUDE)
|
||||
{
|
||||
include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
|
||||
include_from_file.initial_filename = filename ? filename : "";
|
||||
include = &include_from_file.ID3DInclude_iface;
|
||||
}
|
||||
|
||||
|
@ -891,7 +470,6 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen
|
|||
preprocess_info.pfn_open_include = open_include;
|
||||
preprocess_info.pfn_close_include = close_include;
|
||||
preprocess_info.include_context = include;
|
||||
initial_filename = filename ? filename : "";
|
||||
|
||||
hlsl_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO;
|
||||
hlsl_info.next = NULL;
|
||||
|
@ -955,40 +533,16 @@ HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename
|
|||
const D3D_SHADER_MACRO *defines, ID3DInclude *include,
|
||||
ID3DBlob **shader, ID3DBlob **error_messages)
|
||||
{
|
||||
HRESULT hr;
|
||||
ID3DBlob *buffer;
|
||||
|
||||
TRACE("data %p, size %Iu, filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
|
||||
data, size, debugstr_a(filename), defines, include, shader, error_messages);
|
||||
|
||||
if (!data)
|
||||
return E_INVALIDARG;
|
||||
|
||||
EnterCriticalSection(&wpp_mutex);
|
||||
|
||||
if (shader) *shader = NULL;
|
||||
if (error_messages) *error_messages = NULL;
|
||||
|
||||
hr = preprocess_shader(data, size, filename, defines, include, error_messages);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
if (shader)
|
||||
{
|
||||
hr = D3DCreateBlob(wpp_output_size, &buffer);
|
||||
if (FAILED(hr))
|
||||
goto cleanup;
|
||||
CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size);
|
||||
*shader = buffer;
|
||||
}
|
||||
else
|
||||
hr = E_INVALIDARG;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
HeapFree(GetProcessHeap(), 0, wpp_output);
|
||||
LeaveCriticalSection(&wpp_mutex);
|
||||
return hr;
|
||||
return preprocess_shader(data, size, filename, defines, include, shader, error_messages);
|
||||
}
|
||||
|
||||
HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,689 +0,0 @@
|
|||
/*
|
||||
* Wrc preprocessor syntax analysis
|
||||
*
|
||||
* Copyright 1999-2000 Bertho A. Stultiens (BS)
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "wpp_private.h"
|
||||
|
||||
|
||||
#define UNARY_OP(r, v, OP) \
|
||||
switch(v.type) \
|
||||
{ \
|
||||
case cv_sint: r.val.si = OP v.val.si; break; \
|
||||
case cv_uint: r.val.ui = OP v.val.ui; break; \
|
||||
case cv_slong: r.val.sl = OP v.val.sl; break; \
|
||||
case cv_ulong: r.val.ul = OP v.val.ul; break; \
|
||||
case cv_sll: r.val.sll = OP v.val.sll; break; \
|
||||
case cv_ull: r.val.ull = OP v.val.ull; break; \
|
||||
}
|
||||
|
||||
#define cv_signed(v) ((v.type & FLAG_SIGNED) != 0)
|
||||
|
||||
#define BIN_OP_INT(r, v1, v2, OP) \
|
||||
r.type = v1.type; \
|
||||
if(cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.si = v1.val.si OP v2.val.si; \
|
||||
else if(cv_signed(v1) && !cv_signed(v2)) \
|
||||
r.val.si = v1.val.si OP (signed) v2.val.ui; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.si = (signed) v1.val.ui OP v2.val.si; \
|
||||
else \
|
||||
r.val.ui = v1.val.ui OP v2.val.ui;
|
||||
|
||||
#define BIN_OP_LONG(r, v1, v2, OP) \
|
||||
r.type = v1.type; \
|
||||
if(cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sl = v1.val.sl OP v2.val.sl; \
|
||||
else if(cv_signed(v1) && !cv_signed(v2)) \
|
||||
r.val.sl = v1.val.sl OP (signed long) v2.val.ul; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sl = (signed long) v1.val.ul OP v2.val.sl; \
|
||||
else \
|
||||
r.val.ul = v1.val.ul OP v2.val.ul;
|
||||
|
||||
#define BIN_OP_LONGLONG(r, v1, v2, OP) \
|
||||
r.type = v1.type; \
|
||||
if(cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sll = v1.val.sll OP v2.val.sll; \
|
||||
else if(cv_signed(v1) && !cv_signed(v2)) \
|
||||
r.val.sll = v1.val.sll OP (__int64) v2.val.ull; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sll = (__int64) v1.val.ull OP v2.val.sll; \
|
||||
else \
|
||||
r.val.ull = v1.val.ull OP v2.val.ull;
|
||||
|
||||
#define BIN_OP(r, v1, v2, OP) \
|
||||
switch(v1.type & SIZE_MASK) \
|
||||
{ \
|
||||
case SIZE_INT: BIN_OP_INT(r, v1, v2, OP); break; \
|
||||
case SIZE_LONG: BIN_OP_LONG(r, v1, v2, OP); break; \
|
||||
case SIZE_LONGLONG: BIN_OP_LONGLONG(r, v1, v2, OP); break; \
|
||||
default: pp_internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
static int boolean(cval_t *v);
|
||||
static void promote_equal_size(cval_t *v1, cval_t *v2);
|
||||
static void cast_to_sint(cval_t *v);
|
||||
static void cast_to_uint(cval_t *v);
|
||||
static void cast_to_slong(cval_t *v);
|
||||
static void cast_to_ulong(cval_t *v);
|
||||
static void cast_to_sll(cval_t *v);
|
||||
static void cast_to_ull(cval_t *v);
|
||||
static marg_t *new_marg(char *str, def_arg_t type);
|
||||
static marg_t *add_new_marg(char *str, def_arg_t type);
|
||||
static int marg_index(char *id);
|
||||
static mtext_t *new_mtext(char *str, int idx, def_exp_t type);
|
||||
static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp);
|
||||
static char *merge_text(char *s1, char *s2);
|
||||
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
static marg_t **macro_args; /* Macro parameters array while parsing */
|
||||
static int nmacro_args;
|
||||
|
||||
%}
|
||||
|
||||
%define api.prefix {ppy_}
|
||||
|
||||
%union{
|
||||
int sint;
|
||||
unsigned int uint;
|
||||
long slong;
|
||||
unsigned long ulong;
|
||||
__int64 sll;
|
||||
unsigned __int64 ull;
|
||||
int *iptr;
|
||||
char *cptr;
|
||||
cval_t cval;
|
||||
marg_t *marg;
|
||||
mtext_t *mtext;
|
||||
}
|
||||
|
||||
%token tRCINCLUDE
|
||||
%token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
|
||||
%token tINCLUDE tLINE tGCCLINE tERROR tWARNING tPRAGMA tPPIDENT
|
||||
%token tUNDEF tMACROEND tCONCAT tELIPSIS tSTRINGIZE
|
||||
%token <cptr> tIDENT tLITERAL tMACRO tDEFINE
|
||||
%token <cptr> tDQSTRING tSQSTRING tIQSTRING
|
||||
%token <uint> tUINT
|
||||
%token <sint> tSINT
|
||||
%token <ulong> tULONG
|
||||
%token <slong> tSLONG
|
||||
%token <ull> tULONGLONG
|
||||
%token <sll> tSLONGLONG
|
||||
%token <cptr> tRCINCLUDEPATH
|
||||
|
||||
%right '?' ':'
|
||||
%left tLOGOR
|
||||
%left tLOGAND
|
||||
%left '|'
|
||||
%left '^'
|
||||
%left '&'
|
||||
%left tEQ tNE
|
||||
%left '<' tLTE '>' tGTE
|
||||
%left tLSHIFT tRSHIFT
|
||||
%left '+' '-'
|
||||
%left '*' '/'
|
||||
%right '~' '!'
|
||||
|
||||
%type <cval> pp_expr
|
||||
%type <marg> emargs margs
|
||||
%type <mtext> opt_mtexts mtexts mtext
|
||||
%type <sint> allmargs
|
||||
%type <cptr> opt_text text
|
||||
|
||||
/*
|
||||
**************************************************************************
|
||||
* The parser starts here
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
%%
|
||||
|
||||
pp_file : /* Empty */
|
||||
| pp_file preprocessor
|
||||
;
|
||||
|
||||
preprocessor
|
||||
: tINCLUDE tDQSTRING tNL { pp_do_include($2, 1); }
|
||||
| tINCLUDE tIQSTRING tNL { pp_do_include($2, 0); }
|
||||
| tIF pp_expr tNL { pp_next_if_state(boolean(&$2)); }
|
||||
| tIFDEF tIDENT tNL { pp_next_if_state(pplookup($2) != NULL); free($2); }
|
||||
| tIFNDEF tIDENT tNL {
|
||||
int t = pplookup($2) == NULL;
|
||||
if(pp_incl_state.state == 0 && t && !pp_incl_state.seen_junk)
|
||||
{
|
||||
pp_incl_state.state = 1;
|
||||
pp_incl_state.ppp = $2;
|
||||
pp_incl_state.ifdepth = pp_get_if_depth();
|
||||
}
|
||||
else if(pp_incl_state.state != 1)
|
||||
{
|
||||
pp_incl_state.state = -1;
|
||||
free($2);
|
||||
}
|
||||
else
|
||||
free($2);
|
||||
pp_next_if_state(t);
|
||||
}
|
||||
| tELIF pp_expr tNL {
|
||||
pp_if_state_t s = pp_pop_if();
|
||||
switch(s)
|
||||
{
|
||||
case if_true:
|
||||
case if_elif:
|
||||
pp_push_if(if_elif);
|
||||
break;
|
||||
case if_false:
|
||||
pp_push_if(boolean(&$2) ? if_true : if_false);
|
||||
break;
|
||||
case if_ignore:
|
||||
pp_push_if(if_ignore);
|
||||
break;
|
||||
case if_elsetrue:
|
||||
case if_elsefalse:
|
||||
ppy_error("#elif cannot follow #else");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
|
||||
}
|
||||
}
|
||||
| tELSE tNL {
|
||||
pp_if_state_t s = pp_pop_if();
|
||||
switch(s)
|
||||
{
|
||||
case if_true:
|
||||
pp_push_if(if_elsefalse);
|
||||
break;
|
||||
case if_elif:
|
||||
pp_push_if(if_elif);
|
||||
break;
|
||||
case if_false:
|
||||
pp_push_if(if_elsetrue);
|
||||
break;
|
||||
case if_ignore:
|
||||
pp_push_if(if_ignore);
|
||||
break;
|
||||
case if_elsetrue:
|
||||
case if_elsefalse:
|
||||
ppy_error("#else clause already defined");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
|
||||
}
|
||||
}
|
||||
| tENDIF tNL {
|
||||
if(pp_pop_if() != if_error)
|
||||
{
|
||||
if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
|
||||
{
|
||||
pp_incl_state.state = 2;
|
||||
pp_incl_state.seen_junk = 0;
|
||||
}
|
||||
else if(pp_incl_state.state != 1)
|
||||
{
|
||||
pp_incl_state.state = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
| tUNDEF tIDENT tNL { pp_del_define($2); free($2); }
|
||||
| tDEFINE opt_text tNL { pp_add_define($1, $2); free($1); free($2); }
|
||||
| tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
|
||||
pp_add_macro($1, macro_args, nmacro_args, $5);
|
||||
}
|
||||
| tLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d\n", $2, $3, $4); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
|
||||
| tGCCLINE tNL /* The null-token */
|
||||
| tERROR opt_text tNL { ppy_error("#error directive: '%s'", $2); free($2); }
|
||||
| tWARNING opt_text tNL { ppy_warning("#warning directive: '%s'", $2); free($2); }
|
||||
| tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
|
||||
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
|
||||
| tRCINCLUDE tRCINCLUDEPATH {
|
||||
if($2)
|
||||
{
|
||||
int nl=strlen($2) +3;
|
||||
char *fn=pp_xmalloc(nl);
|
||||
if(fn)
|
||||
{
|
||||
sprintf(fn,"\"%s\"",$2);
|
||||
pp_do_include(fn,1);
|
||||
}
|
||||
free($2);
|
||||
}
|
||||
}
|
||||
| tRCINCLUDE tDQSTRING {
|
||||
pp_do_include($2,1);
|
||||
}
|
||||
/*| tNL*/
|
||||
;
|
||||
|
||||
opt_text: /* Empty */ { $$ = NULL; }
|
||||
| text { $$ = $1; }
|
||||
;
|
||||
|
||||
text : tLITERAL { $$ = $1; }
|
||||
| tDQSTRING { $$ = $1; }
|
||||
| tSQSTRING { $$ = $1; }
|
||||
| text tLITERAL { $$ = merge_text($1, $2); }
|
||||
| text tDQSTRING { $$ = merge_text($1, $2); }
|
||||
| text tSQSTRING { $$ = merge_text($1, $2); }
|
||||
;
|
||||
|
||||
res_arg : /* Empty */ { macro_args = NULL; nmacro_args = 0; }
|
||||
;
|
||||
|
||||
allmargs: /* Empty */ { $$ = 0; macro_args = NULL; nmacro_args = 0; }
|
||||
| emargs { $$ = nmacro_args; }
|
||||
;
|
||||
|
||||
emargs : margs { $$ = $1; }
|
||||
| margs ',' tELIPSIS { $$ = add_new_marg(NULL, arg_list); nmacro_args *= -1; }
|
||||
;
|
||||
|
||||
margs : margs ',' tIDENT { $$ = add_new_marg($3, arg_single); }
|
||||
| tIDENT { $$ = add_new_marg($1, arg_single); }
|
||||
;
|
||||
|
||||
opt_mtexts
|
||||
: /* Empty */ { $$ = NULL; }
|
||||
| mtexts {
|
||||
for($$ = $1; $$ && $$->prev; $$ = $$->prev)
|
||||
;
|
||||
}
|
||||
;
|
||||
|
||||
mtexts : mtext { $$ = $1; }
|
||||
| mtexts mtext { $$ = combine_mtext($1, $2); }
|
||||
;
|
||||
|
||||
mtext : tLITERAL { $$ = new_mtext($1, 0, exp_text); }
|
||||
| tDQSTRING { $$ = new_mtext($1, 0, exp_text); }
|
||||
| tSQSTRING { $$ = new_mtext($1, 0, exp_text); }
|
||||
| tCONCAT { $$ = new_mtext(NULL, 0, exp_concat); }
|
||||
| tSTRINGIZE tIDENT {
|
||||
int mat = marg_index($2);
|
||||
if(mat < 0)
|
||||
ppy_error("Stringification identifier must be an argument parameter");
|
||||
else
|
||||
$$ = new_mtext(NULL, mat, exp_stringize);
|
||||
}
|
||||
| tIDENT {
|
||||
int mat = marg_index($1);
|
||||
if(mat >= 0)
|
||||
$$ = new_mtext(NULL, mat, exp_subst);
|
||||
else if($1)
|
||||
$$ = new_mtext($1, 0, exp_text);
|
||||
}
|
||||
;
|
||||
|
||||
pp_expr : tSINT { $$.type = cv_sint; $$.val.si = $1; }
|
||||
| tUINT { $$.type = cv_uint; $$.val.ui = $1; }
|
||||
| tSLONG { $$.type = cv_slong; $$.val.sl = $1; }
|
||||
| tULONG { $$.type = cv_ulong; $$.val.ul = $1; }
|
||||
| tSLONGLONG { $$.type = cv_sll; $$.val.sll = $1; }
|
||||
| tULONGLONG { $$.type = cv_ull; $$.val.ull = $1; }
|
||||
| tDEFINED tIDENT { $$.type = cv_sint; $$.val.si = pplookup($2) != NULL; }
|
||||
| tDEFINED '(' tIDENT ')' { $$.type = cv_sint; $$.val.si = pplookup($3) != NULL; }
|
||||
| tIDENT { $$.type = cv_sint; $$.val.si = 0; }
|
||||
| pp_expr tLOGOR pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) || boolean(&$3); }
|
||||
| pp_expr tLOGAND pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) && boolean(&$3); }
|
||||
| pp_expr tEQ pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ==); }
|
||||
| pp_expr tNE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, !=); }
|
||||
| pp_expr '<' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <); }
|
||||
| pp_expr '>' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >); }
|
||||
| pp_expr tLTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <=); }
|
||||
| pp_expr tGTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >=); }
|
||||
| pp_expr '+' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, +); }
|
||||
| pp_expr '-' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, -); }
|
||||
| pp_expr '^' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ^); }
|
||||
| pp_expr '&' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, &); }
|
||||
| pp_expr '|' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, |); }
|
||||
| pp_expr '*' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, *); }
|
||||
| pp_expr '/' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, /); }
|
||||
| pp_expr tLSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <<); }
|
||||
| pp_expr tRSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >>); }
|
||||
| '+' pp_expr { $$ = $2; }
|
||||
| '-' pp_expr { UNARY_OP($$, $2, -); }
|
||||
| '~' pp_expr { UNARY_OP($$, $2, ~); }
|
||||
| '!' pp_expr { $$.type = cv_sint; $$.val.si = !boolean(&$2); }
|
||||
| '(' pp_expr ')' { $$ = $2; }
|
||||
| pp_expr '?' pp_expr ':' pp_expr { $$ = boolean(&$1) ? $3 : $5; }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
/*
|
||||
**************************************************************************
|
||||
* Support functions
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
static void cast_to_sint(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: break;
|
||||
case cv_uint: break;
|
||||
case cv_slong: v->val.si = v->val.sl; break;
|
||||
case cv_ulong: v->val.si = v->val.ul; break;
|
||||
case cv_sll: v->val.si = v->val.sll; break;
|
||||
case cv_ull: v->val.si = v->val.ull; break;
|
||||
}
|
||||
v->type = cv_sint;
|
||||
}
|
||||
|
||||
static void cast_to_uint(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: break;
|
||||
case cv_uint: break;
|
||||
case cv_slong: v->val.ui = v->val.sl; break;
|
||||
case cv_ulong: v->val.ui = v->val.ul; break;
|
||||
case cv_sll: v->val.ui = v->val.sll; break;
|
||||
case cv_ull: v->val.ui = v->val.ull; break;
|
||||
}
|
||||
v->type = cv_uint;
|
||||
}
|
||||
|
||||
static void cast_to_slong(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: v->val.sl = v->val.si; break;
|
||||
case cv_uint: v->val.sl = v->val.ui; break;
|
||||
case cv_slong: break;
|
||||
case cv_ulong: break;
|
||||
case cv_sll: v->val.sl = v->val.sll; break;
|
||||
case cv_ull: v->val.sl = v->val.ull; break;
|
||||
}
|
||||
v->type = cv_slong;
|
||||
}
|
||||
|
||||
static void cast_to_ulong(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: v->val.ul = v->val.si; break;
|
||||
case cv_uint: v->val.ul = v->val.ui; break;
|
||||
case cv_slong: break;
|
||||
case cv_ulong: break;
|
||||
case cv_sll: v->val.ul = v->val.sll; break;
|
||||
case cv_ull: v->val.ul = v->val.ull; break;
|
||||
}
|
||||
v->type = cv_ulong;
|
||||
}
|
||||
|
||||
static void cast_to_sll(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: v->val.sll = v->val.si; break;
|
||||
case cv_uint: v->val.sll = v->val.ui; break;
|
||||
case cv_slong: v->val.sll = v->val.sl; break;
|
||||
case cv_ulong: v->val.sll = v->val.ul; break;
|
||||
case cv_sll: break;
|
||||
case cv_ull: break;
|
||||
}
|
||||
v->type = cv_sll;
|
||||
}
|
||||
|
||||
static void cast_to_ull(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: v->val.ull = v->val.si; break;
|
||||
case cv_uint: v->val.ull = v->val.ui; break;
|
||||
case cv_slong: v->val.ull = v->val.sl; break;
|
||||
case cv_ulong: v->val.ull = v->val.ul; break;
|
||||
case cv_sll: break;
|
||||
case cv_ull: break;
|
||||
}
|
||||
v->type = cv_ull;
|
||||
}
|
||||
|
||||
|
||||
static void promote_equal_size(cval_t *v1, cval_t *v2)
|
||||
{
|
||||
#define cv_sizeof(v) ((int)(v->type & SIZE_MASK))
|
||||
int s1 = cv_sizeof(v1);
|
||||
int s2 = cv_sizeof(v2);
|
||||
#undef cv_sizeof
|
||||
|
||||
if(s1 == s2)
|
||||
return;
|
||||
else if(s1 > s2)
|
||||
{
|
||||
switch(v1->type)
|
||||
{
|
||||
case cv_sint: cast_to_sint(v2); break;
|
||||
case cv_uint: cast_to_uint(v2); break;
|
||||
case cv_slong: cast_to_slong(v2); break;
|
||||
case cv_ulong: cast_to_ulong(v2); break;
|
||||
case cv_sll: cast_to_sll(v2); break;
|
||||
case cv_ull: cast_to_ull(v2); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(v2->type)
|
||||
{
|
||||
case cv_sint: cast_to_sint(v1); break;
|
||||
case cv_uint: cast_to_uint(v1); break;
|
||||
case cv_slong: cast_to_slong(v1); break;
|
||||
case cv_ulong: cast_to_ulong(v1); break;
|
||||
case cv_sll: cast_to_sll(v1); break;
|
||||
case cv_ull: cast_to_ull(v1); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int boolean(cval_t *v)
|
||||
{
|
||||
switch(v->type)
|
||||
{
|
||||
case cv_sint: return v->val.si != 0;
|
||||
case cv_uint: return v->val.ui != 0;
|
||||
case cv_slong: return v->val.sl != 0;
|
||||
case cv_ulong: return v->val.ul != 0;
|
||||
case cv_sll: return v->val.sll != 0;
|
||||
case cv_ull: return v->val.ull != 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static marg_t *new_marg(char *str, def_arg_t type)
|
||||
{
|
||||
marg_t *ma = pp_xmalloc(sizeof(marg_t));
|
||||
if(!ma)
|
||||
return NULL;
|
||||
ma->arg = str;
|
||||
ma->type = type;
|
||||
ma->nnl = 0;
|
||||
return ma;
|
||||
}
|
||||
|
||||
static marg_t *add_new_marg(char *str, def_arg_t type)
|
||||
{
|
||||
marg_t **new_macro_args;
|
||||
marg_t *ma;
|
||||
if(!str)
|
||||
return NULL;
|
||||
new_macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
|
||||
if(!new_macro_args)
|
||||
return NULL;
|
||||
macro_args = new_macro_args;
|
||||
ma = new_marg(str, type);
|
||||
if(!ma)
|
||||
return NULL;
|
||||
macro_args[nmacro_args] = ma;
|
||||
nmacro_args++;
|
||||
return ma;
|
||||
}
|
||||
|
||||
static int marg_index(char *id)
|
||||
{
|
||||
int t;
|
||||
if(!id)
|
||||
return -1;
|
||||
for(t = 0; t < nmacro_args; t++)
|
||||
{
|
||||
if(!strcmp(id, macro_args[t]->arg))
|
||||
break;
|
||||
}
|
||||
return t < nmacro_args ? t : -1;
|
||||
}
|
||||
|
||||
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
|
||||
{
|
||||
mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
|
||||
if(!mt)
|
||||
return NULL;
|
||||
if(str == NULL)
|
||||
mt->subst.argidx = idx;
|
||||
else
|
||||
mt->subst.text = str;
|
||||
mt->type = type;
|
||||
mt->next = mt->prev = NULL;
|
||||
return mt;
|
||||
}
|
||||
|
||||
static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
|
||||
{
|
||||
if(!tail)
|
||||
return mtp;
|
||||
|
||||
if(!mtp)
|
||||
return tail;
|
||||
|
||||
if(tail->type == exp_text && mtp->type == exp_text)
|
||||
{
|
||||
char *new_text;
|
||||
new_text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
|
||||
if(!new_text)
|
||||
return mtp;
|
||||
tail->subst.text = new_text;
|
||||
strcat(tail->subst.text, mtp->subst.text);
|
||||
free(mtp->subst.text);
|
||||
free(mtp);
|
||||
return tail;
|
||||
}
|
||||
|
||||
if(tail->type == exp_concat && mtp->type == exp_concat)
|
||||
{
|
||||
free(mtp);
|
||||
return tail;
|
||||
}
|
||||
|
||||
if(tail->type == exp_concat && mtp->type == exp_text)
|
||||
{
|
||||
int len = strlen(mtp->subst.text);
|
||||
while(len)
|
||||
{
|
||||
/* FIXME: should delete space from head of string */
|
||||
if(isspace(mtp->subst.text[len-1] & 0xff))
|
||||
mtp->subst.text[--len] = '\0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if(!len)
|
||||
{
|
||||
free(mtp->subst.text);
|
||||
free(mtp);
|
||||
return tail;
|
||||
}
|
||||
}
|
||||
|
||||
if(tail->type == exp_text && mtp->type == exp_concat)
|
||||
{
|
||||
int len = strlen(tail->subst.text);
|
||||
while(len)
|
||||
{
|
||||
if(isspace(tail->subst.text[len-1] & 0xff))
|
||||
tail->subst.text[--len] = '\0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if(!len)
|
||||
{
|
||||
mtp->prev = tail->prev;
|
||||
mtp->next = tail->next;
|
||||
if(tail->prev)
|
||||
tail->prev->next = mtp;
|
||||
free(tail->subst.text);
|
||||
free(tail);
|
||||
return mtp;
|
||||
}
|
||||
}
|
||||
|
||||
tail->next = mtp;
|
||||
mtp->prev = tail;
|
||||
|
||||
return mtp;
|
||||
}
|
||||
|
||||
static char *merge_text(char *s1, char *s2)
|
||||
{
|
||||
int l1;
|
||||
int l2;
|
||||
char *snew;
|
||||
if(!s1)
|
||||
return s2;
|
||||
if(!s2)
|
||||
return s1;
|
||||
l1 = strlen(s1);
|
||||
l2 = strlen(s2);
|
||||
snew = pp_xrealloc(s1, l1+l2+1);
|
||||
if(!snew)
|
||||
{
|
||||
free(s2);
|
||||
return s1;
|
||||
}
|
||||
s1 = snew;
|
||||
memcpy(s1+l1, s2, l2+1);
|
||||
free(s2);
|
||||
return s1;
|
||||
}
|
|
@ -1,447 +0,0 @@
|
|||
/*
|
||||
* Copyright 1998 Bertho A. Stultiens (BS)
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "wpp_private.h"
|
||||
|
||||
struct pp_status pp_status;
|
||||
|
||||
#define HASHKEY 2039
|
||||
|
||||
typedef struct pp_def_state
|
||||
{
|
||||
struct pp_def_state *next;
|
||||
pp_entry_t *defines[HASHKEY];
|
||||
} pp_def_state_t;
|
||||
|
||||
static pp_def_state_t *pp_def_state;
|
||||
|
||||
#define MAXIFSTACK 64
|
||||
static pp_if_state_t if_stack[MAXIFSTACK];
|
||||
static int if_stack_idx = 0;
|
||||
|
||||
void *pp_xmalloc(size_t size)
|
||||
{
|
||||
void *res;
|
||||
|
||||
assert(size > 0);
|
||||
res = malloc(size);
|
||||
if(res == NULL)
|
||||
{
|
||||
/* Set the error flag */
|
||||
pp_status.state = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void *pp_xrealloc(void *p, size_t size)
|
||||
{
|
||||
void *res;
|
||||
|
||||
assert(size > 0);
|
||||
res = realloc(p, size);
|
||||
if(res == NULL)
|
||||
{
|
||||
/* Set the error flag */
|
||||
pp_status.state = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
char *pp_xstrdup(const char *str)
|
||||
{
|
||||
char *s;
|
||||
int len;
|
||||
|
||||
assert(str != NULL);
|
||||
len = strlen(str)+1;
|
||||
s = pp_xmalloc(len);
|
||||
if(!s)
|
||||
return NULL;
|
||||
return memcpy(s, str, len);
|
||||
}
|
||||
|
||||
/* Don't comment on the hash, it's primitive but functional... */
|
||||
static int pphash(const char *str)
|
||||
{
|
||||
int sum = 0;
|
||||
while(*str)
|
||||
sum += *str++;
|
||||
return sum % HASHKEY;
|
||||
}
|
||||
|
||||
pp_entry_t *pplookup(const char *ident)
|
||||
{
|
||||
int idx;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!ident)
|
||||
return NULL;
|
||||
idx = pphash(ident);
|
||||
for(ppp = pp_def_state->defines[idx]; ppp; ppp = ppp->next)
|
||||
{
|
||||
if(!strcmp(ident, ppp->ident))
|
||||
return ppp;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void free_pp_entry( pp_entry_t *ppp, int idx )
|
||||
{
|
||||
if(ppp->iep)
|
||||
{
|
||||
if(ppp->iep == pp_includelogiclist)
|
||||
{
|
||||
pp_includelogiclist = ppp->iep->next;
|
||||
if(pp_includelogiclist)
|
||||
pp_includelogiclist->prev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ppp->iep->prev->next = ppp->iep->next;
|
||||
if(ppp->iep->next)
|
||||
ppp->iep->next->prev = ppp->iep->prev;
|
||||
}
|
||||
free(ppp->iep->filename);
|
||||
free(ppp->iep);
|
||||
}
|
||||
|
||||
if(pp_def_state->defines[idx] == ppp)
|
||||
{
|
||||
pp_def_state->defines[idx] = ppp->next;
|
||||
if(pp_def_state->defines[idx])
|
||||
pp_def_state->defines[idx]->prev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ppp->prev->next = ppp->next;
|
||||
if(ppp->next)
|
||||
ppp->next->prev = ppp->prev;
|
||||
}
|
||||
|
||||
free(ppp);
|
||||
}
|
||||
|
||||
/* push a new (empty) define state */
|
||||
int pp_push_define_state(void)
|
||||
{
|
||||
pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
|
||||
if(!state)
|
||||
return 1;
|
||||
|
||||
memset( state->defines, 0, sizeof(state->defines) );
|
||||
state->next = pp_def_state;
|
||||
pp_def_state = state;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* pop the current define state */
|
||||
void pp_pop_define_state(void)
|
||||
{
|
||||
int i;
|
||||
pp_entry_t *ppp;
|
||||
pp_def_state_t *state;
|
||||
|
||||
for (i = 0; i < HASHKEY; i++)
|
||||
{
|
||||
while ((ppp = pp_def_state->defines[i]) != NULL) pp_del_define( ppp->ident );
|
||||
}
|
||||
state = pp_def_state;
|
||||
pp_def_state = state->next;
|
||||
free( state );
|
||||
}
|
||||
|
||||
void pp_del_define(const char *name)
|
||||
{
|
||||
pp_entry_t *ppp;
|
||||
int idx = pphash(name);
|
||||
|
||||
if((ppp = pplookup(name)) == NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("%s was not defined", name);
|
||||
return;
|
||||
}
|
||||
|
||||
free( ppp->ident );
|
||||
free( ppp->subst.text );
|
||||
free( ppp->filename );
|
||||
free_pp_entry( ppp, idx );
|
||||
}
|
||||
|
||||
pp_entry_t *pp_add_define(const char *def, const char *text)
|
||||
{
|
||||
int len;
|
||||
char *cptr;
|
||||
int idx;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!def)
|
||||
return NULL;
|
||||
idx = pphash(def);
|
||||
if((ppp = pplookup(def)) != NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
|
||||
pp_del_define(def);
|
||||
}
|
||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||
if(!ppp)
|
||||
return NULL;
|
||||
memset( ppp, 0, sizeof(*ppp) );
|
||||
ppp->ident = pp_xstrdup(def);
|
||||
if(!ppp->ident)
|
||||
goto error;
|
||||
ppp->type = def_define;
|
||||
ppp->subst.text = text ? pp_xstrdup(text) : NULL;
|
||||
if(text && !ppp->subst.text)
|
||||
goto error;
|
||||
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
||||
if(!ppp->filename)
|
||||
goto error;
|
||||
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
||||
ppp->next = pp_def_state->defines[idx];
|
||||
pp_def_state->defines[idx] = ppp;
|
||||
if(ppp->next)
|
||||
ppp->next->prev = ppp;
|
||||
if(ppp->subst.text)
|
||||
{
|
||||
/* Strip trailing white space from subst text */
|
||||
len = strlen(ppp->subst.text);
|
||||
while(len && strchr(" \t\r\n", ppp->subst.text[len-1]))
|
||||
{
|
||||
ppp->subst.text[--len] = '\0';
|
||||
}
|
||||
/* Strip leading white space from subst text */
|
||||
for(cptr = ppp->subst.text; *cptr && strchr(" \t\r", *cptr); cptr++)
|
||||
;
|
||||
if(ppp->subst.text != cptr)
|
||||
memmove(ppp->subst.text, cptr, strlen(cptr)+1);
|
||||
}
|
||||
return ppp;
|
||||
|
||||
error:
|
||||
free(ppp->ident);
|
||||
free(ppp->subst.text);
|
||||
free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||
{
|
||||
int idx;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!id)
|
||||
return NULL;
|
||||
idx = pphash(id);
|
||||
if((ppp = pplookup(id)) != NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
|
||||
pp_del_define(id);
|
||||
}
|
||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||
if(!ppp)
|
||||
return NULL;
|
||||
memset( ppp, 0, sizeof(*ppp) );
|
||||
ppp->ident = id;
|
||||
ppp->type = def_macro;
|
||||
ppp->margs = args;
|
||||
ppp->nargs = nargs;
|
||||
ppp->subst.mtext= exp;
|
||||
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
||||
if(!ppp->filename)
|
||||
{
|
||||
free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
||||
ppp->next = pp_def_state->defines[idx];
|
||||
pp_def_state->defines[idx] = ppp;
|
||||
if(ppp->next)
|
||||
ppp->next->prev = ppp;
|
||||
return ppp;
|
||||
}
|
||||
|
||||
|
||||
void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath)
|
||||
{
|
||||
char *path;
|
||||
void *fp;
|
||||
|
||||
if (!(path = wpp_lookup(name, type, parent_name))) return NULL;
|
||||
fp = wpp_open(path, type);
|
||||
|
||||
if (fp)
|
||||
{
|
||||
if (newpath) *newpath = path;
|
||||
else free( path );
|
||||
return fp;
|
||||
}
|
||||
free( path );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
*-------------------------------------------------------------------------
|
||||
* #if, #ifdef, #ifndef, #else, #elif and #endif state management
|
||||
*
|
||||
* #if state transitions are made on basis of the current TOS and the next
|
||||
* required state. The state transitions are required to housekeep because
|
||||
* #if:s can be nested. The ignore case is activated to prevent output from
|
||||
* within a false clause.
|
||||
* Some special cases come from the fact that the #elif cases are not
|
||||
* binary, but three-state. The problem is that all other elif-cases must
|
||||
* be false when one true one has been found. A second problem is that the
|
||||
* #else clause is a final clause. No extra #else:s may follow.
|
||||
*
|
||||
* The states mean:
|
||||
* if_true Process input to output
|
||||
* if_false Process input but no output
|
||||
* if_ignore Process input but no output
|
||||
* if_elif Process input but no output
|
||||
* if_elsefalse Process input but no output
|
||||
* if_elsettrue Process input to output
|
||||
*
|
||||
* The possible state-sequences are [state(stack depth)] (rest can be deduced):
|
||||
* TOS #if 1 #else #endif
|
||||
* if_true(n) if_true(n+1) if_elsefalse(n+1)
|
||||
* if_false(n) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elsetrue(n) if_true(n+1) if_elsefalse(n+1)
|
||||
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elif(n) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_ignore(n) if_ignore(n+1) if_ignore(n+1)
|
||||
*
|
||||
* TOS #if 1 #elif 0 #else #endif
|
||||
* if_true(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
|
||||
* if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elsetrue(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
|
||||
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
*
|
||||
* TOS #if 0 #elif 1 #else #endif
|
||||
* if_true(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
|
||||
* if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elsetrue(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
|
||||
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
* if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void pp_push_if(pp_if_state_t s)
|
||||
{
|
||||
if(if_stack_idx >= MAXIFSTACK)
|
||||
pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
|
||||
|
||||
if_stack[if_stack_idx++] = s;
|
||||
|
||||
switch(s)
|
||||
{
|
||||
case if_true:
|
||||
case if_elsetrue:
|
||||
break;
|
||||
case if_false:
|
||||
case if_elsefalse:
|
||||
case if_elif:
|
||||
case if_ignore:
|
||||
pp_push_ignore_state();
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
}
|
||||
|
||||
pp_if_state_t pp_pop_if(void)
|
||||
{
|
||||
if(if_stack_idx <= 0)
|
||||
{
|
||||
ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
|
||||
return if_error;
|
||||
}
|
||||
|
||||
switch(pp_if_state())
|
||||
{
|
||||
case if_true:
|
||||
case if_elsetrue:
|
||||
break;
|
||||
case if_false:
|
||||
case if_elsefalse:
|
||||
case if_elif:
|
||||
case if_ignore:
|
||||
pp_pop_ignore_state();
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
return if_stack[--if_stack_idx];
|
||||
}
|
||||
|
||||
pp_if_state_t pp_if_state(void)
|
||||
{
|
||||
if(!if_stack_idx)
|
||||
return if_true;
|
||||
else
|
||||
return if_stack[if_stack_idx-1];
|
||||
}
|
||||
|
||||
|
||||
void pp_next_if_state(int i)
|
||||
{
|
||||
switch(pp_if_state())
|
||||
{
|
||||
case if_true:
|
||||
case if_elsetrue:
|
||||
pp_push_if(i ? if_true : if_false);
|
||||
break;
|
||||
case if_false:
|
||||
case if_elsefalse:
|
||||
case if_elif:
|
||||
case if_ignore:
|
||||
pp_push_if(if_ignore);
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #{if,ifdef,ifndef} directive", (int)pp_if_state());
|
||||
}
|
||||
}
|
||||
|
||||
int pp_get_if_depth(void)
|
||||
{
|
||||
return if_stack_idx;
|
||||
}
|
||||
|
||||
void WINAPIV pp_internal_error(const char *file, int line, const char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
|
||||
vfprintf(stderr, s, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
exit(3);
|
||||
}
|
|
@ -34,6 +34,7 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
|
|||
struct shader_test {
|
||||
const char *text;
|
||||
const DWORD bytes[128];
|
||||
BOOL todo;
|
||||
};
|
||||
|
||||
static void dump_shader(DWORD *shader) {
|
||||
|
@ -59,6 +60,7 @@ static void exec_tests(const char *name, struct shader_test tests[], unsigned in
|
|||
messages = NULL;
|
||||
hr = D3DAssemble(tests[i].text, strlen(tests[i].text), NULL, NULL,
|
||||
NULL, D3DCOMPILE_SKIP_VALIDATION, &shader, &messages);
|
||||
todo_wine_if(tests[i].todo)
|
||||
ok(hr == S_OK, "Test %s, shader %u: D3DAssemble failed with error %#lx - %ld.\n", name, i, hr, hr & 0xffff);
|
||||
if(messages) {
|
||||
trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
|
||||
|
@ -211,7 +213,8 @@ static void vs_1_1_test(void) {
|
|||
"vs_1_1\n"
|
||||
"def c12, 0, -1, -0.5, 1024\n",
|
||||
{0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
|
||||
0x44800000, 0x0000ffff}
|
||||
0x44800000, 0x0000ffff},
|
||||
TRUE
|
||||
},
|
||||
{ /* shader 14: writemasks, swizzles */
|
||||
"vs_1_1\n"
|
||||
|
@ -759,7 +762,8 @@ static void vs_2_0_test(void) {
|
|||
"defi i1, 0, 40, 30, 10\n",
|
||||
{0xfffe0200, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
|
||||
0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
|
||||
0x0000000a, 0x0000ffff}
|
||||
0x0000000a, 0x0000ffff},
|
||||
TRUE
|
||||
},
|
||||
{ /* shader 23 */
|
||||
"vs_2_0\n"
|
||||
|
@ -971,7 +975,8 @@ static void ps_2_x_test(void) {
|
|||
"defi i1, 0, 40, 30, 10\n",
|
||||
{0xffff0201, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
|
||||
0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
|
||||
0x0000000a, 0x0000ffff}
|
||||
0x0000000a, 0x0000ffff},
|
||||
TRUE
|
||||
},
|
||||
{ /* shader 2 */
|
||||
"ps_2_x\n"
|
||||
|
@ -1660,7 +1665,7 @@ static void d3dpreprocess_test(void)
|
|||
/* NULL shader test */
|
||||
messages = NULL;
|
||||
hr = D3DPreprocess(test1, strlen(test1), NULL, defines, NULL, NULL, &messages);
|
||||
ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
|
||||
todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
|
||||
|
@ -1671,7 +1676,7 @@ static void d3dpreprocess_test(void)
|
|||
shader = NULL;
|
||||
messages = NULL;
|
||||
hr = D3DPreprocess(quotation_marks_test, strlen(quotation_marks_test), NULL, NULL, NULL, &shader, &messages);
|
||||
todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
|
||||
ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
|
||||
if (messages)
|
||||
{
|
||||
trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
|
||||
|
|
|
@ -1620,7 +1620,8 @@ static void test_include(void)
|
|||
|
||||
#if D3D_COMPILER_VERSION >= 46
|
||||
hr = tests[i](NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &blob, &errors);
|
||||
todo_wine_if (i != 1) ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got unexpected hr %#lx.\n", hr);
|
||||
todo_wine_if (!i)
|
||||
ok(hr == (i == 0 ? D3DXERR_INVALIDDATA : E_FAIL), "Got unexpected hr %#lx.\n", hr);
|
||||
ok(!blob, "Got unexpected blob.\n");
|
||||
ok(!!errors, "Got unexpected errors.\n");
|
||||
ID3D10Blob_Release(errors);
|
||||
|
|
|
@ -1,251 +0,0 @@
|
|||
/*
|
||||
* Copyright 1998 Bertho A. Stultiens (BS)
|
||||
* Copyright 2002 Alexandre Julliard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __WPP_PRIVATE_H
|
||||
#define __WPP_PRIVATE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "windef.h"
|
||||
|
||||
/* Return value == 0 means successful execution */
|
||||
extern int wpp_add_define( const char *name, const char *value );
|
||||
extern void wpp_del_define( const char *name );
|
||||
extern char *wpp_lookup(const char *filename, int type, const char *parent_name);
|
||||
extern void *wpp_open(const char *filename, int type);
|
||||
extern void wpp_close(void *file);
|
||||
extern int wpp_read(void *file, char *buffer, unsigned int len);
|
||||
extern void wpp_write(const char *buffer, unsigned int len);
|
||||
extern int wpp_parse( const char *input, FILE *output );
|
||||
|
||||
struct pp_entry; /* forward */
|
||||
/*
|
||||
* Include logic
|
||||
* A stack of files which are already included and
|
||||
* are protected in the #ifndef/#endif way.
|
||||
*/
|
||||
typedef struct includelogicentry {
|
||||
struct includelogicentry *next;
|
||||
struct includelogicentry *prev;
|
||||
struct pp_entry *ppp; /* The define which protects the file */
|
||||
char *filename; /* The filename of the include */
|
||||
} includelogicentry_t;
|
||||
|
||||
/*
|
||||
* The arguments of a macrodefinition
|
||||
*/
|
||||
typedef enum {
|
||||
arg_single,
|
||||
arg_list
|
||||
} def_arg_t;
|
||||
|
||||
typedef struct marg {
|
||||
def_arg_t type; /* Normal or ... argument */
|
||||
char *arg; /* The textual argument */
|
||||
int nnl; /* Number of newlines in the text to subst */
|
||||
} marg_t;
|
||||
|
||||
/*
|
||||
* The expansiontext of a macro
|
||||
*/
|
||||
typedef enum {
|
||||
exp_text, /* Simple text substitution */
|
||||
exp_concat, /* Concat (##) operator requested */
|
||||
exp_stringize, /* Stringize (#) operator requested */
|
||||
exp_subst /* Substitute argument */
|
||||
} def_exp_t;
|
||||
|
||||
typedef struct mtext {
|
||||
struct mtext *next;
|
||||
struct mtext *prev;
|
||||
def_exp_t type;
|
||||
union {
|
||||
char *text;
|
||||
int argidx; /* For exp_subst and exp_stringize reference */
|
||||
} subst;
|
||||
} mtext_t;
|
||||
|
||||
/*
|
||||
* The define descriptor
|
||||
*/
|
||||
typedef enum {
|
||||
def_none, /* Not-a-define; used as return value */
|
||||
def_define, /* Simple defines */
|
||||
def_macro, /* Macro defines */
|
||||
def_special /* Special expansions like __LINE__ and __FILE__ */
|
||||
} def_type_t;
|
||||
|
||||
typedef struct pp_entry {
|
||||
struct pp_entry *next;
|
||||
struct pp_entry *prev;
|
||||
def_type_t type; /* Define or macro */
|
||||
char *ident; /* The key */
|
||||
marg_t **margs; /* Macro arguments array or NULL if none */
|
||||
int nargs;
|
||||
union {
|
||||
mtext_t *mtext; /* The substitution sequence or NULL if none */
|
||||
char *text;
|
||||
} subst;
|
||||
int expanding; /* Set when feeding substitution into the input */
|
||||
char *filename; /* Filename where it was defined */
|
||||
int linenumber; /* Linenumber where it was defined */
|
||||
includelogicentry_t *iep; /* Points to the include it protects */
|
||||
} pp_entry_t;
|
||||
|
||||
|
||||
/*
|
||||
* If logic
|
||||
*/
|
||||
#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
|
||||
|
||||
typedef enum {
|
||||
if_false,
|
||||
if_true,
|
||||
if_elif,
|
||||
if_elsefalse,
|
||||
if_elsetrue,
|
||||
if_ignore,
|
||||
if_error
|
||||
} pp_if_state_t;
|
||||
|
||||
|
||||
/*
|
||||
* Trace the include files to prevent double reading.
|
||||
* This save 20..30% of processing time for most stuff
|
||||
* that uses complex includes.
|
||||
* States:
|
||||
* -1 Don't track or seen junk
|
||||
* 0 New include, waiting for "#ifndef __xxx_h"
|
||||
* 1 Seen #ifndef, waiting for "#define __xxx_h ..."
|
||||
* 2 Seen #endif, waiting for EOF
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int state;
|
||||
char *ppp; /* The define to be set from the #ifndef */
|
||||
int ifdepth; /* The level of ifs at the #ifdef */
|
||||
int seen_junk; /* Set when junk is seen */
|
||||
} include_state_t;
|
||||
|
||||
#define SIZE_CHAR 1
|
||||
#define SIZE_SHORT 2
|
||||
#define SIZE_INT 3
|
||||
#define SIZE_LONG 4
|
||||
#define SIZE_LONGLONG 5
|
||||
#define SIZE_MASK 0x00ff
|
||||
#define FLAG_SIGNED 0x0100
|
||||
|
||||
typedef enum {
|
||||
#if 0
|
||||
cv_schar = SIZE_CHAR + FLAG_SIGNED,
|
||||
cv_uchar = SIZE_CHAR,
|
||||
cv_sshort = SIZE_SHORT + FLAG_SIGNED,
|
||||
cv_ushort = SIZE_SHORT,
|
||||
#endif
|
||||
cv_sint = SIZE_INT + FLAG_SIGNED,
|
||||
cv_uint = SIZE_INT,
|
||||
cv_slong = SIZE_LONG + FLAG_SIGNED,
|
||||
cv_ulong = SIZE_LONG,
|
||||
cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
|
||||
cv_ull = SIZE_LONGLONG
|
||||
} ctype_t;
|
||||
|
||||
typedef struct cval {
|
||||
ctype_t type;
|
||||
union {
|
||||
#if 0
|
||||
signed char sc; /* Explicitly signed because compilers are stupid */
|
||||
unsigned char uc;
|
||||
short ss;
|
||||
unsigned short us;
|
||||
#endif
|
||||
int si;
|
||||
unsigned int ui;
|
||||
long sl;
|
||||
unsigned long ul;
|
||||
__int64 sll;
|
||||
unsigned __int64 ull;
|
||||
} val;
|
||||
} cval_t;
|
||||
|
||||
|
||||
|
||||
void *pp_xmalloc(size_t);
|
||||
void *pp_xrealloc(void *, size_t);
|
||||
char *pp_xstrdup(const char *str);
|
||||
pp_entry_t *pplookup(const char *ident);
|
||||
int pp_push_define_state(void);
|
||||
void pp_pop_define_state(void);
|
||||
pp_entry_t *pp_add_define(const char *def, const char *text);
|
||||
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
|
||||
void pp_del_define(const char *name);
|
||||
void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath);
|
||||
void pp_push_if(pp_if_state_t s);
|
||||
void pp_next_if_state(int);
|
||||
pp_if_state_t pp_pop_if(void);
|
||||
pp_if_state_t pp_if_state(void);
|
||||
int pp_get_if_depth(void);
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(x) /*nothing*/
|
||||
#endif
|
||||
|
||||
extern const struct wpp_callbacks *wpp_callbacks;
|
||||
|
||||
int WINAPIV ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
|
||||
int WINAPIV ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
|
||||
void WINAPIV pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
|
||||
|
||||
/* current preprocessor state */
|
||||
/* everything is in this structure to avoid polluting the global symbol space */
|
||||
struct pp_status
|
||||
{
|
||||
char *input; /* current input file name */
|
||||
void *file; /* current input file descriptor */
|
||||
int line_number; /* current line number */
|
||||
int char_number; /* current char number in line */
|
||||
int state; /* current error state */
|
||||
int pedantic; /* pedantic option */
|
||||
};
|
||||
|
||||
extern struct pp_status pp_status;
|
||||
extern include_state_t pp_incl_state;
|
||||
extern includelogicentry_t *pp_includelogiclist;
|
||||
|
||||
/*
|
||||
* From ppl.l
|
||||
*/
|
||||
extern FILE *ppy_out;
|
||||
extern char *ppy_text;
|
||||
int ppy_lex(void);
|
||||
int ppy_lex_destroy(void);
|
||||
|
||||
void pp_do_include(char *fname, int type);
|
||||
void pp_push_ignore_state(void);
|
||||
void pp_pop_ignore_state(void);
|
||||
|
||||
void WINAPIV pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
||||
/*
|
||||
* From ppy.y
|
||||
*/
|
||||
int ppy_parse(void);
|
||||
|
||||
#endif /* __WPP_PRIVATE_H */
|
|
@ -1,6 +1,6 @@
|
|||
MODULE = d3dcompiler_46.dll
|
||||
IMPORTLIB = d3dcompiler_46
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=46
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -12,16 +12,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
MODULE = d3dcompiler_47.dll
|
||||
IMPORTLIB = d3dcompiler
|
||||
IMPORTS = wined3d dxguid uuid
|
||||
IMPORTS = wined3d
|
||||
EXTRADEFS = -DD3D_COMPILER_VERSION=47
|
||||
PARENTSRC = ../d3dcompiler_43
|
||||
EXTRAINCL = $(VKD3D_PE_CFLAGS)
|
||||
|
@ -12,16 +12,13 @@ C_SRCS = \
|
|||
blob.c \
|
||||
bytecodewriter.c \
|
||||
compiler.c \
|
||||
preproc.c \
|
||||
reflection.c \
|
||||
utils.c
|
||||
|
||||
LEX_SRCS = \
|
||||
asmshader.l \
|
||||
ppl.l
|
||||
asmshader.l
|
||||
|
||||
BISON_SRCS = \
|
||||
asmshader.y \
|
||||
ppy.y
|
||||
asmshader.y
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -259,7 +259,7 @@ static void assembleshader_test(void)
|
|||
messages = NULL;
|
||||
hr = D3DXAssembleShader(testshader2, strlen(testshader2), NULL, &include.ID3DXInclude_iface,
|
||||
D3DXSHADER_SKIPVALIDATION, &shader, &messages);
|
||||
ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
todo_wine ok(hr == D3D_OK, "D3DXAssembleShader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
|
||||
if(messages) {
|
||||
trace("recursive D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
|
||||
ID3DXBuffer_Release(messages);
|
||||
|
|
Loading…
Reference in New Issue