Skip to content

Control Flow Graph#2558

Closed
ike709 wants to merge 14 commits intoOpenDreamProject:masterfrom
ike709:naughtylist
Closed

Control Flow Graph#2558
ike709 wants to merge 14 commits intoOpenDreamProject:masterfrom
ike709:naughtylist

Conversation

@ike709
Copy link
Copy Markdown
Collaborator

@ike709 ike709 commented May 8, 2026

This is extremely not ready yet to the point this PR will likely go stale and be closed. But I was tired of losing track of the branch and also it gives other people a chance to prod at and point out the (likely stupid) things I am doing.

I haven't even properly looked over this code in months.

@boring-cyborg boring-cyborg Bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels May 8, 2026
@ike709 ike709 marked this pull request as draft May 8, 2026 11:10



private AnnotatedBytecodeInstruction? GetLastInstruction(BasicBlock block)

// TODO: It would be nice to print the arguments properly for all opcodes; need to pass CFG info to DMDisassembler somehow
public void Dump() {
var sb = new System.Text.StringBuilder();
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
List<BasicBlock> Blocks = new();
private DMProc Proc = proc;
// The first AnnotatedBytecodeLabel or AnnotatedBytecodeInstruction in each block; blocks are separated by labels and terminators
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
List<BasicBlock> Blocks = new();
internal class ControlFlowGraph(DMCompiler compiler, DMProc proc) {
// The first AnnotatedBytecodeLabel or AnnotatedBytecodeInstruction in each block; blocks are separated by labels and terminators
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
// The first AnnotatedBytecodeLabel or AnnotatedBytecodeInstruction in each block; blocks are separated by labels and terminators
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
List<BasicBlock> Blocks = new();
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
List<BasicBlock> Blocks = new();
private DMProc Proc = proc;
List<int> BlockLeaderIndices = new(){0}; // start of instructions (idx 0) is a leader
Dictionary<IAnnotatedBytecode, BasicBlock> StartBytecodeToBlock = new(); // The first instruction/label of the block
List<BasicBlock> Blocks = new();
private DMProc Proc = proc;
// TODO: Validate switch() behavior
// TODO: Proper try/catch exception handler shenanigans

if(Proc.Name == "push" && Proc.Location.Line == 102)
// is physically in the same BasicBlock already, so it's inherently marked
// reachable as part of this block
foreach (var instr in block.Instructions) {
if (instr is AnnotatedBytecodeInstruction abi &&
@ike709
Copy link
Copy Markdown
Collaborator Author

ike709 commented May 9, 2026

this PR will likely go stale and be closed

might as well start now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants