• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium 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 #include "components/zucchini/test_disassembler.h"
6 
7 #include "components/zucchini/test_reference_reader.h"
8 
9 namespace zucchini {
10 
11 // |num_equivalence_iterations_| = 2 to cover common case for testing.
TestDisassembler(const ReferenceTypeTraits & traits1,const std::vector<Reference> & refs1,const ReferenceTypeTraits & traits2,const std::vector<Reference> & refs2,const ReferenceTypeTraits & traits3,const std::vector<Reference> & refs3)12 TestDisassembler::TestDisassembler(const ReferenceTypeTraits& traits1,
13                                    const std::vector<Reference>& refs1,
14                                    const ReferenceTypeTraits& traits2,
15                                    const std::vector<Reference>& refs2,
16                                    const ReferenceTypeTraits& traits3,
17                                    const std::vector<Reference>& refs3)
18     : Disassembler(2),
19       traits_{traits1, traits2, traits3},
20       refs_{refs1, refs2, refs3} {}
21 
22 TestDisassembler::~TestDisassembler() = default;
23 
GetExeType() const24 ExecutableType TestDisassembler::GetExeType() const {
25   return kExeTypeUnknown;
26 }
27 
GetExeTypeString() const28 std::string TestDisassembler::GetExeTypeString() const {
29   return "(Unknown)";
30 }
31 
MakeReferenceGroups() const32 std::vector<ReferenceGroup> TestDisassembler::MakeReferenceGroups() const {
33   return {
34       {traits_[0], &TestDisassembler::MakeReadRefs1,
35        &TestDisassembler::MakeWriteRefs1},
36       {traits_[1], &TestDisassembler::MakeReadRefs2,
37        &TestDisassembler::MakeWriteRefs2},
38       {traits_[2], &TestDisassembler::MakeReadRefs3,
39        &TestDisassembler::MakeWriteRefs3},
40   };
41 }
42 
Parse(ConstBufferView image)43 bool TestDisassembler::Parse(ConstBufferView image) {
44   return true;
45 }
46 
MakeReadRefs(int type)47 std::unique_ptr<ReferenceReader> TestDisassembler::MakeReadRefs(int type) {
48   return std::make_unique<TestReferenceReader>(refs_[type]);
49 }
50 
MakeWriteRefs(MutableBufferView image)51 std::unique_ptr<ReferenceWriter> TestDisassembler::MakeWriteRefs(
52     MutableBufferView image) {
53   class NoOpWriter : public ReferenceWriter {
54    public:
55     // ReferenceWriter:
56     void PutNext(Reference) override {}
57   };
58   return std::make_unique<NoOpWriter>();
59 }
60 
61 }  // namespace zucchini
62