Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / validator_ragel / proof_tools_templates.py
1 # Copyright (c) 2014 The Native Client Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Templates for grouping together similar proofs."""
6
7 import proof_tools
8
9
10 def LockedRegWithRegOrMem16bit(mnemonic_name, bitness):
11   """Computes all 16 bit optionally locked reg, reg/mem ops.
12
13   e.g.
14
15   lock instr reg16 mem
16     or
17   instr reg16 mem/reg16.
18
19   Note: when locking is issued, the second operand must be memory and not a reg.
20
21   Args:
22     mnemonic_name: the mnemonic we are producing the pattern for.
23     bitness: the bitness of the architecture (32 or 64)
24   Returns:
25     All possible disassembly sequences that follow the pattern.
26   """
27   assert bitness in (32, 64)
28   instr = proof_tools.MnemonicOp(mnemonic_name)
29   reg16 = proof_tools.GprOperands(bitness=bitness, operand_size=16)
30   mem = proof_tools.AllMemoryOperands(bitness=bitness)
31   lock = proof_tools.LockPrefix()
32   return (proof_tools.OpsProd(lock, instr, reg16, mem) |
33           proof_tools.OpsProd(instr, reg16, reg16 | mem))
34
35
36 def XmmYmmOrMemory3operand(mnemonic_name, bitness):
37   """Set of 3 operand xmm/ymm/memory ops (memory is a possible source operand).
38
39   e.g.
40
41   instr xmm1/mem, xmm2, xmm3
42   or
43   instr ymm1/mem, ymm2, ymm3
44
45   Args:
46     mnemonic_name: the mnemonic we are producing the pattern for.
47     bitness: the bitness of the architecture (32 or 64)
48   Returns:
49     All possible disassembly sequences that follow the pattern.
50   """
51   xmm = proof_tools.AllXMMOperands(bitness)
52   ymm = proof_tools.AllYMMOperands(bitness)
53   mem = proof_tools.AllMemoryOperands(bitness)
54   mnemonic = proof_tools.MnemonicOp(mnemonic_name)
55
56   return (proof_tools.OpsProd(mnemonic, (xmm | mem), xmm, xmm) |
57           proof_tools.OpsProd(mnemonic, (ymm | mem), ymm, ymm))