Merge remote-tracking branch

'origin/GP-3155_caheckman_PR-2810_Pokechu22_countleadingzeros'
(Closes #2810)
This commit is contained in:
Ryan Kurtz 2023-03-24 14:27:51 -04:00
commit 9cf60faef0
94 changed files with 3604 additions and 3451 deletions

View file

@ -231,15 +231,15 @@ sla_opt/%.o: %.cc
$(CXX) $(ARCH_TYPE) -c $(OPT_CXXFLAGS) $(ADDITIONAL_FLAGS) $(SLEIGH_OPT) $< -o $@
grammar.cc: grammar.y
$(YACC) -p cparse -o $@ $<
$(YACC) -l -o $@ $<
xml.cc: xml.y
$(YACC) -p xml -o $@ $<
$(YACC) -l -o $@ $<
pcodeparse.cc: pcodeparse.y
$(YACC) -p pcode -o $@ $<
$(YACC) -l -o $@ $<
slghparse.cc: slghparse.y
$(YACC) -d -o $@ $<
$(YACC) -l -d -o $@ $<
slghscan.cc: slghscan.l
$(LEX) -o$@ $<
$(LEX) -L -o$@ $<
ruleparse.cc: ruleparse.y
$(YACC) -p ruleparse -d -o $@ $<

View file

@ -3619,6 +3619,7 @@ void ActionDeadCode::propagateConsumed(vector<Varnode *> &worklist)
pushConsumed(b,op->getIn(2), worklist);
break;
case CPUI_POPCOUNT:
case CPUI_LZCOUNT:
a = 16 * op->getIn(0)->getSize() - 1; // Mask for possible bits that could be set
a &= outc; // Of the bits that could be set, which are consumed
b = (a == 0) ? 0 : ~((uintb)0); // if any consumed, treat all input bits as consumed
@ -5390,6 +5391,7 @@ void ActionDatabase::universalAction(Architecture *conf)
actprop->addRule( new RulePopcountBoolXor("analysis") );
actprop->addRule( new RuleOrMultiBool("analysis") );
actprop->addRule( new RuleXorSwap("analysis") );
actprop->addRule( new RuleLzcountShiftBool("analysis") );
actprop->addRule( new RuleSubvarAnd("subvar") );
actprop->addRule( new RuleSubvarSubpiece("subvar") );
actprop->addRule( new RuleSplitFlow("subvar") );

View file

@ -55,7 +55,8 @@ const uint4 DynamicHash::transtable[] = {
0, // CAST is skipped
CPUI_INT_ADD, CPUI_INT_ADD, // PTRADD and PTRSUB hash same as INT_ADD
CPUI_SEGMENTOP, CPUI_CPOOLREF, CPUI_NEW, CPUI_INSERT, CPUI_EXTRACT, CPUI_POPCOUNT
CPUI_SEGMENTOP, CPUI_CPOOLREF, CPUI_NEW, CPUI_INSERT, CPUI_EXTRACT,
CPUI_POPCOUNT, CPUI_LZCOUNT
};

View file

@ -73,7 +73,8 @@
/* Pull parsers. */
#define YYPULL 1
/* Substitute the type names. */
#define YYSTYPE GRAMMARSTYPE
/* Substitute the variable and function names. */
#define yyparse grammarparse
#define yylex grammarlex
@ -85,16 +86,15 @@
#define yychar grammarchar
/* Copy the first part of user declarations. */
#line 16 "src/decompile/cpp/grammar.y" /* yacc.c:339 */
#include "grammar.hh"
extern int yylex(void);
extern int yyerror(const char *str);
extern int grammarlex(void);
extern int grammarerror(const char *str);
static CParse *parse;
extern int yydebug;
#line 83 "src/decompile/cpp/grammar.cc" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@ -114,17 +114,25 @@ extern int yydebug;
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#ifndef GRAMMARDEBUG
# if defined YYDEBUG
#if YYDEBUG
# define GRAMMARDEBUG 1
# else
# define GRAMMARDEBUG 0
# endif
# else /* ! defined YYDEBUG */
# define GRAMMARDEBUG 0
# endif /* ! defined YYDEBUG */
#endif /* ! defined GRAMMARDEBUG */
#if GRAMMARDEBUG
extern int grammardebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
#ifndef GRAMMARTOKENTYPE
# define GRAMMARTOKENTYPE
enum grammartokentype
{
DOTDOTDOT = 258,
BADTOKEN = 259,
@ -143,11 +151,11 @@ extern int grammardebug;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
#if ! defined GRAMMARSTYPE && ! defined GRAMMARSTYPE_IS_DECLARED
union YYSTYPE
union GRAMMARSTYPE
{
#line 25 "src/decompile/cpp/grammar.y" /* yacc.c:355 */
uint4 flags;
TypeDeclarator *dec;
@ -160,16 +168,16 @@ union YYSTYPE
string *str;
uintb *i;
#line 149 "src/decompile/cpp/grammar.cc" /* yacc.c:355 */
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
typedef union GRAMMARSTYPE GRAMMARSTYPE;
# define GRAMMARSTYPE_IS_TRIVIAL 1
# define GRAMMARSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE grammarlval;
extern GRAMMARSTYPE grammarlval;
int grammarparse (void);
@ -177,7 +185,7 @@ int grammarparse (void);
/* Copy the second part of user declarations. */
#line 166 "src/decompile/cpp/grammar.cc" /* yacc.c:358 */
#ifdef short
# undef short
@ -358,7 +366,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
|| (defined GRAMMARSTYPE_IS_TRIVIAL && GRAMMARSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
@ -472,7 +480,7 @@ static const yytype_uint8 yytranslate[] =
15
};
#if YYDEBUG
#if GRAMMARDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
@ -487,7 +495,7 @@ static const yytype_uint8 yyrline[] =
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 0
#if GRAMMARDEBUG || YYERROR_VERBOSE || 0
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
@ -706,7 +714,7 @@ while (0)
/* Enable debugging if requested. */
#if YYDEBUG
#if GRAMMARDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
@ -827,12 +835,12 @@ do { \
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
#else /* !GRAMMARDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
#endif /* !GRAMMARDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
@ -1343,427 +1351,427 @@ yyreduce:
switch (yyn)
{
case 2:
#line 60 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ parse->setResultDeclarations((yyvsp[0].declist)); }
#line 1334 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 3:
#line 61 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ vector<TypeDeclarator *> *res = parse->newVecDeclarator(); res->push_back((yyvsp[0].dec)); parse->setResultDeclarations(res); }
#line 1340 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 4:
#line 65 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->mergeSpecDecVec((yyvsp[-1].spec)); }
#line 1346 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 5:
#line 66 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->mergeSpecDecVec((yyvsp[-2].spec),(yyvsp[-1].declist)); }
#line 1352 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 6:
#line 70 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addSpecifier((yyval.spec),(yyvsp[0].str)); }
#line 1358 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 7:
#line 71 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addTypeSpecifier((yyval.spec),(yyvsp[0].type)); }
#line 1364 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 8:
#line 72 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addSpecifier((yyval.spec),(yyvsp[0].str)); }
#line 1370 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 9:
#line 73 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addFuncSpecifier((yyval.spec),(yyvsp[0].str)); }
#line 1376 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 10:
#line 74 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addSpecifier((yyvsp[0].spec),(yyvsp[-1].str)); }
#line 1382 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 11:
#line 75 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addTypeSpecifier((yyvsp[0].spec),(yyvsp[-1].type)); }
#line 1388 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 12:
#line 76 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addSpecifier((yyvsp[0].spec),(yyvsp[-1].str)); }
#line 1394 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 13:
#line 77 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addFuncSpecifier((yyvsp[0].spec),(yyvsp[-1].str)); }
#line 1400 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 14:
#line 81 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->newVecDeclarator(); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1406 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 15:
#line 82 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[-2].declist); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1412 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 16:
#line 86 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[0].dec); }
#line 1418 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 17:
#line 91 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = (yyvsp[0].type); }
#line 1424 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 18:
#line 92 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = (yyvsp[0].type); }
#line 1430 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 19:
#line 93 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = (yyvsp[0].type); }
#line 1436 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 20:
#line 97 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newStruct("",(yyvsp[-1].declist)); }
#line 1442 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 21:
#line 98 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newStruct(*(yyvsp[-3].str),(yyvsp[-1].declist)); }
#line 1448 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 22:
#line 99 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->oldStruct(*(yyvsp[0].str)); }
#line 1454 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 23:
#line 100 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newUnion("",(yyvsp[-1].declist)); }
#line 1460 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 24:
#line 101 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newUnion(*(yyvsp[-3].str),(yyvsp[-1].declist)); }
#line 1466 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 25:
#line 102 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->oldUnion(*(yyvsp[0].str)); }
#line 1472 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 26:
#line 106 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[0].declist); }
#line 1478 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 27:
#line 107 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[-1].declist); (yyval.declist)->insert((yyval.declist)->end(),(yyvsp[0].declist)->begin(),(yyvsp[0].declist)->end()); }
#line 1484 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 28:
#line 111 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->mergeSpecDecVec((yyvsp[-2].spec),(yyvsp[-1].declist)); }
#line 1490 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 29:
#line 115 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addTypeSpecifier((yyval.spec),(yyvsp[0].type)); }
#line 1496 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 30:
#line 116 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addTypeSpecifier((yyvsp[0].spec),(yyvsp[-1].type)); }
#line 1502 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 31:
#line 117 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->newSpecifier(); parse->addSpecifier((yyval.spec),(yyvsp[0].str)); }
#line 1508 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 32:
#line 118 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.spec) = parse->addSpecifier((yyvsp[0].spec),(yyvsp[-1].str)); }
#line 1514 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 33:
#line 122 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->newVecDeclarator(); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1520 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 34:
#line 123 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[-2].declist); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1526 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 35:
#line 127 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[0].dec); }
#line 1532 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 36:
#line 132 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newEnum(*(yyvsp[-3].str),(yyvsp[-1].vecenum)); }
#line 1538 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 37:
#line 133 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newEnum("",(yyvsp[-1].vecenum)); }
#line 1544 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 38:
#line 134 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newEnum(*(yyvsp[-4].str),(yyvsp[-2].vecenum)); }
#line 1550 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 39:
#line 135 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->newEnum("",(yyvsp[-2].vecenum)); }
#line 1556 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 40:
#line 136 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.type) = parse->oldEnum(*(yyvsp[0].str)); }
#line 1562 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 41:
#line 140 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.vecenum) = parse->newVecEnumerator(); (yyval.vecenum)->push_back((yyvsp[0].enumer)); }
#line 1568 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 42:
#line 141 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.vecenum) = (yyvsp[-2].vecenum); (yyval.vecenum)->push_back((yyvsp[0].enumer)); }
#line 1574 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 43:
#line 145 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.enumer) = parse->newEnumerator(*(yyvsp[0].str)); }
#line 1580 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 44:
#line 146 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.enumer) = parse->newEnumerator(*(yyvsp[-2].str),*(yyvsp[0].i)); }
#line 1586 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 45:
#line 150 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[0].dec); }
#line 1592 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 46:
#line 151 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->mergePointer((yyvsp[-1].ptrspec),(yyvsp[0].dec)); }
#line 1598 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 47:
#line 155 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newDeclarator((yyvsp[0].str)); }
#line 1604 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 48:
#line 156 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[-1].dec); }
#line 1610 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 49:
#line 157 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newArray((yyvsp[-4].dec),(yyvsp[-2].flags),(yyvsp[-1].i)); }
#line 1616 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 50:
#line 158 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newArray((yyvsp[-3].dec),0,(yyvsp[-1].i)); }
#line 1622 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 51:
#line 160 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newFunc((yyvsp[-3].dec),(yyvsp[-1].declist)); }
#line 1628 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 52:
#line 165 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.ptrspec) = parse->newPointer(); (yyval.ptrspec)->push_back(0); }
#line 1634 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 53:
#line 166 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.ptrspec) = parse->newPointer(); (yyval.ptrspec)->push_back((yyvsp[0].flags)); }
#line 1640 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 54:
#line 167 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.ptrspec) = (yyvsp[0].ptrspec); (yyval.ptrspec)->push_back(0); }
#line 1646 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 55:
#line 168 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.ptrspec) = (yyvsp[0].ptrspec); (yyval.ptrspec)->push_back((yyvsp[-1].flags)); }
#line 1652 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 56:
#line 172 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.flags) = parse->convertFlag((yyvsp[0].str)); }
#line 1658 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 57:
#line 173 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.flags) = (yyvsp[-1].flags); (yyval.flags) |= parse->convertFlag((yyvsp[0].str)); }
#line 1664 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 58:
#line 177 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[0].declist); }
#line 1670 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 59:
#line 178 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[-2].declist); (yyval.declist)->push_back((TypeDeclarator *)0); }
#line 1676 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 60:
#line 182 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = parse->newVecDeclarator(); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1682 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 61:
#line 183 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.declist) = (yyvsp[-2].declist); (yyval.declist)->push_back((yyvsp[0].dec)); }
#line 1688 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 62:
#line 187 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->mergeSpecDec((yyvsp[-1].spec),(yyvsp[0].dec)); }
#line 1694 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 63:
#line 188 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->mergeSpecDec((yyvsp[0].spec)); }
#line 1700 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 64:
#line 189 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->mergeSpecDec((yyvsp[-1].spec),(yyvsp[0].dec)); }
#line 1706 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 65:
#line 193 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newDeclarator(); parse->mergePointer((yyvsp[0].ptrspec),(yyval.dec)); }
#line 1712 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 66:
#line 194 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[0].dec); }
#line 1718 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 67:
#line 195 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->mergePointer((yyvsp[-1].ptrspec),(yyvsp[0].dec)); }
#line 1724 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 68:
#line 199 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = (yyvsp[-1].dec); }
#line 1730 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 69:
#line 201 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newArray((yyvsp[-3].dec),0,(yyvsp[-1].i)); }
#line 1736 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 70:
#line 203 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.dec) = parse->newFunc((yyvsp[-3].dec),(yyvsp[-1].declist)); }
#line 1742 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
case 71:
#line 207 "src/decompile/cpp/grammar.y" /* yacc.c:1646 */
{ (yyval.i) = (yyvsp[0].i); }
#line 1748 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
break;
#line 1752 "src/decompile/cpp/grammar.cc" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@ -1991,7 +1999,7 @@ yyreturn:
#endif
return yyresult;
}
#line 210 "src/decompile/cpp/grammar.y" /* yacc.c:1906 */
void GrammarToken::set(uint4 tp)
@ -3114,13 +3122,13 @@ bool CParse::parseStream(istream &s,uint4 doctype)
return runParse(doctype);
}
int yylex(void)
int grammarlex(void)
{
return parse->lex();
}
int yyerror(const char *str)
int grammarerror(const char *str)
{
return 0;

View file

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%define api.prefix {grammar}
%{
#include "grammar.hh"
extern int yylex(void);
extern int yyerror(const char *str);
extern int grammarlex(void);
extern int grammarerror(const char *str);
static CParse *parse;
extern int yydebug;
%}
%union {
@ -1329,13 +1329,13 @@ bool CParse::parseStream(istream &s,uint4 doctype)
return runParse(doctype);
}
int yylex(void)
int grammarlex(void)
{
return parse->lex();
}
int yyerror(const char *str)
int grammarerror(const char *str)
{
return 0;

View file

@ -644,6 +644,10 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
resmask = coveringmask((uintb)sz1);
resmask &= fullmask;
break;
case CPUI_LZCOUNT:
resmask = coveringmask(getIn(0)->getSize() * 8);
resmask &= fullmask;
break;
case CPUI_SUBPIECE:
resmask = getIn(0)->getNZMask();
sz1 = (int4)getIn(1)->getOffset();

View file

@ -102,6 +102,7 @@ void OpBehavior::registerInstructions(vector<OpBehavior *> &inst,const Translate
inst[CPUI_INSERT] = new OpBehavior(CPUI_INSERT,false);
inst[CPUI_EXTRACT] = new OpBehavior(CPUI_EXTRACT,false);
inst[CPUI_POPCOUNT] = new OpBehaviorPopcount();
inst[CPUI_LZCOUNT] = new OpBehaviorLzcount();
}
/// \param sizeout is the size of the output in bytes
@ -757,3 +758,8 @@ uintb OpBehaviorPopcount::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) cons
return (uintb)popcount(in1);
}
uintb OpBehaviorLzcount::evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const
{
return (uintb)(count_leading_zeros(in1) - 8*(sizeof(uintb) - sizein));
}

View file

@ -511,4 +511,11 @@ public:
virtual uintb evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const;
};
/// CPUI_LZCOUNT behavior
class OpBehaviorLzcount : public OpBehavior {
public:
OpBehaviorLzcount(void) : OpBehavior(CPUI_LZCOUNT,true) {} ///< Constructor
virtual uintb evaluateUnary(int4 sizeout,int4 sizein,uintb in1) const;
};
#endif

View file

@ -42,14 +42,14 @@ static const char *opcode_name[] = {
"TRUNC", "CEIL", "FLOOR", "ROUND",
"BUILD", "DELAY_SLOT", "PIECE", "SUBPIECE", "CAST",
"LABEL", "CROSSBUILD", "SEGMENTOP", "CPOOLREF", "NEW",
"INSERT", "EXTRACT", "POPCOUNT"
"INSERT", "EXTRACT", "POPCOUNT", "LZCOUNT"
};
static const int4 opcode_indices[] = {
0, 39, 37, 40, 38, 4, 6, 60, 7, 8, 9, 64, 5, 57, 1, 68, 66,
0, 39, 37, 40, 38, 4, 6, 60, 7, 8, 9, 64, 5, 57, 1, 68, 66,
61, 71, 55, 52, 47, 48, 41, 43, 44, 49, 46, 51, 42, 53, 50, 58, 70,
54, 24, 19, 27, 21, 33, 11, 29, 15, 16, 32, 25, 12, 28, 35, 30,
23, 22, 34, 18, 13, 14, 36, 31, 20, 26, 17, 65, 2, 69, 62, 72, 10, 59,
23, 22, 34, 18, 13, 14, 36, 31, 20, 26, 17, 65, 2, 73, 69, 62, 72, 10, 59,
67, 3, 63, 56, 45
};

View file

@ -123,8 +123,9 @@ enum OpCode {
CPUI_INSERT = 70, ///< Insert a bit-range
CPUI_EXTRACT = 71, ///< Extract a bit-range
CPUI_POPCOUNT = 72, ///< Count the 1-bits
CPUI_LZCOUNT = 73, ///< Count the leading 0-bits
CPUI_MAX = 73 ///< Value indicating the end of the op-code values
CPUI_MAX = 74 ///< Value indicating the end of the op-code values
};
extern const char *get_opname(OpCode opc); ///< Convert an OpCode to the name as a string

File diff suppressed because it is too large Load diff

View file

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%define api.prefix {pcode}
%{
#include "pcodeparse.hh"
//#define YYERROR_VERBOSE
extern int yylex(void);
extern int pcodelex(void);
static PcodeSnippet *pcode;
extern int yydebug;
extern int yyerror(const char *str );
extern int pcodeerror(const char *str );
%}
%union {
@ -800,11 +800,11 @@ void PcodeSnippet::addOperand(const string &name,int4 index)
addSymbol(sym);
}
int yylex(void) {
int pcodelex(void) {
return pcode->lex();
}
int yyerror(const char *s)
int pcodeerror(const char *s)
{
pcode->reportError((const Location *)0,s);

View file

@ -329,6 +329,7 @@ public:
virtual void opInsertOp(const PcodeOp *op);
virtual void opExtractOp(const PcodeOp *op);
virtual void opPopcountOp(const PcodeOp *op) { opFunc(op); }
virtual void opLzcountOp(const PcodeOp *op) { opFunc(op); }
};
/// \brief Set of print commands for displaying an open brace '{' and setting a new indent level

View file

@ -554,6 +554,7 @@ public:
virtual void opInsertOp(const PcodeOp *op)=0; ///< Emit an INSERT operator
virtual void opExtractOp(const PcodeOp *op)=0; ///< Emit an EXTRACT operator
virtual void opPopcountOp(const PcodeOp *op)=0; ///< Emit a POPCOUNT operator
virtual void opLzcountOp(const PcodeOp *op)=0; ///< Emit a LZCOUNT operator
virtual string unnamedField(int4 off,int4 size); ///< Generate an artificial field name
static int4 mostNaturalBase(uintb val); ///< Determine the most natural base for an integer

View file

@ -10163,3 +10163,65 @@ int4 RuleXorSwap::applyOp(PcodeOp *op,Funcdata &data)
}
return 0;
}
/// \class RuleLzcountShiftBool
/// \brief Simplify equality checks that use lzcount: `lzcount(X) >> c => X == 0` if X is 2^c bits wide
///
/// Some compilers check if a value is equal to zero by checking the most
/// significant bit in lzcount; for instance on a 32-bit system,
/// the result of lzcount on zero would have the 5th bit set.
/// - `lzcount(a ^ 3) >> 5 => a ^ 3 == 0 => a == 3` (by RuleXorCollapse)
/// - `lzcount(a - 3) >> 5 => a - 3 == 0 => a == 3` (by RuleEqual2Zero)
void RuleLzcountShiftBool::getOpList(vector<uint4> &oplist) const
{
oplist.push_back(CPUI_LZCOUNT);
}
int4 RuleLzcountShiftBool::applyOp(PcodeOp *op,Funcdata &data)
{
Varnode *outVn = op->getOut();
list<PcodeOp *>::const_iterator iter, iter2;
uintb max_return = 8 * op->getIn(0)->getSize();
if (popcount(max_return) != 1) {
// This rule only makes sense with sizes that are powers of 2; if the maximum value
// returned by lzcount was, say, 24, then both 16 >> 4 and 24 >> 4
// are 1, and thus the check does not make sense. (Such processors couldn't
// use lzcount for checking equality in any case.)
return 0;
}
for(iter=outVn->beginDescend();iter!=outVn->endDescend();++iter) {
PcodeOp *baseOp = *iter;
if (baseOp->code() != CPUI_INT_RIGHT && baseOp->code() != CPUI_INT_SRIGHT) continue;
Varnode *vn1 = baseOp->getIn(1);
if (!vn1->isConstant()) continue;
uintb shift = vn1->getOffset();
if ((max_return >> shift) == 1) {
// Becomes a comparison with zero
PcodeOp* newOp = data.newOp(2, baseOp->getAddr());
data.opSetOpcode(newOp, CPUI_INT_EQUAL);
Varnode* b = data.newConstant(op->getIn(0)->getSize(), 0);
data.opSetInput(newOp, op->getIn(0), 0);
data.opSetInput(newOp, b, 1);
// CPUI_INT_EQUAL must produce a 1-byte boolean result
Varnode* eqResVn = data.newUniqueOut(1, newOp);
data.opInsertBefore(newOp, baseOp);
// Because the old output had size op->getIn(0)->getSize(),
// we have to guarantee that a Varnode of this size gets outputted
// to the descending PcodeOps. This is handled here with CPUI_INT_ZEXT.
data.opRemoveInput(baseOp, 1);
if (baseOp->getOut()->getSize() == 1)
data.opSetOpcode(baseOp, CPUI_COPY);
else
data.opSetOpcode(baseOp, CPUI_INT_ZEXT);
data.opSetInput(baseOp, eqResVn, 0);
return 1;
}
}
return 0;
}

View file

@ -1595,4 +1595,14 @@ public:
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
};
class RuleLzcountShiftBool : public Rule {
public:
RuleLzcountShiftBool(const string &g) : Rule( g, 0, "lzcountshiftbool") {} ///< Constructor
virtual Rule *clone(const ActionGroupList &grouplist) const {
if (!grouplist.contains(getGroup())) return (Rule *)0;
return new RuleLzcountShiftBool(getGroup());
}
virtual void getOpList(vector<uint4> &oplist) const;
virtual int4 applyOp(PcodeOp *op,Funcdata &data);
};
#endif

