Skip to content

Commit

Permalink
Merge pull request #117 from OptionalAssistant/master
Browse files Browse the repository at this point in the history
Remove drift variable and unnecessary calculation
  • Loading branch information
ZehMatt authored Mar 27, 2024
2 parents fa85e5f + a741fa1 commit 55aa687
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/zasm/src/encoder/encoder.context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace zasm
std::int64_t va{};
std::int32_t offset{};
std::int32_t instrSize{};
std::int32_t drift{};


struct LabelLink
{
Expand Down
28 changes: 5 additions & 23 deletions src/zasm/src/serialization/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,9 @@ namespace zasm
alignBytesMissing -= dataIndex;
}

if (nodeEntry.length != 0)
if (nodeEntry.length != 0 && nodeEntry.length != alignSize)
{
if (alignSize < nodeEntry.length)
{
ctx.drift += nodeEntry.length - alignSize;
ctx.needsExtraPass = true;
}
else if (alignSize > nodeEntry.length)
{
ctx.drift -= static_cast<std::int64_t>(alignSize) - nodeEntry.length;
ctx.needsExtraPass = true;
}
ctx.needsExtraPass = true;
}
nodeEntry.length = alignSize;

Expand All @@ -166,18 +157,9 @@ namespace zasm
auto& nodeEntry = ctx.nodes[ctx.nodeIndex];
ctx.nodeIndex++;

if (nodeEntry.length != 0)
if (nodeEntry.length != 0 && res->buffer.length != nodeEntry.length)
{
if (res->buffer.length < nodeEntry.length)
{
ctx.drift += nodeEntry.length - static_cast<std::int64_t>(res->buffer.length);
ctx.needsExtraPass = true;
}
else if (res->buffer.length > nodeEntry.length)
{
ctx.drift -= static_cast<std::int64_t>(res->buffer.length) - nodeEntry.length;
ctx.needsExtraPass = true;
}
ctx.needsExtraPass = true;
}
nodeEntry.length = res->buffer.length;
nodeEntry.offset = ctx.offset;
Expand Down Expand Up @@ -503,7 +485,7 @@ namespace zasm
encoderCtx.va = newBase;
encoderCtx.nodeIndex = 0;
encoderCtx.sectionIndex = 0;
encoderCtx.drift = 0;


// Setup default section.
encoderCtx.sections.clear();
Expand Down

0 comments on commit 55aa687

Please sign in to comment.