Open otrho opened 2 years ago
I took a birds eye view of what's in asm_generation
and the pipeline from IR to ASM and took some notes. Might be useful in a refactor. Of note is the duplication of opcodes between VirtualOp
and AllocatedOp
which is nice for type safety but does involve a lot of duplication.
* ir -> asm:
* from_ir.rs:
* compile_ir_to_asm():
* compile_module_to_asm() sway_ir::Context -> AbstractInstructionSet
* remove_unnecessary_jumps() AbstractInstructionSet -> JumpOptimizedAsmSet
* allocate_registers() JumpOptimizedAsmSet -> RegisterAllocatedAsmSet
* realize_labels() AbstractInstructionSet -> RealizedAbstractInstructionSet
* allocate_registers() RealizedAbstractInstructionSet -> InstructionSet via register allocator
* optimize() InstructionSet -> FinalizedAsm
* JumpOptimizedAsmSet - wrapper around AbstractInstructionSet
* RegisterAllocatedAsmSet - wrapper around InstructionSet
* FinalizedAsm - wrapper around InstructionSet
* AbstractInstructionSet - collection of Op
* RealizedAbstractInstructionSet - collection of RealizedOp
* InstructionSet - collection of AllocatedOp
* Op - Either<VirtualOp, OrganizationalOp>
* VirtualOp - giant list of opcodes
* OrganizationalOp - tiny list of opcodes (label, jumps, data section placeholder)
* AllocatedOp - giant list of opcodes
* RealizedOp - VirtualOp
* VirtualOp:
* Opcodes with VirtualRegisters and VirtualImmediates
* AllocatedOp:
* Opcodes with AllocatedRegisters and AllocatedImmediates
This has changed a bit with #2843 but is still desperately needed.
Here are some personal notes I took down at some point which might as well go here. They apply to #2906 too.
Stages in pipeline:
LW data
and LW label
with mulitple data sections.MCPI
etc?Registers are:
Ops are:
enum
. Each variant (Regular
,
ControlFlow
, etc) implements traits. So VirtualOp
, AllocatedOp
, etc. should be able to
derive the trait, each variant provides it, so it works..?
When switching from AST -> ASM to AST -> IR -> ASM all the new IR -> ASM code went in
from_ir.rs
to keep it simple and contained.But the old AST -> ASM code has been removed now and
from_ir.rs
is ~2500 lines and should be broken up and refactored. All the tests called from there and hosted insway-core/tests/ir_to_asm
still need to be moved over tosway/test/src/ir_generation
or somewhere similar, and switched to useFileCheck
.Treating this as a bit of a parent issue, here's some sub-issues:
asm_builder
up further.