mirror of
https://github.com/notwa/lips
synced 2024-05-18 16:33:22 -07:00
allow labels in WORD directives
This commit is contained in:
parent
7c4becf0b6
commit
bf3f86e568
|
@ -80,11 +80,17 @@ function Dumper:add_directive(line, name, a, b)
|
||||||
local b1 = bitrange(a, 8, 15)
|
local b1 = bitrange(a, 8, 15)
|
||||||
self:add_bytes(line, b1, b0)
|
self:add_bytes(line, b1, b0)
|
||||||
elseif name == 'WORD' then
|
elseif name == 'WORD' then
|
||||||
local b0 = bitrange(a, 0, 7)
|
if type(a) == 'string' then
|
||||||
local b1 = bitrange(a, 8, 15)
|
local t = {line=line, kind='label', name=a}
|
||||||
local b2 = bitrange(a, 16, 23)
|
insert(self.commands, t)
|
||||||
local b3 = bitrange(a, 24, 31)
|
self:advance(4)
|
||||||
self:add_bytes(line, b3, b2, b1, b0)
|
else
|
||||||
|
local b0 = bitrange(a, 0, 7)
|
||||||
|
local b1 = bitrange(a, 8, 15)
|
||||||
|
local b2 = bitrange(a, 16, 23)
|
||||||
|
local b3 = bitrange(a, 24, 31)
|
||||||
|
self:add_bytes(line, b3, b2, b1, b0)
|
||||||
|
end
|
||||||
elseif name == 'ORG' then
|
elseif name == 'ORG' then
|
||||||
t.kind = 'goto'
|
t.kind = 'goto'
|
||||||
t.addr = a
|
t.addr = a
|
||||||
|
@ -271,8 +277,16 @@ function Dumper:dump()
|
||||||
else
|
else
|
||||||
self.pos = self.pos + t.skip
|
self.pos = self.pos + t.skip
|
||||||
end
|
end
|
||||||
|
elseif t.kind == 'label' then
|
||||||
|
local val = self:desym{'LABELSYM', t.name}
|
||||||
|
val = (val % 0x80000000) + 0x80000000
|
||||||
|
local b0 = bitrange(val, 0, 7)
|
||||||
|
local b1 = bitrange(val, 8, 15)
|
||||||
|
local b2 = bitrange(val, 16, 23)
|
||||||
|
local b3 = bitrange(val, 24, 31)
|
||||||
|
self:write{b3, b2, b1, b0}
|
||||||
else
|
else
|
||||||
error('Internal Error: unknown command', 1)
|
error('Internal Error: unknown command')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -221,7 +221,6 @@ function Lexer:lex_block_comment(yield)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Lexer:lex_string(yield)
|
function Lexer:lex_string(yield)
|
||||||
-- TODO: support escaping
|
|
||||||
if self.chr ~= '"' then
|
if self.chr ~= '"' then
|
||||||
self:error('expected opening double quote')
|
self:error('expected opening double quote')
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,7 +85,7 @@ function Parser:directive()
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
end
|
end
|
||||||
elseif name == 'BYTE' or name == 'HALFWORD' or name == 'WORD' then
|
elseif name == 'BYTE' or name == 'HALFWORD' then
|
||||||
self.dumper:add_directive(line, name, self:number())
|
self.dumper:add_directive(line, name, self:number())
|
||||||
while not self:is_EOL() do
|
while not self:is_EOL() do
|
||||||
self:advance()
|
self:advance()
|
||||||
|
@ -93,6 +93,14 @@ function Parser:directive()
|
||||||
self.dumper:add_directive(line, name, self:number())
|
self.dumper:add_directive(line, name, self:number())
|
||||||
end
|
end
|
||||||
self:expect_EOL()
|
self:expect_EOL()
|
||||||
|
elseif name == 'WORD' then -- allow labels in word directives
|
||||||
|
self.dumper:add_directive(line, name, self:const()[2])
|
||||||
|
while not self:is_EOL() do
|
||||||
|
self:advance()
|
||||||
|
self:optional_comma()
|
||||||
|
self.dumper:add_directive(line, name, self:const()[2])
|
||||||
|
end
|
||||||
|
self:expect_EOL()
|
||||||
elseif name == 'INC' then
|
elseif name == 'INC' then
|
||||||
-- noop, handled by lexer
|
-- noop, handled by lexer
|
||||||
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
elseif name == 'ASCII' or name == 'ASCIIZ' then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user