Index: courgette/assembly_program.cc |
diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc |
index d36556fc67ad4e90496a551ad5f7b32f51a6bedf..e6c45ba0655b973a57b7b2083740781959f003db 100644 |
--- a/courgette/assembly_program.cc |
+++ b/courgette/assembly_program.cc |
@@ -107,6 +107,107 @@ class InstructionWithLabelARM : public InstructionWithLabel { |
} // namespace |
+/******** InstructionCountReceptor ********/ |
+ |
+// TODO(huangs): 2016/11: Populate these with size_ += ... |
+CheckBool InstructionCountReceptor::EmitPeRelocs() { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitElfRelocation() { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitElfARMRelocation() { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitOrigin(RVA rva) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitSingleByte(uint8_t byte) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitMultipleBytes(const uint8_t* bytes, |
+ size_t len) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitRel32(Label* label) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitRel32ARM(uint16_t op, |
+ Label* label, |
+ const uint8_t* arm_op, |
+ uint16_t op_size) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitAbs32(Label* label) { |
+ return true; |
+} |
+ |
+CheckBool InstructionCountReceptor::EmitAbs64(Label* label) { |
+ return true; |
+} |
+ |
+/******** InstructionStoreReceptor ********/ |
+ |
+// TODO(huangs): 2016/11: Populate these. |
+InstructionStoreReceptor::InstructionStoreReceptor(AssemblyProgram* program) |
+ : program_(program) { |
+ CHECK(program_); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitPeRelocs() { |
+ return program_->EmitPeRelocs(); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitElfRelocation() { |
+ return program_->EmitElfRelocation(); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitElfARMRelocation() { |
+ return program_->EmitElfARMRelocation(); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitOrigin(RVA rva) { |
+ return program_->EmitOrigin(rva); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitSingleByte(uint8_t byte) { |
+ return program_->EmitSingleByte(byte); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitMultipleBytes(const uint8_t* bytes, |
+ size_t len) { |
+ return program_->EmitMultipleBytes(bytes, len); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitRel32(Label* label) { |
+ return program_->EmitRel32(label); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitRel32ARM(uint16_t op, |
+ Label* label, |
+ const uint8_t* arm_op, |
+ uint16_t op_size) { |
+ return program_->EmitRel32ARM(op, label, arm_op, op_size); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitAbs32(Label* label) { |
+ return program_->EmitAbs32(label); |
+} |
+ |
+CheckBool InstructionStoreReceptor::EmitAbs64(Label* label) { |
+ return program_->EmitAbs64(label); |
+} |
+ |
+/******** AssemblyProgram ********/ |
+ |
AssemblyProgram::AssemblyProgram(ExecutableType kind) |
: kind_(kind), image_base_(0) { |
} |
@@ -123,29 +224,28 @@ AssemblyProgram::~AssemblyProgram() { |
} |
} |
-CheckBool AssemblyProgram::EmitPeRelocsInstruction() { |
+CheckBool AssemblyProgram::EmitPeRelocs() { |
return Emit(ScopedInstruction(UncheckedNew<PeRelocsInstruction>())); |
} |
-CheckBool AssemblyProgram::EmitElfRelocationInstruction() { |
+CheckBool AssemblyProgram::EmitElfRelocation() { |
return Emit(ScopedInstruction(UncheckedNew<ElfRelocsInstruction>())); |
} |
-CheckBool AssemblyProgram::EmitElfARMRelocationInstruction() { |
+CheckBool AssemblyProgram::EmitElfARMRelocation() { |
return Emit(ScopedInstruction(UncheckedNew<ElfARMRelocsInstruction>())); |
} |
-CheckBool AssemblyProgram::EmitOriginInstruction(RVA rva) { |
+CheckBool AssemblyProgram::EmitOrigin(RVA rva) { |
return Emit(ScopedInstruction(UncheckedNew<OriginInstruction>(rva))); |
} |
-CheckBool AssemblyProgram::EmitByteInstruction(uint8_t byte) { |
+CheckBool AssemblyProgram::EmitSingleByte(uint8_t byte) { |
return EmitShared(GetByteInstruction(byte)); |
} |
-CheckBool AssemblyProgram::EmitBytesInstruction(const uint8_t* values, |
- size_t len) { |
- return Emit(ScopedInstruction(UncheckedNew<BytesInstruction>(values, len))); |
+CheckBool AssemblyProgram::EmitMultipleBytes(const uint8_t* bytes, size_t len) { |
+ return Emit(ScopedInstruction(UncheckedNew<BytesInstruction>(bytes, len))); |
} |
CheckBool AssemblyProgram::EmitRel32(Label* label) { |
@@ -228,6 +328,27 @@ void AssemblyProgram::HandleInstructionLabels( |
} |
} |
+CheckBool AssemblyProgram::CreateInstructionCountReceptor( |
+ InstructionCountReceptor** ret) { |
+ DCHECK(ret); |
+ DCHECK(!count_receptor_); |
+ count_receptor_.reset(new InstructionCountReceptor); |
+ *ret = count_receptor_.get(); |
+ return true; |
+} |
+ |
+CheckBool AssemblyProgram::CreateInstructionStoreReceptor( |
+ InstructionStoreReceptor** ret) { |
+ DCHECK(ret); |
+ DCHECK(count_receptor_); |
+ DCHECK(!store_receptor_); |
+ store_receptor_.reset(new InstructionStoreReceptor(this)); |
+ // TODO(huangs): 2016/11: Pass |count_receptor_->size()| to |store_receptor_| |
+ // to reserve space for raw data. |
+ *ret = store_receptor_.get(); |
+ return true; |
+} |
+ |
CheckBool AssemblyProgram::Emit(ScopedInstruction instruction) { |
if (!instruction || !instructions_.push_back(instruction.get())) |
return false; |
@@ -250,7 +371,6 @@ void AssemblyProgram::UnassignIndexes(RVAToLabel* labels) { |
// DefaultAssignIndexes takes a set of labels and assigns indexes in increasing |
// address order. |
-// |
void AssemblyProgram::DefaultAssignIndexes(RVAToLabel* labels) { |
int index = 0; |
for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { |
@@ -264,7 +384,6 @@ void AssemblyProgram::DefaultAssignIndexes(RVAToLabel* labels) { |
// AssignRemainingIndexes assigns indexes to any addresses (labels) that are not |
// yet assigned an index. |
-// |
void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) { |
// An address table compresses best when each index is associated with an |
// address that is slight larger than the previous index. |
@@ -289,7 +408,6 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) { |
// Are there any unused labels that happen to be adjacent following a used |
// label? |
- // |
int fill_forward_count = 0; |
Label* prev = 0; |
for (RVAToLabel::iterator p = labels->begin(); p != labels->end(); ++p) { |
@@ -309,7 +427,6 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) { |
// Are there any unused labels that happen to be adjacent preceeding a used |
// label? |
- // |
int fill_backward_count = 0; |
prev = 0; |
for (RVAToLabel::reverse_iterator p = labels->rbegin(); |