예제 #1
0
        private static void ComputeLayout(StructDef structDef)
        {
            int alignOf       = 1;
            int runningOffset = 0;

            foreach (FieldDef fieldDef in structDef.Fields)
            {
                var fieldType      = fieldDef.Type;
                int fieldAlignment = fieldType.AlignmentBytes;
                fieldDef.OffsetBytes = Align(runningOffset, fieldAlignment);
                alignOf       = Math.Max(fieldAlignment, alignOf);
                runningOffset = fieldDef.OffsetBytes + fieldType.SizeBytes;
            }

            structDef.SizeBytes      = Align(runningOffset, alignOf);
            structDef.AlignmentBytes = alignOf;
        }
예제 #2
0
        internal override void Resolve(Dictionary <string, StructDef> allStructs)
        {
            if (IsResolved)
            {
                return;
            }

            StructDef def;

            if (!allStructs.TryGetValue(Name, out def))
            {
                throw new TypeException(this, $"struct {Name} unknown");
            }
            else
            {
                Definition = def;
            }

            foreach (FieldDef fieldDef in def.Fields)
            {
                fieldDef.Type.Resolve(allStructs);
            }
        }
예제 #3
0
 private void EmitFieldStaticChecks(StructDef structDef, FieldDef fieldDef, TextWriter writer)
 {
     writer.WriteLine("_Static_assert(__builtin_offsetof({0}, {1}) == {2}, \"offset of field {0}::{1} does not match assembly output\");",
                      structDef.Name, fieldDef.Name, fieldDef.OffsetBytes);
 }
예제 #4
0
 private void EmitStructStaticChecks(StructDef structDef, TextWriter writer)
 {
     writer.WriteLine("_Static_assert(sizeof({0}) == {1}, \"size of struct {0} does not match assembly output\");",
                      structDef.Name, structDef.SizeBytes);
 }
예제 #5
0
 public StructType(Location loc, string name)
 {
     Location   = loc;
     Name       = name;
     Definition = null;
 }