<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof">
<p dir="ltr" style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="elementToProof"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0 elementToProof">First thanks for this API. I am switching to it from a proprietary library I wrote a long time ago, I really like it. But have
a question about Unbound vs Bound instructions. <br>
<br>
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">I am interested in the rationale behind Bound and Unbound Instructions. It seems to be related to whether they are somehow ‘tethered’ to a BCI/Pos?
or indeed even to a specific CodeModel or var slot. Is that correct? Or is there some other reason for separating the instructions this way?
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">In my use case I am interested in the relative order of instructions and therefore need the BCI for all instructions. For Bound instructions I can
extract the pos (which can be easily mapped to BCI). For Unbound I cannot easily determine the BCI.
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">Undeterred 😉 my first hack was to just create a side mappings Map< Instruction,
Integer> as I walk through the elements.</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"> So....<br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-left:36pt;margin-top:0pt;margin-bottom:0pt">
<span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0">codeModel.elements().forEach((codeElement -> {</span></p>
<p dir="ltr" style="line-height:1.38;margin-left:36pt;margin-top:0pt;margin-bottom:0pt">
<span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0"> /* Build side mappings here */</span></p>
<p dir="ltr" style="line-height:1.38;margin-left:36pt;margin-top:0pt;margin-bottom:0pt">
<span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0">});</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
<br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">Sadly the lack of guaranteed 'identity' from</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">
</span><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0">CodeImpl.bcToInstruction(int bc, int pos)</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0"><br>
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt" class="elementToProof">
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">caught me off-guard :)
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">It turns out that some instructions are indeed allocated</span><span style="font-size: 12pt; font-family: "Courier New"; color: rgb(169, 183, 198); font-weight: 400;"><br class="ContentPasted0">
<br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0">return switch (bc) {</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0"> case BIPUSH -> new BoundArgumentConstantInstruction(... pos);</span></p>
<br class="ContentPasted0">
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">whereas others (those pesky Unbound ones) are pulled from a cache of pre-allocated
instructions</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0">default -> {</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0"> InstructionData.singletonInstructions[bc];</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-weight: 700;" class="ContentPasted0"> </span></p>
<span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">rendering my Map<Instruction, Integer> somewhat useless ;)
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;" class="ContentPasted0">I doubt if my 'need' for accessing the BCI of each instruction is unique, so I am wondering
whether the value of this Unbound/Bound separation might be worth it in the long run.</span><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;">
<br>
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br>
<br>
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;">Or at least whether a CodeModel.getBCI(Instruction) helper method could be introduced, which has tricks to step around
this 'identity' issue.<br>
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br>
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;">Gary<br>
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<b style="font-weight:normal" class="elementToProof"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-weight: 400;"><br class="ContentPasted0">
</span></b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<br>
</div>
</body>
</html>