View file

@ -785,6 +785,9 @@ void ConsistencyChecker::printOpName(ostream &s,OpTpl *op)
case CPUI_POPCOUNT:
s << "Count bits(popcount)";
break;
case CPUI_LZCOUNT:
s << "Count leading zero bits(lzcount)";
break;
default:
break;
}

File diff suppressed because it is too large Load diff

View file

@ -107,71 +107,72 @@ extern int yydebug;
OP_CPOOLREF = 302,
OP_NEW = 303,
OP_POPCOUNT = 304,
BADINTEGER = 305,
GOTO_KEY = 306,
CALL_KEY = 307,
RETURN_KEY = 308,
IF_KEY = 309,
DEFINE_KEY = 310,
ATTACH_KEY = 311,
MACRO_KEY = 312,
SPACE_KEY = 313,
TYPE_KEY = 314,
RAM_KEY = 315,
DEFAULT_KEY = 316,
REGISTER_KEY = 317,
ENDIAN_KEY = 318,
WITH_KEY = 319,
ALIGN_KEY = 320,
OP_UNIMPL = 321,
TOKEN_KEY = 322,
SIGNED_KEY = 323,
NOFLOW_KEY = 324,
HEX_KEY = 325,
DEC_KEY = 326,
BIG_KEY = 327,
LITTLE_KEY = 328,
SIZE_KEY = 329,
WORDSIZE_KEY = 330,
OFFSET_KEY = 331,
NAMES_KEY = 332,
VALUES_KEY = 333,
VARIABLES_KEY = 334,
PCODEOP_KEY = 335,
IS_KEY = 336,
LOCAL_KEY = 337,
DELAYSLOT_KEY = 338,
CROSSBUILD_KEY = 339,
EXPORT_KEY = 340,
BUILD_KEY = 341,
CONTEXT_KEY = 342,
ELLIPSIS_KEY = 343,
GLOBALSET_KEY = 344,
BITRANGE_KEY = 345,
CHAR = 346,
INTEGER = 347,
INTB = 348,
STRING = 349,
SYMBOLSTRING = 350,
SPACESYM = 351,
SECTIONSYM = 352,
TOKENSYM = 353,
USEROPSYM = 354,
VALUESYM = 355,
VALUEMAPSYM = 356,
CONTEXTSYM = 357,
NAMESYM = 358,
VARSYM = 359,
BITSYM = 360,
SPECSYM = 361,
VARLISTSYM = 362,
OPERANDSYM = 363,
STARTSYM = 364,
ENDSYM = 365,
NEXT2SYM = 366,
MACROSYM = 367,
LABELSYM = 368,
SUBTABLESYM = 369
OP_LZCOUNT = 305,
BADINTEGER = 306,
GOTO_KEY = 307,
CALL_KEY = 308,
RETURN_KEY = 309,
IF_KEY = 310,
DEFINE_KEY = 311,
ATTACH_KEY = 312,
MACRO_KEY = 313,
SPACE_KEY = 314,
TYPE_KEY = 315,
RAM_KEY = 316,
DEFAULT_KEY = 317,
REGISTER_KEY = 318,
ENDIAN_KEY = 319,
WITH_KEY = 320,
ALIGN_KEY = 321,
OP_UNIMPL = 322,
TOKEN_KEY = 323,
SIGNED_KEY = 324,
NOFLOW_KEY = 325,
HEX_KEY = 326,
DEC_KEY = 327,
BIG_KEY = 328,
LITTLE_KEY = 329,
SIZE_KEY = 330,
WORDSIZE_KEY = 331,
OFFSET_KEY = 332,
NAMES_KEY = 333,
VALUES_KEY = 334,
VARIABLES_KEY = 335,
PCODEOP_KEY = 336,
IS_KEY = 337,
LOCAL_KEY = 338,
DELAYSLOT_KEY = 339,
CROSSBUILD_KEY = 340,
EXPORT_KEY = 341,
BUILD_KEY = 342,
CONTEXT_KEY = 343,
ELLIPSIS_KEY = 344,
GLOBALSET_KEY = 345,
BITRANGE_KEY = 346,
CHAR = 347,
INTEGER = 348,
INTB = 349,
STRING = 350,
SYMBOLSTRING = 351,
SPACESYM = 352,
SECTIONSYM = 353,
TOKENSYM = 354,
USEROPSYM = 355,
VALUESYM = 356,
VALUEMAPSYM = 357,
CONTEXTSYM = 358,
NAMESYM = 359,
VARSYM = 360,
BITSYM = 361,
SPECSYM = 362,
VARLISTSYM = 363,
OPERANDSYM = 364,
STARTSYM = 365,
ENDSYM = 366,
NEXT2SYM = 367,
MACROSYM = 368,
LABELSYM = 369,
SUBTABLESYM = 370
};
#endif
@ -180,7 +181,7 @@ extern int yydebug;
union YYSTYPE
{
#line 29 "slghparse.y" /* yacc.c:1909 */
char ch;
uintb *i;
@ -225,7 +226,7 @@ union YYSTYPE
FamilySymbol *famsym;
SpecificSymbol *specsym;
#line 214 "slghparse.hh" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;

View file

@ -94,7 +94,7 @@
%right '!' '~'
%token OP_ZEXT OP_CARRY OP_BORROW OP_SEXT OP_SCARRY OP_SBORROW OP_NAN OP_ABS
%token OP_SQRT OP_CEIL OP_FLOOR OP_ROUND OP_INT2FLOAT OP_FLOAT2FLOAT
%token OP_TRUNC OP_CPOOLREF OP_NEW OP_POPCOUNT
%token OP_TRUNC OP_CPOOLREF OP_NEW OP_POPCOUNT OP_LZCOUNT
%token BADINTEGER GOTO_KEY CALL_KEY RETURN_KEY IF_KEY
%token DEFINE_KEY ATTACH_KEY MACRO_KEY SPACE_KEY TYPE_KEY RAM_KEY DEFAULT_KEY
@ -444,6 +444,7 @@ expr: varnode { $$ = new ExprTree($1); }
| OP_NEW '(' expr ')' { $$ = slgh->pcode.createOp(CPUI_NEW,$3); }
| OP_NEW '(' expr ',' expr ')' { $$ = slgh->pcode.createOp(CPUI_NEW,$3,$5); }
| OP_POPCOUNT '(' expr ')' { $$ = slgh->pcode.createOp(CPUI_POPCOUNT,$3); }
| OP_LZCOUNT '(' expr ')' { $$ = slgh->pcode.createOp(CPUI_LZCOUNT,$3); }
| specificsymbol '(' integervarnode ')' { $$ = slgh->pcode.createOp(CPUI_SUBPIECE,new ExprTree($1->getVarnode()),new ExprTree($3)); }
| specificsymbol ':' INTEGER { $$ = slgh->pcode.createBitRange($1,0,(uint4)(*$3 * 8)); delete $3; }
| specificsymbol '[' INTEGER ',' INTEGER ']' { $$ = slgh->pcode.createBitRange($1,(uint4)*$3,(uint4)*$5); delete $3, delete $5; }

File diff suppressed because it is too large Load diff

View file

@ -641,6 +641,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<sem>cpool { return OP_CPOOLREF; }
<sem>newobject { return OP_NEW; }
<sem>popcount { return OP_POPCOUNT; }
<sem>lzcount { return OP_LZCOUNT; }
<sem>if { return IF_KEY; }
<sem>goto { return GOTO_KEY; }
<sem>call { return CALL_KEY; }

View file

@ -102,6 +102,7 @@ void TypeOp::registerInstructions(vector<TypeOp *> &inst,TypeFactory *tlst,
inst[CPUI_INSERT] = new TypeOpInsert(tlst);
inst[CPUI_EXTRACT] = new TypeOpExtract(tlst);
inst[CPUI_POPCOUNT] = new TypeOpPopcount(tlst);
inst[CPUI_LZCOUNT] = new TypeOpLzcount(tlst);
}
/// Change basic data-type info (signed vs unsigned) and operator names ( '>>' vs '>>>' )
@ -2323,3 +2324,10 @@ TypeOpPopcount::TypeOpPopcount(TypeFactory *t)
opflags = PcodeOp::unary;
behave = new OpBehaviorPopcount();
}
TypeOpLzcount::TypeOpLzcount(TypeFactory *t)
: TypeOpFunc(t,CPUI_LZCOUNT,"LZCOUNT",TYPE_INT,TYPE_UNKNOWN)
{
opflags = PcodeOp::unary;
behave = new OpBehaviorLzcount();
}

