Skip to content

Commit

Permalink
CopyTo works. But this isn't perfect. Writing to an existing constant…
Browse files Browse the repository at this point in the history
… set isn't supported, since it would be appending constants, potentially needing to rewrite instruction arguments to their wide formats.
  • Loading branch information
wasabii committed Dec 9, 2024
1 parent 81c30f4 commit d676187
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/IKVM.ByteCode.Tests/Decoding/CodeDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void CanCopyToWithConstant()
]);

var buffer1 = new BlobBuilder();
new CodeBuilder(buffer1).LoadConstant(new StringConstantHandle(1)).Pop().Return();
new CodeBuilder(buffer1).LoadConstant(new IntegerConstantHandle(1)).Pop().Return();
var code1 = new CodeDecoder(buffer1.ToArray());

// copy from decoder into new builder
Expand Down
3 changes: 1 addition & 2 deletions src/IKVM.ByteCode/Decoding/CodeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public readonly void CopyTo<TConstantView, TConstantPool>(TConstantView constant
where TConstantPool : IConstantPool
{
// copy code to new blob
var codeOffset = (int)Code.Length;
var code = new BlobBuilder((int)Code.Length);
new CodeDecoder(Code).CopyTo(constantView, constantPool, new CodeBuilder(code));

Expand All @@ -80,7 +79,7 @@ public readonly void CopyTo<TConstantView, TConstantPool>(TConstantView constant

// add code attribute with copied values
var excp = ExceptionTable;
encoder.Code(constantPool.Get(AttributeName.Code), MaxStack, MaxLocals, code, e => excp.CopyTo(constantView, constantPool, ref e, codeOffset), attr);
encoder.Code(constantPool.Get(AttributeName.Code), MaxStack, MaxLocals, code, e => excp.CopyTo(constantView, constantPool, ref e, 0), attr);
}

}
Expand Down

0 comments on commit d676187

Please sign in to comment.