1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/block_graph/filter_util.h"
16 :
17 : namespace block_graph {
18 :
19 : bool IsFiltered(const RelativeAddressFilter& filter,
20 E : const BlockGraph::Block* block) {
21 E : DCHECK(block != NULL);
22 :
23 : // We iterate over all of the source ranges in the block. If any of them are
24 : // marked then we return false.
25 : BlockGraph::Block::SourceRanges::RangePairs::const_iterator it =
26 E : block->source_ranges().range_pairs().begin();
27 E : for (; it != block->source_ranges().range_pairs().end(); ++it) {
28 : // If a block is *not* unmarked, then it's at least partially marked.
29 : // Which to us means it is filtered.
30 E : if (!filter.IsUnmarked(it->second))
31 E : return true;
32 E : }
33 :
34 E : return false;
35 E : }
36 :
37 : bool IsFiltered(const RelativeAddressFilter& filter,
38 E : const BasicBlock* basic_block) {
39 E : DCHECK(basic_block != NULL);
40 :
41 E : if (basic_block->type() == BasicBlock::BASIC_DATA_BLOCK) {
42 E : const BasicDataBlock* basic_data_block = BasicDataBlock::Cast(basic_block);
43 E : DCHECK(basic_data_block != NULL);
44 E : if (!IsFiltered(filter, basic_data_block))
45 E : return false;
46 E : } else {
47 E : DCHECK_EQ(BasicBlock::BASIC_CODE_BLOCK, basic_block->type());
48 E : const BasicCodeBlock* basic_code_block = BasicCodeBlock::Cast(basic_block);
49 E : DCHECK(basic_code_block != NULL);
50 E : if (!IsFiltered(filter, basic_code_block))
51 E : return false;
52 : }
53 :
54 E : return true;
55 E : }
56 :
57 : bool IsFiltered(const RelativeAddressFilter& filter,
58 E : const BasicCodeBlock* basic_block) {
59 E : DCHECK(basic_block != NULL);
60 :
61 : // Iterate over all of the instructions and check their source ranges. If any
62 : // of them are at all marked then the basic block is filtered.
63 : BasicBlock::Instructions::const_iterator it =
64 E : basic_block->instructions().begin();
65 E : for (; it != basic_block->instructions().end(); ++it) {
66 E : if (!filter.IsUnmarked(it->source_range()))
67 E : return true;
68 E : }
69 :
70 E : return false;
71 E : }
72 :
73 : bool IsFiltered(const RelativeAddressFilter& filter,
74 E : const BasicDataBlock* basic_block) {
75 E : DCHECK(basic_block != NULL);
76 :
77 E : if (filter.IsUnmarked(basic_block->source_range()))
78 E : return false;
79 :
80 E : return true;
81 E : }
82 :
83 : bool IsFiltered(const RelativeAddressFilter& filter,
84 E : const Instruction& instruction) {
85 E : if (filter.IsUnmarked(instruction.source_range()))
86 E : return false;
87 :
88 E : return true;
89 E : }
90 :
91 : } // namespace block_graph
|