View file

@ -857,4 +857,11 @@ public:
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opPopcountOp(op); }
};
/// \brief Information about the LZCOUNT op-code
class TypeOpLzcount : public TypeOpFunc {
public:
TypeOpLzcount(TypeFactory *t); ///< Constructor
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opLzcountOp(op); }
};
#endif

View file

@ -476,6 +476,7 @@ void ScoreUnionFields::scoreTrialDown(const Trial &trial,bool lastLevel)
case CPUI_INT_AND:
case CPUI_INT_OR:
case CPUI_POPCOUNT:
case CPUI_LZCOUNT:
if (meta == TYPE_ARRAY || meta == TYPE_STRUCT || meta == TYPE_UNION || meta == TYPE_CODE || meta == TYPE_FLOAT)
score = -5;
else if (meta == TYPE_PTR || meta == TYPE_BOOL)
@ -717,6 +718,7 @@ void ScoreUnionFields::scoreTrialUp(const Trial &trial,bool lastLevel)
case CPUI_INT_AND:
case CPUI_INT_OR:
case CPUI_POPCOUNT:
case CPUI_LZCOUNT:
if (meta == TYPE_ARRAY || meta == TYPE_STRUCT || meta == TYPE_UNION || meta == TYPE_CODE || meta == TYPE_FLOAT)
score = -5;
else if (meta == TYPE_PTR || meta == TYPE_BOOL)

