sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin ir_match.h ---*/ |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 9 | |
sewardj | 89ae847 | 2013-10-18 14:12:58 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2013 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 29 | |
| 30 | Neither the names of the U.S. Department of Energy nor the |
| 31 | University of California nor the names of its contributors may be |
| 32 | used to endorse or promote products derived from this software |
| 33 | without prior written permission. |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | /* Provides a facility for doing IR tree matching. */ |
| 37 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 38 | #ifndef __VEX_IR_MATCH_H |
| 39 | #define __VEX_IR_MATCH_H |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 40 | |
| 41 | #include "libvex_basictypes.h" |
| 42 | #include "libvex_ir.h" |
| 43 | |
| 44 | |
| 45 | /* Patterns are simply IRExpr* trees, with IRExpr_Binder nodes at the |
| 46 | leaves, indicating binding points. Use these magic macros to |
| 47 | declare and define patterns. */ |
| 48 | |
| 49 | #define DECLARE_PATTERN(_patt) \ |
| 50 | static IRExpr* _patt = NULL |
| 51 | |
| 52 | #define DEFINE_PATTERN(_patt,_expr) \ |
| 53 | do { \ |
| 54 | if (!(_patt)) { \ |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 55 | vassert(vexGetAllocMode() == VexAllocModeTEMP); \ |
| 56 | vexSetAllocMode(VexAllocModePERM); \ |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 57 | _patt = (_expr); \ |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 58 | vexSetAllocMode(VexAllocModeTEMP); \ |
| 59 | vassert(vexGetAllocMode() == VexAllocModeTEMP); \ |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 60 | } \ |
| 61 | } while (0) |
| 62 | |
| 63 | |
| 64 | /* This type returns the result of a match -- it records what |
| 65 | the binders got instantiated to. */ |
| 66 | |
| 67 | #define N_IRMATCH_BINDERS 4 |
| 68 | |
| 69 | typedef |
| 70 | struct { |
| 71 | IRExpr* bindee[N_IRMATCH_BINDERS]; |
| 72 | } |
| 73 | MatchInfo; |
| 74 | |
| 75 | |
| 76 | /* The matching function. p is expected to have zero or more |
| 77 | IRExpr_Binds in it, numbered 0, 1, 2 ... Returns True if a match |
| 78 | succeeded. */ |
| 79 | |
| 80 | extern |
| 81 | Bool matchIRExpr ( MatchInfo* mi, IRExpr* p/*attern*/, IRExpr* e/*xpr*/ ); |
| 82 | |
| 83 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 84 | #endif /* ndef __VEX_IR_MATCH_H */ |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 85 | |
| 86 | |
| 87 | |
| 88 | /*---------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 89 | /*--- end ir_match.h ---*/ |
sewardj | 69933ac | 2004-12-20 04:12:14 +0000 | [diff] [blame] | 90 | /*---------------------------------------------------------------*/ |