| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "courgette/assembly_program.h" | 5 #include "courgette/assembly_program.h" |
| 6 | 6 |
| 7 #include <memory.h> | 7 #include <memory.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <sstream> | 11 #include <sstream> |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { | 211 for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { |
| 212 int index = p->second->index_; | 212 int index = p->second->index_; |
| 213 if (index != Label::kNoIndex) { | 213 if (index != Label::kNoIndex) { |
| 214 while (static_cast<size_t>(index) >= available.size()) | 214 while (static_cast<size_t>(index) >= available.size()) |
| 215 available.push_back(true); | 215 available.push_back(true); |
| 216 available.at(index) = false; | 216 available.at(index) = false; |
| 217 ++used; | 217 ++used; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 LOG(INFO) << used << " of " << labels->size() << " labels pre-assigned"; | 221 VLOG(1) << used << " of " << labels->size() << " labels pre-assigned"; |
| 222 | 222 |
| 223 // Are there any unused labels that happen to be adjacent following a used | 223 // Are there any unused labels that happen to be adjacent following a used |
| 224 // label? | 224 // label? |
| 225 // | 225 // |
| 226 int fill_forward_count = 0; | 226 int fill_forward_count = 0; |
| 227 Label* prev = 0; | 227 Label* prev = 0; |
| 228 for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { | 228 for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { |
| 229 Label* current = p->second; | 229 Label* current = p->second; |
| 230 if (current->index_ == Label::kNoIndex) { | 230 if (current->index_ == Label::kNoIndex) { |
| 231 size_t index = 0; | 231 size_t index = 0; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 while (!available.at(index)) { | 275 while (!available.at(index)) { |
| 276 ++index; | 276 ++index; |
| 277 } | 277 } |
| 278 current->index_ = index; | 278 current->index_ = index; |
| 279 available.at(index) = false; | 279 available.at(index) = false; |
| 280 ++index; | 280 ++index; |
| 281 ++fill_infill_count; | 281 ++fill_infill_count; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 LOG(INFO) << " fill" | 285 VLOG(1) << " fill forward " << fill_forward_count |
| 286 << " forward " << fill_forward_count << " " | 286 << " backward " << fill_backward_count |
| 287 << " backward " << fill_backward_count << " " | 287 << " infill " << fill_infill_count; |
| 288 << " infill " << fill_infill_count; | |
| 289 } | 288 } |
| 290 | 289 |
| 291 typedef void (EncodedProgram::*DefineLabelMethod)(int index, RVA value); | 290 typedef void (EncodedProgram::*DefineLabelMethod)(int index, RVA value); |
| 292 | 291 |
| 293 static void DefineLabels(const RVAToLabel& labels, | 292 static void DefineLabels(const RVAToLabel& labels, |
| 294 EncodedProgram* encoded_format, | 293 EncodedProgram* encoded_format, |
| 295 DefineLabelMethod define_label) { | 294 DefineLabelMethod define_label) { |
| 296 for (RVAToLabel::const_iterator p = labels.begin(); p != labels.end(); ++p) { | 295 for (RVAToLabel::const_iterator p = labels.begin(); p != labels.end(); ++p) { |
| 297 Label* label = p->second; | 296 Label* label = p->second; |
| 298 (encoded_format->*define_label)(label->index_, label->rva_); | 297 (encoded_format->*define_label)(label->index_, label->rva_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 EncodedProgram *encoded = program->Encode(); | 361 EncodedProgram *encoded = program->Encode(); |
| 363 if (encoded) { | 362 if (encoded) { |
| 364 *output = encoded; | 363 *output = encoded; |
| 365 return C_OK; | 364 return C_OK; |
| 366 } else { | 365 } else { |
| 367 return C_GENERAL_ERROR; | 366 return C_GENERAL_ERROR; |
| 368 } | 367 } |
| 369 } | 368 } |
| 370 | 369 |
| 371 } // namespace courgette | 370 } // namespace courgette |
| OLD | NEW |