示例#1
0
    internal int AlignAndSize(GAlign ga, out int sz)
    {
        if (IsBasic)
        {
            throw new Exception(string.Format("basic type {0} does not have alignment or size", Name));
        }

        ulong v;

        if (layout.TryGetValue(ga, out v))
        {
            sz = (int)(v >> 32);
            return((int)v);
        }

        Close();

        /*
         * Each object starts with a pointer-sized header.
         */
        int addr = ga.SizeRef(OBJECT);
        int ma   = ga.AlignRef(OBJECT);

        foreach (XTypeElt e in orderedContents)
        {
            int a, s;
            a     = e.AlignAndSize(ga, out s);
            addr  = (addr + a - 1) & ~(a - 1);
            addr += s;
            ma    = Math.Max(ma, a);
        }
        sz         = (addr + ma - 1) & ~(ma - 1);
        layout[ga] = ((ulong)sz << 32) | (ulong)(uint)ma;
        return(ma);
    }
示例#2
0
 internal override int AlignAndSizeInner(GAlign ga, out int sz)
 {
     sz = size * ga.SizeRef(ft);
     return(ga.AlignRef(ft));
 }