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

Deref/memory assignments on defined constant labels fixed #37

Merged
Merged
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
8 changes: 5 additions & 3 deletions lua/wire/client/hlzasm/hc_codetree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
-- Returns free (non-busy) register. Does not check EBP and ESP
function HCOMP:FreeRegister()
-- Try to find a free register
for i=1,#self.RegisterBusy do

Check warning on line 93 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
if not self.RegisterBusy[i] then return i end
end

Expand Down Expand Up @@ -210,11 +210,13 @@
operands[index] = { MemoryRegister = operands[index].MemoryPointer.Register, Temporary = operands[index].MemoryPointer.Temporary }
return operands[index].Register
elseif operands[index].MemoryPointer.Constant then
if istable(operands[index].MemoryPointer.Constant) then
-- Don't decay a label constant expression into an unusable memory address if possible
for _,item in pairs(operands[index].MemoryPointer.Constant) do
if item.Type == self.TOKEN.IDENT then
operands[index] = { MemoryPointer = operands[index].MemoryPointer.Constant }
return nil
if item.Type == self.TOKEN.IDENT then
operands[index] = { MemoryPointer = operands[index].MemoryPointer.Constant }

Check warning on line 217 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Scope depth"

Are you Egyptian? What's with these fucking scope pyramids!?
return nil
end
end
end
operands[index] = { Memory = operands[index].MemoryPointer.Constant }
Expand All @@ -226,7 +228,7 @@
movLeaf.Operands[2] = operands[index].MemoryPointer
self.RegisterBusy[freeReg] = true

local addrReg,isTemp = self:GenerateLeaf(movLeaf,true)

Check warning on line 231 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Shadowing"

Variable 'addrReg' shadows existing binding, defined at line 207, column 14
operands[index] = { MemoryRegister = addrReg, Temporary = isTemp }
self.RegisterBusy[addrReg] = isTemp
return addrReg
Expand All @@ -246,7 +248,7 @@
operand.Constant = label.Expression or {{ Type = self.TOKEN.IDENT, Data = label.Name, Position = self.ErrorReportLeaf.CurrentPosition }}
else
if not label.Name then self:Error("Internal error 033") end
self:Error("Undefined label: "..label.Name,self.ErrorReportLeaf)

Check warning on line 251 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end

Expand Down Expand Up @@ -286,7 +288,7 @@
if not leaf.Opcode then
if not leaf.PreviousLeaf then --not leaf.Register then
if istable(leaf.Constant) then
self:Warning("Trying to generate invalid code ("..self:PrintTokens(leaf.Constant)..")",leaf)

Check warning on line 291 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 291 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace after ')'
elseif not leaf.ForceTemporary then
self:Warning("Trying to generate invalid code",leaf)
end
Expand All @@ -304,7 +306,7 @@

-- Check if this opcode writes to its first argument
local opcodeWritesFirstOperand = (#leaf.Operands == 2) or
((#leaf.Operands == 1) and (self.OpcodeWritesOperand[leaf.Opcode]))

Check warning on line 309 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses

-- Generate explict operands for this leaf
local genOperands = {}
Expand All @@ -326,7 +328,7 @@
leaf.Operands[i].Constant = label.Expression or {{ Type = self.TOKEN.IDENT, Data = label.Name, Position = self.ErrorReportLeaf.CurrentPosition }}
else
if not label.Name then self:Error("Internal error 033") end
self:Error("Undefined label: "..label.Name,self.ErrorReportLeaf)

Check warning on line 331 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end
if leaf.Operands[i].MemoryPointer and
Expand All @@ -343,7 +345,7 @@
leaf.Operands[i].MemoryPointer = { MemoryRegister = label.Value }
else
if not label.Name then self:Error("Internal error 033") end
self:Error("Undefined label: "..label.Name,self.ErrorReportLeaf)

Check warning on line 348 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end

Expand Down Expand Up @@ -371,10 +373,10 @@
-- Do not gen explict value if our opcode is MOV though (we can turn it into sstack later)
-- Also do not generate explict value if its an explict assign
if genOperands[i].Stack then
if ((i == 1) and (leaf.Opcode ~= "mov")) or -- Force value out of stack if we are about to perform an instruction on it
(i == 2) then -- Or if we are about to read from it
self:ReadOperandFromStack(genOperands,i)
end

Check warning on line 379 in lua/wire/client/hlzasm/hc_codetree.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

-- Need a real explict value if its a non-constant address to memory
Expand Down
Loading