Comment by demurgos
6 years ago
I recently [0] updated my Control Flow Graph representation in a Typescript parser for AVM1 bytecode because I had the exact same issue as in the article. I previously represented my graph as an array of blocks. But a graph always has at least one block (the entry point). The old representation forced me to check for the empty case despite knowing that valid graphs always have at least one block.
Here is the old representation:
export interface Cfg {
blocks: CfgBlock[];
}
And here is the new one:
export interface Cfg {
head: CfgBlock;
tail: CfgBlock[];
}
Switching to this new representation allowed to then simplify code manipulating this graph. This representation is also simple enough that most schema validators can represent it.
You still have to note that with this representation you no longer have a single array. It's not an issue in my case but your situation may vary. You may try the tuple-based solution mentioned in a sibling comment if you need to have a single array.
[0] https://github.com/open-flash/avm1-types/commit/ec85efab8c9e...
No comments yet
Contribute on Hacker News ↗