Commit 011b2eca authored by Alexandre Julliard's avatar Alexandre Julliard

d3dcompiler: Copy the C preprocessor source into d3dcompiler_43.

parent 21d91ef0
MODULE = d3dcompiler_33.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=33
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_34.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=34
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_35.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=35
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_36.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=36
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_37.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=37
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_38.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=38
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_39.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=39
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_40.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=40
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_41.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=41
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_42.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=42
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_43.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=43
C_SRCS = \
......@@ -9,15 +8,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
......@@ -20,11 +20,13 @@
#define COBJMACROS
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <time.h>
#include "wine/debug.h"
#include "wine/unicode.h"
#include "d3dcompiler_private.h"
#include "wine/wpp.h"
#include "wpp_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
......@@ -61,6 +63,15 @@ 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 */
......@@ -124,26 +135,34 @@ static void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...)
va_end(args);
}
static void wpp_error(const char *file, int line, int col, const char *near,
const char *msg, va_list ap)
int ppy_error(const char *msg, ...)
{
wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
line, col, "Error");
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;
}
static void wpp_warning(const char *file, int line, int col, const char *near,
const char *msg, va_list ap)
int ppy_warning(const char *msg, ...)
{
wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'",
line, col, "Warning");
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;
}
static char *wpp_lookup_mem(const char *filename, int type, const char *parent_name,
char **include_path, int include_path_count)
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(). */
......@@ -176,7 +195,7 @@ static char *wpp_lookup_mem(const char *filename, int type, const char *parent_n
return path;
}
static void *wpp_open_mem(const char *filename, int type)
void *wpp_open(const char *filename, int type)
{
struct mem_file_desc *desc;
HRESULT hr;
......@@ -239,7 +258,7 @@ error:
return NULL;
}
static void wpp_close_mem(void *file)
void wpp_close(void *file)
{
struct mem_file_desc *desc = file;
......@@ -255,7 +274,7 @@ static void wpp_close_mem(void *file)
}
}
static int wpp_read_mem(void *file, char *buffer, unsigned int len)
int wpp_read(void *file, char *buffer, unsigned int len)
{
struct mem_file_desc *desc = file;
......@@ -265,7 +284,7 @@ static int wpp_read_mem(void *file, char *buffer, unsigned int len)
return len;
}
static void wpp_write_mem(const char *buffer, unsigned int len)
void wpp_write(const char *buffer, unsigned int len)
{
char *new_wpp_output;
......@@ -307,6 +326,164 @@ static int wpp_close_output(void)
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();
del_special_defines();
del_cmdline_defines();
pp_pop_define_state();
return ret;
}
static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename,
const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages)
{
......@@ -314,17 +491,6 @@ static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char
HRESULT hr = S_OK;
const D3D_SHADER_MACRO *def = defines;
static const struct wpp_callbacks wpp_callbacks =
{
wpp_lookup_mem,
wpp_open_mem,
wpp_close_mem,
wpp_read_mem,
wpp_write_mem,
wpp_error,
wpp_warning,
};
if (def != NULL)
{
while (def->Name != NULL)
......@@ -339,7 +505,6 @@ static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char
wpp_output_size = wpp_output_capacity = 0;
wpp_output = NULL;
wpp_set_callbacks(&wpp_callbacks);
wpp_messages_size = wpp_messages_capacity = 0;
wpp_messages = NULL;
current_shader.buffer = data;
......
/*
* 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 ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void 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);
void pp_do_include(char *fname, int type);
void pp_push_ignore_state(void);
void pp_pop_ignore_state(void);
void pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
/*
* From ppy.y
*/
int ppy_parse(void);
#endif /* __WPP_PRIVATE_H */
MODULE = d3dcompiler_46.dll
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=46
PARENTSRC = ../d3dcompiler_43
......@@ -10,15 +9,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
MODULE = d3dcompiler_47.dll
IMPORTLIB = d3dcompiler
IMPORTS = dxguid uuid
EXTRALIBS = -lwpp
EXTRADEFS = -DD3D_COMPILER_VERSION=47
PARENTSRC = ../d3dcompiler_43
......@@ -11,15 +10,18 @@ C_SRCS = \
bytecodewriter.c \
compiler.c \
main.c \
preproc.c \
reflection.c \
utils.c
LEX_SRCS = \
asmshader.l \
hlsl.l
hlsl.l \
ppl.l
BISON_SRCS = \
asmshader.y \
hlsl.y
hlsl.y \
ppy.y
RC_SRCS = version.rc
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