View file

@ -73,7 +73,8 @@
/* Pull parsers. */
#define YYPULL 1
/* Substitute the type names. */
#define YYSTYPE XMLSTYPE
/* Substitute the variable and function names. */
#define yyparse xmlparse
#define yylex xmllex
@ -85,7 +86,7 @@
#define yychar xmlchar
/* Copy the first part of user declarations. */
#line 16 "src/decompile/cpp/xml.y" /* yacc.c:339 */
#include "xml.hh"
// CharData mode look for '<' '&' or "]]>"
@ -179,16 +180,15 @@ struct NameValue {
string *value; ///< The value
};
extern int yylex(void); ///< Interface to the scanner
extern int yyerror(const char *str); ///< Interface for registering an error in parsing
extern int xmllex(void); ///< Interface to the scanner
extern int xmlerror(const char *str); ///< Interface for registering an error in parsing
extern void print_content(const string &str); ///< Send character data to the ContentHandler
extern int4 convertEntityRef(const string &ref); ///< Convert an XML entity to its equivalent character
extern int4 convertCharRef(const string &ref); ///< Convert an XML character reference to its equivalent character
static XmlScan *global_scan; ///< Global reference to the scanner
static ContentHandler *handler; ///< Global reference to the content handler
extern int yydebug; ///< Debug mode
#line 177 "src/decompile/cpp/xml.cc" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@ -208,17 +208,25 @@ extern int yydebug; ///< Debug mode
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#ifndef XMLDEBUG
# if defined YYDEBUG
#if YYDEBUG
# define XMLDEBUG 1
# else
# define XMLDEBUG 0
# endif
# else /* ! defined YYDEBUG */
# define XMLDEBUG 0
# endif /* ! defined YYDEBUG */
#endif /* ! defined XMLDEBUG */
#if XMLDEBUG
extern int xmldebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
#ifndef XMLTOKENTYPE
# define XMLTOKENTYPE
enum xmltokentype
{
CHARDATA = 258,
CDATA = 259,
@ -233,27 +241,27 @@ extern int xmldebug;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
#if ! defined XMLSTYPE && ! defined XMLSTYPE_IS_DECLARED
union YYSTYPE
union XMLSTYPE
{
#line 119 "src/decompile/cpp/xml.y" /* yacc.c:355 */
int4 i;
string *str;
Attributes *attr;
NameValue *pair;
#line 233 "src/decompile/cpp/xml.cc" /* yacc.c:355 */
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
typedef union XMLSTYPE XMLSTYPE;
# define XMLSTYPE_IS_TRIVIAL 1
# define XMLSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE xmllval;
extern XMLSTYPE xmllval;
int xmlparse (void);
@ -261,7 +269,7 @@ int xmlparse (void);
/* Copy the second part of user declarations. */
#line 250 "src/decompile/cpp/xml.cc" /* yacc.c:358 */
#ifdef short
# undef short
@ -442,7 +450,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
|| (defined XMLSTYPE_IS_TRIVIAL && XMLSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
@ -555,7 +563,7 @@ static const yytype_uint8 yytranslate[] =
5, 6, 7, 8, 9, 10, 11
};
#if YYDEBUG
#if XMLDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
@ -570,7 +578,7 @@ static const yytype_uint8 yyrline[] =
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 0
#if XMLDEBUG || YYERROR_VERBOSE || 0
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
@ -815,7 +823,7 @@ while (0)
/* Enable debugging if requested. */
#if YYDEBUG
#if XMLDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
@ -936,12 +944,12 @@ do { \
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
#else /* !XMLDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
#endif /* !XMLDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
@ -1452,259 +1460,259 @@ yyreduce:
switch (yyn)
{
case 10:
#line 144 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = new string; global_scan->setmode(XmlScan::AttValueSingleMode); }
#line 1443 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 11:
#line 145 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); *(yyval.str) += *(yyvsp[0].str); delete (yyvsp[0].str); global_scan->setmode(XmlScan::AttValueSingleMode); }
#line 1449 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 12:
#line 146 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); *(yyval.str) += (yyvsp[0].i); global_scan->setmode(XmlScan::AttValueSingleMode); }
#line 1455 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 13:
#line 147 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = new string; global_scan->setmode(XmlScan::AttValueDoubleMode); }
#line 1461 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 14:
#line 148 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); *(yyval.str) += *(yyvsp[0].str); delete (yyvsp[0].str); global_scan->setmode(XmlScan::AttValueDoubleMode); }
#line 1467 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 15:
#line 149 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); *(yyval.str) += (yyvsp[0].i); global_scan->setmode(XmlScan::AttValueDoubleMode); }
#line 1473 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 16:
#line 150 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1479 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 17:
#line 151 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1485 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 18:
#line 152 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::NameMode); delete (yyvsp[0].str); }
#line 1491 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 19:
#line 153 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CommentMode); delete (yyvsp[-3].str); }
#line 1497 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 20:
#line 154 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ delete (yyvsp[-3].str); }
#line 1503 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 21:
#line 155 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ delete (yyvsp[-1].str); yyerror("Processing instructions are not supported"); YYERROR; }
#line 1509 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 22:
#line 156 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1515 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 23:
#line 157 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CDataMode); delete (yyvsp[-8].str); }
#line 1521 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 32:
#line 168 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ delete (yyvsp[-8].str); yyerror("DTD's not supported"); YYERROR; }
#line 1527 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 39:
#line 176 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->setVersion(*(yyvsp[0].str)); delete (yyvsp[0].str); }
#line 1533 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 40:
#line 177 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->setEncoding(*(yyvsp[0].str)); delete (yyvsp[0].str); }
#line 1539 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 46:
#line 184 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->endElement((yyvsp[0].attr)->getelemURI(),(yyvsp[0].attr)->getelemName(),(yyvsp[0].attr)->getelemName()); delete (yyvsp[0].attr); }
#line 1545 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 47:
#line 185 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->endElement((yyvsp[-2].attr)->getelemURI(),(yyvsp[-2].attr)->getelemName(),(yyvsp[-2].attr)->getelemName()); delete (yyvsp[-2].attr); delete (yyvsp[0].str); }
#line 1551 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 48:
#line 187 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->startElement((yyvsp[-1].attr)->getelemURI(),(yyvsp[-1].attr)->getelemName(),(yyvsp[-1].attr)->getelemName(),*(yyvsp[-1].attr)); (yyval.attr) = (yyvsp[-1].attr); }
#line 1557 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 49:
#line 188 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->startElement((yyvsp[-2].attr)->getelemURI(),(yyvsp[-2].attr)->getelemName(),(yyvsp[-2].attr)->getelemName(),*(yyvsp[-2].attr)); (yyval.attr) = (yyvsp[-2].attr); }
#line 1563 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 50:
#line 189 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->startElement((yyvsp[-2].attr)->getelemURI(),(yyvsp[-2].attr)->getelemName(),(yyvsp[-2].attr)->getelemName(),*(yyvsp[-2].attr)); (yyval.attr) = (yyvsp[-2].attr); }
#line 1569 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 51:
#line 190 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ handler->startElement((yyvsp[-3].attr)->getelemURI(),(yyvsp[-3].attr)->getelemName(),(yyvsp[-3].attr)->getelemName(),*(yyvsp[-3].attr)); (yyval.attr) = (yyvsp[-3].attr); }
#line 1575 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 52:
#line 192 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.attr) = new Attributes((yyvsp[0].str)); global_scan->setmode(XmlScan::SNameMode); }
#line 1581 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 53:
#line 193 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.attr) = (yyvsp[-1].attr); (yyval.attr)->add_attribute( (yyvsp[0].pair)->name, (yyvsp[0].pair)->value); delete (yyvsp[0].pair); global_scan->setmode(XmlScan::SNameMode); }
#line 1587 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 54:
#line 194 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.pair) = new NameValue; (yyval.pair)->name = (yyvsp[-2].str); (yyval.pair)->value = (yyvsp[0].str); }
#line 1593 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 55:
#line 195 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::NameMode); delete (yyvsp[-1].str); }
#line 1599 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 56:
#line 196 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1605 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 57:
#line 197 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-2].str); }
#line 1611 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 58:
#line 199 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CharDataMode); }
#line 1617 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 59:
#line 200 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ print_content( *(yyvsp[0].str) ); delete (yyvsp[0].str); global_scan->setmode(XmlScan::CharDataMode); }
#line 1623 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 60:
#line 201 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CharDataMode); }
#line 1629 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 61:
#line 202 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ string *tmp=new string(); *tmp += (yyvsp[0].i); print_content(*tmp); delete tmp; global_scan->setmode(XmlScan::CharDataMode); }
#line 1635 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 62:
#line 203 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ print_content( *(yyvsp[0].str) ); delete (yyvsp[0].str); global_scan->setmode(XmlScan::CharDataMode); }
#line 1641 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 63:
#line 204 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CharDataMode); }
#line 1647 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 64:
#line 205 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CharDataMode); }
#line 1653 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 65:
#line 207 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.i) = convertEntityRef(*(yyvsp[0].str)); delete (yyvsp[0].str); }
#line 1659 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 66:
#line 208 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.i) = convertCharRef(*(yyvsp[0].str)); delete (yyvsp[0].str); }
#line 1665 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 67:
#line 210 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::NameMode); }
#line 1671 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 68:
#line 211 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ global_scan->setmode(XmlScan::CharRefMode); }
#line 1677 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 69:
#line 212 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1683 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
case 70:
#line 213 "src/decompile/cpp/xml.y" /* yacc.c:1646 */
{ (yyval.str) = (yyvsp[-1].str); }
#line 1689 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
break;
#line 1693 "src/decompile/cpp/xml.cc" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@ -1932,7 +1940,7 @@ yyreturn:
#endif
return yyresult;
}
#line 214 "src/decompile/cpp/xml.y" /* yacc.c:1906 */
XmlScan::XmlScan(istream &t) : s(t)
@ -2217,7 +2225,7 @@ int4 convertCharRef(const string &ref)
return val;
}
int yylex(void)
int xmllex(void)
{
int res = global_scan->nexttoken();
@ -2226,7 +2234,7 @@ int yylex(void)
return res;
}
int yyerror(const char *str)
int xmlerror(const char *str)
{
handler->setError(str);

View file

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%define api.prefix {xml}
%{
#include "xml.hh"
// CharData mode look for '<' '&' or "]]>"
@ -106,14 +107,13 @@ struct NameValue {
string *value; ///< The value
};
extern int yylex(void); ///< Interface to the scanner
extern int yyerror(const char *str); ///< Interface for registering an error in parsing
extern int xmllex(void); ///< Interface to the scanner
extern int xmlerror(const char *str); ///< Interface for registering an error in parsing
extern void print_content(const string &str); ///< Send character data to the ContentHandler
extern int4 convertEntityRef(const string &ref); ///< Convert an XML entity to its equivalent character
extern int4 convertCharRef(const string &ref); ///< Convert an XML character reference to its equivalent character
static XmlScan *global_scan; ///< Global reference to the scanner
static ContentHandler *handler; ///< Global reference to the content handler
extern int yydebug; ///< Debug mode
%}
%union {
@ -495,7 +495,7 @@ int4 convertCharRef(const string &ref)
return val;
}
int yylex(void)
int xmllex(void)
{
int res = global_scan->nexttoken();
@ -504,7 +504,7 @@ int yylex(void)
return res;
}
int yyerror(const char *str)
int xmlerror(const char *str)
{
handler->setError(str);