| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 | 211 |
| 212 Label* AssemblyProgram::FindAbs32Label(RVA rva) { | 212 Label* AssemblyProgram::FindAbs32Label(RVA rva) { |
| 213 return abs32_label_manager_.Find(rva); | 213 return abs32_label_manager_.Find(rva); |
| 214 } | 214 } |
| 215 | 215 |
| 216 Label* AssemblyProgram::FindRel32Label(RVA rva) { | 216 Label* AssemblyProgram::FindRel32Label(RVA rva) { |
| 217 return rel32_label_manager_.Find(rva); | 217 return rel32_label_manager_.Find(rva); |
| 218 } | 218 } |
| 219 | 219 |
| 220 Label* AssemblyProgram::InstructionAbs32Label( | 220 void AssemblyProgram::HandleInstructionLabels( |
| 221 const Instruction* instruction) const { | 221 const AssemblyProgram::LabelHandlerMap& handler_map) const { |
| 222 if (instruction->op() == ABS32) | 222 for (const Instruction* instruction : instructions_) { |
| 223 return static_cast<const InstructionWithLabel*>(instruction)->label(); | 223 LabelHandlerMap::const_iterator it = handler_map.find(instruction->op()); |
| 224 return NULL; | 224 if (it != handler_map.end()) { |
| 225 } | 225 it->second.Run( |
| 226 | 226 static_cast<const InstructionWithLabel*>(instruction)->label()); |
| 227 Label* AssemblyProgram::InstructionAbs64Label( | 227 } |
| 228 const Instruction* instruction) const { | |
| 229 if (instruction->op() == ABS64) | |
| 230 return static_cast<const InstructionWithLabel*>(instruction)->label(); | |
| 231 return NULL; | |
| 232 } | |
| 233 | |
| 234 Label* AssemblyProgram::InstructionRel32Label( | |
| 235 const Instruction* instruction) const { | |
| 236 if (instruction->op() == REL32 || instruction->op() == REL32ARM) { | |
| 237 Label* label = | |
| 238 static_cast<const InstructionWithLabel*>(instruction)->label(); | |
| 239 return label; | |
| 240 } | 228 } |
| 241 return NULL; | |
| 242 } | 229 } |
| 243 | 230 |
| 244 CheckBool AssemblyProgram::Emit(ScopedInstruction instruction) { | 231 CheckBool AssemblyProgram::Emit(ScopedInstruction instruction) { |
| 245 if (!instruction || !instructions_.push_back(instruction.get())) | 232 if (!instruction || !instructions_.push_back(instruction.get())) |
| 246 return false; | 233 return false; |
| 247 // Ownership successfully passed to instructions_. | 234 // Ownership successfully passed to instructions_. |
| 248 ignore_result(instruction.release()); | 235 ignore_result(instruction.release()); |
| 249 return true; | 236 return true; |
| 250 } | 237 } |
| 251 | 238 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 Status Encode(const AssemblyProgram& program, | 467 Status Encode(const AssemblyProgram& program, |
| 481 std::unique_ptr<EncodedProgram>* output) { | 468 std::unique_ptr<EncodedProgram>* output) { |
| 482 // Explicitly release any memory associated with the output before encoding. | 469 // Explicitly release any memory associated with the output before encoding. |
| 483 output->reset(); | 470 output->reset(); |
| 484 | 471 |
| 485 *output = program.Encode(); | 472 *output = program.Encode(); |
| 486 return (*output) ? C_OK : C_GENERAL_ERROR; | 473 return (*output) ? C_OK : C_GENERAL_ERROR; |
| 487 } | 474 } |
| 488 | 475 |
| 489 } // namespace courgette | 476 } // namespace courgette |
| OLD | NEW |