Improved variable lifetime tracking

This commit is contained in:
Eduard Urbach 2024-06-30 00:17:14 +02:00
parent 1510f88165
commit b8c011d742
Signed by: eduard
GPG key ID: 49226B848C78F6C8
17 changed files with 114 additions and 31 deletions

View file

@ -260,7 +260,18 @@ func scanFile(path string, functions chan<- *Function) error {
if len(tokens) == 1 {
name := tokens[0].Text()
register := x64.CallRegisters[len(function.variables)]
variable := &Variable{Name: name, Register: register}
uses := countIdentifier(function.Body, name)
if uses == 0 {
return errors.New(&errors.UnusedVariable{Name: name}, file, tokens[0].Position)
}
variable := &Variable{
Name: name,
Register: register,
Alive: uses,
}
function.addVariable(variable)
return nil
}