@typeberry/convert 0.4.1-818bae8 → 0.4.1-8a21145

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.
Files changed (3) hide show
  1. package/index.js +1678 -1656
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -4339,6 +4339,15 @@ class Compatibility {
4339
4339
  function isBrowser() {
4340
4340
  return typeof process === "undefined" || typeof process.abort === "undefined";
4341
4341
  }
4342
+ /**
4343
+ * Get current time in milliseconds (works in both Node and browser).
4344
+ *
4345
+ * Node.js implementation converts hrtime bigint nanoseconds to milliseconds.
4346
+ * This is safe because dividing nanoseconds by 1_000_000 yields milliseconds,
4347
+ * which remain well below Number.MAX_SAFE_INTEGER for practical runtimes
4348
+ * (would take ~285 years to overflow).
4349
+ */
4350
+ const now = isBrowser() ? () => performance.now() : () => Number(process.hrtime.bigint() / 1000000n);
4342
4351
  /**
4343
4352
  * A function to perform runtime assertions.
4344
4353
  *
@@ -4427,19 +4436,10 @@ function debug_inspect(val) {
4427
4436
  return v;
4428
4437
  }
4429
4438
  /** Utility function to measure time taken for some operation [ms]. */
4430
- const measure = isBrowser()
4431
- ? (id) => {
4432
- const start = performance.now();
4433
- return () => `${id} took ${performance.now() - start}ms`;
4434
- }
4435
- : (id) => {
4436
- const start = process.hrtime.bigint();
4437
- return () => {
4438
- const tookNano = process.hrtime.bigint() - start;
4439
- const tookMilli = Number(tookNano / 1000000n).toFixed(2);
4440
- return `${id} took ${tookMilli}ms`;
4441
- };
4442
- };
4439
+ function measure(id) {
4440
+ const start = now();
4441
+ return () => `${id} took ${(now() - start).toFixed(2)}ms`;
4442
+ }
4443
4443
  /** A class that adds `toString` method that prints all properties of an object. */
4444
4444
  class WithDebug {
4445
4445
  toString() {
@@ -4843,6 +4843,7 @@ function isResult(x) {
4843
4843
 
4844
4844
 
4845
4845
 
4846
+
4846
4847
  // EXTERNAL MODULE: ./node_modules/minimist/index.js
4847
4848
  var minimist = __nccwpck_require__(595);
4848
4849
  var minimist_default = /*#__PURE__*/__nccwpck_require__.n(minimist);
@@ -11869,7 +11870,7 @@ class FuzzTarget {
11869
11870
 
11870
11871
 
11871
11872
 
11872
- ;// CONCATENATED MODULE: ./packages/core/pvm-spi-decoder/memory-conts.ts
11873
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/spi-decoder/memory-conts.ts
11873
11874
  // GP reference: https://graypaper.fluffylabs.dev/#/7e6ff6a/2d32002d3200?v=0.6.7
11874
11875
  const memory_conts_PAGE_SIZE = 2 ** 12; // Z_P from GP
11875
11876
  const SEGMENT_SIZE = 2 ** 16; // Z_Z from GP
@@ -11878,7 +11879,7 @@ const STACK_SEGMENT = 0xfe_fe_00_00; // 2^32 - 2Z_Z - Z_I from GP
11878
11879
  const ARGS_SEGMENT = 0xfe_ff_00_00; // 2^32 - Z_Z - Z_I from GP
11879
11880
  const LAST_PAGE = 0xff_ff_00_00;
11880
11881
 
11881
- ;// CONCATENATED MODULE: ./packages/core/pvm-spi-decoder/memory-utils.ts
11882
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/spi-decoder/memory-utils.ts
11882
11883
 
11883
11884
  // GP reference: https://graypaper.fluffylabs.dev/#/579bd12/2bd2022bd202
11884
11885
  function alignToSegmentSize(size) {
@@ -11890,7 +11891,7 @@ function memory_utils_alignToPageSize(size) {
11890
11891
  return memory_conts_PAGE_SIZE * Math.ceil(size / memory_conts_PAGE_SIZE);
11891
11892
  }
11892
11893
 
11893
- ;// CONCATENATED MODULE: ./packages/core/pvm-spi-decoder/decode-standard-program.ts
11894
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/spi-decoder/decode-standard-program.ts
11894
11895
 
11895
11896
 
11896
11897
 
@@ -12000,7 +12001,9 @@ function getRegisters(argsLength) {
12000
12001
  return regs;
12001
12002
  }
12002
12003
 
12003
- ;// CONCATENATED MODULE: ./packages/core/pvm-spi-decoder/index.ts
12004
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/spi-decoder/index.ts
12005
+
12006
+
12004
12007
 
12005
12008
 
12006
12009
  ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-output.ts
@@ -16264,408 +16267,658 @@ var status_Status;
16264
16267
 
16265
16268
 
16266
16269
 
16267
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
16268
-
16269
-
16270
- const memory_index_tryAsMemoryIndex = (index) => {
16271
- debug_check `${index >= 0 && index <= memory_MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
16272
- return opaque_asOpaqueType(index);
16273
- };
16274
- const memory_index_tryAsSbrkIndex = (index) => {
16275
- check `${index >= 0 && index <= MAX_MEMORY_INDEX + 1} Incorrect sbrk index: ${index}!`;
16276
- return asOpaqueType(index);
16277
- };
16278
-
16279
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-consts.ts
16280
-
16281
-
16282
- const memory_consts_PAGE_SIZE_SHIFT = 12;
16283
- // PAGE_SIZE has to be a power of 2
16284
- const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
16285
- const MIN_ALLOCATION_SHIFT = (() => {
16286
- const MIN_ALLOCATION_SHIFT = 7;
16287
- debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
16288
- return MIN_ALLOCATION_SHIFT;
16289
- })();
16290
- const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
16291
- const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
16292
- /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
16293
- const memory_consts_RESERVED_NUMBER_OF_PAGES = 16;
16294
- /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
16295
- const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
16296
-
16297
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
16270
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/program-decoder/mask.ts
16298
16271
 
16299
16272
 
16300
- /** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
16301
- const page_utils_tryAsPageIndex = (index) => {
16302
- check `${index >= 0 && index < PAGE_SIZE}, Incorect page index: ${index}!`;
16303
- return asOpaqueType(index);
16304
- };
16305
- /** Ensure that given `index` represents an index of one of the pages. */
16306
- const page_utils_tryAsPageNumber = (index) => {
16307
- debug_check `${index >= 0 && index <= LAST_PAGE_NUMBER}, Incorect page number: ${index}!`;
16308
- return opaque_asOpaqueType(index);
16309
- };
16310
16273
  /**
16311
- * Get the next page number and wrap the result if it is bigger than LAST_PAGE_NUMBER
16312
- *
16313
- * GP references:
16314
- * 1. The modulo subscription operator is used in all load/store instructions, for example:
16315
- * https://graypaper.fluffylabs.dev/#/579bd12/25af0125af01
16274
+ * Upper bound of instruction distance - it is equal to max value of GP's skip function + 1
16275
+ */
16276
+ const MAX_INSTRUCTION_DISTANCE = 25;
16277
+ /**
16278
+ * Mask class is an implementation of skip function defined in GP.
16316
16279
  *
16317
- * 2. Here is the definition of the modulo subscription operator:
16318
- * https://graypaper.fluffylabs.dev/#/579bd12/073a00073a00
16280
+ * https://graypaper.fluffylabs.dev/#/5f542d7/237201239801
16319
16281
  */
16320
- function getNextPageNumber(pageNumber) {
16321
- const newPageNumber = pageNumber === LAST_PAGE_NUMBER ? 0 : pageNumber + 1;
16322
- return page_utils_tryAsPageNumber(newPageNumber);
16323
- }
16324
-
16325
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-utils.ts
16326
-
16327
-
16328
-
16329
- function memory_memory_utils_alignToPageSize(length) {
16330
- return PAGE_SIZE * Math.ceil(length / PAGE_SIZE);
16331
- }
16332
- function memory_utils_getPageNumber(address) {
16333
- return page_utils_tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
16334
- }
16335
- function memory_utils_getStartPageIndex(address) {
16336
- return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
16337
- }
16338
- function getStartPageIndexFromPageNumber(pageNumber) {
16339
- // >>> 0 is needed to avoid changing sign of the number
16340
- return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
16341
- }
16342
-
16343
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
16344
-
16345
-
16346
-
16347
-
16348
-
16349
- class errors_PageFault {
16350
- address;
16351
- isAccessFault;
16352
- constructor(address, isAccessFault = true) {
16353
- this.address = address;
16354
- this.isAccessFault = isAccessFault;
16282
+ class mask_Mask {
16283
+ /**
16284
+ * The lookup table will have `0` at the index which corresponds to an instruction on the same index in the bytecode.
16285
+ * In case the value is non-zero it signifies the offset to the index with next instruction.
16286
+ *
16287
+ * Example:
16288
+ * ```
16289
+ * 0..1..2..3..4..5..6..7..8..9 # Indices
16290
+ * 0..2..1..0..1..0..3..2..1..0 # lookupTable forward values
16291
+ * ```
16292
+ * There are instructions at indices `0, 3, 5, 9`.
16293
+ */
16294
+ lookupTableForward;
16295
+ constructor(mask) {
16296
+ this.lookupTableForward = this.buildLookupTableForward(mask);
16355
16297
  }
16356
- static fromPageNumber(maybePageNumber, isAccessFault = false) {
16357
- const pageNumber = page_utils_tryAsPageNumber(maybePageNumber);
16358
- const startPageIndex = getStartPageIndexFromPageNumber(pageNumber);
16359
- return new errors_PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
16298
+ isInstruction(index) {
16299
+ return this.lookupTableForward[index] === 0;
16360
16300
  }
16361
- static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
16362
- const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
16363
- const startPageIndex = memory_utils_getStartPageIndex(memoryIndex);
16364
- return new errors_PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
16301
+ getNoOfBytesToNextInstruction(index) {
16302
+ check `${index >= 0} index (${index}) cannot be a negative number`;
16303
+ return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
16365
16304
  }
16366
- }
16367
- class OutOfBounds extends Error {
16368
- constructor() {
16369
- super("Out of bounds");
16305
+ buildLookupTableForward(mask) {
16306
+ const table = safeAllocUint8Array(mask.bitLength);
16307
+ let lastInstructionOffset = 0;
16308
+ for (let i = mask.bitLength - 1; i >= 0; i--) {
16309
+ if (mask.isSet(i)) {
16310
+ lastInstructionOffset = 0;
16311
+ }
16312
+ else {
16313
+ lastInstructionOffset++;
16314
+ }
16315
+ table[i] = lastInstructionOffset;
16316
+ }
16317
+ return table;
16370
16318
  }
16371
- }
16372
- class ChunkOverlap extends Error {
16373
- constructor() {
16374
- super("Memory chunks cannot overlap each other!");
16319
+ static empty() {
16320
+ return new mask_Mask(BitVec.empty(0));
16375
16321
  }
16376
16322
  }
16377
- class ChunkTooLong extends Error {
16378
- constructor() {
16379
- super("Memory chunk is longer than the address range!");
16323
+
16324
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/argument-type.ts
16325
+ var argument_type_ArgumentType;
16326
+ (function (ArgumentType) {
16327
+ ArgumentType[ArgumentType["NO_ARGUMENTS"] = 0] = "NO_ARGUMENTS";
16328
+ ArgumentType[ArgumentType["ONE_IMMEDIATE"] = 1] = "ONE_IMMEDIATE";
16329
+ ArgumentType[ArgumentType["TWO_IMMEDIATES"] = 2] = "TWO_IMMEDIATES";
16330
+ ArgumentType[ArgumentType["ONE_OFFSET"] = 3] = "ONE_OFFSET";
16331
+ ArgumentType[ArgumentType["ONE_REGISTER_ONE_IMMEDIATE"] = 4] = "ONE_REGISTER_ONE_IMMEDIATE";
16332
+ ArgumentType[ArgumentType["ONE_REGISTER_TWO_IMMEDIATES"] = 5] = "ONE_REGISTER_TWO_IMMEDIATES";
16333
+ ArgumentType[ArgumentType["ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET"] = 6] = "ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET";
16334
+ ArgumentType[ArgumentType["TWO_REGISTERS"] = 7] = "TWO_REGISTERS";
16335
+ ArgumentType[ArgumentType["TWO_REGISTERS_ONE_IMMEDIATE"] = 8] = "TWO_REGISTERS_ONE_IMMEDIATE";
16336
+ ArgumentType[ArgumentType["TWO_REGISTERS_ONE_OFFSET"] = 9] = "TWO_REGISTERS_ONE_OFFSET";
16337
+ ArgumentType[ArgumentType["TWO_REGISTERS_TWO_IMMEDIATES"] = 10] = "TWO_REGISTERS_TWO_IMMEDIATES";
16338
+ ArgumentType[ArgumentType["THREE_REGISTERS"] = 11] = "THREE_REGISTERS";
16339
+ ArgumentType[ArgumentType["ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE"] = 12] = "ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE";
16340
+ })(argument_type_ArgumentType || (argument_type_ArgumentType = {}));
16341
+
16342
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/decoders/nibbles-decoder.ts
16343
+
16344
+ const MAX_REGISTER_INDEX = registers_NO_OF_REGISTERS - 1;
16345
+ const nibbles_decoder_MAX_LENGTH = 4;
16346
+ class nibbles_decoder_NibblesDecoder {
16347
+ byte = new Int8Array(1);
16348
+ setByte(byte) {
16349
+ this.byte[0] = byte;
16380
16350
  }
16381
- }
16382
- class errors_IncorrectSbrkIndex extends Error {
16383
- constructor() {
16384
- super("Space between sbrk index and max heap index should be empty!");
16351
+ getHighNibble() {
16352
+ return (this.byte[0] & 0xf0) >>> 4;
16385
16353
  }
16386
- }
16387
- class errors_FinalizedBuilderModification extends Error {
16388
- constructor() {
16389
- super("MemoryBuilder was finalized and cannot be changed!");
16354
+ getLowNibble() {
16355
+ return this.byte[0] & 0x0f;
16390
16356
  }
16391
- }
16392
- class errors_ReservedMemoryFault extends Error {
16393
- constructor() {
16394
- super("You are trying to access reserved memory!");
16357
+ getHighNibbleAsRegisterIndex() {
16358
+ return Math.min(this.getHighNibble(), MAX_REGISTER_INDEX);
16395
16359
  }
16396
- }
16397
- class errors_PageNotExist extends Error {
16398
- constructor() {
16399
- super("You try to fill data on memory page that does not exist!");
16360
+ getLowNibbleAsRegisterIndex() {
16361
+ return Math.min(this.getLowNibble(), MAX_REGISTER_INDEX);
16400
16362
  }
16401
- }
16402
- class ChunkNotFound extends Error {
16403
- constructor() {
16404
- super("Chunk does not exist or is too short");
16363
+ getHighNibbleAsLength() {
16364
+ return Math.min(this.getHighNibble(), nibbles_decoder_MAX_LENGTH);
16405
16365
  }
16406
- }
16407
- class errors_OutOfMemory extends Error {
16408
- constructor() {
16409
- super("Out of memory");
16366
+ getLowNibbleAsLength() {
16367
+ return Math.min(this.getLowNibble(), nibbles_decoder_MAX_LENGTH);
16410
16368
  }
16411
16369
  }
16412
16370
 
16413
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-range.ts
16371
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/args-decoder.ts
16414
16372
 
16415
16373
 
16416
16374
 
16417
- /**
16418
- * A representation of open-ended range of consecutive indices in memory,
16419
- * possibly empty or wrapping around.
16420
- *
16421
- * `[start, start + length)`
16422
- */
16423
- class memory_range_MemoryRange {
16424
- start;
16425
- length;
16426
- /**
16427
- * Exclusive end index of the range.
16428
- *
16429
- * NOTE: The index may be wrapped around and smaller than `start`!
16430
- */
16431
- end;
16432
- /**
16433
- * Inclusive last index of the range (present unless the range is empty).
16434
- *
16435
- * NOTE: the index may be wrapped around and smaller than `start`!
16436
- */
16437
- lastIndex = null;
16438
- constructor(start, length) {
16439
- this.start = start;
16440
- this.length = length;
16441
- this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
16442
- if (length > 0) {
16443
- this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
16444
- }
16375
+
16376
+ const IMMEDIATE_AND_OFFSET_MAX_LENGTH = 4;
16377
+ class args_decoder_ArgsDecoder {
16378
+ nibblesDecoder = new NibblesDecoder();
16379
+ offsetDecoder = new ImmediateDecoder();
16380
+ code = new Uint8Array();
16381
+ mask = Mask.empty();
16382
+ reset(code, mask) {
16383
+ this.code = code;
16384
+ this.mask = mask;
16445
16385
  }
16446
- /** Creates a memory range from given starting point and length */
16447
- static fromStartAndLength(start, length) {
16448
- if (!Number.isInteger(length) || length < 0 || length > MEMORY_SIZE) {
16449
- throw new TypeError(`length must be a non-negative integer and less than ${MEMORY_SIZE}, got ${length}`);
16450
- }
16451
- return new memory_range_MemoryRange(start, length);
16452
- }
16453
- /** Checks if a range is empty (`length === 0`) */
16454
- isEmpty() {
16455
- return this.length === 0;
16456
- }
16457
- /** Returns true if the range is wrapped (`start` >= `end`) and is not empty */
16458
- isWrapped() {
16459
- return this.start >= this.end && !this.isEmpty();
16460
- }
16461
- /** Checks if given memory address is within the range */
16462
- isInRange(address) {
16463
- if (this.isWrapped()) {
16464
- return address >= this.start || address < this.end;
16465
- }
16466
- return address >= this.start && address < this.end;
16467
- }
16468
- /** Checks if this range overlaps with another range */
16469
- overlapsWith(other) {
16470
- if (this.lastIndex === null || other.lastIndex === null) {
16471
- return false;
16386
+ fillArgs(pc, result) {
16387
+ const nextInstructionDistance = 1 + this.mask.getNoOfBytesToNextInstruction(pc + 1);
16388
+ result.noOfBytesToSkip = nextInstructionDistance;
16389
+ switch (result.type) {
16390
+ case ArgumentType.NO_ARGUMENTS:
16391
+ break;
16392
+ case ArgumentType.ONE_IMMEDIATE: {
16393
+ const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, nextInstructionDistance - 1);
16394
+ const argsStartIndex = pc + 1;
16395
+ result.immediateDecoder.setBytes(this.code.subarray(argsStartIndex, argsStartIndex + immediateLength));
16396
+ break;
16397
+ }
16398
+ case ArgumentType.THREE_REGISTERS: {
16399
+ const firstByte = this.code[pc + 1];
16400
+ const secondByte = this.code[pc + 2];
16401
+ this.nibblesDecoder.setByte(firstByte);
16402
+ result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16403
+ result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
16404
+ this.nibblesDecoder.setByte(secondByte);
16405
+ result.thirdRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16406
+ break;
16407
+ }
16408
+ case ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE: {
16409
+ const firstByte = this.code[pc + 1];
16410
+ this.nibblesDecoder.setByte(firstByte);
16411
+ result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16412
+ result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
16413
+ const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
16414
+ const immediateStartIndex = pc + 2;
16415
+ const immediateEndIndex = immediateStartIndex + immediateLength;
16416
+ result.immediateDecoder.setBytes(this.code.subarray(immediateStartIndex, immediateEndIndex));
16417
+ break;
16418
+ }
16419
+ case ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET: {
16420
+ const firstByte = this.code[pc + 1];
16421
+ this.nibblesDecoder.setByte(firstByte);
16422
+ result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16423
+ const immediateLength = this.nibblesDecoder.getHighNibbleAsLength();
16424
+ const immediateStartIndex = pc + 2;
16425
+ const immediateEndIndex = immediateStartIndex + immediateLength;
16426
+ result.immediateDecoder.setBytes(this.code.subarray(immediateStartIndex, immediateEndIndex));
16427
+ const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - immediateLength));
16428
+ const offsetStartIndex = pc + 2 + immediateLength;
16429
+ const offsetEndIndex = offsetStartIndex + offsetLength;
16430
+ this.offsetDecoder.setBytes(this.code.subarray(offsetStartIndex, offsetEndIndex));
16431
+ result.nextPc = pc + this.offsetDecoder.getSigned();
16432
+ break;
16433
+ }
16434
+ case ArgumentType.TWO_REGISTERS_ONE_OFFSET: {
16435
+ const firstByte = this.code[pc + 1];
16436
+ this.nibblesDecoder.setByte(firstByte);
16437
+ result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16438
+ result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
16439
+ const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
16440
+ const offsetStartIndex = pc + 2;
16441
+ const offsetEndIndex = offsetStartIndex + offsetLength;
16442
+ this.offsetDecoder.setBytes(this.code.subarray(offsetStartIndex, offsetEndIndex));
16443
+ result.nextPc = pc + this.offsetDecoder.getSigned();
16444
+ break;
16445
+ }
16446
+ case ArgumentType.TWO_REGISTERS: {
16447
+ const firstByte = this.code[pc + 1];
16448
+ this.nibblesDecoder.setByte(firstByte);
16449
+ result.firstRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
16450
+ result.secondRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16451
+ break;
16452
+ }
16453
+ case ArgumentType.ONE_OFFSET: {
16454
+ const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, nextInstructionDistance - 1);
16455
+ const offsetStartIndex = pc + 1;
16456
+ const offsetEndIndex = offsetStartIndex + offsetLength;
16457
+ const offsetBytes = this.code.subarray(offsetStartIndex, offsetEndIndex);
16458
+ this.offsetDecoder.setBytes(offsetBytes);
16459
+ const offsetValue = this.offsetDecoder.getSigned();
16460
+ result.nextPc = pc + offsetValue;
16461
+ break;
16462
+ }
16463
+ case ArgumentType.ONE_REGISTER_ONE_IMMEDIATE: {
16464
+ const firstByte = this.code[pc + 1];
16465
+ this.nibblesDecoder.setByte(firstByte);
16466
+ result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16467
+ const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
16468
+ const immediateStartIndex = pc + 2;
16469
+ const immediateEndIndex = immediateStartIndex + immediateLength;
16470
+ const immediateBytes = this.code.subarray(immediateStartIndex, immediateEndIndex);
16471
+ result.immediateDecoder.setBytes(immediateBytes);
16472
+ break;
16473
+ }
16474
+ case ArgumentType.TWO_IMMEDIATES: {
16475
+ const firstByte = this.code[pc + 1];
16476
+ this.nibblesDecoder.setByte(firstByte);
16477
+ const firstImmediateLength = this.nibblesDecoder.getLowNibbleAsLength();
16478
+ const firstImmediateStartIndex = pc + 2;
16479
+ const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
16480
+ const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
16481
+ result.firstImmediateDecoder.setBytes(firstImmediateBytes);
16482
+ const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - firstImmediateLength));
16483
+ const secondImmediateStartIndex = firstImmediateEndIndex;
16484
+ const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
16485
+ const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
16486
+ result.secondImmediateDecoder.setBytes(secondImmediateBytes);
16487
+ break;
16488
+ }
16489
+ case ArgumentType.ONE_REGISTER_TWO_IMMEDIATES: {
16490
+ const firstByte = this.code[pc + 1];
16491
+ this.nibblesDecoder.setByte(firstByte);
16492
+ result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16493
+ const firstImmediateLength = this.nibblesDecoder.getHighNibbleAsLength();
16494
+ const firstImmediateStartIndex = pc + 2;
16495
+ const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
16496
+ const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
16497
+ result.firstImmediateDecoder.setBytes(firstImmediateBytes);
16498
+ const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - firstImmediateLength));
16499
+ const secondImmediateStartIndex = firstImmediateEndIndex;
16500
+ const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
16501
+ const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
16502
+ result.secondImmediateDecoder.setBytes(secondImmediateBytes);
16503
+ break;
16504
+ }
16505
+ case ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES: {
16506
+ const firstByte = this.code[pc + 1];
16507
+ this.nibblesDecoder.setByte(firstByte);
16508
+ result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16509
+ result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
16510
+ const secondByte = this.code[pc + 2];
16511
+ this.nibblesDecoder.setByte(secondByte);
16512
+ const firstImmediateLength = this.nibblesDecoder.getLowNibbleAsLength();
16513
+ const firstImmediateStartIndex = pc + 3;
16514
+ const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
16515
+ const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
16516
+ result.firstImmediateDecoder.setBytes(firstImmediateBytes);
16517
+ const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 3 - firstImmediateLength));
16518
+ const secondImmediateStartIndex = firstImmediateEndIndex;
16519
+ const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
16520
+ const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
16521
+ result.secondImmediateDecoder.setBytes(secondImmediateBytes);
16522
+ break;
16523
+ }
16524
+ case ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE: {
16525
+ const firstByte = this.code[pc + 1];
16526
+ this.nibblesDecoder.setByte(firstByte);
16527
+ result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
16528
+ const immediateStartIndex = pc + 2;
16529
+ const immediateEndIndex = immediateStartIndex + 8;
16530
+ const immediateBytes = this.code.subarray(immediateStartIndex, immediateEndIndex);
16531
+ result.immediateDecoder.setBytes(immediateBytes);
16532
+ break;
16533
+ }
16472
16534
  }
16473
- return (this.isInRange(other.start) ||
16474
- this.isInRange(other.lastIndex) ||
16475
- other.isInRange(this.start) ||
16476
- other.isInRange(this.lastIndex));
16477
16535
  }
16478
16536
  }
16479
- /**
16480
- * The first 16 pages of memory are reserved.
16481
- *
16482
- * https://graypaper.fluffylabs.dev/#/cc517d7/24d00024d000?v=0.6.5
16483
- *
16484
- * it should be in `memory-consts` but it cannot be there because of circular dependency
16485
- */
16486
- const memory_range_RESERVED_MEMORY_RANGE = memory_range_MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), memory_consts_RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
16487
16537
 
16488
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
16538
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/args-decoding-results.ts
16489
16539
 
16490
16540
 
16491
16541
 
16492
- /**
16493
- * A half-open range of memory pages. Similarly to [`MemoryRange`], can be empty
16494
- * or wrapped around the memory.
16495
- */
16496
- class page_range_PageRange {
16497
- start;
16498
- length;
16499
- /**
16500
- * Exclusive end of the page range.
16501
- *
16502
- * NOTE: it may be smaller than `start` in case the range is wrapped.
16503
- */
16504
- end;
16505
- constructor(start, length) {
16506
- this.start = start;
16507
- this.length = length;
16508
- this.end = page_utils_tryAsPageNumber((this.start + this.length) % MAX_NUMBER_OF_PAGES);
16509
- }
16510
- /**
16511
- * Creates range of pages that includes all indices in a given memory range.
16512
- *
16513
- * Example: For memory range `[PAGE_SIZE, MEMORY_SIZE - PAGE_SIZE)`
16514
- * we will get `[1, MAX_NUMBER_OF_PAGES - 1)` page range.
16515
- */
16516
- static fromMemoryRange(range) {
16517
- const startPage = memory_utils_getPageNumber(range.start);
16518
- if (range.isEmpty()) {
16519
- return new page_range_PageRange(startPage, 0);
16520
- }
16521
- // lastIndex is not null because we just ensured that the range is not empty
16522
- const pageWithLastIndex = memory_utils_getPageNumber(range.lastIndex ?? range.end);
16523
- const endPage = getNextPageNumber(pageWithLastIndex);
16524
- if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
16525
- // full range
16526
- return new page_range_PageRange(startPage, MAX_NUMBER_OF_PAGES);
16527
- }
16528
- const length = startPage < endPage ? endPage - startPage : MAX_NUMBER_OF_PAGES - startPage + endPage;
16529
- return page_range_PageRange.fromStartAndLength(startPage, length);
16530
- }
16531
- /** Creates a page range from given starting point and length */
16532
- static fromStartAndLength(start, length) {
16533
- if (!Number.isInteger(length) || length < 0 || length > MAX_NUMBER_OF_PAGES) {
16534
- throw new TypeError(`length must be a non-negative integer and less than ${MAX_NUMBER_OF_PAGES}, got ${length}`);
16535
- }
16536
- return new page_range_PageRange(start, length);
16537
- }
16538
- /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
16539
- isWrapped() {
16540
- return this.start >= this.end && !this.isEmpty();
16541
- }
16542
- /** Checks if given page number is within the range */
16543
- isInRange(page) {
16544
- if (this.isWrapped()) {
16545
- return page >= this.start || page < this.end;
16546
- }
16547
- return page >= this.start && page < this.end;
16548
- }
16549
- /** Checks if a range is empty (`length === 0`) */
16550
- isEmpty() {
16551
- return this.length === 0;
16552
- }
16553
- *[Symbol.iterator]() {
16554
- if (this.isEmpty()) {
16555
- return;
16556
- }
16557
- const end = this.end;
16558
- let i = this.start;
16559
- do {
16560
- yield i;
16561
- i = getNextPageNumber(i);
16562
- } while (i !== end);
16563
- }
16564
- }
16565
-
16566
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/memory-page.ts
16567
-
16568
- class MemoryPage {
16569
- start;
16570
- constructor(pageNumber) {
16571
- this.start = getStartPageIndexFromPageNumber(pageNumber);
16572
- }
16573
- }
16574
-
16575
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/readable-page.ts
16542
+ const ARGUMENT_TYPE_LENGTH = Object.keys(argument_type_ArgumentType).length / 2;
16543
+ const args_decoding_results_createResults = () => {
16544
+ const results = new Array(ARGUMENT_TYPE_LENGTH);
16545
+ results[ArgumentType.NO_ARGUMENTS] = {
16546
+ type: ArgumentType.NO_ARGUMENTS,
16547
+ noOfBytesToSkip: 1,
16548
+ };
16549
+ results[ArgumentType.ONE_IMMEDIATE] = {
16550
+ type: ArgumentType.ONE_IMMEDIATE,
16551
+ noOfBytesToSkip: 1,
16552
+ immediateDecoder: new ImmediateDecoder(),
16553
+ };
16554
+ results[ArgumentType.TWO_REGISTERS] = {
16555
+ type: ArgumentType.TWO_REGISTERS,
16556
+ noOfBytesToSkip: 1,
16557
+ firstRegisterIndex: 0,
16558
+ secondRegisterIndex: 0,
16559
+ };
16560
+ results[ArgumentType.THREE_REGISTERS] = {
16561
+ type: ArgumentType.THREE_REGISTERS,
16562
+ noOfBytesToSkip: 1,
16563
+ firstRegisterIndex: 0,
16564
+ secondRegisterIndex: 0,
16565
+ thirdRegisterIndex: 0,
16566
+ };
16567
+ results[ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET] = {
16568
+ type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET,
16569
+ noOfBytesToSkip: 1,
16570
+ registerIndex: 0,
16571
+ immediateDecoder: new ImmediateDecoder(),
16572
+ nextPc: 0,
16573
+ };
16574
+ results[ArgumentType.TWO_REGISTERS_ONE_OFFSET] = {
16575
+ type: ArgumentType.TWO_REGISTERS_ONE_OFFSET,
16576
+ noOfBytesToSkip: 1,
16577
+ firstRegisterIndex: 0,
16578
+ secondRegisterIndex: 0,
16579
+ nextPc: 0,
16580
+ };
16581
+ results[ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE] = {
16582
+ type: ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE,
16583
+ noOfBytesToSkip: 1,
16584
+ firstRegisterIndex: 0,
16585
+ secondRegisterIndex: 0,
16586
+ immediateDecoder: new ImmediateDecoder(),
16587
+ };
16588
+ results[ArgumentType.ONE_REGISTER_ONE_IMMEDIATE] = {
16589
+ type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE,
16590
+ noOfBytesToSkip: 1,
16591
+ registerIndex: 0,
16592
+ immediateDecoder: new ImmediateDecoder(),
16593
+ };
16594
+ results[ArgumentType.ONE_REGISTER_TWO_IMMEDIATES] = {
16595
+ type: ArgumentType.ONE_REGISTER_TWO_IMMEDIATES,
16596
+ noOfBytesToSkip: 1,
16597
+ registerIndex: 0,
16598
+ firstImmediateDecoder: new ImmediateDecoder(),
16599
+ secondImmediateDecoder: new ImmediateDecoder(),
16600
+ };
16601
+ results[ArgumentType.ONE_OFFSET] = {
16602
+ type: ArgumentType.ONE_OFFSET,
16603
+ noOfBytesToSkip: 1,
16604
+ nextPc: 0,
16605
+ };
16606
+ results[ArgumentType.TWO_IMMEDIATES] = {
16607
+ type: ArgumentType.TWO_IMMEDIATES,
16608
+ noOfBytesToSkip: 1,
16609
+ firstImmediateDecoder: new ImmediateDecoder(),
16610
+ secondImmediateDecoder: new ImmediateDecoder(),
16611
+ };
16612
+ results[ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES] = {
16613
+ type: ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES,
16614
+ noOfBytesToSkip: 1,
16615
+ firstImmediateDecoder: new ImmediateDecoder(),
16616
+ secondImmediateDecoder: new ImmediateDecoder(),
16617
+ firstRegisterIndex: 0,
16618
+ secondRegisterIndex: 0,
16619
+ };
16620
+ results[ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE] = {
16621
+ type: ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE,
16622
+ noOfBytesToSkip: 9,
16623
+ registerIndex: 0,
16624
+ immediateDecoder: new ExtendedWitdthImmediateDecoder(),
16625
+ };
16626
+ return results;
16627
+ };
16576
16628
 
16629
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction.ts
16630
+ var instruction_Instruction;
16631
+ (function (Instruction) {
16632
+ Instruction[Instruction["TRAP"] = 0] = "TRAP";
16633
+ Instruction[Instruction["FALLTHROUGH"] = 1] = "FALLTHROUGH";
16634
+ Instruction[Instruction["ECALLI"] = 10] = "ECALLI";
16635
+ Instruction[Instruction["LOAD_IMM_64"] = 20] = "LOAD_IMM_64";
16636
+ Instruction[Instruction["STORE_IMM_U8"] = 30] = "STORE_IMM_U8";
16637
+ Instruction[Instruction["STORE_IMM_U16"] = 31] = "STORE_IMM_U16";
16638
+ Instruction[Instruction["STORE_IMM_U32"] = 32] = "STORE_IMM_U32";
16639
+ Instruction[Instruction["STORE_IMM_U64"] = 33] = "STORE_IMM_U64";
16640
+ Instruction[Instruction["JUMP"] = 40] = "JUMP";
16641
+ Instruction[Instruction["JUMP_IND"] = 50] = "JUMP_IND";
16642
+ Instruction[Instruction["LOAD_IMM"] = 51] = "LOAD_IMM";
16643
+ Instruction[Instruction["LOAD_U8"] = 52] = "LOAD_U8";
16644
+ Instruction[Instruction["LOAD_I8"] = 53] = "LOAD_I8";
16645
+ Instruction[Instruction["LOAD_U16"] = 54] = "LOAD_U16";
16646
+ Instruction[Instruction["LOAD_I16"] = 55] = "LOAD_I16";
16647
+ Instruction[Instruction["LOAD_U32"] = 56] = "LOAD_U32";
16648
+ Instruction[Instruction["LOAD_I32"] = 57] = "LOAD_I32";
16649
+ Instruction[Instruction["LOAD_U64"] = 58] = "LOAD_U64";
16650
+ Instruction[Instruction["STORE_U8"] = 59] = "STORE_U8";
16651
+ Instruction[Instruction["STORE_U16"] = 60] = "STORE_U16";
16652
+ Instruction[Instruction["STORE_U32"] = 61] = "STORE_U32";
16653
+ Instruction[Instruction["STORE_U64"] = 62] = "STORE_U64";
16654
+ Instruction[Instruction["STORE_IMM_IND_U8"] = 70] = "STORE_IMM_IND_U8";
16655
+ Instruction[Instruction["STORE_IMM_IND_U16"] = 71] = "STORE_IMM_IND_U16";
16656
+ Instruction[Instruction["STORE_IMM_IND_U32"] = 72] = "STORE_IMM_IND_U32";
16657
+ Instruction[Instruction["STORE_IMM_IND_U64"] = 73] = "STORE_IMM_IND_U64";
16658
+ Instruction[Instruction["LOAD_IMM_JUMP"] = 80] = "LOAD_IMM_JUMP";
16659
+ Instruction[Instruction["BRANCH_EQ_IMM"] = 81] = "BRANCH_EQ_IMM";
16660
+ Instruction[Instruction["BRANCH_NE_IMM"] = 82] = "BRANCH_NE_IMM";
16661
+ Instruction[Instruction["BRANCH_LT_U_IMM"] = 83] = "BRANCH_LT_U_IMM";
16662
+ Instruction[Instruction["BRANCH_LE_U_IMM"] = 84] = "BRANCH_LE_U_IMM";
16663
+ Instruction[Instruction["BRANCH_GE_U_IMM"] = 85] = "BRANCH_GE_U_IMM";
16664
+ Instruction[Instruction["BRANCH_GT_U_IMM"] = 86] = "BRANCH_GT_U_IMM";
16665
+ Instruction[Instruction["BRANCH_LT_S_IMM"] = 87] = "BRANCH_LT_S_IMM";
16666
+ Instruction[Instruction["BRANCH_LE_S_IMM"] = 88] = "BRANCH_LE_S_IMM";
16667
+ Instruction[Instruction["BRANCH_GE_S_IMM"] = 89] = "BRANCH_GE_S_IMM";
16668
+ Instruction[Instruction["BRANCH_GT_S_IMM"] = 90] = "BRANCH_GT_S_IMM";
16669
+ Instruction[Instruction["MOVE_REG"] = 100] = "MOVE_REG";
16670
+ Instruction[Instruction["SBRK"] = 101] = "SBRK";
16671
+ Instruction[Instruction["COUNT_SET_BITS_64"] = 102] = "COUNT_SET_BITS_64";
16672
+ Instruction[Instruction["COUNT_SET_BITS_32"] = 103] = "COUNT_SET_BITS_32";
16673
+ Instruction[Instruction["LEADING_ZERO_BITS_64"] = 104] = "LEADING_ZERO_BITS_64";
16674
+ Instruction[Instruction["LEADING_ZERO_BITS_32"] = 105] = "LEADING_ZERO_BITS_32";
16675
+ Instruction[Instruction["TRAILING_ZERO_BITS_64"] = 106] = "TRAILING_ZERO_BITS_64";
16676
+ Instruction[Instruction["TRAILING_ZERO_BITS_32"] = 107] = "TRAILING_ZERO_BITS_32";
16677
+ Instruction[Instruction["SIGN_EXTEND_8"] = 108] = "SIGN_EXTEND_8";
16678
+ Instruction[Instruction["SIGN_EXTEND_16"] = 109] = "SIGN_EXTEND_16";
16679
+ Instruction[Instruction["ZERO_EXTEND_16"] = 110] = "ZERO_EXTEND_16";
16680
+ Instruction[Instruction["REVERSE_BYTES"] = 111] = "REVERSE_BYTES";
16681
+ Instruction[Instruction["STORE_IND_U8"] = 120] = "STORE_IND_U8";
16682
+ Instruction[Instruction["STORE_IND_U16"] = 121] = "STORE_IND_U16";
16683
+ Instruction[Instruction["STORE_IND_U32"] = 122] = "STORE_IND_U32";
16684
+ Instruction[Instruction["STORE_IND_U64"] = 123] = "STORE_IND_U64";
16685
+ Instruction[Instruction["LOAD_IND_U8"] = 124] = "LOAD_IND_U8";
16686
+ Instruction[Instruction["LOAD_IND_I8"] = 125] = "LOAD_IND_I8";
16687
+ Instruction[Instruction["LOAD_IND_U16"] = 126] = "LOAD_IND_U16";
16688
+ Instruction[Instruction["LOAD_IND_I16"] = 127] = "LOAD_IND_I16";
16689
+ Instruction[Instruction["LOAD_IND_U32"] = 128] = "LOAD_IND_U32";
16690
+ Instruction[Instruction["LOAD_IND_I32"] = 129] = "LOAD_IND_I32";
16691
+ Instruction[Instruction["LOAD_IND_U64"] = 130] = "LOAD_IND_U64";
16692
+ Instruction[Instruction["ADD_IMM_32"] = 131] = "ADD_IMM_32";
16693
+ Instruction[Instruction["AND_IMM"] = 132] = "AND_IMM";
16694
+ Instruction[Instruction["XOR_IMM"] = 133] = "XOR_IMM";
16695
+ Instruction[Instruction["OR_IMM"] = 134] = "OR_IMM";
16696
+ Instruction[Instruction["MUL_IMM_32"] = 135] = "MUL_IMM_32";
16697
+ Instruction[Instruction["SET_LT_U_IMM"] = 136] = "SET_LT_U_IMM";
16698
+ Instruction[Instruction["SET_LT_S_IMM"] = 137] = "SET_LT_S_IMM";
16699
+ Instruction[Instruction["SHLO_L_IMM_32"] = 138] = "SHLO_L_IMM_32";
16700
+ Instruction[Instruction["SHLO_R_IMM_32"] = 139] = "SHLO_R_IMM_32";
16701
+ Instruction[Instruction["SHAR_R_IMM_32"] = 140] = "SHAR_R_IMM_32";
16702
+ Instruction[Instruction["NEG_ADD_IMM_32"] = 141] = "NEG_ADD_IMM_32";
16703
+ Instruction[Instruction["SET_GT_U_IMM"] = 142] = "SET_GT_U_IMM";
16704
+ Instruction[Instruction["SET_GT_S_IMM"] = 143] = "SET_GT_S_IMM";
16705
+ Instruction[Instruction["SHLO_L_IMM_ALT_32"] = 144] = "SHLO_L_IMM_ALT_32";
16706
+ Instruction[Instruction["SHLO_R_IMM_ALT_32"] = 145] = "SHLO_R_IMM_ALT_32";
16707
+ Instruction[Instruction["SHAR_R_IMM_ALT_32"] = 146] = "SHAR_R_IMM_ALT_32";
16708
+ Instruction[Instruction["CMOV_IZ_IMM"] = 147] = "CMOV_IZ_IMM";
16709
+ Instruction[Instruction["CMOV_NZ_IMM"] = 148] = "CMOV_NZ_IMM";
16710
+ Instruction[Instruction["ADD_IMM_64"] = 149] = "ADD_IMM_64";
16711
+ Instruction[Instruction["MUL_IMM_64"] = 150] = "MUL_IMM_64";
16712
+ Instruction[Instruction["SHLO_L_IMM_64"] = 151] = "SHLO_L_IMM_64";
16713
+ Instruction[Instruction["SHLO_R_IMM_64"] = 152] = "SHLO_R_IMM_64";
16714
+ Instruction[Instruction["SHAR_R_IMM_64"] = 153] = "SHAR_R_IMM_64";
16715
+ Instruction[Instruction["NEG_ADD_IMM_64"] = 154] = "NEG_ADD_IMM_64";
16716
+ Instruction[Instruction["SHLO_L_IMM_ALT_64"] = 155] = "SHLO_L_IMM_ALT_64";
16717
+ Instruction[Instruction["SHLO_R_IMM_ALT_64"] = 156] = "SHLO_R_IMM_ALT_64";
16718
+ Instruction[Instruction["SHAR_R_IMM_ALT_64"] = 157] = "SHAR_R_IMM_ALT_64";
16719
+ Instruction[Instruction["ROT_R_64_IMM"] = 158] = "ROT_R_64_IMM";
16720
+ Instruction[Instruction["ROT_R_64_IMM_ALT"] = 159] = "ROT_R_64_IMM_ALT";
16721
+ Instruction[Instruction["ROT_R_32_IMM"] = 160] = "ROT_R_32_IMM";
16722
+ Instruction[Instruction["ROT_R_32_IMM_ALT"] = 161] = "ROT_R_32_IMM_ALT";
16723
+ Instruction[Instruction["BRANCH_EQ"] = 170] = "BRANCH_EQ";
16724
+ Instruction[Instruction["BRANCH_NE"] = 171] = "BRANCH_NE";
16725
+ Instruction[Instruction["BRANCH_LT_U"] = 172] = "BRANCH_LT_U";
16726
+ Instruction[Instruction["BRANCH_LT_S"] = 173] = "BRANCH_LT_S";
16727
+ Instruction[Instruction["BRANCH_GE_U"] = 174] = "BRANCH_GE_U";
16728
+ Instruction[Instruction["BRANCH_GE_S"] = 175] = "BRANCH_GE_S";
16729
+ Instruction[Instruction["LOAD_IMM_JUMP_IND"] = 180] = "LOAD_IMM_JUMP_IND";
16730
+ Instruction[Instruction["ADD_32"] = 190] = "ADD_32";
16731
+ Instruction[Instruction["SUB_32"] = 191] = "SUB_32";
16732
+ Instruction[Instruction["MUL_32"] = 192] = "MUL_32";
16733
+ Instruction[Instruction["DIV_U_32"] = 193] = "DIV_U_32";
16734
+ Instruction[Instruction["DIV_S_32"] = 194] = "DIV_S_32";
16735
+ Instruction[Instruction["REM_U_32"] = 195] = "REM_U_32";
16736
+ Instruction[Instruction["REM_S_32"] = 196] = "REM_S_32";
16737
+ Instruction[Instruction["SHLO_L_32"] = 197] = "SHLO_L_32";
16738
+ Instruction[Instruction["SHLO_R_32"] = 198] = "SHLO_R_32";
16739
+ Instruction[Instruction["SHAR_R_32"] = 199] = "SHAR_R_32";
16740
+ Instruction[Instruction["ADD_64"] = 200] = "ADD_64";
16741
+ Instruction[Instruction["SUB_64"] = 201] = "SUB_64";
16742
+ Instruction[Instruction["MUL_64"] = 202] = "MUL_64";
16743
+ Instruction[Instruction["DIV_U_64"] = 203] = "DIV_U_64";
16744
+ Instruction[Instruction["DIV_S_64"] = 204] = "DIV_S_64";
16745
+ Instruction[Instruction["REM_U_64"] = 205] = "REM_U_64";
16746
+ Instruction[Instruction["REM_S_64"] = 206] = "REM_S_64";
16747
+ Instruction[Instruction["SHLO_L_64"] = 207] = "SHLO_L_64";
16748
+ Instruction[Instruction["SHLO_R_64"] = 208] = "SHLO_R_64";
16749
+ Instruction[Instruction["SHAR_R_64"] = 209] = "SHAR_R_64";
16750
+ Instruction[Instruction["AND"] = 210] = "AND";
16751
+ Instruction[Instruction["XOR"] = 211] = "XOR";
16752
+ Instruction[Instruction["OR"] = 212] = "OR";
16753
+ Instruction[Instruction["MUL_UPPER_S_S"] = 213] = "MUL_UPPER_S_S";
16754
+ Instruction[Instruction["MUL_UPPER_U_U"] = 214] = "MUL_UPPER_U_U";
16755
+ Instruction[Instruction["MUL_UPPER_S_U"] = 215] = "MUL_UPPER_S_U";
16756
+ Instruction[Instruction["SET_LT_U"] = 216] = "SET_LT_U";
16757
+ Instruction[Instruction["SET_LT_S"] = 217] = "SET_LT_S";
16758
+ Instruction[Instruction["CMOV_IZ"] = 218] = "CMOV_IZ";
16759
+ Instruction[Instruction["CMOV_NZ"] = 219] = "CMOV_NZ";
16760
+ Instruction[Instruction["ROT_L_64"] = 220] = "ROT_L_64";
16761
+ Instruction[Instruction["ROT_L_32"] = 221] = "ROT_L_32";
16762
+ Instruction[Instruction["ROT_R_64"] = 222] = "ROT_R_64";
16763
+ Instruction[Instruction["ROT_R_32"] = 223] = "ROT_R_32";
16764
+ Instruction[Instruction["AND_INV"] = 224] = "AND_INV";
16765
+ Instruction[Instruction["OR_INV"] = 225] = "OR_INV";
16766
+ Instruction[Instruction["XNOR"] = 226] = "XNOR";
16767
+ Instruction[Instruction["MAX"] = 227] = "MAX";
16768
+ Instruction[Instruction["MAX_U"] = 228] = "MAX_U";
16769
+ Instruction[Instruction["MIN"] = 229] = "MIN";
16770
+ Instruction[Instruction["MIN_U"] = 230] = "MIN_U";
16771
+ })(instruction_Instruction || (instruction_Instruction = {}));
16772
+ const HIGHEST_INSTRUCTION_NUMBER = instruction_Instruction.MIN_U;
16577
16773
 
16774
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/instruction-argument-type-map.ts
16578
16775
 
16579
16776
 
16580
- class readable_page_ReadablePage extends MemoryPage {
16581
- data;
16582
- constructor(pageNumber, data) {
16583
- super(pageNumber);
16584
- this.data = data;
16585
- }
16586
- loadInto(result, startIndex, length) {
16587
- const endIndex = startIndex + length;
16588
- if (endIndex > memory_consts_PAGE_SIZE) {
16589
- return result_Result.error(errors_PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
16590
- }
16591
- const bytes = this.data.subarray(startIndex, endIndex);
16592
- // we zero the bytes, since data might not yet be initialized at `endIndex`.
16593
- result.fill(0, bytes.length, length);
16594
- result.set(bytes);
16595
- return result_Result.ok(result_OK);
16596
- }
16597
- storeFrom(_address, _data) {
16598
- return result_Result.error(errors_PageFault.fromMemoryIndex(this.start, true), () => `Page fault: attempted to write to read-only page at ${this.start}`);
16599
- }
16600
- setData(pageIndex, data) {
16601
- this.data.set(data, pageIndex);
16602
- }
16603
- isWriteable() {
16604
- return false;
16605
- }
16606
- getPageDump() {
16607
- return this.data;
16608
- }
16609
- }
16610
-
16611
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/writeable-page.ts
16612
-
16613
-
16614
-
16615
-
16616
- class writeable_page_WriteablePage extends MemoryPage {
16617
- buffer;
16618
- view;
16619
- constructor(pageNumber, initialData) {
16620
- super(pageNumber);
16621
- const dataLength = initialData?.length ?? 0;
16622
- const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
16623
- this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
16624
- this.view = new Uint8Array(this.buffer);
16625
- if (initialData !== undefined) {
16626
- this.view.set(initialData);
16627
- }
16628
- }
16629
- loadInto(result, startIndex, length) {
16630
- const endIndex = startIndex + length;
16631
- if (endIndex > memory_consts_PAGE_SIZE) {
16632
- return result_Result.error(errors_PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
16633
- }
16634
- const bytes = this.view.subarray(startIndex, endIndex);
16635
- // we zero the bytes, since the view might not yet be initialized at `endIndex`.
16636
- result.fill(0, bytes.length, length);
16637
- result.set(bytes);
16638
- return result_Result.ok(result_OK);
16639
- }
16640
- storeFrom(startIndex, bytes) {
16641
- if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
16642
- const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
16643
- this.buffer.resize(newLength);
16644
- }
16645
- this.view.set(bytes, startIndex);
16646
- return result_Result.ok(result_OK);
16647
- }
16648
- setData(pageIndex, data) {
16649
- if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
16650
- const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
16651
- this.buffer.resize(newLength);
16652
- }
16653
- this.view.set(data, pageIndex);
16654
- }
16655
- isWriteable() {
16656
- return true;
16657
- }
16658
- getPageDump() {
16659
- return this.view;
16660
- }
16661
- }
16662
-
16663
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/index.ts
16664
-
16665
-
16666
-
16667
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory.ts
16777
+ const instruction_argument_type_map_instructionArgumentTypeMap = (() => {
16778
+ const instructionArgumentTypeMap = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
16779
+ instructionArgumentTypeMap[instruction_Instruction.TRAP] = argument_type_ArgumentType.NO_ARGUMENTS;
16780
+ instructionArgumentTypeMap[instruction_Instruction.FALLTHROUGH] = argument_type_ArgumentType.NO_ARGUMENTS;
16781
+ instructionArgumentTypeMap[instruction_Instruction.ECALLI] = argument_type_ArgumentType.ONE_IMMEDIATE;
16782
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_64] = argument_type_ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE;
16783
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U8] = argument_type_ArgumentType.TWO_IMMEDIATES;
16784
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U16] = argument_type_ArgumentType.TWO_IMMEDIATES;
16785
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U32] = argument_type_ArgumentType.TWO_IMMEDIATES;
16786
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U64] = argument_type_ArgumentType.TWO_IMMEDIATES;
16787
+ instructionArgumentTypeMap[instruction_Instruction.JUMP] = argument_type_ArgumentType.ONE_OFFSET;
16788
+ instructionArgumentTypeMap[instruction_Instruction.JUMP_IND] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16789
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16790
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_U8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16791
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_I8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16792
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_U16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16793
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_I16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16794
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_U32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16795
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_I32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16796
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_U64] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16797
+ instructionArgumentTypeMap[instruction_Instruction.STORE_U8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16798
+ instructionArgumentTypeMap[instruction_Instruction.STORE_U16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16799
+ instructionArgumentTypeMap[instruction_Instruction.STORE_U32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16800
+ instructionArgumentTypeMap[instruction_Instruction.STORE_U64] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
16801
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U8] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
16802
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U16] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
16803
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U32] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
16804
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U64] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
16805
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_JUMP] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16806
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_EQ_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16807
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_NE_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16808
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16809
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LE_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16810
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16811
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GT_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16812
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16813
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LE_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16814
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16815
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GT_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
16816
+ instructionArgumentTypeMap[instruction_Instruction.MOVE_REG] = argument_type_ArgumentType.TWO_REGISTERS;
16817
+ instructionArgumentTypeMap[instruction_Instruction.SBRK] = argument_type_ArgumentType.TWO_REGISTERS;
16818
+ instructionArgumentTypeMap[instruction_Instruction.COUNT_SET_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
16819
+ instructionArgumentTypeMap[instruction_Instruction.COUNT_SET_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
16820
+ instructionArgumentTypeMap[instruction_Instruction.LEADING_ZERO_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
16821
+ instructionArgumentTypeMap[instruction_Instruction.LEADING_ZERO_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
16822
+ instructionArgumentTypeMap[instruction_Instruction.TRAILING_ZERO_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
16823
+ instructionArgumentTypeMap[instruction_Instruction.TRAILING_ZERO_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
16824
+ instructionArgumentTypeMap[instruction_Instruction.SIGN_EXTEND_8] = argument_type_ArgumentType.TWO_REGISTERS;
16825
+ instructionArgumentTypeMap[instruction_Instruction.SIGN_EXTEND_16] = argument_type_ArgumentType.TWO_REGISTERS;
16826
+ instructionArgumentTypeMap[instruction_Instruction.ZERO_EXTEND_16] = argument_type_ArgumentType.TWO_REGISTERS;
16827
+ instructionArgumentTypeMap[instruction_Instruction.REVERSE_BYTES] = argument_type_ArgumentType.TWO_REGISTERS;
16828
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16829
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16830
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16831
+ instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16832
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16833
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16834
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16835
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16836
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16837
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16838
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16839
+ instructionArgumentTypeMap[instruction_Instruction.ADD_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16840
+ instructionArgumentTypeMap[instruction_Instruction.ADD_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16841
+ instructionArgumentTypeMap[instruction_Instruction.AND_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16842
+ instructionArgumentTypeMap[instruction_Instruction.XOR_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16843
+ instructionArgumentTypeMap[instruction_Instruction.OR_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16844
+ instructionArgumentTypeMap[instruction_Instruction.MUL_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16845
+ instructionArgumentTypeMap[instruction_Instruction.MUL_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16846
+ instructionArgumentTypeMap[instruction_Instruction.SET_LT_U_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16847
+ instructionArgumentTypeMap[instruction_Instruction.SET_LT_S_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16848
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16849
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16850
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16851
+ instructionArgumentTypeMap[instruction_Instruction.NEG_ADD_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16852
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16853
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16854
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16855
+ instructionArgumentTypeMap[instruction_Instruction.NEG_ADD_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16856
+ instructionArgumentTypeMap[instruction_Instruction.SET_GT_U_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16857
+ instructionArgumentTypeMap[instruction_Instruction.SET_GT_S_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16858
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16859
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16860
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16861
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16862
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16863
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16864
+ instructionArgumentTypeMap[instruction_Instruction.CMOV_IZ_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16865
+ instructionArgumentTypeMap[instruction_Instruction.CMOV_NZ_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16866
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_64_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16867
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_64_IMM_ALT] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16868
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_32_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16869
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_32_IMM_ALT] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
16870
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_EQ] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16871
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_NE] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16872
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_U] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16873
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_S] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16874
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_U] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16875
+ instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_S] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
16876
+ instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_JUMP_IND] = argument_type_ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES;
16877
+ instructionArgumentTypeMap[instruction_Instruction.ADD_32] = argument_type_ArgumentType.THREE_REGISTERS;
16878
+ instructionArgumentTypeMap[instruction_Instruction.ADD_64] = argument_type_ArgumentType.THREE_REGISTERS;
16879
+ instructionArgumentTypeMap[instruction_Instruction.SUB_32] = argument_type_ArgumentType.THREE_REGISTERS;
16880
+ instructionArgumentTypeMap[instruction_Instruction.SUB_64] = argument_type_ArgumentType.THREE_REGISTERS;
16881
+ instructionArgumentTypeMap[instruction_Instruction.AND] = argument_type_ArgumentType.THREE_REGISTERS;
16882
+ instructionArgumentTypeMap[instruction_Instruction.XOR] = argument_type_ArgumentType.THREE_REGISTERS;
16883
+ instructionArgumentTypeMap[instruction_Instruction.OR] = argument_type_ArgumentType.THREE_REGISTERS;
16884
+ instructionArgumentTypeMap[instruction_Instruction.MUL_32] = argument_type_ArgumentType.THREE_REGISTERS;
16885
+ instructionArgumentTypeMap[instruction_Instruction.MUL_64] = argument_type_ArgumentType.THREE_REGISTERS;
16886
+ instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_S_S] = argument_type_ArgumentType.THREE_REGISTERS;
16887
+ instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_U_U] = argument_type_ArgumentType.THREE_REGISTERS;
16888
+ instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_S_U] = argument_type_ArgumentType.THREE_REGISTERS;
16889
+ instructionArgumentTypeMap[instruction_Instruction.DIV_U_32] = argument_type_ArgumentType.THREE_REGISTERS;
16890
+ instructionArgumentTypeMap[instruction_Instruction.DIV_S_32] = argument_type_ArgumentType.THREE_REGISTERS;
16891
+ instructionArgumentTypeMap[instruction_Instruction.REM_U_32] = argument_type_ArgumentType.THREE_REGISTERS;
16892
+ instructionArgumentTypeMap[instruction_Instruction.REM_S_32] = argument_type_ArgumentType.THREE_REGISTERS;
16893
+ instructionArgumentTypeMap[instruction_Instruction.DIV_U_64] = argument_type_ArgumentType.THREE_REGISTERS;
16894
+ instructionArgumentTypeMap[instruction_Instruction.DIV_S_64] = argument_type_ArgumentType.THREE_REGISTERS;
16895
+ instructionArgumentTypeMap[instruction_Instruction.REM_U_64] = argument_type_ArgumentType.THREE_REGISTERS;
16896
+ instructionArgumentTypeMap[instruction_Instruction.REM_S_64] = argument_type_ArgumentType.THREE_REGISTERS;
16897
+ instructionArgumentTypeMap[instruction_Instruction.SET_LT_U] = argument_type_ArgumentType.THREE_REGISTERS;
16898
+ instructionArgumentTypeMap[instruction_Instruction.SET_LT_S] = argument_type_ArgumentType.THREE_REGISTERS;
16899
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_32] = argument_type_ArgumentType.THREE_REGISTERS;
16900
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
16901
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
16902
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_L_64] = argument_type_ArgumentType.THREE_REGISTERS;
16903
+ instructionArgumentTypeMap[instruction_Instruction.SHLO_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
16904
+ instructionArgumentTypeMap[instruction_Instruction.SHAR_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
16905
+ instructionArgumentTypeMap[instruction_Instruction.CMOV_IZ] = argument_type_ArgumentType.THREE_REGISTERS;
16906
+ instructionArgumentTypeMap[instruction_Instruction.CMOV_NZ] = argument_type_ArgumentType.THREE_REGISTERS;
16907
+ instructionArgumentTypeMap[instruction_Instruction.ROT_L_64] = argument_type_ArgumentType.THREE_REGISTERS;
16908
+ instructionArgumentTypeMap[instruction_Instruction.ROT_L_32] = argument_type_ArgumentType.THREE_REGISTERS;
16909
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
16910
+ instructionArgumentTypeMap[instruction_Instruction.ROT_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
16911
+ instructionArgumentTypeMap[instruction_Instruction.AND_INV] = argument_type_ArgumentType.THREE_REGISTERS;
16912
+ instructionArgumentTypeMap[instruction_Instruction.OR_INV] = argument_type_ArgumentType.THREE_REGISTERS;
16913
+ instructionArgumentTypeMap[instruction_Instruction.XNOR] = argument_type_ArgumentType.THREE_REGISTERS;
16914
+ instructionArgumentTypeMap[instruction_Instruction.MAX] = argument_type_ArgumentType.THREE_REGISTERS;
16915
+ instructionArgumentTypeMap[instruction_Instruction.MAX_U] = argument_type_ArgumentType.THREE_REGISTERS;
16916
+ instructionArgumentTypeMap[instruction_Instruction.MIN] = argument_type_ArgumentType.THREE_REGISTERS;
16917
+ instructionArgumentTypeMap[instruction_Instruction.MIN_U] = argument_type_ArgumentType.THREE_REGISTERS;
16918
+ return instructionArgumentTypeMap;
16919
+ })();
16668
16920
 
16921
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/index.ts
16669
16922
 
16670
16923
 
16671
16924
 
@@ -16674,1380 +16927,993 @@ class writeable_page_WriteablePage extends MemoryPage {
16674
16927
 
16675
16928
 
16676
16929
 
16930
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/is-termination-instruction.ts
16677
16931
 
16932
+ const is_termination_instruction_terminationInstructions = (() => {
16933
+ const terminationInstructions = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
16934
+ terminationInstructions.fill(false);
16935
+ terminationInstructions[instruction_Instruction.TRAP] = true;
16936
+ terminationInstructions[instruction_Instruction.FALLTHROUGH] = true;
16937
+ terminationInstructions[instruction_Instruction.JUMP] = true;
16938
+ terminationInstructions[instruction_Instruction.JUMP_IND] = true;
16939
+ terminationInstructions[instruction_Instruction.LOAD_IMM_JUMP] = true;
16940
+ terminationInstructions[instruction_Instruction.LOAD_IMM_JUMP_IND] = true;
16941
+ terminationInstructions[instruction_Instruction.BRANCH_EQ] = true;
16942
+ terminationInstructions[instruction_Instruction.BRANCH_NE] = true;
16943
+ terminationInstructions[instruction_Instruction.BRANCH_GE_U] = true;
16944
+ terminationInstructions[instruction_Instruction.BRANCH_GE_S] = true;
16945
+ terminationInstructions[instruction_Instruction.BRANCH_LT_U] = true;
16946
+ terminationInstructions[instruction_Instruction.BRANCH_LT_S] = true;
16947
+ terminationInstructions[instruction_Instruction.BRANCH_EQ_IMM] = true;
16948
+ terminationInstructions[instruction_Instruction.BRANCH_NE_IMM] = true;
16949
+ terminationInstructions[instruction_Instruction.BRANCH_LT_U_IMM] = true;
16950
+ terminationInstructions[instruction_Instruction.BRANCH_LT_S_IMM] = true;
16951
+ terminationInstructions[instruction_Instruction.BRANCH_LE_U_IMM] = true;
16952
+ terminationInstructions[instruction_Instruction.BRANCH_LE_S_IMM] = true;
16953
+ terminationInstructions[instruction_Instruction.BRANCH_GE_U_IMM] = true;
16954
+ terminationInstructions[instruction_Instruction.BRANCH_GE_S_IMM] = true;
16955
+ terminationInstructions[instruction_Instruction.BRANCH_GT_U_IMM] = true;
16956
+ terminationInstructions[instruction_Instruction.BRANCH_GT_S_IMM] = true;
16957
+ return terminationInstructions;
16958
+ })();
16678
16959
 
16960
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/basic-blocks.ts
16679
16961
 
16680
- var AccessType;
16681
- (function (AccessType) {
16682
- AccessType[AccessType["READ"] = 0] = "READ";
16683
- AccessType[AccessType["WRITE"] = 1] = "WRITE";
16684
- })(AccessType || (AccessType = {}));
16685
- const memory_logger = Logger.new(import.meta.filename, "pvm:mem");
16686
- class memory_Memory {
16687
- sbrkIndex;
16688
- virtualSbrkIndex;
16689
- endHeapIndex;
16690
- memory;
16691
- static fromInitialMemory(initialMemoryState) {
16692
- return new memory_Memory(initialMemoryState?.sbrkIndex, initialMemoryState?.sbrkIndex, initialMemoryState?.endHeapIndex, initialMemoryState?.memory);
16693
- }
16694
- constructor(sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX), memory = new Map()) {
16695
- this.sbrkIndex = sbrkIndex;
16696
- this.virtualSbrkIndex = virtualSbrkIndex;
16697
- this.endHeapIndex = endHeapIndex;
16698
- this.memory = memory;
16699
- }
16700
- store(address, bytes) {
16701
- return this.storeFrom(tryAsMemoryIndex(address), bytes);
16702
- }
16703
- read(address, output) {
16704
- return this.loadInto(output, tryAsMemoryIndex(address));
16705
- }
16706
- reset() {
16707
- this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
16708
- this.virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
16709
- this.endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX);
16710
- this.memory = new Map(); // TODO [MaSi]: We should keep allocated pages somewhere and reuse it when it is possible
16711
- }
16712
- copyFrom(memory) {
16713
- this.sbrkIndex = memory.sbrkIndex;
16714
- this.virtualSbrkIndex = memory.virtualSbrkIndex;
16715
- this.endHeapIndex = memory.endHeapIndex;
16716
- this.memory = memory.memory;
16717
- }
16718
- storeFrom(address, bytes) {
16719
- if (bytes.length === 0) {
16720
- return Result.ok(OK);
16721
- }
16722
- memory_logger.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
16723
- const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
16724
- if (pagesResult.isError) {
16725
- return Result.error(pagesResult.error, pagesResult.details);
16726
- }
16727
- const pages = pagesResult.ok;
16728
- let currentPosition = address;
16729
- let bytesLeft = bytes.length;
16730
- for (const page of pages) {
16731
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
16732
- const bytesToWrite = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
16733
- const sourceStartIndex = currentPosition - address;
16734
- const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
16735
- page.storeFrom(pageStartIndex, source);
16736
- currentPosition += bytesToWrite;
16737
- bytesLeft -= bytesToWrite;
16738
- }
16739
- return Result.ok(OK);
16740
- }
16741
- getPages(startAddress, length, accessType) {
16742
- if (length === 0) {
16743
- return Result.ok([]);
16744
- }
16745
- const memoryRange = MemoryRange.fromStartAndLength(startAddress, length);
16746
- const pageRange = PageRange.fromMemoryRange(memoryRange);
16747
- const pages = [];
16748
- for (const pageNumber of pageRange) {
16749
- if (pageNumber < RESERVED_NUMBER_OF_PAGES) {
16750
- return Result.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to access reserved page ${pageNumber}`);
16751
- }
16752
- const page = this.memory.get(pageNumber);
16753
- if (page === undefined) {
16754
- return Result.error(PageFault.fromPageNumber(pageNumber), () => `Page fault: page ${pageNumber} not allocated`);
16755
- }
16756
- if (accessType === AccessType.WRITE && !page.isWriteable()) {
16757
- return Result.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to write to read-only page ${pageNumber}`);
16962
+ class basic_blocks_BasicBlocks {
16963
+ basicBlocks = new Set();
16964
+ reset(code, mask) {
16965
+ this.basicBlocks.clear();
16966
+ this.basicBlocks.add(0);
16967
+ const codeLength = code.length;
16968
+ const isBasicBlockTermination = (index) => mask.isInstruction(index) && terminationInstructions[code[index]];
16969
+ for (let i = 0; i < codeLength; i++) {
16970
+ if (mask.isInstruction(i) && isBasicBlockTermination(i)) {
16971
+ this.basicBlocks.add(i + 1 + mask.getNoOfBytesToNextInstruction(i + 1));
16758
16972
  }
16759
- pages.push(page);
16760
- }
16761
- return Result.ok(pages);
16762
- }
16763
- /**
16764
- * Read content of the memory at `[address, address + result.length)` and
16765
- * write the result into the `result` buffer.
16766
- *
16767
- * Returns `null` if the data was read successfully or `PageFault` otherwise.
16768
- */
16769
- loadInto(result, startAddress) {
16770
- if (result.length === 0) {
16771
- return Result.ok(OK);
16772
- }
16773
- const pagesResult = this.getPages(startAddress, result.length, AccessType.READ);
16774
- if (pagesResult.isError) {
16775
- return Result.error(pagesResult.error, pagesResult.details);
16776
- }
16777
- const pages = pagesResult.ok;
16778
- let currentPosition = startAddress;
16779
- let bytesLeft = result.length;
16780
- for (const page of pages) {
16781
- const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
16782
- const bytesToRead = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
16783
- const destinationStartIndex = currentPosition - startAddress;
16784
- const destination = result.subarray(destinationStartIndex);
16785
- page.loadInto(destination, pageStartIndex, bytesToRead);
16786
- currentPosition += bytesToRead;
16787
- bytesLeft -= bytesToRead;
16788
- }
16789
- memory_logger.insane `MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`;
16790
- return Result.ok(OK);
16791
- }
16792
- sbrk(length) {
16793
- const currentSbrkIndex = this.sbrkIndex;
16794
- const currentVirtualSbrkIndex = this.virtualSbrkIndex;
16795
- // new sbrk index is bigger than 2 ** 32 or endHeapIndex
16796
- if (MAX_MEMORY_INDEX < currentVirtualSbrkIndex + length || currentVirtualSbrkIndex + length > this.endHeapIndex) {
16797
- throw new OutOfMemory();
16798
- }
16799
- const newVirtualSbrkIndex = tryAsSbrkIndex(this.virtualSbrkIndex + length);
16800
- // no alllocation needed
16801
- if (newVirtualSbrkIndex <= currentSbrkIndex) {
16802
- this.virtualSbrkIndex = newVirtualSbrkIndex;
16803
- return currentVirtualSbrkIndex;
16804
16973
  }
16805
- // standard allocation using "Writeable" pages
16806
- const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
16807
- // TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
16808
- const firstPageNumber = getPageNumber(currentSbrkIndex);
16809
- const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / PAGE_SIZE;
16810
- const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
16811
- for (const pageNumber of rangeToAllocate) {
16812
- const page = new WriteablePage(pageNumber);
16813
- this.memory.set(pageNumber, page);
16814
- }
16815
- this.virtualSbrkIndex = newVirtualSbrkIndex;
16816
- this.sbrkIndex = newSbrkIndex;
16817
- return currentVirtualSbrkIndex;
16818
- }
16819
- getPageDump(pageNumber) {
16820
- const page = this.memory.get(pageNumber);
16821
- return page?.getPageDump() ?? null;
16822
16974
  }
16823
- getDirtyPages() {
16824
- return this.memory.keys();
16975
+ isBeginningOfBasicBlock(index) {
16976
+ return this.basicBlocks.has(index);
16825
16977
  }
16826
16978
  }
16827
16979
 
16828
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-builder.ts
16829
-
16830
-
16831
-
16832
-
16833
-
16834
-
16980
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
16835
16981
 
16836
16982
 
16983
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/assemblify.ts
16837
16984
 
16838
16985
 
16839
- class memory_builder_MemoryBuilder {
16840
- initialMemory = new Map();
16841
- isFinalized = false;
16842
- ensureNotFinalized() {
16843
- if (this.isFinalized) {
16844
- throw new FinalizedBuilderModification();
16845
- }
16846
- }
16847
- ensureNoReservedMemoryUsage(range) {
16848
- if (range.overlapsWith(RESERVED_MEMORY_RANGE)) {
16849
- throw new ReservedMemoryFault();
16850
- }
16851
- }
16852
- /**
16853
- * Create entire readable pages to handle the `[start, end)` range.
16854
- *
16855
- * Note that both `start` and `end` must be multiple of the `PAGE_SIZE`, i.e.
16856
- * they need to be the start indices of the pages.
16857
- *
16858
- * The data passed will be placed at `start`, but might be shorter than the requested range,
16859
- * prepend it with zeros if you don't wish to have it at the beginning of the page.
16860
- */
16861
- setReadablePages(start, end, data = new Uint8Array()) {
16862
- this.ensureNotFinalized();
16863
- check `${start < end} end has to be bigger than start`;
16864
- check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
16865
- check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
16866
- check `${data.length <= end - start} the initial data is longer than address range`;
16867
- const length = end - start;
16868
- const range = MemoryRange.fromStartAndLength(start, length);
16869
- this.ensureNoReservedMemoryUsage(range);
16870
- const pages = Array.from(PageRange.fromMemoryRange(range));
16871
- const noOfPages = pages.length;
16872
- for (let i = 0; i < noOfPages; i++) {
16873
- const pageNumber = pages[i];
16874
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
16875
- const page = new ReadablePage(pageNumber, dataChunk);
16876
- this.initialMemory.set(pageNumber, page);
16877
- }
16878
- return this;
16879
- }
16880
- /**
16881
- * Create entire writeable pages to handle the `[start, end)` range.
16882
- *
16883
- * Note that both `start` and `end` must be multiple of the `PAGE_SIZE`, i.e.
16884
- * they need to be the start indices of the pages.
16885
- *
16886
- * The data passed will be placed at `start`, but might be shorter than the requested range,
16887
- * prepend it with zeros if you don't wish to have it at the beginning of the page.
16888
- */
16889
- setWriteablePages(start, end, data = new Uint8Array()) {
16890
- this.ensureNotFinalized();
16891
- check `${start < end} end has to be bigger than start`;
16892
- check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
16893
- check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
16894
- check `${data.length <= end - start} the initial data is longer than address range`;
16895
- const length = end - start;
16896
- const range = MemoryRange.fromStartAndLength(start, length);
16897
- this.ensureNoReservedMemoryUsage(range);
16898
- const pages = Array.from(PageRange.fromMemoryRange(range));
16899
- const noOfPages = pages.length;
16900
- for (let i = 0; i < noOfPages; i++) {
16901
- const pageNumber = pages[i];
16902
- const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
16903
- const page = new WriteablePage(pageNumber, dataChunk);
16904
- this.initialMemory.set(pageNumber, page);
16905
- }
16906
- return this;
16907
- }
16908
- /**
16909
- * This function can be useful when page map and initial memory data are provided separatelly.
16910
- * You can use setWriteablePages/setReadablePages to create empty pages and then setData to fill them
16911
- */
16912
- setData(start, data) {
16913
- this.ensureNotFinalized();
16914
- const pageOffset = start % PAGE_SIZE;
16915
- const remainingSpaceOnPage = PAGE_SIZE - pageOffset;
16916
- check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
16917
- const length = data.length;
16918
- const range = MemoryRange.fromStartAndLength(start, length);
16919
- this.ensureNoReservedMemoryUsage(range);
16920
- const pageNumber = getPageNumber(start);
16921
- const page = this.initialMemory.get(pageNumber);
16922
- if (page === undefined) {
16923
- throw new PageNotExist();
16924
- }
16925
- const startPageIndex = tryAsPageIndex(start - page.start);
16926
- page.setData(startPageIndex, data);
16927
- return this;
16928
- }
16929
- finalize(startHeapIndex, endHeapIndex) {
16930
- check `
16931
- ${startHeapIndex <= endHeapIndex}
16932
- startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
16933
- `;
16934
- this.ensureNotFinalized();
16935
- const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
16936
- const heapPagesRange = PageRange.fromMemoryRange(heapRange);
16937
- const initializedPageNumbers = Array.from(this.initialMemory.keys());
16938
- for (const pageNumber of initializedPageNumbers) {
16939
- if (heapPagesRange.isInRange(pageNumber)) {
16940
- throw new IncorrectSbrkIndex();
16941
- }
16986
+ const instructionsWithoutArgs = [
16987
+ [instruction_Instruction.TRAP, 1],
16988
+ [instruction_Instruction.FALLTHROUGH, 1],
16989
+ ];
16990
+ const instructionsWithOneImmediate = [[instruction_Instruction.ECALLI, 1]];
16991
+ const instructionsWithOneRegisterAndOneExtendedWidthImmediate = [[instruction_Instruction.LOAD_IMM_64, 1]];
16992
+ const instructionsWithTwoImmediates = [
16993
+ [instruction_Instruction.STORE_IMM_U8, 1],
16994
+ [instruction_Instruction.STORE_IMM_U16, 1],
16995
+ [instruction_Instruction.STORE_IMM_U32, 1],
16996
+ [instruction_Instruction.STORE_IMM_U64, 1],
16997
+ ];
16998
+ const instructionsWithOneOffset = [[instruction_Instruction.JUMP, 1]];
16999
+ const instructionsWithOneRegisterAndOneImmediate = [
17000
+ [instruction_Instruction.JUMP_IND, 1],
17001
+ [instruction_Instruction.LOAD_IMM, 1],
17002
+ [instruction_Instruction.LOAD_U8, 1],
17003
+ [instruction_Instruction.LOAD_I8, 1],
17004
+ [instruction_Instruction.LOAD_U16, 1],
17005
+ [instruction_Instruction.LOAD_I16, 1],
17006
+ [instruction_Instruction.LOAD_U32, 1],
17007
+ [instruction_Instruction.LOAD_I32, 1],
17008
+ [instruction_Instruction.LOAD_U64, 1],
17009
+ [instruction_Instruction.STORE_U8, 1],
17010
+ [instruction_Instruction.STORE_U16, 1],
17011
+ [instruction_Instruction.STORE_U32, 1],
17012
+ [instruction_Instruction.STORE_U64, 1],
17013
+ ];
17014
+ const instructionsWithOneRegisterAndTwoImmediate = [
17015
+ [instruction_Instruction.STORE_IMM_IND_U8, 1],
17016
+ [instruction_Instruction.STORE_IMM_IND_U16, 1],
17017
+ [instruction_Instruction.STORE_IMM_IND_U32, 1],
17018
+ [instruction_Instruction.STORE_IMM_IND_U64, 1],
17019
+ ];
17020
+ const instructionsWithOneRegisterOneImmediateAndOneOffset = [
17021
+ [instruction_Instruction.LOAD_IMM_JUMP, 1],
17022
+ [instruction_Instruction.BRANCH_EQ_IMM, 1],
17023
+ [instruction_Instruction.BRANCH_NE_IMM, 1],
17024
+ [instruction_Instruction.BRANCH_LT_U_IMM, 1],
17025
+ [instruction_Instruction.BRANCH_LE_U_IMM, 1],
17026
+ [instruction_Instruction.BRANCH_GE_U_IMM, 1],
17027
+ [instruction_Instruction.BRANCH_GT_U_IMM, 1],
17028
+ [instruction_Instruction.BRANCH_LT_S_IMM, 1],
17029
+ [instruction_Instruction.BRANCH_LE_S_IMM, 1],
17030
+ [instruction_Instruction.BRANCH_GE_S_IMM, 1],
17031
+ [instruction_Instruction.BRANCH_GT_S_IMM, 1],
17032
+ ];
17033
+ const instructionsWithTwoRegisters = [
17034
+ [instruction_Instruction.MOVE_REG, 1],
17035
+ [instruction_Instruction.SBRK, 1],
17036
+ [instruction_Instruction.COUNT_SET_BITS_64, 1],
17037
+ [instruction_Instruction.COUNT_SET_BITS_32, 1],
17038
+ [instruction_Instruction.LEADING_ZERO_BITS_64, 1],
17039
+ [instruction_Instruction.LEADING_ZERO_BITS_32, 1],
17040
+ [instruction_Instruction.TRAILING_ZERO_BITS_64, 1],
17041
+ [instruction_Instruction.TRAILING_ZERO_BITS_32, 1],
17042
+ [instruction_Instruction.SIGN_EXTEND_8, 1],
17043
+ [instruction_Instruction.SIGN_EXTEND_16, 1],
17044
+ [instruction_Instruction.ZERO_EXTEND_16, 1],
17045
+ [instruction_Instruction.REVERSE_BYTES, 1],
17046
+ ];
17047
+ const instructionsWithTwoRegistersAndOneImmediate = [
17048
+ [instruction_Instruction.STORE_IND_U8, 1],
17049
+ [instruction_Instruction.STORE_IND_U16, 1],
17050
+ [instruction_Instruction.STORE_IND_U32, 1],
17051
+ [instruction_Instruction.STORE_IND_U64, 1],
17052
+ [instruction_Instruction.LOAD_IND_U8, 1],
17053
+ [instruction_Instruction.LOAD_IND_I8, 1],
17054
+ [instruction_Instruction.LOAD_IND_U16, 1],
17055
+ [instruction_Instruction.LOAD_IND_I16, 1],
17056
+ [instruction_Instruction.LOAD_IND_U32, 1],
17057
+ [instruction_Instruction.LOAD_IND_I32, 1],
17058
+ [instruction_Instruction.LOAD_IND_U64, 1],
17059
+ [instruction_Instruction.ADD_IMM_32, 1],
17060
+ [instruction_Instruction.AND_IMM, 1],
17061
+ [instruction_Instruction.XOR_IMM, 1],
17062
+ [instruction_Instruction.OR_IMM, 1],
17063
+ [instruction_Instruction.MUL_IMM_32, 1],
17064
+ [instruction_Instruction.SET_LT_U_IMM, 1],
17065
+ [instruction_Instruction.SET_LT_S_IMM, 1],
17066
+ [instruction_Instruction.SHLO_L_IMM_32, 1],
17067
+ [instruction_Instruction.SHLO_R_IMM_32, 1],
17068
+ [instruction_Instruction.SHAR_R_IMM_32, 1],
17069
+ [instruction_Instruction.NEG_ADD_IMM_32, 1],
17070
+ [instruction_Instruction.SET_GT_U_IMM, 1],
17071
+ [instruction_Instruction.SET_GT_S_IMM, 1],
17072
+ [instruction_Instruction.SHLO_L_IMM_ALT_32, 1],
17073
+ [instruction_Instruction.SHLO_R_IMM_ALT_32, 1],
17074
+ [instruction_Instruction.SHAR_R_IMM_ALT_32, 1],
17075
+ [instruction_Instruction.CMOV_IZ_IMM, 1],
17076
+ [instruction_Instruction.CMOV_NZ_IMM, 1],
17077
+ [instruction_Instruction.ADD_IMM_64, 1],
17078
+ [instruction_Instruction.MUL_IMM_64, 1],
17079
+ [instruction_Instruction.SHLO_L_IMM_64, 1],
17080
+ [instruction_Instruction.SHLO_R_IMM_64, 1],
17081
+ [instruction_Instruction.SHAR_R_IMM_64, 1],
17082
+ [instruction_Instruction.NEG_ADD_IMM_64, 1],
17083
+ [instruction_Instruction.SHLO_L_IMM_ALT_64, 1],
17084
+ [instruction_Instruction.SHLO_R_IMM_ALT_64, 1],
17085
+ [instruction_Instruction.SHAR_R_IMM_ALT_64, 1],
17086
+ [instruction_Instruction.ROT_R_64_IMM, 1],
17087
+ [instruction_Instruction.ROT_R_64_IMM_ALT, 1],
17088
+ [instruction_Instruction.ROT_R_32_IMM, 1],
17089
+ [instruction_Instruction.ROT_R_32_IMM_ALT, 1],
17090
+ ];
17091
+ const instructionsWithTwoRegistersAndOneOffset = [
17092
+ [instruction_Instruction.BRANCH_EQ, 1],
17093
+ [instruction_Instruction.BRANCH_NE, 1],
17094
+ [instruction_Instruction.BRANCH_LT_U, 1],
17095
+ [instruction_Instruction.BRANCH_LT_S, 1],
17096
+ [instruction_Instruction.BRANCH_GE_U, 1],
17097
+ [instruction_Instruction.BRANCH_GE_S, 1],
17098
+ ];
17099
+ const instructionWithTwoRegistersAndTwoImmediates = [[instruction_Instruction.LOAD_IMM_JUMP_IND, 1]];
17100
+ const instructionsWithThreeRegisters = [
17101
+ [instruction_Instruction.ADD_32, 1],
17102
+ [instruction_Instruction.SUB_32, 1],
17103
+ [instruction_Instruction.MUL_32, 1],
17104
+ [instruction_Instruction.DIV_U_32, 1],
17105
+ [instruction_Instruction.DIV_S_32, 1],
17106
+ [instruction_Instruction.REM_U_32, 1],
17107
+ [instruction_Instruction.REM_S_32, 1],
17108
+ [instruction_Instruction.SHLO_L_32, 1],
17109
+ [instruction_Instruction.SHLO_R_32, 1],
17110
+ [instruction_Instruction.SHAR_R_32, 1],
17111
+ [instruction_Instruction.ADD_64, 1],
17112
+ [instruction_Instruction.SUB_64, 1],
17113
+ [instruction_Instruction.MUL_64, 1],
17114
+ [instruction_Instruction.DIV_U_64, 1],
17115
+ [instruction_Instruction.DIV_S_64, 1],
17116
+ [instruction_Instruction.REM_U_64, 1],
17117
+ [instruction_Instruction.REM_S_64, 1],
17118
+ [instruction_Instruction.SHLO_L_64, 1],
17119
+ [instruction_Instruction.SHLO_R_64, 1],
17120
+ [instruction_Instruction.SHAR_R_64, 1],
17121
+ [instruction_Instruction.AND, 1],
17122
+ [instruction_Instruction.XOR, 1],
17123
+ [instruction_Instruction.OR, 1],
17124
+ [instruction_Instruction.MUL_UPPER_S_S, 1],
17125
+ [instruction_Instruction.MUL_UPPER_U_U, 1],
17126
+ [instruction_Instruction.MUL_UPPER_S_U, 1],
17127
+ [instruction_Instruction.SET_LT_U, 1],
17128
+ [instruction_Instruction.SET_LT_S, 1],
17129
+ [instruction_Instruction.CMOV_IZ, 1],
17130
+ [instruction_Instruction.CMOV_NZ, 1],
17131
+ [instruction_Instruction.ROT_L_64, 1],
17132
+ [instruction_Instruction.ROT_L_32, 1],
17133
+ [instruction_Instruction.ROT_R_64, 1],
17134
+ [instruction_Instruction.ROT_R_32, 1],
17135
+ [instruction_Instruction.AND_INV, 1],
17136
+ [instruction_Instruction.OR_INV, 1],
17137
+ [instruction_Instruction.XNOR, 1],
17138
+ [instruction_Instruction.MAX, 1],
17139
+ [instruction_Instruction.MAX_U, 1],
17140
+ [instruction_Instruction.MIN, 1],
17141
+ [instruction_Instruction.MIN_U, 1],
17142
+ ];
17143
+ const instructions = [
17144
+ ...instructionsWithoutArgs,
17145
+ ...instructionsWithOneImmediate,
17146
+ ...instructionsWithOneRegisterAndOneExtendedWidthImmediate,
17147
+ ...instructionsWithTwoImmediates,
17148
+ ...instructionsWithOneOffset,
17149
+ ...instructionsWithOneRegisterAndOneImmediate,
17150
+ ...instructionsWithOneRegisterAndTwoImmediate,
17151
+ ...instructionsWithOneRegisterOneImmediateAndOneOffset,
17152
+ ...instructionsWithTwoRegisters,
17153
+ ...instructionsWithTwoRegistersAndOneImmediate,
17154
+ ...instructionsWithTwoRegistersAndOneOffset,
17155
+ ...instructionWithTwoRegistersAndTwoImmediates,
17156
+ ...instructionsWithThreeRegisters,
17157
+ ];
17158
+ const createOpCodeEntry = ([byte, gas]) => [byte, { gas: tryAsSmallGas(gas) }];
17159
+ const byteToOpCodeMap = instructions.reduce((acc, instruction) => {
17160
+ const [byte, opCode] = createOpCodeEntry(instruction);
17161
+ acc[byte] = opCode;
17162
+ return acc;
17163
+ }, {});
17164
+ function assemblify_assemblify(program, mask) {
17165
+ return program.reduce((acc, byte, index) => {
17166
+ if (mask.isInstruction(index)) {
17167
+ acc.push([Instruction[byte]]);
16942
17168
  }
16943
- const memory = Memory.fromInitialMemory({
16944
- memory: this.initialMemory,
16945
- sbrkIndex: tryAsSbrkIndex(startHeapIndex),
16946
- endHeapIndex,
16947
- });
16948
- this.isFinalized = true;
16949
- return memory;
16950
- }
17169
+ else {
17170
+ acc[acc.length - 1].push(byte);
17171
+ }
17172
+ return acc;
17173
+ }, []);
16951
17174
  }
16952
17175
 
16953
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/index.ts
16954
-
16955
-
16956
-
16957
-
16958
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/registers.ts
17176
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
16959
17177
 
16960
17178
 
16961
- const REGISTER_SIZE_SHIFT = 3; // x << 3 === x * 8
16962
- const tryAsRegisterIndex = (index) => {
16963
- check `${index >= 0 && index < NO_OF_REGISTERS} Incorrect register index: ${index}!`;
16964
- return asOpaqueType(index);
16965
- };
16966
- class registers_Registers {
16967
- bytes;
16968
- asSigned;
16969
- asUnsigned;
16970
- constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS << REGISTER_SIZE_SHIFT)) {
16971
- this.bytes = bytes;
16972
- check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
16973
- this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
16974
- this.asUnsigned = new BigUint64Array(bytes.buffer, bytes.byteOffset);
16975
- }
16976
- getAllEncoded() {
16977
- return this.bytes;
17179
+ /** Create a new gas counter instance depending on the gas value. */
17180
+ function gas_gasCounter(gas) {
17181
+ return new GasCounterU64(tryAsU64(gas));
17182
+ }
17183
+ class GasCounterU64 {
17184
+ gas;
17185
+ initialGas;
17186
+ constructor(gas) {
17187
+ this.gas = gas;
17188
+ this.initialGas = tryAsGas(gas);
16978
17189
  }
16979
- setAllEncoded(bytes) {
16980
- check `${bytes.length === this.bytes.length} Incorrect size of input registers. Got: ${bytes.length}, need: ${this.bytes.length}`;
16981
- this.bytes.set(bytes, 0);
17190
+ set(g) {
17191
+ this.gas = tryAsU64(g);
16982
17192
  }
16983
- static fromBytes(bytes) {
16984
- check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
16985
- return new registers_Registers(bytes);
17193
+ get() {
17194
+ return tryAsGas(this.gas);
16986
17195
  }
16987
- getBytesAsLittleEndian(index, len) {
16988
- const offset = index << REGISTER_SIZE_SHIFT;
16989
- return this.bytes.subarray(offset, offset + len);
17196
+ sub(g) {
17197
+ const result = this.gas - tryAsU64(g);
17198
+ if (result >= 0n) {
17199
+ this.gas = tryAsU64(result);
17200
+ return false;
17201
+ }
17202
+ this.gas = tryAsU64(0n);
17203
+ return true;
16990
17204
  }
16991
- copyFrom(regs) {
16992
- const array = regs instanceof BigUint64Array ? regs : regs.asUnsigned;
16993
- this.asUnsigned.set(array);
16994
- }
16995
- reset() {
16996
- for (let i = 0; i < NO_OF_REGISTERS; i++) {
16997
- this.asUnsigned[i] = 0n;
17205
+ used() {
17206
+ const gasConsumed = tryAsU64(this.initialGas) - this.gas;
17207
+ // In we have less than zero left we assume that all gas has been consumed.
17208
+ if (gasConsumed < 0) {
17209
+ return this.initialGas;
16998
17210
  }
17211
+ return tryAsGas(gasConsumed);
16999
17212
  }
17000
- getLowerU32(registerIndex) {
17001
- return Number(this.asUnsigned[registerIndex] & 0xffffffffn);
17002
- }
17003
- getLowerI32(registerIndex) {
17004
- return Number(this.getLowerU32(registerIndex)) >> 0;
17213
+ }
17214
+
17215
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
17216
+
17217
+
17218
+ const instruction_gas_map_instructionGasMap = (() => {
17219
+ const instructionGasMap = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
17220
+ for (let i = 0; i < HIGHEST_INSTRUCTION_NUMBER + 1; i++) {
17221
+ const gas = byteToOpCodeMap[i]?.gas;
17222
+ instructionGasMap[i] = gas;
17005
17223
  }
17006
- setU32(registerIndex, value) {
17007
- this.asUnsigned[registerIndex] = registers_signExtend32To64(value);
17224
+ return instructionGasMap;
17225
+ })();
17226
+
17227
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-index.ts
17228
+
17229
+
17230
+ const memory_index_tryAsMemoryIndex = (index) => {
17231
+ debug_check `${index >= 0 && index <= memory_MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
17232
+ return opaque_asOpaqueType(index);
17233
+ };
17234
+ const memory_index_tryAsSbrkIndex = (index) => {
17235
+ check `${index >= 0 && index <= MAX_MEMORY_INDEX + 1} Incorrect sbrk index: ${index}!`;
17236
+ return asOpaqueType(index);
17237
+ };
17238
+
17239
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-consts.ts
17240
+
17241
+
17242
+ const memory_consts_PAGE_SIZE_SHIFT = 12;
17243
+ // PAGE_SIZE has to be a power of 2
17244
+ const memory_consts_PAGE_SIZE = 1 << memory_consts_PAGE_SIZE_SHIFT;
17245
+ const MIN_ALLOCATION_SHIFT = (() => {
17246
+ const MIN_ALLOCATION_SHIFT = 7;
17247
+ debug_check `${MIN_ALLOCATION_SHIFT >= 0 && MIN_ALLOCATION_SHIFT < memory_consts_PAGE_SIZE_SHIFT} incorrect minimal allocation shift`;
17248
+ return MIN_ALLOCATION_SHIFT;
17249
+ })();
17250
+ const MIN_ALLOCATION_LENGTH = memory_consts_PAGE_SIZE >> MIN_ALLOCATION_SHIFT;
17251
+ const LAST_PAGE_NUMBER = (MEMORY_SIZE - memory_consts_PAGE_SIZE) / memory_consts_PAGE_SIZE;
17252
+ /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
17253
+ const memory_consts_RESERVED_NUMBER_OF_PAGES = 16;
17254
+ /** https://graypaper.fluffylabs.dev/#/68eaa1f/35a60235a602?v=0.6.4 */
17255
+ const MAX_NUMBER_OF_PAGES = MEMORY_SIZE / memory_consts_PAGE_SIZE;
17256
+
17257
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/page-utils.ts
17258
+
17259
+
17260
+ /** Ensure that given memory `index` is within `[0...PAGE_SIZE)` and can be used to index a page */
17261
+ const page_utils_tryAsPageIndex = (index) => {
17262
+ check `${index >= 0 && index < PAGE_SIZE}, Incorect page index: ${index}!`;
17263
+ return asOpaqueType(index);
17264
+ };
17265
+ /** Ensure that given `index` represents an index of one of the pages. */
17266
+ const page_utils_tryAsPageNumber = (index) => {
17267
+ debug_check `${index >= 0 && index <= LAST_PAGE_NUMBER}, Incorect page number: ${index}!`;
17268
+ return opaque_asOpaqueType(index);
17269
+ };
17270
+ /**
17271
+ * Get the next page number and wrap the result if it is bigger than LAST_PAGE_NUMBER
17272
+ *
17273
+ * GP references:
17274
+ * 1. The modulo subscription operator is used in all load/store instructions, for example:
17275
+ * https://graypaper.fluffylabs.dev/#/579bd12/25af0125af01
17276
+ *
17277
+ * 2. Here is the definition of the modulo subscription operator:
17278
+ * https://graypaper.fluffylabs.dev/#/579bd12/073a00073a00
17279
+ */
17280
+ function getNextPageNumber(pageNumber) {
17281
+ const newPageNumber = pageNumber === LAST_PAGE_NUMBER ? 0 : pageNumber + 1;
17282
+ return page_utils_tryAsPageNumber(newPageNumber);
17283
+ }
17284
+
17285
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-utils.ts
17286
+
17287
+
17288
+
17289
+ function memory_memory_utils_alignToPageSize(length) {
17290
+ return PAGE_SIZE * Math.ceil(length / PAGE_SIZE);
17291
+ }
17292
+ function memory_utils_getPageNumber(address) {
17293
+ return page_utils_tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
17294
+ }
17295
+ function memory_utils_getStartPageIndex(address) {
17296
+ return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
17297
+ }
17298
+ function getStartPageIndexFromPageNumber(pageNumber) {
17299
+ // >>> 0 is needed to avoid changing sign of the number
17300
+ return memory_index_tryAsMemoryIndex((pageNumber << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
17301
+ }
17302
+
17303
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/errors.ts
17304
+
17305
+
17306
+
17307
+
17308
+
17309
+ class errors_PageFault {
17310
+ address;
17311
+ isAccessFault;
17312
+ constructor(address, isAccessFault = true) {
17313
+ this.address = address;
17314
+ this.isAccessFault = isAccessFault;
17008
17315
  }
17009
- setI32(registerIndex, value) {
17010
- this.asSigned[registerIndex] = registers_signExtend32To64(value);
17316
+ static fromPageNumber(maybePageNumber, isAccessFault = false) {
17317
+ const pageNumber = page_utils_tryAsPageNumber(maybePageNumber);
17318
+ const startPageIndex = getStartPageIndexFromPageNumber(pageNumber);
17319
+ return new errors_PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
17011
17320
  }
17012
- getU64(registerIndex) {
17013
- return this.asUnsigned[registerIndex];
17321
+ static fromMemoryIndex(maybeMemoryIndex, isAccessFault = false) {
17322
+ const memoryIndex = memory_index_tryAsMemoryIndex(maybeMemoryIndex % MEMORY_SIZE);
17323
+ const startPageIndex = memory_utils_getStartPageIndex(memoryIndex);
17324
+ return new errors_PageFault(numbers_tryAsU32(startPageIndex), isAccessFault);
17014
17325
  }
17015
- getI64(registerIndex) {
17016
- return this.asSigned[registerIndex];
17326
+ }
17327
+ class OutOfBounds extends Error {
17328
+ constructor() {
17329
+ super("Out of bounds");
17017
17330
  }
17018
- setU64(registerIndex, value) {
17019
- this.asUnsigned[registerIndex] = value;
17331
+ }
17332
+ class ChunkOverlap extends Error {
17333
+ constructor() {
17334
+ super("Memory chunks cannot overlap each other!");
17020
17335
  }
17021
- setI64(registerIndex, value) {
17022
- this.asSigned[registerIndex] = value;
17336
+ }
17337
+ class ChunkTooLong extends Error {
17338
+ constructor() {
17339
+ super("Memory chunk is longer than the address range!");
17023
17340
  }
17024
- getAllU64() {
17025
- return this.asUnsigned;
17341
+ }
17342
+ class errors_IncorrectSbrkIndex extends Error {
17343
+ constructor() {
17344
+ super("Space between sbrk index and max heap index should be empty!");
17026
17345
  }
17027
17346
  }
17028
- function registers_signExtend32To64(value) {
17029
- // Convert to BigInt if the value is a number
17030
- const bigValue = typeof value === "number" ? BigInt(value) : value;
17031
- // Ensure the value is treated as a 32-bit integer
17032
- const mask32 = BigInt(0xffffffff);
17033
- const signBit = BigInt(0x80000000);
17034
- const maskedValue = bigValue & mask32;
17035
- // Check the sign bit and extend the sign if necessary
17036
- if ((maskedValue & signBit) !== BigInt(0)) {
17037
- // If the sign bit is set, extend with ones
17038
- return maskedValue | ~mask32;
17347
+ class errors_FinalizedBuilderModification extends Error {
17348
+ constructor() {
17349
+ super("MemoryBuilder was finalized and cannot be changed!");
17039
17350
  }
17040
- // If the sign bit is not set, return as is
17041
- return maskedValue;
17042
17351
  }
17043
-
17044
- ;// CONCATENATED MODULE: ./packages/core/pvm-program/program.ts
17045
-
17046
-
17047
-
17048
-
17049
-
17050
- class program_Program {
17051
- code;
17052
- registers;
17053
- memory;
17054
- metadata;
17055
- static fromSpi(blob, args, hasMetadata) {
17056
- const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
17057
- const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
17058
- const regs = new Registers();
17059
- regs.copyFrom(registers);
17060
- const memoryBuilder = new MemoryBuilder();
17061
- for (const { start, end, data } of rawMemory.readable) {
17062
- const startIndex = tryAsMemoryIndex(start);
17063
- const endIndex = tryAsMemoryIndex(end);
17064
- memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
17065
- }
17066
- for (const { start, end, data } of rawMemory.writeable) {
17067
- const startIndex = tryAsMemoryIndex(start);
17068
- const endIndex = tryAsMemoryIndex(end);
17069
- memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
17070
- }
17071
- const heapStart = tryAsMemoryIndex(rawMemory.sbrkIndex);
17072
- const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
17073
- const memory = memoryBuilder.finalize(heapStart, heapEnd);
17074
- return new program_Program(code, regs, memory, metadata);
17352
+ class errors_ReservedMemoryFault extends Error {
17353
+ constructor() {
17354
+ super("You are trying to access reserved memory!");
17075
17355
  }
17076
- static fromGeneric(blob, hasMetadata) {
17077
- const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
17078
- const regs = new Registers();
17079
- const memory = new Memory();
17080
- return new program_Program(code, regs, memory, metadata);
17356
+ }
17357
+ class errors_PageNotExist extends Error {
17358
+ constructor() {
17359
+ super("You try to fill data on memory page that does not exist!");
17081
17360
  }
17082
- constructor(code, registers, memory, metadata = new Uint8Array()) {
17083
- this.code = code;
17084
- this.registers = registers;
17085
- this.memory = memory;
17086
- this.metadata = metadata;
17361
+ }
17362
+ class ChunkNotFound extends Error {
17363
+ constructor() {
17364
+ super("Chunk does not exist or is too short");
17087
17365
  }
17088
17366
  }
17089
- /**
17090
- * A function that splits preimage into metadata and code.
17091
- *
17092
- * https://graypaper.fluffylabs.dev/#/cc517d7/109a01109a01?v=0.6.5
17093
- */
17094
- function extractCodeAndMetadata(blobWithMetadata) {
17095
- const decoder = Decoder.fromBlob(blobWithMetadata);
17096
- const metadata = decoder.bytesBlob().raw;
17097
- const code = decoder.remainingBytes().raw;
17098
- return { metadata, code };
17367
+ class errors_OutOfMemory extends Error {
17368
+ constructor() {
17369
+ super("Out of memory");
17370
+ }
17099
17371
  }
17100
17372
 
17101
- ;// CONCATENATED MODULE: ./packages/core/pvm-program/index.ts
17102
-
17373
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-range.ts
17103
17374
 
17104
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/program-decoder/mask.ts
17105
17375
 
17106
17376
 
17107
17377
  /**
17108
- * Upper bound of instruction distance - it is equal to max value of GP's skip function + 1
17109
- */
17110
- const MAX_INSTRUCTION_DISTANCE = 25;
17111
- /**
17112
- * Mask class is an implementation of skip function defined in GP.
17378
+ * A representation of open-ended range of consecutive indices in memory,
17379
+ * possibly empty or wrapping around.
17113
17380
  *
17114
- * https://graypaper.fluffylabs.dev/#/5f542d7/237201239801
17381
+ * `[start, start + length)`
17115
17382
  */
17116
- class mask_Mask {
17383
+ class memory_range_MemoryRange {
17384
+ start;
17385
+ length;
17117
17386
  /**
17118
- * The lookup table will have `0` at the index which corresponds to an instruction on the same index in the bytecode.
17119
- * In case the value is non-zero it signifies the offset to the index with next instruction.
17387
+ * Exclusive end index of the range.
17120
17388
  *
17121
- * Example:
17122
- * ```
17123
- * 0..1..2..3..4..5..6..7..8..9 # Indices
17124
- * 0..2..1..0..1..0..3..2..1..0 # lookupTable forward values
17125
- * ```
17126
- * There are instructions at indices `0, 3, 5, 9`.
17389
+ * NOTE: The index may be wrapped around and smaller than `start`!
17127
17390
  */
17128
- lookupTableForward;
17129
- constructor(mask) {
17130
- this.lookupTableForward = this.buildLookupTableForward(mask);
17391
+ end;
17392
+ /**
17393
+ * Inclusive last index of the range (present unless the range is empty).
17394
+ *
17395
+ * NOTE: the index may be wrapped around and smaller than `start`!
17396
+ */
17397
+ lastIndex = null;
17398
+ constructor(start, length) {
17399
+ this.start = start;
17400
+ this.length = length;
17401
+ this.end = memory_index_tryAsMemoryIndex((this.start + this.length) % MEMORY_SIZE);
17402
+ if (length > 0) {
17403
+ this.lastIndex = memory_index_tryAsMemoryIndex((this.end - 1 + MEMORY_SIZE) % MEMORY_SIZE);
17404
+ }
17131
17405
  }
17132
- isInstruction(index) {
17133
- return this.lookupTableForward[index] === 0;
17406
+ /** Creates a memory range from given starting point and length */
17407
+ static fromStartAndLength(start, length) {
17408
+ if (!Number.isInteger(length) || length < 0 || length > MEMORY_SIZE) {
17409
+ throw new TypeError(`length must be a non-negative integer and less than ${MEMORY_SIZE}, got ${length}`);
17410
+ }
17411
+ return new memory_range_MemoryRange(start, length);
17134
17412
  }
17135
- getNoOfBytesToNextInstruction(index) {
17136
- check `${index >= 0} index (${index}) cannot be a negative number`;
17137
- return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
17413
+ /** Checks if a range is empty (`length === 0`) */
17414
+ isEmpty() {
17415
+ return this.length === 0;
17138
17416
  }
17139
- buildLookupTableForward(mask) {
17140
- const table = safeAllocUint8Array(mask.bitLength);
17141
- let lastInstructionOffset = 0;
17142
- for (let i = mask.bitLength - 1; i >= 0; i--) {
17143
- if (mask.isSet(i)) {
17144
- lastInstructionOffset = 0;
17145
- }
17146
- else {
17147
- lastInstructionOffset++;
17148
- }
17149
- table[i] = lastInstructionOffset;
17417
+ /** Returns true if the range is wrapped (`start` >= `end`) and is not empty */
17418
+ isWrapped() {
17419
+ return this.start >= this.end && !this.isEmpty();
17420
+ }
17421
+ /** Checks if given memory address is within the range */
17422
+ isInRange(address) {
17423
+ if (this.isWrapped()) {
17424
+ return address >= this.start || address < this.end;
17150
17425
  }
17151
- return table;
17426
+ return address >= this.start && address < this.end;
17152
17427
  }
17153
- static empty() {
17154
- return new mask_Mask(BitVec.empty(0));
17428
+ /** Checks if this range overlaps with another range */
17429
+ overlapsWith(other) {
17430
+ if (this.lastIndex === null || other.lastIndex === null) {
17431
+ return false;
17432
+ }
17433
+ return (this.isInRange(other.start) ||
17434
+ this.isInRange(other.lastIndex) ||
17435
+ other.isInRange(this.start) ||
17436
+ other.isInRange(this.lastIndex));
17155
17437
  }
17156
17438
  }
17439
+ /**
17440
+ * The first 16 pages of memory are reserved.
17441
+ *
17442
+ * https://graypaper.fluffylabs.dev/#/cc517d7/24d00024d000?v=0.6.5
17443
+ *
17444
+ * it should be in `memory-consts` but it cannot be there because of circular dependency
17445
+ */
17446
+ const memory_range_RESERVED_MEMORY_RANGE = memory_range_MemoryRange.fromStartAndLength(memory_index_tryAsMemoryIndex(0), memory_consts_RESERVED_NUMBER_OF_PAGES * memory_consts_PAGE_SIZE);
17157
17447
 
17158
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/argument-type.ts
17159
- var argument_type_ArgumentType;
17160
- (function (ArgumentType) {
17161
- ArgumentType[ArgumentType["NO_ARGUMENTS"] = 0] = "NO_ARGUMENTS";
17162
- ArgumentType[ArgumentType["ONE_IMMEDIATE"] = 1] = "ONE_IMMEDIATE";
17163
- ArgumentType[ArgumentType["TWO_IMMEDIATES"] = 2] = "TWO_IMMEDIATES";
17164
- ArgumentType[ArgumentType["ONE_OFFSET"] = 3] = "ONE_OFFSET";
17165
- ArgumentType[ArgumentType["ONE_REGISTER_ONE_IMMEDIATE"] = 4] = "ONE_REGISTER_ONE_IMMEDIATE";
17166
- ArgumentType[ArgumentType["ONE_REGISTER_TWO_IMMEDIATES"] = 5] = "ONE_REGISTER_TWO_IMMEDIATES";
17167
- ArgumentType[ArgumentType["ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET"] = 6] = "ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET";
17168
- ArgumentType[ArgumentType["TWO_REGISTERS"] = 7] = "TWO_REGISTERS";
17169
- ArgumentType[ArgumentType["TWO_REGISTERS_ONE_IMMEDIATE"] = 8] = "TWO_REGISTERS_ONE_IMMEDIATE";
17170
- ArgumentType[ArgumentType["TWO_REGISTERS_ONE_OFFSET"] = 9] = "TWO_REGISTERS_ONE_OFFSET";
17171
- ArgumentType[ArgumentType["TWO_REGISTERS_TWO_IMMEDIATES"] = 10] = "TWO_REGISTERS_TWO_IMMEDIATES";
17172
- ArgumentType[ArgumentType["THREE_REGISTERS"] = 11] = "THREE_REGISTERS";
17173
- ArgumentType[ArgumentType["ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE"] = 12] = "ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE";
17174
- })(argument_type_ArgumentType || (argument_type_ArgumentType = {}));
17448
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/page-range.ts
17175
17449
 
17176
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/decoders/nibbles-decoder.ts
17177
17450
 
17178
- const MAX_REGISTER_INDEX = registers_NO_OF_REGISTERS - 1;
17179
- const nibbles_decoder_MAX_LENGTH = 4;
17180
- class nibbles_decoder_NibblesDecoder {
17181
- byte = new Int8Array(1);
17182
- setByte(byte) {
17183
- this.byte[0] = byte;
17451
+
17452
+ /**
17453
+ * A half-open range of memory pages. Similarly to [`MemoryRange`], can be empty
17454
+ * or wrapped around the memory.
17455
+ */
17456
+ class page_range_PageRange {
17457
+ start;
17458
+ length;
17459
+ /**
17460
+ * Exclusive end of the page range.
17461
+ *
17462
+ * NOTE: it may be smaller than `start` in case the range is wrapped.
17463
+ */
17464
+ end;
17465
+ constructor(start, length) {
17466
+ this.start = start;
17467
+ this.length = length;
17468
+ this.end = page_utils_tryAsPageNumber((this.start + this.length) % MAX_NUMBER_OF_PAGES);
17184
17469
  }
17185
- getHighNibble() {
17186
- return (this.byte[0] & 0xf0) >>> 4;
17470
+ /**
17471
+ * Creates range of pages that includes all indices in a given memory range.
17472
+ *
17473
+ * Example: For memory range `[PAGE_SIZE, MEMORY_SIZE - PAGE_SIZE)`
17474
+ * we will get `[1, MAX_NUMBER_OF_PAGES - 1)` page range.
17475
+ */
17476
+ static fromMemoryRange(range) {
17477
+ const startPage = memory_utils_getPageNumber(range.start);
17478
+ if (range.isEmpty()) {
17479
+ return new page_range_PageRange(startPage, 0);
17480
+ }
17481
+ // lastIndex is not null because we just ensured that the range is not empty
17482
+ const pageWithLastIndex = memory_utils_getPageNumber(range.lastIndex ?? range.end);
17483
+ const endPage = getNextPageNumber(pageWithLastIndex);
17484
+ if ((startPage === endPage || startPage === pageWithLastIndex) && range.length > memory_consts_PAGE_SIZE) {
17485
+ // full range
17486
+ return new page_range_PageRange(startPage, MAX_NUMBER_OF_PAGES);
17487
+ }
17488
+ const length = startPage < endPage ? endPage - startPage : MAX_NUMBER_OF_PAGES - startPage + endPage;
17489
+ return page_range_PageRange.fromStartAndLength(startPage, length);
17187
17490
  }
17188
- getLowNibble() {
17189
- return this.byte[0] & 0x0f;
17491
+ /** Creates a page range from given starting point and length */
17492
+ static fromStartAndLength(start, length) {
17493
+ if (!Number.isInteger(length) || length < 0 || length > MAX_NUMBER_OF_PAGES) {
17494
+ throw new TypeError(`length must be a non-negative integer and less than ${MAX_NUMBER_OF_PAGES}, got ${length}`);
17495
+ }
17496
+ return new page_range_PageRange(start, length);
17190
17497
  }
17191
- getHighNibbleAsRegisterIndex() {
17192
- return Math.min(this.getHighNibble(), MAX_REGISTER_INDEX);
17498
+ /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
17499
+ isWrapped() {
17500
+ return this.start >= this.end && !this.isEmpty();
17193
17501
  }
17194
- getLowNibbleAsRegisterIndex() {
17195
- return Math.min(this.getLowNibble(), MAX_REGISTER_INDEX);
17502
+ /** Checks if given page number is within the range */
17503
+ isInRange(page) {
17504
+ if (this.isWrapped()) {
17505
+ return page >= this.start || page < this.end;
17506
+ }
17507
+ return page >= this.start && page < this.end;
17196
17508
  }
17197
- getHighNibbleAsLength() {
17198
- return Math.min(this.getHighNibble(), nibbles_decoder_MAX_LENGTH);
17509
+ /** Checks if a range is empty (`length === 0`) */
17510
+ isEmpty() {
17511
+ return this.length === 0;
17199
17512
  }
17200
- getLowNibbleAsLength() {
17201
- return Math.min(this.getLowNibble(), nibbles_decoder_MAX_LENGTH);
17513
+ *[Symbol.iterator]() {
17514
+ if (this.isEmpty()) {
17515
+ return;
17516
+ }
17517
+ const end = this.end;
17518
+ let i = this.start;
17519
+ do {
17520
+ yield i;
17521
+ i = getNextPageNumber(i);
17522
+ } while (i !== end);
17202
17523
  }
17203
17524
  }
17204
17525
 
17205
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/args-decoder.ts
17206
-
17207
-
17208
-
17526
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/memory-page.ts
17209
17527
 
17210
- const IMMEDIATE_AND_OFFSET_MAX_LENGTH = 4;
17211
- class args_decoder_ArgsDecoder {
17212
- nibblesDecoder = new NibblesDecoder();
17213
- offsetDecoder = new ImmediateDecoder();
17214
- code = new Uint8Array();
17215
- mask = Mask.empty();
17216
- reset(code, mask) {
17217
- this.code = code;
17218
- this.mask = mask;
17219
- }
17220
- fillArgs(pc, result) {
17221
- const nextInstructionDistance = 1 + this.mask.getNoOfBytesToNextInstruction(pc + 1);
17222
- result.noOfBytesToSkip = nextInstructionDistance;
17223
- switch (result.type) {
17224
- case ArgumentType.NO_ARGUMENTS:
17225
- break;
17226
- case ArgumentType.ONE_IMMEDIATE: {
17227
- const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, nextInstructionDistance - 1);
17228
- const argsStartIndex = pc + 1;
17229
- result.immediateDecoder.setBytes(this.code.subarray(argsStartIndex, argsStartIndex + immediateLength));
17230
- break;
17231
- }
17232
- case ArgumentType.THREE_REGISTERS: {
17233
- const firstByte = this.code[pc + 1];
17234
- const secondByte = this.code[pc + 2];
17235
- this.nibblesDecoder.setByte(firstByte);
17236
- result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17237
- result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
17238
- this.nibblesDecoder.setByte(secondByte);
17239
- result.thirdRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17240
- break;
17241
- }
17242
- case ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE: {
17243
- const firstByte = this.code[pc + 1];
17244
- this.nibblesDecoder.setByte(firstByte);
17245
- result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17246
- result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
17247
- const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
17248
- const immediateStartIndex = pc + 2;
17249
- const immediateEndIndex = immediateStartIndex + immediateLength;
17250
- result.immediateDecoder.setBytes(this.code.subarray(immediateStartIndex, immediateEndIndex));
17251
- break;
17252
- }
17253
- case ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET: {
17254
- const firstByte = this.code[pc + 1];
17255
- this.nibblesDecoder.setByte(firstByte);
17256
- result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17257
- const immediateLength = this.nibblesDecoder.getHighNibbleAsLength();
17258
- const immediateStartIndex = pc + 2;
17259
- const immediateEndIndex = immediateStartIndex + immediateLength;
17260
- result.immediateDecoder.setBytes(this.code.subarray(immediateStartIndex, immediateEndIndex));
17261
- const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - immediateLength));
17262
- const offsetStartIndex = pc + 2 + immediateLength;
17263
- const offsetEndIndex = offsetStartIndex + offsetLength;
17264
- this.offsetDecoder.setBytes(this.code.subarray(offsetStartIndex, offsetEndIndex));
17265
- result.nextPc = pc + this.offsetDecoder.getSigned();
17266
- break;
17267
- }
17268
- case ArgumentType.TWO_REGISTERS_ONE_OFFSET: {
17269
- const firstByte = this.code[pc + 1];
17270
- this.nibblesDecoder.setByte(firstByte);
17271
- result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17272
- result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
17273
- const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
17274
- const offsetStartIndex = pc + 2;
17275
- const offsetEndIndex = offsetStartIndex + offsetLength;
17276
- this.offsetDecoder.setBytes(this.code.subarray(offsetStartIndex, offsetEndIndex));
17277
- result.nextPc = pc + this.offsetDecoder.getSigned();
17278
- break;
17279
- }
17280
- case ArgumentType.TWO_REGISTERS: {
17281
- const firstByte = this.code[pc + 1];
17282
- this.nibblesDecoder.setByte(firstByte);
17283
- result.firstRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
17284
- result.secondRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17285
- break;
17286
- }
17287
- case ArgumentType.ONE_OFFSET: {
17288
- const offsetLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, nextInstructionDistance - 1);
17289
- const offsetStartIndex = pc + 1;
17290
- const offsetEndIndex = offsetStartIndex + offsetLength;
17291
- const offsetBytes = this.code.subarray(offsetStartIndex, offsetEndIndex);
17292
- this.offsetDecoder.setBytes(offsetBytes);
17293
- const offsetValue = this.offsetDecoder.getSigned();
17294
- result.nextPc = pc + offsetValue;
17295
- break;
17296
- }
17297
- case ArgumentType.ONE_REGISTER_ONE_IMMEDIATE: {
17298
- const firstByte = this.code[pc + 1];
17299
- this.nibblesDecoder.setByte(firstByte);
17300
- result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17301
- const immediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2));
17302
- const immediateStartIndex = pc + 2;
17303
- const immediateEndIndex = immediateStartIndex + immediateLength;
17304
- const immediateBytes = this.code.subarray(immediateStartIndex, immediateEndIndex);
17305
- result.immediateDecoder.setBytes(immediateBytes);
17306
- break;
17307
- }
17308
- case ArgumentType.TWO_IMMEDIATES: {
17309
- const firstByte = this.code[pc + 1];
17310
- this.nibblesDecoder.setByte(firstByte);
17311
- const firstImmediateLength = this.nibblesDecoder.getLowNibbleAsLength();
17312
- const firstImmediateStartIndex = pc + 2;
17313
- const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
17314
- const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
17315
- result.firstImmediateDecoder.setBytes(firstImmediateBytes);
17316
- const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - firstImmediateLength));
17317
- const secondImmediateStartIndex = firstImmediateEndIndex;
17318
- const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
17319
- const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
17320
- result.secondImmediateDecoder.setBytes(secondImmediateBytes);
17321
- break;
17322
- }
17323
- case ArgumentType.ONE_REGISTER_TWO_IMMEDIATES: {
17324
- const firstByte = this.code[pc + 1];
17325
- this.nibblesDecoder.setByte(firstByte);
17326
- result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17327
- const firstImmediateLength = this.nibblesDecoder.getHighNibbleAsLength();
17328
- const firstImmediateStartIndex = pc + 2;
17329
- const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
17330
- const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
17331
- result.firstImmediateDecoder.setBytes(firstImmediateBytes);
17332
- const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 2 - firstImmediateLength));
17333
- const secondImmediateStartIndex = firstImmediateEndIndex;
17334
- const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
17335
- const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
17336
- result.secondImmediateDecoder.setBytes(secondImmediateBytes);
17337
- break;
17338
- }
17339
- case ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES: {
17340
- const firstByte = this.code[pc + 1];
17341
- this.nibblesDecoder.setByte(firstByte);
17342
- result.firstRegisterIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17343
- result.secondRegisterIndex = this.nibblesDecoder.getHighNibbleAsRegisterIndex();
17344
- const secondByte = this.code[pc + 2];
17345
- this.nibblesDecoder.setByte(secondByte);
17346
- const firstImmediateLength = this.nibblesDecoder.getLowNibbleAsLength();
17347
- const firstImmediateStartIndex = pc + 3;
17348
- const firstImmediateEndIndex = firstImmediateStartIndex + firstImmediateLength;
17349
- const firstImmediateBytes = this.code.subarray(firstImmediateStartIndex, firstImmediateEndIndex);
17350
- result.firstImmediateDecoder.setBytes(firstImmediateBytes);
17351
- const secondImmediateLength = Math.min(IMMEDIATE_AND_OFFSET_MAX_LENGTH, Math.max(0, nextInstructionDistance - 3 - firstImmediateLength));
17352
- const secondImmediateStartIndex = firstImmediateEndIndex;
17353
- const secondImmediateEndIndex = secondImmediateStartIndex + secondImmediateLength;
17354
- const secondImmediateBytes = this.code.subarray(secondImmediateStartIndex, secondImmediateEndIndex);
17355
- result.secondImmediateDecoder.setBytes(secondImmediateBytes);
17356
- break;
17357
- }
17358
- case ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE: {
17359
- const firstByte = this.code[pc + 1];
17360
- this.nibblesDecoder.setByte(firstByte);
17361
- result.registerIndex = this.nibblesDecoder.getLowNibbleAsRegisterIndex();
17362
- const immediateStartIndex = pc + 2;
17363
- const immediateEndIndex = immediateStartIndex + 8;
17364
- const immediateBytes = this.code.subarray(immediateStartIndex, immediateEndIndex);
17365
- result.immediateDecoder.setBytes(immediateBytes);
17366
- break;
17367
- }
17368
- }
17528
+ class MemoryPage {
17529
+ start;
17530
+ constructor(pageNumber) {
17531
+ this.start = getStartPageIndexFromPageNumber(pageNumber);
17369
17532
  }
17370
17533
  }
17371
17534
 
17372
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/args-decoding-results.ts
17373
-
17374
-
17375
-
17376
- const ARGUMENT_TYPE_LENGTH = Object.keys(argument_type_ArgumentType).length / 2;
17377
- const args_decoding_results_createResults = () => {
17378
- const results = new Array(ARGUMENT_TYPE_LENGTH);
17379
- results[ArgumentType.NO_ARGUMENTS] = {
17380
- type: ArgumentType.NO_ARGUMENTS,
17381
- noOfBytesToSkip: 1,
17382
- };
17383
- results[ArgumentType.ONE_IMMEDIATE] = {
17384
- type: ArgumentType.ONE_IMMEDIATE,
17385
- noOfBytesToSkip: 1,
17386
- immediateDecoder: new ImmediateDecoder(),
17387
- };
17388
- results[ArgumentType.TWO_REGISTERS] = {
17389
- type: ArgumentType.TWO_REGISTERS,
17390
- noOfBytesToSkip: 1,
17391
- firstRegisterIndex: 0,
17392
- secondRegisterIndex: 0,
17393
- };
17394
- results[ArgumentType.THREE_REGISTERS] = {
17395
- type: ArgumentType.THREE_REGISTERS,
17396
- noOfBytesToSkip: 1,
17397
- firstRegisterIndex: 0,
17398
- secondRegisterIndex: 0,
17399
- thirdRegisterIndex: 0,
17400
- };
17401
- results[ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET] = {
17402
- type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET,
17403
- noOfBytesToSkip: 1,
17404
- registerIndex: 0,
17405
- immediateDecoder: new ImmediateDecoder(),
17406
- nextPc: 0,
17407
- };
17408
- results[ArgumentType.TWO_REGISTERS_ONE_OFFSET] = {
17409
- type: ArgumentType.TWO_REGISTERS_ONE_OFFSET,
17410
- noOfBytesToSkip: 1,
17411
- firstRegisterIndex: 0,
17412
- secondRegisterIndex: 0,
17413
- nextPc: 0,
17414
- };
17415
- results[ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE] = {
17416
- type: ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE,
17417
- noOfBytesToSkip: 1,
17418
- firstRegisterIndex: 0,
17419
- secondRegisterIndex: 0,
17420
- immediateDecoder: new ImmediateDecoder(),
17421
- };
17422
- results[ArgumentType.ONE_REGISTER_ONE_IMMEDIATE] = {
17423
- type: ArgumentType.ONE_REGISTER_ONE_IMMEDIATE,
17424
- noOfBytesToSkip: 1,
17425
- registerIndex: 0,
17426
- immediateDecoder: new ImmediateDecoder(),
17427
- };
17428
- results[ArgumentType.ONE_REGISTER_TWO_IMMEDIATES] = {
17429
- type: ArgumentType.ONE_REGISTER_TWO_IMMEDIATES,
17430
- noOfBytesToSkip: 1,
17431
- registerIndex: 0,
17432
- firstImmediateDecoder: new ImmediateDecoder(),
17433
- secondImmediateDecoder: new ImmediateDecoder(),
17434
- };
17435
- results[ArgumentType.ONE_OFFSET] = {
17436
- type: ArgumentType.ONE_OFFSET,
17437
- noOfBytesToSkip: 1,
17438
- nextPc: 0,
17439
- };
17440
- results[ArgumentType.TWO_IMMEDIATES] = {
17441
- type: ArgumentType.TWO_IMMEDIATES,
17442
- noOfBytesToSkip: 1,
17443
- firstImmediateDecoder: new ImmediateDecoder(),
17444
- secondImmediateDecoder: new ImmediateDecoder(),
17445
- };
17446
- results[ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES] = {
17447
- type: ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES,
17448
- noOfBytesToSkip: 1,
17449
- firstImmediateDecoder: new ImmediateDecoder(),
17450
- secondImmediateDecoder: new ImmediateDecoder(),
17451
- firstRegisterIndex: 0,
17452
- secondRegisterIndex: 0,
17453
- };
17454
- results[ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE] = {
17455
- type: ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE,
17456
- noOfBytesToSkip: 9,
17457
- registerIndex: 0,
17458
- immediateDecoder: new ExtendedWitdthImmediateDecoder(),
17459
- };
17460
- return results;
17461
- };
17462
-
17463
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction.ts
17464
- var instruction_Instruction;
17465
- (function (Instruction) {
17466
- Instruction[Instruction["TRAP"] = 0] = "TRAP";
17467
- Instruction[Instruction["FALLTHROUGH"] = 1] = "FALLTHROUGH";
17468
- Instruction[Instruction["ECALLI"] = 10] = "ECALLI";
17469
- Instruction[Instruction["LOAD_IMM_64"] = 20] = "LOAD_IMM_64";
17470
- Instruction[Instruction["STORE_IMM_U8"] = 30] = "STORE_IMM_U8";
17471
- Instruction[Instruction["STORE_IMM_U16"] = 31] = "STORE_IMM_U16";
17472
- Instruction[Instruction["STORE_IMM_U32"] = 32] = "STORE_IMM_U32";
17473
- Instruction[Instruction["STORE_IMM_U64"] = 33] = "STORE_IMM_U64";
17474
- Instruction[Instruction["JUMP"] = 40] = "JUMP";
17475
- Instruction[Instruction["JUMP_IND"] = 50] = "JUMP_IND";
17476
- Instruction[Instruction["LOAD_IMM"] = 51] = "LOAD_IMM";
17477
- Instruction[Instruction["LOAD_U8"] = 52] = "LOAD_U8";
17478
- Instruction[Instruction["LOAD_I8"] = 53] = "LOAD_I8";
17479
- Instruction[Instruction["LOAD_U16"] = 54] = "LOAD_U16";
17480
- Instruction[Instruction["LOAD_I16"] = 55] = "LOAD_I16";
17481
- Instruction[Instruction["LOAD_U32"] = 56] = "LOAD_U32";
17482
- Instruction[Instruction["LOAD_I32"] = 57] = "LOAD_I32";
17483
- Instruction[Instruction["LOAD_U64"] = 58] = "LOAD_U64";
17484
- Instruction[Instruction["STORE_U8"] = 59] = "STORE_U8";
17485
- Instruction[Instruction["STORE_U16"] = 60] = "STORE_U16";
17486
- Instruction[Instruction["STORE_U32"] = 61] = "STORE_U32";
17487
- Instruction[Instruction["STORE_U64"] = 62] = "STORE_U64";
17488
- Instruction[Instruction["STORE_IMM_IND_U8"] = 70] = "STORE_IMM_IND_U8";
17489
- Instruction[Instruction["STORE_IMM_IND_U16"] = 71] = "STORE_IMM_IND_U16";
17490
- Instruction[Instruction["STORE_IMM_IND_U32"] = 72] = "STORE_IMM_IND_U32";
17491
- Instruction[Instruction["STORE_IMM_IND_U64"] = 73] = "STORE_IMM_IND_U64";
17492
- Instruction[Instruction["LOAD_IMM_JUMP"] = 80] = "LOAD_IMM_JUMP";
17493
- Instruction[Instruction["BRANCH_EQ_IMM"] = 81] = "BRANCH_EQ_IMM";
17494
- Instruction[Instruction["BRANCH_NE_IMM"] = 82] = "BRANCH_NE_IMM";
17495
- Instruction[Instruction["BRANCH_LT_U_IMM"] = 83] = "BRANCH_LT_U_IMM";
17496
- Instruction[Instruction["BRANCH_LE_U_IMM"] = 84] = "BRANCH_LE_U_IMM";
17497
- Instruction[Instruction["BRANCH_GE_U_IMM"] = 85] = "BRANCH_GE_U_IMM";
17498
- Instruction[Instruction["BRANCH_GT_U_IMM"] = 86] = "BRANCH_GT_U_IMM";
17499
- Instruction[Instruction["BRANCH_LT_S_IMM"] = 87] = "BRANCH_LT_S_IMM";
17500
- Instruction[Instruction["BRANCH_LE_S_IMM"] = 88] = "BRANCH_LE_S_IMM";
17501
- Instruction[Instruction["BRANCH_GE_S_IMM"] = 89] = "BRANCH_GE_S_IMM";
17502
- Instruction[Instruction["BRANCH_GT_S_IMM"] = 90] = "BRANCH_GT_S_IMM";
17503
- Instruction[Instruction["MOVE_REG"] = 100] = "MOVE_REG";
17504
- Instruction[Instruction["SBRK"] = 101] = "SBRK";
17505
- Instruction[Instruction["COUNT_SET_BITS_64"] = 102] = "COUNT_SET_BITS_64";
17506
- Instruction[Instruction["COUNT_SET_BITS_32"] = 103] = "COUNT_SET_BITS_32";
17507
- Instruction[Instruction["LEADING_ZERO_BITS_64"] = 104] = "LEADING_ZERO_BITS_64";
17508
- Instruction[Instruction["LEADING_ZERO_BITS_32"] = 105] = "LEADING_ZERO_BITS_32";
17509
- Instruction[Instruction["TRAILING_ZERO_BITS_64"] = 106] = "TRAILING_ZERO_BITS_64";
17510
- Instruction[Instruction["TRAILING_ZERO_BITS_32"] = 107] = "TRAILING_ZERO_BITS_32";
17511
- Instruction[Instruction["SIGN_EXTEND_8"] = 108] = "SIGN_EXTEND_8";
17512
- Instruction[Instruction["SIGN_EXTEND_16"] = 109] = "SIGN_EXTEND_16";
17513
- Instruction[Instruction["ZERO_EXTEND_16"] = 110] = "ZERO_EXTEND_16";
17514
- Instruction[Instruction["REVERSE_BYTES"] = 111] = "REVERSE_BYTES";
17515
- Instruction[Instruction["STORE_IND_U8"] = 120] = "STORE_IND_U8";
17516
- Instruction[Instruction["STORE_IND_U16"] = 121] = "STORE_IND_U16";
17517
- Instruction[Instruction["STORE_IND_U32"] = 122] = "STORE_IND_U32";
17518
- Instruction[Instruction["STORE_IND_U64"] = 123] = "STORE_IND_U64";
17519
- Instruction[Instruction["LOAD_IND_U8"] = 124] = "LOAD_IND_U8";
17520
- Instruction[Instruction["LOAD_IND_I8"] = 125] = "LOAD_IND_I8";
17521
- Instruction[Instruction["LOAD_IND_U16"] = 126] = "LOAD_IND_U16";
17522
- Instruction[Instruction["LOAD_IND_I16"] = 127] = "LOAD_IND_I16";
17523
- Instruction[Instruction["LOAD_IND_U32"] = 128] = "LOAD_IND_U32";
17524
- Instruction[Instruction["LOAD_IND_I32"] = 129] = "LOAD_IND_I32";
17525
- Instruction[Instruction["LOAD_IND_U64"] = 130] = "LOAD_IND_U64";
17526
- Instruction[Instruction["ADD_IMM_32"] = 131] = "ADD_IMM_32";
17527
- Instruction[Instruction["AND_IMM"] = 132] = "AND_IMM";
17528
- Instruction[Instruction["XOR_IMM"] = 133] = "XOR_IMM";
17529
- Instruction[Instruction["OR_IMM"] = 134] = "OR_IMM";
17530
- Instruction[Instruction["MUL_IMM_32"] = 135] = "MUL_IMM_32";
17531
- Instruction[Instruction["SET_LT_U_IMM"] = 136] = "SET_LT_U_IMM";
17532
- Instruction[Instruction["SET_LT_S_IMM"] = 137] = "SET_LT_S_IMM";
17533
- Instruction[Instruction["SHLO_L_IMM_32"] = 138] = "SHLO_L_IMM_32";
17534
- Instruction[Instruction["SHLO_R_IMM_32"] = 139] = "SHLO_R_IMM_32";
17535
- Instruction[Instruction["SHAR_R_IMM_32"] = 140] = "SHAR_R_IMM_32";
17536
- Instruction[Instruction["NEG_ADD_IMM_32"] = 141] = "NEG_ADD_IMM_32";
17537
- Instruction[Instruction["SET_GT_U_IMM"] = 142] = "SET_GT_U_IMM";
17538
- Instruction[Instruction["SET_GT_S_IMM"] = 143] = "SET_GT_S_IMM";
17539
- Instruction[Instruction["SHLO_L_IMM_ALT_32"] = 144] = "SHLO_L_IMM_ALT_32";
17540
- Instruction[Instruction["SHLO_R_IMM_ALT_32"] = 145] = "SHLO_R_IMM_ALT_32";
17541
- Instruction[Instruction["SHAR_R_IMM_ALT_32"] = 146] = "SHAR_R_IMM_ALT_32";
17542
- Instruction[Instruction["CMOV_IZ_IMM"] = 147] = "CMOV_IZ_IMM";
17543
- Instruction[Instruction["CMOV_NZ_IMM"] = 148] = "CMOV_NZ_IMM";
17544
- Instruction[Instruction["ADD_IMM_64"] = 149] = "ADD_IMM_64";
17545
- Instruction[Instruction["MUL_IMM_64"] = 150] = "MUL_IMM_64";
17546
- Instruction[Instruction["SHLO_L_IMM_64"] = 151] = "SHLO_L_IMM_64";
17547
- Instruction[Instruction["SHLO_R_IMM_64"] = 152] = "SHLO_R_IMM_64";
17548
- Instruction[Instruction["SHAR_R_IMM_64"] = 153] = "SHAR_R_IMM_64";
17549
- Instruction[Instruction["NEG_ADD_IMM_64"] = 154] = "NEG_ADD_IMM_64";
17550
- Instruction[Instruction["SHLO_L_IMM_ALT_64"] = 155] = "SHLO_L_IMM_ALT_64";
17551
- Instruction[Instruction["SHLO_R_IMM_ALT_64"] = 156] = "SHLO_R_IMM_ALT_64";
17552
- Instruction[Instruction["SHAR_R_IMM_ALT_64"] = 157] = "SHAR_R_IMM_ALT_64";
17553
- Instruction[Instruction["ROT_R_64_IMM"] = 158] = "ROT_R_64_IMM";
17554
- Instruction[Instruction["ROT_R_64_IMM_ALT"] = 159] = "ROT_R_64_IMM_ALT";
17555
- Instruction[Instruction["ROT_R_32_IMM"] = 160] = "ROT_R_32_IMM";
17556
- Instruction[Instruction["ROT_R_32_IMM_ALT"] = 161] = "ROT_R_32_IMM_ALT";
17557
- Instruction[Instruction["BRANCH_EQ"] = 170] = "BRANCH_EQ";
17558
- Instruction[Instruction["BRANCH_NE"] = 171] = "BRANCH_NE";
17559
- Instruction[Instruction["BRANCH_LT_U"] = 172] = "BRANCH_LT_U";
17560
- Instruction[Instruction["BRANCH_LT_S"] = 173] = "BRANCH_LT_S";
17561
- Instruction[Instruction["BRANCH_GE_U"] = 174] = "BRANCH_GE_U";
17562
- Instruction[Instruction["BRANCH_GE_S"] = 175] = "BRANCH_GE_S";
17563
- Instruction[Instruction["LOAD_IMM_JUMP_IND"] = 180] = "LOAD_IMM_JUMP_IND";
17564
- Instruction[Instruction["ADD_32"] = 190] = "ADD_32";
17565
- Instruction[Instruction["SUB_32"] = 191] = "SUB_32";
17566
- Instruction[Instruction["MUL_32"] = 192] = "MUL_32";
17567
- Instruction[Instruction["DIV_U_32"] = 193] = "DIV_U_32";
17568
- Instruction[Instruction["DIV_S_32"] = 194] = "DIV_S_32";
17569
- Instruction[Instruction["REM_U_32"] = 195] = "REM_U_32";
17570
- Instruction[Instruction["REM_S_32"] = 196] = "REM_S_32";
17571
- Instruction[Instruction["SHLO_L_32"] = 197] = "SHLO_L_32";
17572
- Instruction[Instruction["SHLO_R_32"] = 198] = "SHLO_R_32";
17573
- Instruction[Instruction["SHAR_R_32"] = 199] = "SHAR_R_32";
17574
- Instruction[Instruction["ADD_64"] = 200] = "ADD_64";
17575
- Instruction[Instruction["SUB_64"] = 201] = "SUB_64";
17576
- Instruction[Instruction["MUL_64"] = 202] = "MUL_64";
17577
- Instruction[Instruction["DIV_U_64"] = 203] = "DIV_U_64";
17578
- Instruction[Instruction["DIV_S_64"] = 204] = "DIV_S_64";
17579
- Instruction[Instruction["REM_U_64"] = 205] = "REM_U_64";
17580
- Instruction[Instruction["REM_S_64"] = 206] = "REM_S_64";
17581
- Instruction[Instruction["SHLO_L_64"] = 207] = "SHLO_L_64";
17582
- Instruction[Instruction["SHLO_R_64"] = 208] = "SHLO_R_64";
17583
- Instruction[Instruction["SHAR_R_64"] = 209] = "SHAR_R_64";
17584
- Instruction[Instruction["AND"] = 210] = "AND";
17585
- Instruction[Instruction["XOR"] = 211] = "XOR";
17586
- Instruction[Instruction["OR"] = 212] = "OR";
17587
- Instruction[Instruction["MUL_UPPER_S_S"] = 213] = "MUL_UPPER_S_S";
17588
- Instruction[Instruction["MUL_UPPER_U_U"] = 214] = "MUL_UPPER_U_U";
17589
- Instruction[Instruction["MUL_UPPER_S_U"] = 215] = "MUL_UPPER_S_U";
17590
- Instruction[Instruction["SET_LT_U"] = 216] = "SET_LT_U";
17591
- Instruction[Instruction["SET_LT_S"] = 217] = "SET_LT_S";
17592
- Instruction[Instruction["CMOV_IZ"] = 218] = "CMOV_IZ";
17593
- Instruction[Instruction["CMOV_NZ"] = 219] = "CMOV_NZ";
17594
- Instruction[Instruction["ROT_L_64"] = 220] = "ROT_L_64";
17595
- Instruction[Instruction["ROT_L_32"] = 221] = "ROT_L_32";
17596
- Instruction[Instruction["ROT_R_64"] = 222] = "ROT_R_64";
17597
- Instruction[Instruction["ROT_R_32"] = 223] = "ROT_R_32";
17598
- Instruction[Instruction["AND_INV"] = 224] = "AND_INV";
17599
- Instruction[Instruction["OR_INV"] = 225] = "OR_INV";
17600
- Instruction[Instruction["XNOR"] = 226] = "XNOR";
17601
- Instruction[Instruction["MAX"] = 227] = "MAX";
17602
- Instruction[Instruction["MAX_U"] = 228] = "MAX_U";
17603
- Instruction[Instruction["MIN"] = 229] = "MIN";
17604
- Instruction[Instruction["MIN_U"] = 230] = "MIN_U";
17605
- })(instruction_Instruction || (instruction_Instruction = {}));
17606
- const HIGHEST_INSTRUCTION_NUMBER = instruction_Instruction.MIN_U;
17607
-
17608
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/args-decoder/instruction-argument-type-map.ts
17609
-
17610
-
17611
- const instruction_argument_type_map_instructionArgumentTypeMap = (() => {
17612
- const instructionArgumentTypeMap = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
17613
- instructionArgumentTypeMap[instruction_Instruction.TRAP] = argument_type_ArgumentType.NO_ARGUMENTS;
17614
- instructionArgumentTypeMap[instruction_Instruction.FALLTHROUGH] = argument_type_ArgumentType.NO_ARGUMENTS;
17615
- instructionArgumentTypeMap[instruction_Instruction.ECALLI] = argument_type_ArgumentType.ONE_IMMEDIATE;
17616
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_64] = argument_type_ArgumentType.ONE_REGISTER_ONE_EXTENDED_WIDTH_IMMEDIATE;
17617
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U8] = argument_type_ArgumentType.TWO_IMMEDIATES;
17618
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U16] = argument_type_ArgumentType.TWO_IMMEDIATES;
17619
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U32] = argument_type_ArgumentType.TWO_IMMEDIATES;
17620
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_U64] = argument_type_ArgumentType.TWO_IMMEDIATES;
17621
- instructionArgumentTypeMap[instruction_Instruction.JUMP] = argument_type_ArgumentType.ONE_OFFSET;
17622
- instructionArgumentTypeMap[instruction_Instruction.JUMP_IND] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17623
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17624
- instructionArgumentTypeMap[instruction_Instruction.LOAD_U8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17625
- instructionArgumentTypeMap[instruction_Instruction.LOAD_I8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17626
- instructionArgumentTypeMap[instruction_Instruction.LOAD_U16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17627
- instructionArgumentTypeMap[instruction_Instruction.LOAD_I16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17628
- instructionArgumentTypeMap[instruction_Instruction.LOAD_U32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17629
- instructionArgumentTypeMap[instruction_Instruction.LOAD_I32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17630
- instructionArgumentTypeMap[instruction_Instruction.LOAD_U64] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17631
- instructionArgumentTypeMap[instruction_Instruction.STORE_U8] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17632
- instructionArgumentTypeMap[instruction_Instruction.STORE_U16] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17633
- instructionArgumentTypeMap[instruction_Instruction.STORE_U32] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17634
- instructionArgumentTypeMap[instruction_Instruction.STORE_U64] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE;
17635
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U8] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
17636
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U16] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
17637
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U32] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
17638
- instructionArgumentTypeMap[instruction_Instruction.STORE_IMM_IND_U64] = argument_type_ArgumentType.ONE_REGISTER_TWO_IMMEDIATES;
17639
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_JUMP] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17640
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_EQ_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17641
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_NE_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17642
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17643
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LE_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17644
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17645
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GT_U_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17646
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17647
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LE_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17648
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17649
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GT_S_IMM] = argument_type_ArgumentType.ONE_REGISTER_ONE_IMMEDIATE_ONE_OFFSET;
17650
- instructionArgumentTypeMap[instruction_Instruction.MOVE_REG] = argument_type_ArgumentType.TWO_REGISTERS;
17651
- instructionArgumentTypeMap[instruction_Instruction.SBRK] = argument_type_ArgumentType.TWO_REGISTERS;
17652
- instructionArgumentTypeMap[instruction_Instruction.COUNT_SET_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
17653
- instructionArgumentTypeMap[instruction_Instruction.COUNT_SET_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
17654
- instructionArgumentTypeMap[instruction_Instruction.LEADING_ZERO_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
17655
- instructionArgumentTypeMap[instruction_Instruction.LEADING_ZERO_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
17656
- instructionArgumentTypeMap[instruction_Instruction.TRAILING_ZERO_BITS_64] = argument_type_ArgumentType.TWO_REGISTERS;
17657
- instructionArgumentTypeMap[instruction_Instruction.TRAILING_ZERO_BITS_32] = argument_type_ArgumentType.TWO_REGISTERS;
17658
- instructionArgumentTypeMap[instruction_Instruction.SIGN_EXTEND_8] = argument_type_ArgumentType.TWO_REGISTERS;
17659
- instructionArgumentTypeMap[instruction_Instruction.SIGN_EXTEND_16] = argument_type_ArgumentType.TWO_REGISTERS;
17660
- instructionArgumentTypeMap[instruction_Instruction.ZERO_EXTEND_16] = argument_type_ArgumentType.TWO_REGISTERS;
17661
- instructionArgumentTypeMap[instruction_Instruction.REVERSE_BYTES] = argument_type_ArgumentType.TWO_REGISTERS;
17662
- instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17663
- instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17664
- instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17665
- instructionArgumentTypeMap[instruction_Instruction.STORE_IND_U64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17666
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17667
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I8] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17668
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17669
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I16] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17670
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17671
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_I32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17672
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IND_U64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17673
- instructionArgumentTypeMap[instruction_Instruction.ADD_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17674
- instructionArgumentTypeMap[instruction_Instruction.ADD_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17675
- instructionArgumentTypeMap[instruction_Instruction.AND_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17676
- instructionArgumentTypeMap[instruction_Instruction.XOR_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17677
- instructionArgumentTypeMap[instruction_Instruction.OR_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17678
- instructionArgumentTypeMap[instruction_Instruction.MUL_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17679
- instructionArgumentTypeMap[instruction_Instruction.MUL_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17680
- instructionArgumentTypeMap[instruction_Instruction.SET_LT_U_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17681
- instructionArgumentTypeMap[instruction_Instruction.SET_LT_S_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17682
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17683
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17684
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17685
- instructionArgumentTypeMap[instruction_Instruction.NEG_ADD_IMM_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17686
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17687
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17688
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17689
- instructionArgumentTypeMap[instruction_Instruction.NEG_ADD_IMM_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17690
- instructionArgumentTypeMap[instruction_Instruction.SET_GT_U_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17691
- instructionArgumentTypeMap[instruction_Instruction.SET_GT_S_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17692
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17693
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17694
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_ALT_32] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17695
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17696
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17697
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_IMM_ALT_64] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17698
- instructionArgumentTypeMap[instruction_Instruction.CMOV_IZ_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17699
- instructionArgumentTypeMap[instruction_Instruction.CMOV_NZ_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17700
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_64_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17701
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_64_IMM_ALT] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17702
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_32_IMM] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17703
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_32_IMM_ALT] = argument_type_ArgumentType.TWO_REGISTERS_ONE_IMMEDIATE;
17704
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_EQ] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17705
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_NE] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17706
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_U] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17707
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_LT_S] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17708
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_U] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17709
- instructionArgumentTypeMap[instruction_Instruction.BRANCH_GE_S] = argument_type_ArgumentType.TWO_REGISTERS_ONE_OFFSET;
17710
- instructionArgumentTypeMap[instruction_Instruction.LOAD_IMM_JUMP_IND] = argument_type_ArgumentType.TWO_REGISTERS_TWO_IMMEDIATES;
17711
- instructionArgumentTypeMap[instruction_Instruction.ADD_32] = argument_type_ArgumentType.THREE_REGISTERS;
17712
- instructionArgumentTypeMap[instruction_Instruction.ADD_64] = argument_type_ArgumentType.THREE_REGISTERS;
17713
- instructionArgumentTypeMap[instruction_Instruction.SUB_32] = argument_type_ArgumentType.THREE_REGISTERS;
17714
- instructionArgumentTypeMap[instruction_Instruction.SUB_64] = argument_type_ArgumentType.THREE_REGISTERS;
17715
- instructionArgumentTypeMap[instruction_Instruction.AND] = argument_type_ArgumentType.THREE_REGISTERS;
17716
- instructionArgumentTypeMap[instruction_Instruction.XOR] = argument_type_ArgumentType.THREE_REGISTERS;
17717
- instructionArgumentTypeMap[instruction_Instruction.OR] = argument_type_ArgumentType.THREE_REGISTERS;
17718
- instructionArgumentTypeMap[instruction_Instruction.MUL_32] = argument_type_ArgumentType.THREE_REGISTERS;
17719
- instructionArgumentTypeMap[instruction_Instruction.MUL_64] = argument_type_ArgumentType.THREE_REGISTERS;
17720
- instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_S_S] = argument_type_ArgumentType.THREE_REGISTERS;
17721
- instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_U_U] = argument_type_ArgumentType.THREE_REGISTERS;
17722
- instructionArgumentTypeMap[instruction_Instruction.MUL_UPPER_S_U] = argument_type_ArgumentType.THREE_REGISTERS;
17723
- instructionArgumentTypeMap[instruction_Instruction.DIV_U_32] = argument_type_ArgumentType.THREE_REGISTERS;
17724
- instructionArgumentTypeMap[instruction_Instruction.DIV_S_32] = argument_type_ArgumentType.THREE_REGISTERS;
17725
- instructionArgumentTypeMap[instruction_Instruction.REM_U_32] = argument_type_ArgumentType.THREE_REGISTERS;
17726
- instructionArgumentTypeMap[instruction_Instruction.REM_S_32] = argument_type_ArgumentType.THREE_REGISTERS;
17727
- instructionArgumentTypeMap[instruction_Instruction.DIV_U_64] = argument_type_ArgumentType.THREE_REGISTERS;
17728
- instructionArgumentTypeMap[instruction_Instruction.DIV_S_64] = argument_type_ArgumentType.THREE_REGISTERS;
17729
- instructionArgumentTypeMap[instruction_Instruction.REM_U_64] = argument_type_ArgumentType.THREE_REGISTERS;
17730
- instructionArgumentTypeMap[instruction_Instruction.REM_S_64] = argument_type_ArgumentType.THREE_REGISTERS;
17731
- instructionArgumentTypeMap[instruction_Instruction.SET_LT_U] = argument_type_ArgumentType.THREE_REGISTERS;
17732
- instructionArgumentTypeMap[instruction_Instruction.SET_LT_S] = argument_type_ArgumentType.THREE_REGISTERS;
17733
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_32] = argument_type_ArgumentType.THREE_REGISTERS;
17734
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
17735
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
17736
- instructionArgumentTypeMap[instruction_Instruction.SHLO_L_64] = argument_type_ArgumentType.THREE_REGISTERS;
17737
- instructionArgumentTypeMap[instruction_Instruction.SHLO_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
17738
- instructionArgumentTypeMap[instruction_Instruction.SHAR_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
17739
- instructionArgumentTypeMap[instruction_Instruction.CMOV_IZ] = argument_type_ArgumentType.THREE_REGISTERS;
17740
- instructionArgumentTypeMap[instruction_Instruction.CMOV_NZ] = argument_type_ArgumentType.THREE_REGISTERS;
17741
- instructionArgumentTypeMap[instruction_Instruction.ROT_L_64] = argument_type_ArgumentType.THREE_REGISTERS;
17742
- instructionArgumentTypeMap[instruction_Instruction.ROT_L_32] = argument_type_ArgumentType.THREE_REGISTERS;
17743
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_64] = argument_type_ArgumentType.THREE_REGISTERS;
17744
- instructionArgumentTypeMap[instruction_Instruction.ROT_R_32] = argument_type_ArgumentType.THREE_REGISTERS;
17745
- instructionArgumentTypeMap[instruction_Instruction.AND_INV] = argument_type_ArgumentType.THREE_REGISTERS;
17746
- instructionArgumentTypeMap[instruction_Instruction.OR_INV] = argument_type_ArgumentType.THREE_REGISTERS;
17747
- instructionArgumentTypeMap[instruction_Instruction.XNOR] = argument_type_ArgumentType.THREE_REGISTERS;
17748
- instructionArgumentTypeMap[instruction_Instruction.MAX] = argument_type_ArgumentType.THREE_REGISTERS;
17749
- instructionArgumentTypeMap[instruction_Instruction.MAX_U] = argument_type_ArgumentType.THREE_REGISTERS;
17750
- instructionArgumentTypeMap[instruction_Instruction.MIN] = argument_type_ArgumentType.THREE_REGISTERS;
17751
- instructionArgumentTypeMap[instruction_Instruction.MIN_U] = argument_type_ArgumentType.THREE_REGISTERS;
17752
- return instructionArgumentTypeMap;
17753
- })();
17535
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/readable-page.ts
17754
17536
 
17755
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/assemblify.ts
17756
17537
 
17757
17538
 
17758
- const instructionsWithoutArgs = [
17759
- [instruction_Instruction.TRAP, 1],
17760
- [instruction_Instruction.FALLTHROUGH, 1],
17761
- ];
17762
- const instructionsWithOneImmediate = [[instruction_Instruction.ECALLI, 1]];
17763
- const instructionsWithOneRegisterAndOneExtendedWidthImmediate = [[instruction_Instruction.LOAD_IMM_64, 1]];
17764
- const instructionsWithTwoImmediates = [
17765
- [instruction_Instruction.STORE_IMM_U8, 1],
17766
- [instruction_Instruction.STORE_IMM_U16, 1],
17767
- [instruction_Instruction.STORE_IMM_U32, 1],
17768
- [instruction_Instruction.STORE_IMM_U64, 1],
17769
- ];
17770
- const instructionsWithOneOffset = [[instruction_Instruction.JUMP, 1]];
17771
- const instructionsWithOneRegisterAndOneImmediate = [
17772
- [instruction_Instruction.JUMP_IND, 1],
17773
- [instruction_Instruction.LOAD_IMM, 1],
17774
- [instruction_Instruction.LOAD_U8, 1],
17775
- [instruction_Instruction.LOAD_I8, 1],
17776
- [instruction_Instruction.LOAD_U16, 1],
17777
- [instruction_Instruction.LOAD_I16, 1],
17778
- [instruction_Instruction.LOAD_U32, 1],
17779
- [instruction_Instruction.LOAD_I32, 1],
17780
- [instruction_Instruction.LOAD_U64, 1],
17781
- [instruction_Instruction.STORE_U8, 1],
17782
- [instruction_Instruction.STORE_U16, 1],
17783
- [instruction_Instruction.STORE_U32, 1],
17784
- [instruction_Instruction.STORE_U64, 1],
17785
- ];
17786
- const instructionsWithOneRegisterAndTwoImmediate = [
17787
- [instruction_Instruction.STORE_IMM_IND_U8, 1],
17788
- [instruction_Instruction.STORE_IMM_IND_U16, 1],
17789
- [instruction_Instruction.STORE_IMM_IND_U32, 1],
17790
- [instruction_Instruction.STORE_IMM_IND_U64, 1],
17791
- ];
17792
- const instructionsWithOneRegisterOneImmediateAndOneOffset = [
17793
- [instruction_Instruction.LOAD_IMM_JUMP, 1],
17794
- [instruction_Instruction.BRANCH_EQ_IMM, 1],
17795
- [instruction_Instruction.BRANCH_NE_IMM, 1],
17796
- [instruction_Instruction.BRANCH_LT_U_IMM, 1],
17797
- [instruction_Instruction.BRANCH_LE_U_IMM, 1],
17798
- [instruction_Instruction.BRANCH_GE_U_IMM, 1],
17799
- [instruction_Instruction.BRANCH_GT_U_IMM, 1],
17800
- [instruction_Instruction.BRANCH_LT_S_IMM, 1],
17801
- [instruction_Instruction.BRANCH_LE_S_IMM, 1],
17802
- [instruction_Instruction.BRANCH_GE_S_IMM, 1],
17803
- [instruction_Instruction.BRANCH_GT_S_IMM, 1],
17804
- ];
17805
- const instructionsWithTwoRegisters = [
17806
- [instruction_Instruction.MOVE_REG, 1],
17807
- [instruction_Instruction.SBRK, 1],
17808
- [instruction_Instruction.COUNT_SET_BITS_64, 1],
17809
- [instruction_Instruction.COUNT_SET_BITS_32, 1],
17810
- [instruction_Instruction.LEADING_ZERO_BITS_64, 1],
17811
- [instruction_Instruction.LEADING_ZERO_BITS_32, 1],
17812
- [instruction_Instruction.TRAILING_ZERO_BITS_64, 1],
17813
- [instruction_Instruction.TRAILING_ZERO_BITS_32, 1],
17814
- [instruction_Instruction.SIGN_EXTEND_8, 1],
17815
- [instruction_Instruction.SIGN_EXTEND_16, 1],
17816
- [instruction_Instruction.ZERO_EXTEND_16, 1],
17817
- [instruction_Instruction.REVERSE_BYTES, 1],
17818
- ];
17819
- const instructionsWithTwoRegistersAndOneImmediate = [
17820
- [instruction_Instruction.STORE_IND_U8, 1],
17821
- [instruction_Instruction.STORE_IND_U16, 1],
17822
- [instruction_Instruction.STORE_IND_U32, 1],
17823
- [instruction_Instruction.STORE_IND_U64, 1],
17824
- [instruction_Instruction.LOAD_IND_U8, 1],
17825
- [instruction_Instruction.LOAD_IND_I8, 1],
17826
- [instruction_Instruction.LOAD_IND_U16, 1],
17827
- [instruction_Instruction.LOAD_IND_I16, 1],
17828
- [instruction_Instruction.LOAD_IND_U32, 1],
17829
- [instruction_Instruction.LOAD_IND_I32, 1],
17830
- [instruction_Instruction.LOAD_IND_U64, 1],
17831
- [instruction_Instruction.ADD_IMM_32, 1],
17832
- [instruction_Instruction.AND_IMM, 1],
17833
- [instruction_Instruction.XOR_IMM, 1],
17834
- [instruction_Instruction.OR_IMM, 1],
17835
- [instruction_Instruction.MUL_IMM_32, 1],
17836
- [instruction_Instruction.SET_LT_U_IMM, 1],
17837
- [instruction_Instruction.SET_LT_S_IMM, 1],
17838
- [instruction_Instruction.SHLO_L_IMM_32, 1],
17839
- [instruction_Instruction.SHLO_R_IMM_32, 1],
17840
- [instruction_Instruction.SHAR_R_IMM_32, 1],
17841
- [instruction_Instruction.NEG_ADD_IMM_32, 1],
17842
- [instruction_Instruction.SET_GT_U_IMM, 1],
17843
- [instruction_Instruction.SET_GT_S_IMM, 1],
17844
- [instruction_Instruction.SHLO_L_IMM_ALT_32, 1],
17845
- [instruction_Instruction.SHLO_R_IMM_ALT_32, 1],
17846
- [instruction_Instruction.SHAR_R_IMM_ALT_32, 1],
17847
- [instruction_Instruction.CMOV_IZ_IMM, 1],
17848
- [instruction_Instruction.CMOV_NZ_IMM, 1],
17849
- [instruction_Instruction.ADD_IMM_64, 1],
17850
- [instruction_Instruction.MUL_IMM_64, 1],
17851
- [instruction_Instruction.SHLO_L_IMM_64, 1],
17852
- [instruction_Instruction.SHLO_R_IMM_64, 1],
17853
- [instruction_Instruction.SHAR_R_IMM_64, 1],
17854
- [instruction_Instruction.NEG_ADD_IMM_64, 1],
17855
- [instruction_Instruction.SHLO_L_IMM_ALT_64, 1],
17856
- [instruction_Instruction.SHLO_R_IMM_ALT_64, 1],
17857
- [instruction_Instruction.SHAR_R_IMM_ALT_64, 1],
17858
- [instruction_Instruction.ROT_R_64_IMM, 1],
17859
- [instruction_Instruction.ROT_R_64_IMM_ALT, 1],
17860
- [instruction_Instruction.ROT_R_32_IMM, 1],
17861
- [instruction_Instruction.ROT_R_32_IMM_ALT, 1],
17862
- ];
17863
- const instructionsWithTwoRegistersAndOneOffset = [
17864
- [instruction_Instruction.BRANCH_EQ, 1],
17865
- [instruction_Instruction.BRANCH_NE, 1],
17866
- [instruction_Instruction.BRANCH_LT_U, 1],
17867
- [instruction_Instruction.BRANCH_LT_S, 1],
17868
- [instruction_Instruction.BRANCH_GE_U, 1],
17869
- [instruction_Instruction.BRANCH_GE_S, 1],
17870
- ];
17871
- const instructionWithTwoRegistersAndTwoImmediates = [[instruction_Instruction.LOAD_IMM_JUMP_IND, 1]];
17872
- const instructionsWithThreeRegisters = [
17873
- [instruction_Instruction.ADD_32, 1],
17874
- [instruction_Instruction.SUB_32, 1],
17875
- [instruction_Instruction.MUL_32, 1],
17876
- [instruction_Instruction.DIV_U_32, 1],
17877
- [instruction_Instruction.DIV_S_32, 1],
17878
- [instruction_Instruction.REM_U_32, 1],
17879
- [instruction_Instruction.REM_S_32, 1],
17880
- [instruction_Instruction.SHLO_L_32, 1],
17881
- [instruction_Instruction.SHLO_R_32, 1],
17882
- [instruction_Instruction.SHAR_R_32, 1],
17883
- [instruction_Instruction.ADD_64, 1],
17884
- [instruction_Instruction.SUB_64, 1],
17885
- [instruction_Instruction.MUL_64, 1],
17886
- [instruction_Instruction.DIV_U_64, 1],
17887
- [instruction_Instruction.DIV_S_64, 1],
17888
- [instruction_Instruction.REM_U_64, 1],
17889
- [instruction_Instruction.REM_S_64, 1],
17890
- [instruction_Instruction.SHLO_L_64, 1],
17891
- [instruction_Instruction.SHLO_R_64, 1],
17892
- [instruction_Instruction.SHAR_R_64, 1],
17893
- [instruction_Instruction.AND, 1],
17894
- [instruction_Instruction.XOR, 1],
17895
- [instruction_Instruction.OR, 1],
17896
- [instruction_Instruction.MUL_UPPER_S_S, 1],
17897
- [instruction_Instruction.MUL_UPPER_U_U, 1],
17898
- [instruction_Instruction.MUL_UPPER_S_U, 1],
17899
- [instruction_Instruction.SET_LT_U, 1],
17900
- [instruction_Instruction.SET_LT_S, 1],
17901
- [instruction_Instruction.CMOV_IZ, 1],
17902
- [instruction_Instruction.CMOV_NZ, 1],
17903
- [instruction_Instruction.ROT_L_64, 1],
17904
- [instruction_Instruction.ROT_L_32, 1],
17905
- [instruction_Instruction.ROT_R_64, 1],
17906
- [instruction_Instruction.ROT_R_32, 1],
17907
- [instruction_Instruction.AND_INV, 1],
17908
- [instruction_Instruction.OR_INV, 1],
17909
- [instruction_Instruction.XNOR, 1],
17910
- [instruction_Instruction.MAX, 1],
17911
- [instruction_Instruction.MAX_U, 1],
17912
- [instruction_Instruction.MIN, 1],
17913
- [instruction_Instruction.MIN_U, 1],
17914
- ];
17915
- const instructions = [
17916
- ...instructionsWithoutArgs,
17917
- ...instructionsWithOneImmediate,
17918
- ...instructionsWithOneRegisterAndOneExtendedWidthImmediate,
17919
- ...instructionsWithTwoImmediates,
17920
- ...instructionsWithOneOffset,
17921
- ...instructionsWithOneRegisterAndOneImmediate,
17922
- ...instructionsWithOneRegisterAndTwoImmediate,
17923
- ...instructionsWithOneRegisterOneImmediateAndOneOffset,
17924
- ...instructionsWithTwoRegisters,
17925
- ...instructionsWithTwoRegistersAndOneImmediate,
17926
- ...instructionsWithTwoRegistersAndOneOffset,
17927
- ...instructionWithTwoRegistersAndTwoImmediates,
17928
- ...instructionsWithThreeRegisters,
17929
- ];
17930
- const createOpCodeEntry = ([byte, gas]) => [byte, { gas: tryAsSmallGas(gas) }];
17931
- const byteToOpCodeMap = instructions.reduce((acc, instruction) => {
17932
- const [byte, opCode] = createOpCodeEntry(instruction);
17933
- acc[byte] = opCode;
17934
- return acc;
17935
- }, {});
17936
- function assemblify_assemblify(program, mask) {
17937
- return program.reduce((acc, byte, index) => {
17938
- if (mask.isInstruction(index)) {
17939
- acc.push([Instruction[byte]]);
17539
+
17540
+ class readable_page_ReadablePage extends MemoryPage {
17541
+ data;
17542
+ constructor(pageNumber, data) {
17543
+ super(pageNumber);
17544
+ this.data = data;
17545
+ }
17546
+ loadInto(result, startIndex, length) {
17547
+ const endIndex = startIndex + length;
17548
+ if (endIndex > memory_consts_PAGE_SIZE) {
17549
+ return result_Result.error(errors_PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
17940
17550
  }
17941
- else {
17942
- acc[acc.length - 1].push(byte);
17551
+ const bytes = this.data.subarray(startIndex, endIndex);
17552
+ // we zero the bytes, since data might not yet be initialized at `endIndex`.
17553
+ result.fill(0, bytes.length, length);
17554
+ result.set(bytes);
17555
+ return result_Result.ok(result_OK);
17556
+ }
17557
+ storeFrom(_address, _data) {
17558
+ return result_Result.error(errors_PageFault.fromMemoryIndex(this.start, true), () => `Page fault: attempted to write to read-only page at ${this.start}`);
17559
+ }
17560
+ setData(pageIndex, data) {
17561
+ this.data.set(data, pageIndex);
17562
+ }
17563
+ isWriteable() {
17564
+ return false;
17565
+ }
17566
+ getPageDump() {
17567
+ return this.data;
17568
+ }
17569
+ }
17570
+
17571
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/writeable-page.ts
17572
+
17573
+
17574
+
17575
+
17576
+ class writeable_page_WriteablePage extends MemoryPage {
17577
+ buffer;
17578
+ view;
17579
+ constructor(pageNumber, initialData) {
17580
+ super(pageNumber);
17581
+ const dataLength = initialData?.length ?? 0;
17582
+ const initialPageLength = Math.min(memory_consts_PAGE_SIZE, Math.max(dataLength, MIN_ALLOCATION_LENGTH));
17583
+ this.buffer = new ArrayBuffer(initialPageLength, { maxByteLength: memory_consts_PAGE_SIZE });
17584
+ this.view = new Uint8Array(this.buffer);
17585
+ if (initialData !== undefined) {
17586
+ this.view.set(initialData);
17587
+ }
17588
+ }
17589
+ loadInto(result, startIndex, length) {
17590
+ const endIndex = startIndex + length;
17591
+ if (endIndex > memory_consts_PAGE_SIZE) {
17592
+ return result_Result.error(errors_PageFault.fromMemoryIndex(this.start + memory_consts_PAGE_SIZE), () => `Page fault: read beyond page boundary at ${this.start + memory_consts_PAGE_SIZE}`);
17593
+ }
17594
+ const bytes = this.view.subarray(startIndex, endIndex);
17595
+ // we zero the bytes, since the view might not yet be initialized at `endIndex`.
17596
+ result.fill(0, bytes.length, length);
17597
+ result.set(bytes);
17598
+ return result_Result.ok(result_OK);
17599
+ }
17600
+ storeFrom(startIndex, bytes) {
17601
+ if (this.buffer.byteLength < startIndex + bytes.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
17602
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, startIndex + bytes.length));
17603
+ this.buffer.resize(newLength);
17604
+ }
17605
+ this.view.set(bytes, startIndex);
17606
+ return result_Result.ok(result_OK);
17607
+ }
17608
+ setData(pageIndex, data) {
17609
+ if (this.buffer.byteLength < pageIndex + data.length && this.buffer.byteLength < memory_consts_PAGE_SIZE) {
17610
+ const newLength = Math.min(memory_consts_PAGE_SIZE, Math.max(MIN_ALLOCATION_LENGTH, pageIndex + data.length));
17611
+ this.buffer.resize(newLength);
17943
17612
  }
17944
- return acc;
17945
- }, []);
17613
+ this.view.set(data, pageIndex);
17614
+ }
17615
+ isWriteable() {
17616
+ return true;
17617
+ }
17618
+ getPageDump() {
17619
+ return this.view;
17620
+ }
17946
17621
  }
17947
17622
 
17948
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/is-termination-instruction.ts
17623
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/pages/index.ts
17949
17624
 
17950
- const is_termination_instruction_terminationInstructions = (() => {
17951
- const terminationInstructions = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
17952
- terminationInstructions.fill(false);
17953
- terminationInstructions[instruction_Instruction.TRAP] = true;
17954
- terminationInstructions[instruction_Instruction.FALLTHROUGH] = true;
17955
- terminationInstructions[instruction_Instruction.JUMP] = true;
17956
- terminationInstructions[instruction_Instruction.JUMP_IND] = true;
17957
- terminationInstructions[instruction_Instruction.LOAD_IMM_JUMP] = true;
17958
- terminationInstructions[instruction_Instruction.LOAD_IMM_JUMP_IND] = true;
17959
- terminationInstructions[instruction_Instruction.BRANCH_EQ] = true;
17960
- terminationInstructions[instruction_Instruction.BRANCH_NE] = true;
17961
- terminationInstructions[instruction_Instruction.BRANCH_GE_U] = true;
17962
- terminationInstructions[instruction_Instruction.BRANCH_GE_S] = true;
17963
- terminationInstructions[instruction_Instruction.BRANCH_LT_U] = true;
17964
- terminationInstructions[instruction_Instruction.BRANCH_LT_S] = true;
17965
- terminationInstructions[instruction_Instruction.BRANCH_EQ_IMM] = true;
17966
- terminationInstructions[instruction_Instruction.BRANCH_NE_IMM] = true;
17967
- terminationInstructions[instruction_Instruction.BRANCH_LT_U_IMM] = true;
17968
- terminationInstructions[instruction_Instruction.BRANCH_LT_S_IMM] = true;
17969
- terminationInstructions[instruction_Instruction.BRANCH_LE_U_IMM] = true;
17970
- terminationInstructions[instruction_Instruction.BRANCH_LE_S_IMM] = true;
17971
- terminationInstructions[instruction_Instruction.BRANCH_GE_U_IMM] = true;
17972
- terminationInstructions[instruction_Instruction.BRANCH_GE_S_IMM] = true;
17973
- terminationInstructions[instruction_Instruction.BRANCH_GT_U_IMM] = true;
17974
- terminationInstructions[instruction_Instruction.BRANCH_GT_S_IMM] = true;
17975
- return terminationInstructions;
17976
- })();
17977
17625
 
17978
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/basic-blocks.ts
17979
17626
 
17980
- class basic_blocks_BasicBlocks {
17981
- basicBlocks = new Set();
17982
- reset(code, mask) {
17983
- this.basicBlocks.clear();
17984
- this.basicBlocks.add(0);
17985
- const codeLength = code.length;
17986
- const isBasicBlockTermination = (index) => mask.isInstruction(index) && terminationInstructions[code[index]];
17987
- for (let i = 0; i < codeLength; i++) {
17988
- if (mask.isInstruction(i) && isBasicBlockTermination(i)) {
17989
- this.basicBlocks.add(i + 1 + mask.getNoOfBytesToNextInstruction(i + 1));
17627
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory.ts
17628
+
17629
+
17630
+
17631
+
17632
+
17633
+
17634
+
17635
+
17636
+
17637
+
17638
+
17639
+
17640
+ var AccessType;
17641
+ (function (AccessType) {
17642
+ AccessType[AccessType["READ"] = 0] = "READ";
17643
+ AccessType[AccessType["WRITE"] = 1] = "WRITE";
17644
+ })(AccessType || (AccessType = {}));
17645
+ const memory_logger = Logger.new(import.meta.filename, "pvm:mem");
17646
+ class memory_Memory {
17647
+ sbrkIndex;
17648
+ virtualSbrkIndex;
17649
+ endHeapIndex;
17650
+ memory;
17651
+ static fromInitialMemory(initialMemoryState) {
17652
+ return new memory_Memory(initialMemoryState?.sbrkIndex, initialMemoryState?.sbrkIndex, initialMemoryState?.endHeapIndex, initialMemoryState?.memory);
17653
+ }
17654
+ constructor(sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end), endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX), memory = new Map()) {
17655
+ this.sbrkIndex = sbrkIndex;
17656
+ this.virtualSbrkIndex = virtualSbrkIndex;
17657
+ this.endHeapIndex = endHeapIndex;
17658
+ this.memory = memory;
17659
+ }
17660
+ store(address, bytes) {
17661
+ return this.storeFrom(tryAsMemoryIndex(address), bytes);
17662
+ }
17663
+ read(address, output) {
17664
+ return this.loadInto(output, tryAsMemoryIndex(address));
17665
+ }
17666
+ reset() {
17667
+ this.sbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
17668
+ this.virtualSbrkIndex = tryAsSbrkIndex(RESERVED_MEMORY_RANGE.end);
17669
+ this.endHeapIndex = tryAsSbrkIndex(MAX_MEMORY_INDEX);
17670
+ this.memory = new Map(); // TODO [MaSi]: We should keep allocated pages somewhere and reuse it when it is possible
17671
+ }
17672
+ copyFrom(memory) {
17673
+ this.sbrkIndex = memory.sbrkIndex;
17674
+ this.virtualSbrkIndex = memory.virtualSbrkIndex;
17675
+ this.endHeapIndex = memory.endHeapIndex;
17676
+ this.memory = memory.memory;
17677
+ }
17678
+ storeFrom(address, bytes) {
17679
+ if (bytes.length === 0) {
17680
+ return Result.ok(OK);
17681
+ }
17682
+ memory_logger.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
17683
+ const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
17684
+ if (pagesResult.isError) {
17685
+ return Result.error(pagesResult.error, pagesResult.details);
17686
+ }
17687
+ const pages = pagesResult.ok;
17688
+ let currentPosition = address;
17689
+ let bytesLeft = bytes.length;
17690
+ for (const page of pages) {
17691
+ const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
17692
+ const bytesToWrite = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
17693
+ const sourceStartIndex = currentPosition - address;
17694
+ const source = bytes.subarray(sourceStartIndex, sourceStartIndex + bytesToWrite);
17695
+ page.storeFrom(pageStartIndex, source);
17696
+ currentPosition += bytesToWrite;
17697
+ bytesLeft -= bytesToWrite;
17698
+ }
17699
+ return Result.ok(OK);
17700
+ }
17701
+ getPages(startAddress, length, accessType) {
17702
+ if (length === 0) {
17703
+ return Result.ok([]);
17704
+ }
17705
+ const memoryRange = MemoryRange.fromStartAndLength(startAddress, length);
17706
+ const pageRange = PageRange.fromMemoryRange(memoryRange);
17707
+ const pages = [];
17708
+ for (const pageNumber of pageRange) {
17709
+ if (pageNumber < RESERVED_NUMBER_OF_PAGES) {
17710
+ return Result.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to access reserved page ${pageNumber}`);
17711
+ }
17712
+ const page = this.memory.get(pageNumber);
17713
+ if (page === undefined) {
17714
+ return Result.error(PageFault.fromPageNumber(pageNumber), () => `Page fault: page ${pageNumber} not allocated`);
17715
+ }
17716
+ if (accessType === AccessType.WRITE && !page.isWriteable()) {
17717
+ return Result.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to write to read-only page ${pageNumber}`);
17990
17718
  }
17719
+ pages.push(page);
17991
17720
  }
17721
+ return Result.ok(pages);
17992
17722
  }
17993
- isBeginningOfBasicBlock(index) {
17994
- return this.basicBlocks.has(index);
17723
+ /**
17724
+ * Read content of the memory at `[address, address + result.length)` and
17725
+ * write the result into the `result` buffer.
17726
+ *
17727
+ * Returns `null` if the data was read successfully or `PageFault` otherwise.
17728
+ */
17729
+ loadInto(result, startAddress) {
17730
+ if (result.length === 0) {
17731
+ return Result.ok(OK);
17732
+ }
17733
+ const pagesResult = this.getPages(startAddress, result.length, AccessType.READ);
17734
+ if (pagesResult.isError) {
17735
+ return Result.error(pagesResult.error, pagesResult.details);
17736
+ }
17737
+ const pages = pagesResult.ok;
17738
+ let currentPosition = startAddress;
17739
+ let bytesLeft = result.length;
17740
+ for (const page of pages) {
17741
+ const pageStartIndex = tryAsPageIndex(currentPosition % PAGE_SIZE);
17742
+ const bytesToRead = Math.min(PAGE_SIZE - pageStartIndex, bytesLeft);
17743
+ const destinationStartIndex = currentPosition - startAddress;
17744
+ const destination = result.subarray(destinationStartIndex);
17745
+ page.loadInto(destination, pageStartIndex, bytesToRead);
17746
+ currentPosition += bytesToRead;
17747
+ bytesLeft -= bytesToRead;
17748
+ }
17749
+ memory_logger.insane `MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`;
17750
+ return Result.ok(OK);
17751
+ }
17752
+ sbrk(length) {
17753
+ const currentSbrkIndex = this.sbrkIndex;
17754
+ const currentVirtualSbrkIndex = this.virtualSbrkIndex;
17755
+ // new sbrk index is bigger than 2 ** 32 or endHeapIndex
17756
+ if (MAX_MEMORY_INDEX < currentVirtualSbrkIndex + length || currentVirtualSbrkIndex + length > this.endHeapIndex) {
17757
+ throw new OutOfMemory();
17758
+ }
17759
+ const newVirtualSbrkIndex = tryAsSbrkIndex(this.virtualSbrkIndex + length);
17760
+ // no alllocation needed
17761
+ if (newVirtualSbrkIndex <= currentSbrkIndex) {
17762
+ this.virtualSbrkIndex = newVirtualSbrkIndex;
17763
+ return currentVirtualSbrkIndex;
17764
+ }
17765
+ // standard allocation using "Writeable" pages
17766
+ const newSbrkIndex = tryAsSbrkIndex(alignToPageSize(newVirtualSbrkIndex));
17767
+ // TODO [MaSi]: `getPageNumber` works incorrectly for SbrkIndex. Sbrk index should be changed to MemoryIndex
17768
+ const firstPageNumber = getPageNumber(currentSbrkIndex);
17769
+ const pagesToAllocate = (newSbrkIndex - currentSbrkIndex) / PAGE_SIZE;
17770
+ const rangeToAllocate = PageRange.fromStartAndLength(firstPageNumber, pagesToAllocate);
17771
+ for (const pageNumber of rangeToAllocate) {
17772
+ const page = new WriteablePage(pageNumber);
17773
+ this.memory.set(pageNumber, page);
17774
+ }
17775
+ this.virtualSbrkIndex = newVirtualSbrkIndex;
17776
+ this.sbrkIndex = newSbrkIndex;
17777
+ return currentVirtualSbrkIndex;
17778
+ }
17779
+ getPageDump(pageNumber) {
17780
+ const page = this.memory.get(pageNumber);
17781
+ return page?.getPageDump() ?? null;
17782
+ }
17783
+ getDirtyPages() {
17784
+ return this.memory.keys();
17995
17785
  }
17996
17786
  }
17997
17787
 
17998
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/basic-blocks/index.ts
17788
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/memory-builder.ts
17999
17789
 
18000
17790
 
18001
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/gas.ts
18002
17791
 
18003
17792
 
18004
- /** Create a new gas counter instance depending on the gas value. */
18005
- function gas_gasCounter(gas) {
18006
- return new GasCounterU64(tryAsU64(gas));
18007
- }
18008
- class GasCounterU64 {
18009
- gas;
18010
- initialGas;
18011
- constructor(gas) {
18012
- this.gas = gas;
18013
- this.initialGas = tryAsGas(gas);
17793
+
17794
+
17795
+
17796
+
17797
+
17798
+
17799
+ class memory_builder_MemoryBuilder {
17800
+ initialMemory = new Map();
17801
+ isFinalized = false;
17802
+ ensureNotFinalized() {
17803
+ if (this.isFinalized) {
17804
+ throw new FinalizedBuilderModification();
17805
+ }
18014
17806
  }
18015
- set(g) {
18016
- this.gas = tryAsU64(g);
17807
+ ensureNoReservedMemoryUsage(range) {
17808
+ if (range.overlapsWith(RESERVED_MEMORY_RANGE)) {
17809
+ throw new ReservedMemoryFault();
17810
+ }
17811
+ }
17812
+ /**
17813
+ * Create entire readable pages to handle the `[start, end)` range.
17814
+ *
17815
+ * Note that both `start` and `end` must be multiple of the `PAGE_SIZE`, i.e.
17816
+ * they need to be the start indices of the pages.
17817
+ *
17818
+ * The data passed will be placed at `start`, but might be shorter than the requested range,
17819
+ * prepend it with zeros if you don't wish to have it at the beginning of the page.
17820
+ */
17821
+ setReadablePages(start, end, data = new Uint8Array()) {
17822
+ this.ensureNotFinalized();
17823
+ check `${start < end} end has to be bigger than start`;
17824
+ check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
17825
+ check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
17826
+ check `${data.length <= end - start} the initial data is longer than address range`;
17827
+ const length = end - start;
17828
+ const range = MemoryRange.fromStartAndLength(start, length);
17829
+ this.ensureNoReservedMemoryUsage(range);
17830
+ const pages = Array.from(PageRange.fromMemoryRange(range));
17831
+ const noOfPages = pages.length;
17832
+ for (let i = 0; i < noOfPages; i++) {
17833
+ const pageNumber = pages[i];
17834
+ const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
17835
+ const page = new ReadablePage(pageNumber, dataChunk);
17836
+ this.initialMemory.set(pageNumber, page);
17837
+ }
17838
+ return this;
18017
17839
  }
18018
- get() {
18019
- return tryAsGas(this.gas);
17840
+ /**
17841
+ * Create entire writeable pages to handle the `[start, end)` range.
17842
+ *
17843
+ * Note that both `start` and `end` must be multiple of the `PAGE_SIZE`, i.e.
17844
+ * they need to be the start indices of the pages.
17845
+ *
17846
+ * The data passed will be placed at `start`, but might be shorter than the requested range,
17847
+ * prepend it with zeros if you don't wish to have it at the beginning of the page.
17848
+ */
17849
+ setWriteablePages(start, end, data = new Uint8Array()) {
17850
+ this.ensureNotFinalized();
17851
+ check `${start < end} end has to be bigger than start`;
17852
+ check `${start % PAGE_SIZE === 0} start needs to be a multiple of page size (${PAGE_SIZE})`;
17853
+ check `${end % PAGE_SIZE === 0} end needs to be a multiple of page size (${PAGE_SIZE})`;
17854
+ check `${data.length <= end - start} the initial data is longer than address range`;
17855
+ const length = end - start;
17856
+ const range = MemoryRange.fromStartAndLength(start, length);
17857
+ this.ensureNoReservedMemoryUsage(range);
17858
+ const pages = Array.from(PageRange.fromMemoryRange(range));
17859
+ const noOfPages = pages.length;
17860
+ for (let i = 0; i < noOfPages; i++) {
17861
+ const pageNumber = pages[i];
17862
+ const dataChunk = data.subarray(i * PAGE_SIZE, (i + 1) * PAGE_SIZE);
17863
+ const page = new WriteablePage(pageNumber, dataChunk);
17864
+ this.initialMemory.set(pageNumber, page);
17865
+ }
17866
+ return this;
18020
17867
  }
18021
- sub(g) {
18022
- const result = this.gas - tryAsU64(g);
18023
- if (result >= 0n) {
18024
- this.gas = tryAsU64(result);
18025
- return false;
17868
+ /**
17869
+ * This function can be useful when page map and initial memory data are provided separatelly.
17870
+ * You can use setWriteablePages/setReadablePages to create empty pages and then setData to fill them
17871
+ */
17872
+ setData(start, data) {
17873
+ this.ensureNotFinalized();
17874
+ const pageOffset = start % PAGE_SIZE;
17875
+ const remainingSpaceOnPage = PAGE_SIZE - pageOffset;
17876
+ check `${data.length <= remainingSpaceOnPage} The data has to fit into a single page.`;
17877
+ const length = data.length;
17878
+ const range = MemoryRange.fromStartAndLength(start, length);
17879
+ this.ensureNoReservedMemoryUsage(range);
17880
+ const pageNumber = getPageNumber(start);
17881
+ const page = this.initialMemory.get(pageNumber);
17882
+ if (page === undefined) {
17883
+ throw new PageNotExist();
18026
17884
  }
18027
- this.gas = tryAsU64(0n);
18028
- return true;
17885
+ const startPageIndex = tryAsPageIndex(start - page.start);
17886
+ page.setData(startPageIndex, data);
17887
+ return this;
18029
17888
  }
18030
- used() {
18031
- const gasConsumed = tryAsU64(this.initialGas) - this.gas;
18032
- // In we have less than zero left we assume that all gas has been consumed.
18033
- if (gasConsumed < 0) {
18034
- return this.initialGas;
17889
+ finalize(startHeapIndex, endHeapIndex) {
17890
+ check `
17891
+ ${startHeapIndex <= endHeapIndex}
17892
+ startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
17893
+ `;
17894
+ this.ensureNotFinalized();
17895
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
17896
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
17897
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
17898
+ for (const pageNumber of initializedPageNumbers) {
17899
+ if (heapPagesRange.isInRange(pageNumber)) {
17900
+ throw new IncorrectSbrkIndex();
17901
+ }
18035
17902
  }
18036
- return tryAsGas(gasConsumed);
17903
+ const memory = Memory.fromInitialMemory({
17904
+ memory: this.initialMemory,
17905
+ sbrkIndex: tryAsSbrkIndex(startHeapIndex),
17906
+ endHeapIndex,
17907
+ });
17908
+ this.isFinalized = true;
17909
+ return memory;
18037
17910
  }
18038
17911
  }
18039
17912
 
18040
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/instruction-gas-map.ts
17913
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/memory/index.ts
17914
+
18041
17915
 
18042
17916
 
18043
- const instruction_gas_map_instructionGasMap = (() => {
18044
- const instructionGasMap = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
18045
- for (let i = 0; i < HIGHEST_INSTRUCTION_NUMBER + 1; i++) {
18046
- const gas = byteToOpCodeMap[i]?.gas;
18047
- instructionGasMap[i] = gas;
18048
- }
18049
- return instructionGasMap;
18050
- })();
18051
17917
 
18052
17918
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-utils.ts
18053
17919
 
@@ -18522,6 +18388,92 @@ class load_ops_LoadOps {
18522
18388
  }
18523
18389
  }
18524
18390
 
18391
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/registers.ts
18392
+
18393
+
18394
+ const REGISTER_SIZE_SHIFT = 3; // x << 3 === x * 8
18395
+ const tryAsRegisterIndex = (index) => {
18396
+ check `${index >= 0 && index < NO_OF_REGISTERS} Incorrect register index: ${index}!`;
18397
+ return asOpaqueType(index);
18398
+ };
18399
+ class registers_Registers {
18400
+ bytes;
18401
+ asSigned;
18402
+ asUnsigned;
18403
+ constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS << REGISTER_SIZE_SHIFT)) {
18404
+ this.bytes = bytes;
18405
+ check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
18406
+ this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
18407
+ this.asUnsigned = new BigUint64Array(bytes.buffer, bytes.byteOffset);
18408
+ }
18409
+ getAllEncoded() {
18410
+ return this.bytes;
18411
+ }
18412
+ setAllEncoded(bytes) {
18413
+ check `${bytes.length === this.bytes.length} Incorrect size of input registers. Got: ${bytes.length}, need: ${this.bytes.length}`;
18414
+ this.bytes.set(bytes, 0);
18415
+ }
18416
+ static fromBytes(bytes) {
18417
+ check `${bytes.length === NO_OF_REGISTERS << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
18418
+ return new registers_Registers(bytes);
18419
+ }
18420
+ getBytesAsLittleEndian(index, len) {
18421
+ const offset = index << REGISTER_SIZE_SHIFT;
18422
+ return this.bytes.subarray(offset, offset + len);
18423
+ }
18424
+ copyFrom(regs) {
18425
+ const array = regs instanceof BigUint64Array ? regs : regs.asUnsigned;
18426
+ this.asUnsigned.set(array);
18427
+ }
18428
+ reset() {
18429
+ for (let i = 0; i < NO_OF_REGISTERS; i++) {
18430
+ this.asUnsigned[i] = 0n;
18431
+ }
18432
+ }
18433
+ getLowerU32(registerIndex) {
18434
+ return Number(this.asUnsigned[registerIndex] & 0xffffffffn);
18435
+ }
18436
+ getLowerI32(registerIndex) {
18437
+ return Number(this.getLowerU32(registerIndex)) >> 0;
18438
+ }
18439
+ setU32(registerIndex, value) {
18440
+ this.asUnsigned[registerIndex] = registers_signExtend32To64(value);
18441
+ }
18442
+ setI32(registerIndex, value) {
18443
+ this.asSigned[registerIndex] = registers_signExtend32To64(value);
18444
+ }
18445
+ getU64(registerIndex) {
18446
+ return this.asUnsigned[registerIndex];
18447
+ }
18448
+ getI64(registerIndex) {
18449
+ return this.asSigned[registerIndex];
18450
+ }
18451
+ setU64(registerIndex, value) {
18452
+ this.asUnsigned[registerIndex] = value;
18453
+ }
18454
+ setI64(registerIndex, value) {
18455
+ this.asSigned[registerIndex] = value;
18456
+ }
18457
+ getAllU64() {
18458
+ return this.asUnsigned;
18459
+ }
18460
+ }
18461
+ function registers_signExtend32To64(value) {
18462
+ // Convert to BigInt if the value is a number
18463
+ const bigValue = typeof value === "number" ? BigInt(value) : value;
18464
+ // Ensure the value is treated as a 32-bit integer
18465
+ const mask32 = BigInt(0xffffffff);
18466
+ const signBit = BigInt(0x80000000);
18467
+ const maskedValue = bigValue & mask32;
18468
+ // Check the sign bit and extend the sign if necessary
18469
+ if ((maskedValue & signBit) !== BigInt(0)) {
18470
+ // If the sign bit is set, extend with ones
18471
+ return maskedValue | ~mask32;
18472
+ }
18473
+ // If the sign bit is not set, return as is
18474
+ return maskedValue;
18475
+ }
18476
+
18525
18477
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-ops.ts
18526
18478
 
18527
18479
 
@@ -19517,6 +19469,63 @@ class two_regs_two_imms_dispatcher_TwoRegsTwoImmsDispatcher {
19517
19469
 
19518
19470
 
19519
19471
 
19472
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/program.ts
19473
+
19474
+
19475
+
19476
+
19477
+
19478
+ class program_Program {
19479
+ code;
19480
+ registers;
19481
+ memory;
19482
+ metadata;
19483
+ static fromSpi(blob, args, hasMetadata) {
19484
+ const { code: spiCode, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
19485
+ const { code, memory: rawMemory, registers } = decodeStandardProgram(spiCode, args);
19486
+ const regs = new Registers();
19487
+ regs.copyFrom(registers);
19488
+ const memoryBuilder = new MemoryBuilder();
19489
+ for (const { start, end, data } of rawMemory.readable) {
19490
+ const startIndex = tryAsMemoryIndex(start);
19491
+ const endIndex = tryAsMemoryIndex(end);
19492
+ memoryBuilder.setReadablePages(startIndex, endIndex, data ?? new Uint8Array());
19493
+ }
19494
+ for (const { start, end, data } of rawMemory.writeable) {
19495
+ const startIndex = tryAsMemoryIndex(start);
19496
+ const endIndex = tryAsMemoryIndex(end);
19497
+ memoryBuilder.setWriteablePages(startIndex, endIndex, data ?? new Uint8Array());
19498
+ }
19499
+ const heapStart = tryAsMemoryIndex(rawMemory.sbrkIndex);
19500
+ const heapEnd = tryAsSbrkIndex(rawMemory.heapEnd);
19501
+ const memory = memoryBuilder.finalize(heapStart, heapEnd);
19502
+ return new program_Program(code, regs, memory, metadata);
19503
+ }
19504
+ static fromGeneric(blob, hasMetadata) {
19505
+ const { code, metadata } = hasMetadata ? extractCodeAndMetadata(blob) : { code: blob };
19506
+ const regs = new Registers();
19507
+ const memory = new Memory();
19508
+ return new program_Program(code, regs, memory, metadata);
19509
+ }
19510
+ constructor(code, registers, memory, metadata = new Uint8Array()) {
19511
+ this.code = code;
19512
+ this.registers = registers;
19513
+ this.memory = memory;
19514
+ this.metadata = metadata;
19515
+ }
19516
+ }
19517
+ /**
19518
+ * A function that splits preimage into metadata and code.
19519
+ *
19520
+ * https://graypaper.fluffylabs.dev/#/cc517d7/109a01109a01?v=0.6.5
19521
+ */
19522
+ function extractCodeAndMetadata(blobWithMetadata) {
19523
+ const decoder = Decoder.fromBlob(blobWithMetadata);
19524
+ const metadata = decoder.bytesBlob().raw;
19525
+ const code = decoder.remainingBytes().raw;
19526
+ return { metadata, code };
19527
+ }
19528
+
19520
19529
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/program-decoder/jump-table.ts
19521
19530
 
19522
19531
  class jump_table_JumpTable {
@@ -19709,8 +19718,8 @@ class interpreter_Interpreter {
19709
19718
  this.oneImmDispatcher = new OneImmDispatcher(hostCallOps);
19710
19719
  this.oneRegOneExtImmDispatcher = new OneRegOneExtImmDispatcher(loadOps);
19711
19720
  }
19712
- resetJam(program, args, pc, gas) {
19713
- const p = Program.fromSpi(program, args, true);
19721
+ resetJam(program, args, pc, gas, hasMetadata = true) {
19722
+ const p = Program.fromSpi(program, args, hasMetadata);
19714
19723
  this.resetGeneric(p.code, pc, gas, p.registers, p.memory);
19715
19724
  }
19716
19725
  resetGeneric(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
@@ -19897,6 +19906,9 @@ class DebuggerAdapter {
19897
19906
  constructor(useSbrkGas = false) {
19898
19907
  this.pvm = new Interpreter({ useSbrkGas });
19899
19908
  }
19909
+ resetJAM(jamProgram, pc, gas, args, hasMetadata = false) {
19910
+ this.pvm.resetJam(jamProgram, args, pc, tryAsGas(gas), hasMetadata);
19911
+ }
19900
19912
  resetGeneric(rawProgram, flatRegisters, initialGas) {
19901
19913
  this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
19902
19914
  }
@@ -19941,7 +19953,7 @@ class DebuggerAdapter {
19941
19953
  return true;
19942
19954
  }
19943
19955
  getRegisters() {
19944
- return this.pvm.registers.getAllU64();
19956
+ return this.pvm.registers.getAllEncoded();
19945
19957
  }
19946
19958
  setRegisters(registers) {
19947
19959
  this.pvm.registers.copyFrom(new Registers(registers));
@@ -19960,6 +19972,11 @@ class DebuggerAdapter {
19960
19972
  }
19961
19973
  }
19962
19974
 
19975
+ ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/program-decoder/index.ts
19976
+
19977
+
19978
+
19979
+
19963
19980
  ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/index.ts
19964
19981
 
19965
19982
 
@@ -19967,6 +19984,11 @@ class DebuggerAdapter {
19967
19984
 
19968
19985
 
19969
19986
 
19987
+
19988
+
19989
+
19990
+
19991
+
19970
19992
  ;// CONCATENATED MODULE: ./bin/test-runner/w3f/pvm.ts
19971
19993
 
19972
19994