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; }
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); } }
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); }
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); }
public StructType(Location loc, string name) { Location = loc; Name = name; Definition = null; }