// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "courgette/encoded_program.h" #include #include #include #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "courgette/image_utils.h" #include "courgette/label_manager.h" #include "courgette/streams.h" #include "testing/gtest/include/gtest/gtest.h" namespace courgette { namespace { // Helper class to instantiate RVAToLabel while managing allocation. class RVAToLabelMaker { public: RVAToLabelMaker() {} ~RVAToLabelMaker() {} // Adds a Label for storage. Must be called before Make(), since |labels_map_| // has pointers into |labels_|, and |labels_.push_back()| can invalidate them. void Add(int index, RVA rva) { DCHECK(label_map_.empty()); labels_.push_back(Label(rva, index)); // Don't care about |count_|. } // Initializes |label_map_| and returns a pointer to it. RVAToLabel* Make() { for (size_t i = 0; i < labels_.size(); ++i) { DCHECK_EQ(0U, label_map_.count(labels_[i].rva_)); label_map_[labels_[i].rva_] = &labels_[i]; } return &label_map_; } const std::vector