@tsvm/bytecode 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,12 +4,9 @@ function generateRemappedOpcodes(seed) {
|
|
|
4
4
|
const forward = /* @__PURE__ */ new Map();
|
|
5
5
|
const reverse = /* @__PURE__ */ new Map();
|
|
6
6
|
const rng = new SeededRandom(seed);
|
|
7
|
-
const opcodes =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
opcodes.push(Number(key));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
7
|
+
const opcodes = Object.values(OpCode).filter(
|
|
8
|
+
(v) => typeof v === "number"
|
|
9
|
+
);
|
|
13
10
|
const availableSlots = [];
|
|
14
11
|
for (let i = 0; i < 256; i++) {
|
|
15
12
|
availableSlots.push(i);
|
|
@@ -53,7 +50,7 @@ function encodeBytecode(instructions, mapping, config, rng) {
|
|
|
53
50
|
if (Array.isArray(forward)) {
|
|
54
51
|
if (!rng) throw new Error("SeededRandom required when opcodeMap is provided");
|
|
55
52
|
mappedOp = forward[Math.floor(rng.next() * forward.length)];
|
|
56
|
-
} else if (forward
|
|
53
|
+
} else if (typeof forward === "number") {
|
|
57
54
|
mappedOp = forward;
|
|
58
55
|
}
|
|
59
56
|
}
|
|
@@ -499,11 +496,11 @@ function compileToBytecode(irModule, config) {
|
|
|
499
496
|
changed = true;
|
|
500
497
|
}
|
|
501
498
|
const inst = flatInsts[i];
|
|
502
|
-
let mappedOp = inst.mappedOp
|
|
503
|
-
const forward = mapping.forward.get(inst.opcode);
|
|
499
|
+
let mappedOp = inst.mappedOp ?? inst.opcode;
|
|
504
500
|
if (inst.mappedOp === void 0) {
|
|
501
|
+
const forward = mapping.forward.get(inst.opcode);
|
|
505
502
|
if (Array.isArray(forward)) mappedOp = forward[0];
|
|
506
|
-
else if (forward
|
|
503
|
+
else if (typeof forward === "number") mappedOp = forward;
|
|
507
504
|
}
|
|
508
505
|
let size = 1;
|
|
509
506
|
if (config.junkInsertion) {
|
|
@@ -605,6 +602,9 @@ function compileToBytecode(irModule, config) {
|
|
|
605
602
|
|
|
606
603
|
// src/decoder.ts
|
|
607
604
|
import { ImmediateEncodingScheme as ImmediateEncodingScheme2, ConstantEncodingScheme as ConstantEncodingScheme2, OperandKind as OperandKind3, OpCode as OpCode4, ConstantKind } from "@tsvm/shared";
|
|
605
|
+
function assertOpCode(value) {
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
608
608
|
function numToOperandKind(kind) {
|
|
609
609
|
switch (kind) {
|
|
610
610
|
case 0:
|
|
@@ -747,7 +747,7 @@ function decodeBytecode(bytes, mapping, config) {
|
|
|
747
747
|
mappedOp = raw[offset.pos++];
|
|
748
748
|
}
|
|
749
749
|
const canonicalOp = mapping.reverse.get(mappedOp);
|
|
750
|
-
const opcode = canonicalOp ?? mappedOp;
|
|
750
|
+
const opcode = canonicalOp ?? assertOpCode(mappedOp);
|
|
751
751
|
const numJunk = config.junkInsertion ? (opcode * 7 + config.seed) % 4 : 0;
|
|
752
752
|
offset.pos += numJunk;
|
|
753
753
|
const layout = opcodeLayout[opcode] ?? OPCODE_DEFAULT_LAYOUT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsvm/bytecode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"LICENSE"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tsvm/shared": "0.1.
|
|
22
|
+
"@tsvm/shared": "0.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"tsup": "^8.4.0",
|