From 59a2a614badfbacb8fb5f695a87c122bb0ada7df Mon Sep 17 00:00:00 2001 From: g012 Date: Wed, 20 Sep 2017 11:09:51 +0200 Subject: [PATCH] Optimized a bit linking strategy. --- 6502.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/6502.lua b/6502.lua index 070453e..fa407c2 100644 --- a/6502.lua +++ b/6502.lua @@ -62,7 +62,7 @@ M.link = function() end end -- position independent sections - table.sort(position_independent_sections, function(a,b) return a.size < b.size end) + table.sort(position_independent_sections, function(a,b) return a.size==b.size and a.label>b.label or a.size>b.size end) for _,section in ipairs(position_independent_sections) do local chunks = {} for _,chunk in ipairs(location.chunks) do @@ -87,8 +87,13 @@ M.link = function() if constraint.type == 'samepage' then goto constraints_not_met end end end - local w = math.min(address - chunk.start, chunk.size - (address - chunk.start)) - if w < waste then waste=w position=address end + local w = math.min(address - chunk.start, chunk.size - (address+section.size - chunk.start)) + if w < waste then waste=w position=address + elseif w==waste then + -- if waste is the same, keep the one that leaves most aligned addresses for other sections + -- TODO + if position and address>position then waste=w position=address end + end ::constraints_not_met:: end end @@ -197,6 +202,10 @@ M.writesym = function(filename) f:close() end +M.getstats = function() + return 'TODO' -- TODO +end + M.location = function(start, finish) if type(start) == 'table' then for _,v in ipairs(locations) do if v == start then