Alignment done (at least for now). Now there is a working access to df.

develop
Warmist 2012-03-16 02:08:55 +02:00
parent f092edaa99
commit dea215d0b9
3 changed files with 71 additions and 7 deletions

@ -27,8 +27,13 @@ function parseTree(t)
for k,v in ipairs(t) do for k,v in ipairs(t) do
if v.xarg~=nil and v.xarg["type-name"]~=nil and v.label=="ld:global-type" then if v.xarg~=nil and v.xarg["type-name"]~=nil and v.label=="ld:global-type" then
local name=v.xarg["type-name"]; local name=v.xarg["type-name"];
if name=="world" then
PRINT_PADS=1
else
PRINT_PADS=nil
end
if(types[name]==nil) then if(types[name]==nil) then
--print("Parsing:"..name)
--for kk,vv in pairs(v.xarg) do --for kk,vv in pairs(v.xarg) do
-- print("\t"..kk.." "..tostring(vv)) -- print("\t"..kk.." "..tostring(vv))
--end --end

@ -46,7 +46,9 @@ function padAddress(curoff,typetoadd) --return new offset to place things... May
if(math.mod(curoff,typetoadd.__align)==0) then if(math.mod(curoff,typetoadd.__align)==0) then
return curoff return curoff
else else
if PRINT_PADS then
print("padding off:"..curoff.." with align:"..typetoadd.__align.." pad="..(typetoadd.__align-math.mod(curoff,typetoadd.__align))) print("padding off:"..curoff.." with align:"..typetoadd.__align.." pad="..(typetoadd.__align-math.mod(curoff,typetoadd.__align)))
end
return curoff+(typetoadd.__align-math.mod(curoff,typetoadd.__align)) return curoff+(typetoadd.__align-math.mod(curoff,typetoadd.__align))
end end
end end
@ -62,7 +64,7 @@ function sarr.new(node,obj)
o.count=tonumber(node.xarg.count) o.count=tonumber(node.xarg.count)
--print("got count:"..o.count) --print("got count:"..o.count)
o.ctype=makeType(first_of_type(node,"ld:item")) o.ctype=makeType(first_of_type(node,"ld:item"))
o.__align=o.ctype.__align or 4
o.size=o.count*o.ctype.size o.size=o.count*o.ctype.size
--print("got subtypesize:"..o.ctype.size) --print("got subtypesize:"..o.ctype.size)
return o return o
@ -110,7 +112,7 @@ simpletypes.int32_t={DWORD,4,4}
simpletypes.int16_t={WORD,2,2} simpletypes.int16_t={WORD,2,2}
simpletypes.int8_t={BYTE,1,1} simpletypes.int8_t={BYTE,1,1}
simpletypes.bool={BYTE,1,1} simpletypes.bool={BYTE,1,1}
simpletypes["stl-string"]={STD_STRING,24,8} simpletypes["stl-string"]={STD_STRING,28,4}
function getSimpleType(typename,obj) function getSimpleType(typename,obj)
if simpletypes[typename] == nil then return end if simpletypes[typename] == nil then return end
local o=obj or {} local o=obj or {}
@ -135,6 +137,7 @@ function type_enum.new(node,obj)
--print(btype.." t="..convertType(btype)) --print(btype.." t="..convertType(btype))
o.type=getSimpleType(btype) -- should be simple type o.type=getSimpleType(btype) -- should be simple type
o.size=o.type.size o.size=o.type.size
o.__align=o.type.__align
return o return o
end end
xtypes["enum-type"]=type_enum xtypes["enum-type"]=type_enum
@ -147,7 +150,7 @@ function type_bitfield.new(node,obj)
o.size=0 o.size=0
o.fields_named={} o.fields_named={}
o.fields_numed={} o.fields_numed={}
o.__align=8 o.__align=1
for k,v in pairs(node) do for k,v in pairs(node) do
if type(v)=="table" and v.xarg~=nil then if type(v)=="table" and v.xarg~=nil then
@ -244,11 +247,18 @@ function type_class.new(node,obj)
o.types={} o.types={}
o.base={} o.base={}
o.size=0 o.size=0
local isunion=false
if node.xarg["is-union"]=="true" then
--error("unions not supported!")
isunion=true
end
local firsttype;
--o.baseoffset=0 --o.baseoffset=0
if node.xarg["inherits-from"]~=nil then if node.xarg["inherits-from"]~=nil then
table.insert(o.base,getGlobal(node.xarg["inherits-from"])) table.insert(o.base,getGlobal(node.xarg["inherits-from"]))
--error("Base class:"..node.xarg["inherits-from"]) --error("Base class:"..node.xarg["inherits-from"])
end end
for k,v in ipairs(o.base) do for k,v in ipairs(o.base) do
for kk,vv in pairs(v.types) do for kk,vv in pairs(v.types) do
o.types[kk]={vv[1],vv[2]+o.size} o.types[kk]={vv[1],vv[2]+o.size}
@ -269,16 +279,56 @@ function type_class.new(node,obj)
--for k,v in pairs(ttype) do --for k,v in pairs(ttype) do
-- print(k..tostring(v)) -- print(k..tostring(v))
--end --end
local off=padAddress(o.size,ttype) local off=padAddress(o.size,ttype)
if PRINT_PADS then
if ttype.__align then
print(name.." "..ttype.__align .. " off:"..off.." "..math.mod(off,ttype.__align))
end
if off~=o.size then if off~=o.size then
print("var:"..name.."size:"..ttype.size) print("var:"..name.." size:"..ttype.size)
end
end end
--print("var:"..name.." ->"..tostring(off).. " :"..ttype.size) --print("var:"..name.." ->"..tostring(off).. " :"..ttype.size)
if isunion then
if ttype.size > o.size then
o.size=ttype.size
end
o.types[name]={ttype,0}
else
o.size=off o.size=off
o.types[name]={ttype,o.size}--+o.baseoffset o.types[name]={ttype,o.size}--+o.baseoffset
o.size=o.size+ttype.size o.size=o.size+ttype.size
end end
if firsttype== nil then
firsttype=o.types[name][1]
end end
end
end
if isunion then
o.__align=0
for k,v in pairs(o.types) do
if v[1].__align~= nil and v[1].__align>o.__align then
o.__align=v[1].__align
end
end
else
if o.base[1]~= nil then
o.__align=o.base[1].__align
elseif firsttype~= nil then
o.__align=firsttype.__align
if o.__align~=nil then
print("\t\t setting align to:"..(o.__align or ""))
--else
--o.__align=4
--print("\t\t NIL ALIGNMENT!")
end
end
end
return o return o
end end
@ -330,6 +380,7 @@ function type_pointer.new(node,obj)
end end
o.size=4 o.size=4
o.__align=4
return o return o
end end
type_pointer.wrap={} type_pointer.wrap={}
@ -365,6 +416,7 @@ function dfarr.new(node,obj)
local o=obj or {} local o=obj or {}
setmetatable(o,dfarr) setmetatable(o,dfarr)
o.size=8 o.size=8
o.__align=4
return o return o
end end
function dfarr:makewrap(address) function dfarr:makewrap(address)
@ -403,6 +455,7 @@ function farr.new(node,obj)
local o=obj or {} local o=obj or {}
setmetatable(o,farr) setmetatable(o,farr)
o.size=8 o.size=8
o.__align=4
return o return o
end end
function farr:makewrap(address) function farr:makewrap(address)
@ -448,6 +501,10 @@ function bytes_pad.new(node,obj)
local o=obj or {} local o=obj or {}
setmetatable(o,bytes_pad) setmetatable(o,bytes_pad)
o.size=tonumber(node.xarg.size) o.size=tonumber(node.xarg.size)
if node.xarg.alignment~=nil then
print("Aligned bytes!")
o.__align=tonumber(node.xarg.alignment)
end
return o return o
end end
xtypes["bytes"]=bytes_pad xtypes["bytes"]=bytes_pad

@ -71,6 +71,7 @@ function stl_vec_bit.new(node,obj)
local o=obj or {} local o=obj or {}
setmetatable(o,stl_vec_bit) setmetatable(o,stl_vec_bit)
o.size=20 o.size=20
o.align=4
return o return o
end end
function stl_vec_bit:makewrap(address) function stl_vec_bit:makewrap(address)
@ -120,6 +121,7 @@ function stl_deque.new(node,obj)
local o=obj or {} local o=obj or {}
setmetatable(o,stl_deque) setmetatable(o,stl_deque)
o.size=24 o.size=24
o.__align=4
return o return o
end end
xtypes.containers["stl-deque"]=stl_deque xtypes.containers["stl-deque"]=stl_deque