Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify tmp registers #1010

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions compiler/modules/bir/verify.bal
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,34 @@ class VerifyContext {

public function verifyFunctionCode(Module mod, FunctionDefn defn, FunctionCode code) returns Error? {
VerifyContext cx = new(mod, defn);
boolean[] tmpRegisterInitialized = [];
if code.registers.length() > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner to do tmpRegisterIntialized.setLength(code.registers.length());

tmpRegisterInitialized[code.registers.length() - 1] = false;
}
foreach BasicBlock b in code.blocks {
check verifyBasicBlock(cx, b);
check verifyBasicBlock(cx, b, tmpRegisterInitialized);
}
}

type IntBinaryInsn IntArithmeticBinaryInsn|IntBitwiseBinaryInsn;

type Error err:Semantic|err:Internal;

function verifyBasicBlock(VerifyContext vc, BasicBlock bb) returns Error? {
function verifyBasicBlock(VerifyContext vc, BasicBlock bb, boolean[] tmpRegisterInitialized) returns Error? {
foreach Insn insn in bb.insns {
check verifyInsn(vc, insn);
check verifyTmpRegisterAssignment(vc, insn, tmpRegisterInitialized);
}
}

function verifyTmpRegisterAssignment(VerifyContext vc, Insn insn, boolean[] tmpRegisterInitialized) returns Error? {
if insn is ResultInsnBase {
if tmpRegisterInitialized[insn.result.number] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add int num = insn.result.number;

return vc.invalidErr("multiple assignments to a tmp register", insn.pos);
}
else {
tmpRegisterInitialized[insn.result.number] = true;
}
}
}

Expand Down