Skip to content

Commit

Permalink
Relax macro objects equality check when merging (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast authored Jan 8, 2025
1 parent 8711216 commit f5b1e77
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/cs/production/c2ffi.Tool/Merge/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,23 @@ private void BuildCrossPlatformNodes(
}

var areAllEqual = true;
var firstNode = nodes[0].Node;
var nodeA = nodes[0].Node;
for (var i = 1; i < nodes.Length; i++)
{
var node = nodes[i].Node;
var nodeB = nodes[i].Node;

var nodesAreEqual = node.Equals(firstNode);
var nodesAreEqual = nodeB.Equals(nodeA);
if (!nodesAreEqual)
{
var x = node.Equals(firstNode);

if (node is CMacroObject nodeMacroObject && firstNode is CMacroObject firstNodeMacroObject)
if (nodeA is CMacroObject nodeMacroObjectA && nodeB is CMacroObject nodeMacroObjectB)
{
if (nodeMacroObject.EqualsWithoutValue(firstNodeMacroObject))
if (IsEqualMacroObjectsRelaxed(nodeMacroObjectA, nodeMacroObjectB))
{
areAllEqual = false;
break;
}
}

LogNodeNotEqual(nodeName, firstNode.NodeKind.ToString());
LogNodeNotEqual(nodeName, nodeA.NodeKind.ToString());
areAllEqual = false;
break;
}
Expand All @@ -218,6 +215,34 @@ private void BuildCrossPlatformNodes(
}
}

private static bool IsEqualMacroObjectsRelaxed(
CMacroObject macroObjectA,
CMacroObject macroObjectB)
{
var typeA = macroObjectA.Type;
var typeB = macroObjectB.Type;

var isSameSize = typeA.SizeOf == typeB.SizeOf && typeA.AlignOf == typeB.AlignOf;
if (!isSameSize)
{
return false;
}

var isSameValue = macroObjectA.Value == macroObjectB.Value;
if (!isSameValue)
{
return false;
}

if ((typeA.Name == "unsigned long long" && typeB.Name == "unsigned long") ||
(typeA.Name == "unsigned long" && typeB.Name == "unsigned long long"))
{
return true;
}

return false;
}

private ImmutableSortedDictionary<string, ImmutableArray<CNodeWithTargetPlatform>> GetPlatformNodesByKey(
ImmutableArray<CFfiTargetPlatform> platformFfis)
{
Expand Down

0 comments on commit f5b1e77

Please sign in to comment.