d3dcompiler: Copy the C preprocessor source into d3dcompiler_43.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-07-02 13:26:27 +02:00
parent 21d91ef04b
commit 011b2eca46
18 changed files with 3210 additions and 66 deletions

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -1,6 +1,5 @@
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

View file

@ -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;

1560
dlls/d3dcompiler_43/ppl.l Normal file

File diff suppressed because it is too large Load diff

690
dlls/d3dcompiler_43/ppy.y Normal file
View file

@ -0,0 +1,690 @@
/*
* 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 "config.h"
#include "wine/port.h"
#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;
%}
%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;
}

View file

@ -0,0 +1,453 @@
/*
* 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 "config.h"
#include "wine/port.h"
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#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 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);
}

View file

@ -0,0 +1,250 @@
/*
* 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 */

View file

@ -1,6 +1,5 @@
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

View file

@ -1,7 +1,6 @@
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