mirror of
https://github.com/notwa/lips
synced 2024-11-14 18:19:03 -08:00
fix .align directive and data measurement
This commit is contained in:
parent
bf439cafb3
commit
901d7ceac5
3 changed files with 14 additions and 18 deletions
|
@ -88,7 +88,7 @@ function Collector:directive()
|
||||||
add(name, self:const(nil, 'no labels'))
|
add(name, self:const(nil, 'no labels'))
|
||||||
elseif name == 'ALIGN' or name == 'SKIP' then
|
elseif name == 'ALIGN' or name == 'SKIP' then
|
||||||
if self:is_EOL() and name == 'ALIGN' then
|
if self:is_EOL() and name == 'ALIGN' then
|
||||||
add(name, self:token('NUM', 0))
|
add(name)
|
||||||
else
|
else
|
||||||
local size = self:number()
|
local size = self:number()
|
||||||
if self:is_EOL() then
|
if self:is_EOL() then
|
||||||
|
|
|
@ -35,10 +35,6 @@ function Dumper:export_labels(t)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
function Dumper:advance(by)
|
|
||||||
self.pos = self.pos + by
|
|
||||||
end
|
|
||||||
|
|
||||||
function Dumper:desym(t)
|
function Dumper:desym(t)
|
||||||
if t.tt == 'REL' then
|
if t.tt == 'REL' then
|
||||||
local target = t.tok % 0x80000000
|
local target = t.tok % 0x80000000
|
||||||
|
@ -313,7 +309,7 @@ end
|
||||||
function Dumper:load(statements)
|
function Dumper:load(statements)
|
||||||
self.labels = {}
|
self.labels = {}
|
||||||
|
|
||||||
local pos = 0
|
local pos = self.options.offset or 0
|
||||||
local new_statements = {}
|
local new_statements = {}
|
||||||
for i=1, #statements do
|
for i=1, #statements do
|
||||||
local s = statements[i]
|
local s = statements[i]
|
||||||
|
@ -345,14 +341,13 @@ function Dumper:load(statements)
|
||||||
content = s[2] and s[2].tok or nil
|
content = s[2] and s[2].tok or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if content == nil then
|
|
||||||
pos = pos + length
|
pos = pos + length
|
||||||
|
if content == nil then
|
||||||
local new = Statement(self.fn, self.line, '!ORG', pos)
|
local new = Statement(self.fn, self.line, '!ORG', pos)
|
||||||
insert(new_statements, new)
|
insert(new_statements, new)
|
||||||
elseif length > 0 then
|
elseif length > 0 then
|
||||||
insert(new_statements, self:fill(length, content))
|
insert(new_statements, self:fill(length, content))
|
||||||
elseif length < 0 then
|
elseif length < 0 then
|
||||||
pos = pos + length
|
|
||||||
local new = Statement(self.fn, self.line, '!ORG', pos)
|
local new = Statement(self.fn, self.line, '!ORG', pos)
|
||||||
insert(new_statements, new)
|
insert(new_statements, new)
|
||||||
insert(new_statements, self:fill(length, content))
|
insert(new_statements, self:fill(length, content))
|
||||||
|
@ -372,16 +367,15 @@ function Dumper:load(statements)
|
||||||
|
|
||||||
statements = new_statements
|
statements = new_statements
|
||||||
new_statements = {}
|
new_statements = {}
|
||||||
-- TODO: keep track of lengths here?
|
self.pos = self.options.offset or 0
|
||||||
self.pos = 0
|
|
||||||
for i=1, #statements do
|
for i=1, #statements do
|
||||||
local s = statements[i]
|
local s = statements[i]
|
||||||
self.fn = s.fn
|
self.fn = s.fn
|
||||||
self.line = s.line
|
self.line = s.line
|
||||||
if s.type:sub(1, 1) ~= '!' then
|
if s.type:sub(1, 1) ~= '!' then
|
||||||
local new = self:assemble(s)
|
local new = self:assemble(s)
|
||||||
insert(new_statements, new)
|
|
||||||
self.pos = self.pos + 4
|
self.pos = self.pos + 4
|
||||||
|
insert(new_statements, new)
|
||||||
elseif s.type == '!DATA' then
|
elseif s.type == '!DATA' then
|
||||||
for i, t in ipairs(s) do
|
for i, t in ipairs(s) do
|
||||||
if t.tt == 'LABEL' then
|
if t.tt == 'LABEL' then
|
||||||
|
@ -390,14 +384,14 @@ function Dumper:load(statements)
|
||||||
self:error('undefined label', t.tok)
|
self:error('undefined label', t.tok)
|
||||||
end
|
end
|
||||||
t.tt = 'WORDS'
|
t.tt = 'WORDS'
|
||||||
t.tok = {self.labels[t.tok]}
|
t.tok = {label}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
insert(new_statements, s)
|
|
||||||
self.pos = self.pos + util.measure_data(s)
|
self.pos = self.pos + util.measure_data(s)
|
||||||
elseif s.type == '!ORG' then
|
|
||||||
insert(new_statements, s)
|
insert(new_statements, s)
|
||||||
|
elseif s.type == '!ORG' then
|
||||||
self.pos = s[1].tok
|
self.pos = s[1].tok
|
||||||
|
insert(new_statements, s)
|
||||||
elseif s.type == '!LABEL' then
|
elseif s.type == '!LABEL' then
|
||||||
-- noop
|
-- noop
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,14 +43,16 @@ local function measure_data(s)
|
||||||
assert(s and s.type == '!DATA', 'Internal Error: expected !DATA statement')
|
assert(s and s.type == '!DATA', 'Internal Error: expected !DATA statement')
|
||||||
local n = 0
|
local n = 0
|
||||||
for i, t in ipairs(s) do
|
for i, t in ipairs(s) do
|
||||||
if t.type == 'LABEL' then
|
if t.tt == 'LABEL' then
|
||||||
n = n + 4
|
n = n + 4
|
||||||
elseif t.type == 'WORDS' then
|
elseif t.tt == 'WORDS' then
|
||||||
n = n + #t.tok * 4
|
n = n + #t.tok * 4
|
||||||
elseif t.type == 'HALFWORDS' then
|
elseif t.tt == 'HALFWORDS' then
|
||||||
n = n + #t.tok * 2
|
n = n + #t.tok * 2
|
||||||
elseif t.type == 'BYTES' then
|
elseif t.tt == 'BYTES' then
|
||||||
n = n + #t.tok * 1
|
n = n + #t.tok * 1
|
||||||
|
else
|
||||||
|
error('Internal Error: unknown data type in !DATA')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return n
|
return n
|
||||||
|
|
Loading…
Reference in a new issue