• huangs's avatar
    [Courgette] Refactor: Add and use Instruction*Receptor classes; call ParseFile() in 2 passes. · 7b221a5e
    huangs authored
    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
    
    Review-Url: https://codereview.chromium.org/2462993003
    Cr-Commit-Position: refs/heads/master@{#431053}
    7b221a5e
disassembler_win32_x86.cc 2.06 KB