Description[Courgette] Refactor: Add and use Instruction*Receptor classes; call ParseFile() in 2 passes.
We wish to reduce AssemblyProgram's memory usage on instruction storage.
This requires changing Disassembler*::Disassemble() to call ParseFile()
in 2 passes: (1) count bytes needed (so we can preallocate) (2) store
bytes. This CL implements the 2-pass system, focusing on callers. Details:
- Add AssemblyProgram::GenerateInstructions() as main entrance point
from Disassembler*. It takes InstructionGenerator, which is just
Disassembler*::ParseFile() wrapped in a Closure.
- Change Disassembler*::ParseFile() and downstream functions to const,
to assert absence of Disassembler state change for the passes.
- Exception: For ELF, we need to stort abs32_locations_ and
re32_locations_ to obtain different traversal orders. This doesn't
add/remove elements. So we make these containers mutable.
- Emit*() functions are moved from AssemblyProgram to new interface
InstructionReceptor. Updating all Emit*() calls to accommodate.
- Add InstructionReceptor interface with 2 implementations:
- InstructionCountReceptor for pass 1 (no-op in this CL).
- InstructionStoreReceptor for pass 2 (calls AssemblyProgram::Emit*()
in this CL).
- Rename Emit*Instruction() to Emit*().
TEST=Correctness without behavioral change; Courgette-gen and Courgette-apply are not slowed down, and do not use more memory.
BUG=660980
Committed: https://crrev.com/7b221a5ec1175ffba9955aede222b9bdd4056183
Cr-Commit-Position: refs/heads/master@{#431053}
Patch Set 1 #Patch Set 2 : Make AssemblyProgram::CreateInstruction*Receptor() return CheckBool. #
Total comments: 34
Patch Set 3 : Fix style and comments; lint; remove size param from InstructionStoreReceptor ctor. #
Total comments: 4
Patch Set 4 : Hide 2-pass from caller. #
Total comments: 4
Patch Set 5 : Fix comments. #
Messages
Total messages: 32 (16 generated)
|