@yowasp/yosys 0.37.13-dev.624 → 0.37.13-dev.628

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.
@@ -14,6 +14,15 @@ function wallClockNow() {
14
14
  const nanoseconds = now % 1e3 * 1e6;
15
15
  return { seconds, nanoseconds };
16
16
  }
17
+ var randomBytesImpl = function() {
18
+ throw "not implemented";
19
+ };
20
+ function setRandomBytesImpl(impl) {
21
+ randomBytesImpl = impl;
22
+ }
23
+ function getRandomBytes(len) {
24
+ return randomBytesImpl(Number(len));
25
+ }
17
26
  var IoError = class extends Error {
18
27
  };
19
28
  var InputStream = class {
@@ -201,9 +210,21 @@ var Descriptor = class _Descriptor {
201
210
  }
202
211
  return new _Descriptor(openEntry);
203
212
  }
213
+ read(length, offset) {
214
+ if (this.entry instanceof Directory)
215
+ throw "is-directory";
216
+ [length, offset] = [Number(length), Number(offset)];
217
+ return [this.entry.data.subarray(offset, offset + length), offset + length >= this.entry.data.byteLength];
218
+ }
204
219
  readViaStream(offset) {
205
220
  return new ReadStream(this.entry, offset);
206
221
  }
222
+ write(_buffer, _offset) {
223
+ if (this.entry instanceof Directory)
224
+ throw "is-directory";
225
+ console.error("Descriptor.write not implemented");
226
+ throw "unsupported";
227
+ }
207
228
  writeViaStream(offset) {
208
229
  return new WriteStream(this.entry, offset);
209
230
  }
@@ -265,7 +286,7 @@ function directoryIntoTree(directory, { decodeASCII = true } = {}) {
265
286
  if (entry instanceof File)
266
287
  tree[filename] = decodeASCII && isASCII(entry.data) ? new TextDecoder().decode(entry.data) : entry.data;
267
288
  if (entry instanceof Directory)
268
- tree[filename] = directoryIntoTree(entry);
289
+ tree[filename] = directoryIntoTree(entry, { decodeASCII });
269
290
  }
270
291
  return tree;
271
292
  }
@@ -286,6 +307,9 @@ var Environment = class {
286
307
  wallClock: {
287
308
  now: wallClockNow
288
309
  },
310
+ random: {
311
+ getRandomBytes
312
+ },
289
313
  io: {
290
314
  Error: IoError,
291
315
  InputStream,
@@ -345,24 +369,25 @@ var Environment = class {
345
369
 
346
370
  // node_modules/@yowasp/runtime/lib/api-base.js
347
371
  var BaseApplication = class {
348
- constructor(getResources, wasmModules, instantiate2, argv0) {
349
- this._resources = null;
350
- this.getResources = getResources;
351
- this.wasmModules = wasmModules;
372
+ constructor(resourceFileURL2, instantiate2, argv0) {
373
+ this.resourceFileURL = resourceFileURL2;
374
+ this.resources = null;
352
375
  this.instantiate = instantiate2;
353
376
  this.argv0 = argv0;
354
377
  }
355
- async run(args, files = {}, { printLine = console.log, decodeASCII = true } = {}) {
356
- if (this._resources === null)
357
- this._resources = await this.getResources();
378
+ async run(args = null, files = {}, { printLine = console.log, decodeASCII = true } = {}) {
379
+ if (this.resources === null)
380
+ this.resources = await this._fetchResources();
381
+ if (args === null)
382
+ return;
358
383
  const environment = new Environment();
359
384
  environment.args = [this.argv0].concat(args);
360
385
  environment.root = directoryFromTree(files);
361
- for (const [dirName, resourceFiles] of Object.entries(this._resources))
362
- environment.root.files[dirName] = directoryFromTree(resourceFiles);
386
+ for (const [dirName, dirContents] of Object.entries(this.resources.filesystem))
387
+ environment.root.files[dirName] = directoryFromTree(dirContents);
363
388
  environment.printLine = printLine;
364
389
  const wasmCommand = await this.instantiate(
365
- (filename) => this.wasmModules[filename],
390
+ (filename) => this.resources.modules[filename],
366
391
  { runtime: environment.exports }
367
392
  );
368
393
  let error = null;
@@ -374,7 +399,7 @@ var BaseApplication = class {
374
399
  if (e instanceof Exit && e.code !== 0)
375
400
  error = e;
376
401
  }
377
- for (const dirName of Object.keys(this._resources))
402
+ for (const dirName of Object.keys(this.resources.filesystem))
378
403
  delete environment.root.files[dirName];
379
404
  files = directoryIntoTree(environment.root, { decodeASCII });
380
405
  if (error !== null) {
@@ -384,21 +409,49 @@ var BaseApplication = class {
384
409
  return files;
385
410
  }
386
411
  }
412
+ async _fetchResources() {
413
+ console.log(`[YoWASP runtime] Fetching resource bundle ${this.resourceFileURL}`);
414
+ const { modules, filesystem } = await import(this.resourceFileURL);
415
+ return {
416
+ modules: await this._fetchObject(modules, this._fetchWebAssembly),
417
+ filesystem: await this._fetchObject(filesystem, this._fetchUint8Array)
418
+ };
419
+ }
420
+ async _fetchObject(obj, fetchFn) {
421
+ for (const [key, value] of Object.entries(obj)) {
422
+ if (value instanceof URL) {
423
+ console.log(`[YoWASP runtime] Fetching resource file ${value}`);
424
+ obj[key] = await fetchFn(value);
425
+ } else if (typeof value === "string" || value instanceof Uint8Array) {
426
+ obj[key] = value;
427
+ } else {
428
+ obj[key] = await this._fetchObject(value, fetchFn);
429
+ }
430
+ }
431
+ return obj;
432
+ }
433
+ async _fetchUint8Array(_url) {
434
+ throw "not implemented";
435
+ }
436
+ async _fetchWebAssembly(_url) {
437
+ throw "not implemented";
438
+ }
387
439
  };
388
440
 
389
441
  // node_modules/@yowasp/runtime/lib/api-browser.js
442
+ setRandomBytesImpl(function(length) {
443
+ const QUOTA = 65536;
444
+ const bytes = new Uint8Array(length);
445
+ for (var offset = 0; offset < length; offset += QUOTA)
446
+ crypto.getRandomValues(bytes.slice(offset, offset + QUOTA));
447
+ return bytes;
448
+ });
390
449
  var Application = class extends BaseApplication {
391
- constructor(baseURL, resourceFilenames, wasmFilenames, instantiate2, argv0) {
392
- async function getResources() {
393
- const resources = {};
394
- for (const [dirName, jsonFilename] of Object.entries(resourceFilenames))
395
- resources[dirName] = await fetch(new URL(jsonFilename, baseURL)).then((resp) => resp.json());
396
- return resources;
397
- }
398
- const wasmModules = {};
399
- for (const [modName, wasmFilename] of Object.entries(wasmFilenames))
400
- wasmModules[modName] = fetch(new URL(wasmFilename, baseURL)).then(WebAssembly.compileStreaming);
401
- super(getResources, wasmModules, instantiate2, argv0);
450
+ _fetchUint8Array(url) {
451
+ return fetch(url).then((resp) => resp.arrayBuffer()).then((buf) => new Uint8Array(buf));
452
+ }
453
+ _fetchWebAssembly(url) {
454
+ return fetch(url).then(WebAssembly.compileStreaming);
402
455
  }
403
456
  };
404
457
 
@@ -4552,17 +4605,12 @@ async function instantiate(getCoreModule, imports, instantiateCore = WebAssembly
4552
4605
  }
4553
4606
 
4554
4607
  // lib/api.js
4555
- var yosys = new Application(import.meta.url, {
4556
- "share": "./yosys-share.json"
4557
- }, {
4558
- "yosys.core.wasm": "./yosys.core.wasm",
4559
- "yosys.core2.wasm": "./yosys.core2.wasm",
4560
- "yosys.core3.wasm": "./yosys.core3.wasm",
4561
- "yosys.core4.wasm": "./yosys.core4.wasm"
4562
- }, instantiate, "yowasp-yosys");
4608
+ var resourceFileURL = new URL("./resources-yosys.js", import.meta.url);
4609
+ var yosys = new Application(resourceFileURL, instantiate, "yowasp-yosys");
4563
4610
  var runYosys = yosys.run.bind(yosys);
4611
+ var commands = { "yosys": runYosys };
4564
4612
  export {
4565
4613
  Exit,
4566
- runYosys as "cmd:yosys",
4614
+ commands,
4567
4615
  runYosys
4568
4616
  };
@@ -1,5 +1,5 @@
1
1
  // node_modules/@yowasp/runtime/lib/api-node.js
2
- import { readFile } from "fs/promises";
2
+ import { randomBytes } from "crypto";
3
3
 
4
4
  // node_modules/@yowasp/runtime/lib/wasi-virt.js
5
5
  var Exit = class extends Error {
@@ -17,6 +17,15 @@ function wallClockNow() {
17
17
  const nanoseconds = now % 1e3 * 1e6;
18
18
  return { seconds, nanoseconds };
19
19
  }
20
+ var randomBytesImpl = function() {
21
+ throw "not implemented";
22
+ };
23
+ function setRandomBytesImpl(impl) {
24
+ randomBytesImpl = impl;
25
+ }
26
+ function getRandomBytes(len) {
27
+ return randomBytesImpl(Number(len));
28
+ }
20
29
  var IoError = class extends Error {
21
30
  };
22
31
  var InputStream = class {
@@ -204,9 +213,21 @@ var Descriptor = class _Descriptor {
204
213
  }
205
214
  return new _Descriptor(openEntry);
206
215
  }
216
+ read(length, offset) {
217
+ if (this.entry instanceof Directory)
218
+ throw "is-directory";
219
+ [length, offset] = [Number(length), Number(offset)];
220
+ return [this.entry.data.subarray(offset, offset + length), offset + length >= this.entry.data.byteLength];
221
+ }
207
222
  readViaStream(offset) {
208
223
  return new ReadStream(this.entry, offset);
209
224
  }
225
+ write(_buffer, _offset) {
226
+ if (this.entry instanceof Directory)
227
+ throw "is-directory";
228
+ console.error("Descriptor.write not implemented");
229
+ throw "unsupported";
230
+ }
210
231
  writeViaStream(offset) {
211
232
  return new WriteStream(this.entry, offset);
212
233
  }
@@ -268,7 +289,7 @@ function directoryIntoTree(directory, { decodeASCII = true } = {}) {
268
289
  if (entry instanceof File)
269
290
  tree[filename] = decodeASCII && isASCII(entry.data) ? new TextDecoder().decode(entry.data) : entry.data;
270
291
  if (entry instanceof Directory)
271
- tree[filename] = directoryIntoTree(entry);
292
+ tree[filename] = directoryIntoTree(entry, { decodeASCII });
272
293
  }
273
294
  return tree;
274
295
  }
@@ -289,6 +310,9 @@ var Environment = class {
289
310
  wallClock: {
290
311
  now: wallClockNow
291
312
  },
313
+ random: {
314
+ getRandomBytes
315
+ },
292
316
  io: {
293
317
  Error: IoError,
294
318
  InputStream,
@@ -346,26 +370,30 @@ var Environment = class {
346
370
  }
347
371
  };
348
372
 
373
+ // node_modules/@yowasp/runtime/lib/api-node.js
374
+ import { readFile } from "fs/promises";
375
+
349
376
  // node_modules/@yowasp/runtime/lib/api-base.js
350
377
  var BaseApplication = class {
351
- constructor(getResources, wasmModules, instantiate2, argv0) {
352
- this._resources = null;
353
- this.getResources = getResources;
354
- this.wasmModules = wasmModules;
378
+ constructor(resourceFileURL2, instantiate2, argv0) {
379
+ this.resourceFileURL = resourceFileURL2;
380
+ this.resources = null;
355
381
  this.instantiate = instantiate2;
356
382
  this.argv0 = argv0;
357
383
  }
358
- async run(args, files = {}, { printLine = console.log, decodeASCII = true } = {}) {
359
- if (this._resources === null)
360
- this._resources = await this.getResources();
384
+ async run(args = null, files = {}, { printLine = console.log, decodeASCII = true } = {}) {
385
+ if (this.resources === null)
386
+ this.resources = await this._fetchResources();
387
+ if (args === null)
388
+ return;
361
389
  const environment = new Environment();
362
390
  environment.args = [this.argv0].concat(args);
363
391
  environment.root = directoryFromTree(files);
364
- for (const [dirName, resourceFiles] of Object.entries(this._resources))
365
- environment.root.files[dirName] = directoryFromTree(resourceFiles);
392
+ for (const [dirName, dirContents] of Object.entries(this.resources.filesystem))
393
+ environment.root.files[dirName] = directoryFromTree(dirContents);
366
394
  environment.printLine = printLine;
367
395
  const wasmCommand = await this.instantiate(
368
- (filename) => this.wasmModules[filename],
396
+ (filename) => this.resources.modules[filename],
369
397
  { runtime: environment.exports }
370
398
  );
371
399
  let error = null;
@@ -377,7 +405,7 @@ var BaseApplication = class {
377
405
  if (e instanceof Exit && e.code !== 0)
378
406
  error = e;
379
407
  }
380
- for (const dirName of Object.keys(this._resources))
408
+ for (const dirName of Object.keys(this.resources.filesystem))
381
409
  delete environment.root.files[dirName];
382
410
  files = directoryIntoTree(environment.root, { decodeASCII });
383
411
  if (error !== null) {
@@ -387,21 +415,43 @@ var BaseApplication = class {
387
415
  return files;
388
416
  }
389
417
  }
418
+ async _fetchResources() {
419
+ console.log(`[YoWASP runtime] Fetching resource bundle ${this.resourceFileURL}`);
420
+ const { modules, filesystem } = await import(this.resourceFileURL);
421
+ return {
422
+ modules: await this._fetchObject(modules, this._fetchWebAssembly),
423
+ filesystem: await this._fetchObject(filesystem, this._fetchUint8Array)
424
+ };
425
+ }
426
+ async _fetchObject(obj, fetchFn) {
427
+ for (const [key, value] of Object.entries(obj)) {
428
+ if (value instanceof URL) {
429
+ console.log(`[YoWASP runtime] Fetching resource file ${value}`);
430
+ obj[key] = await fetchFn(value);
431
+ } else if (typeof value === "string" || value instanceof Uint8Array) {
432
+ obj[key] = value;
433
+ } else {
434
+ obj[key] = await this._fetchObject(value, fetchFn);
435
+ }
436
+ }
437
+ return obj;
438
+ }
439
+ async _fetchUint8Array(_url) {
440
+ throw "not implemented";
441
+ }
442
+ async _fetchWebAssembly(_url) {
443
+ throw "not implemented";
444
+ }
390
445
  };
391
446
 
392
447
  // node_modules/@yowasp/runtime/lib/api-node.js
448
+ setRandomBytesImpl(randomBytes);
393
449
  var Application = class extends BaseApplication {
394
- constructor(baseURL, resourceFilenames, wasmFilenames, instantiate2, argv0) {
395
- async function getResources() {
396
- const resources = {};
397
- for (const [dirName, jsonFilename] of Object.entries(resourceFilenames))
398
- resources[dirName] = JSON.parse(await readFile(new URL(jsonFilename, baseURL)));
399
- return resources;
400
- }
401
- const wasmModules = {};
402
- for (const [modName, wasmFilename] of Object.entries(wasmFilenames))
403
- wasmModules[modName] = readFile(new URL(wasmFilename, baseURL)).then(WebAssembly.compile);
404
- super(getResources, wasmModules, instantiate2, argv0);
450
+ _fetchUint8Array(url) {
451
+ return readFile(url);
452
+ }
453
+ _fetchWebAssembly(url) {
454
+ return readFile(url).then(WebAssembly.compile);
405
455
  }
406
456
  };
407
457
 
@@ -4555,17 +4605,12 @@ async function instantiate(getCoreModule, imports, instantiateCore = WebAssembly
4555
4605
  }
4556
4606
 
4557
4607
  // lib/api.js
4558
- var yosys = new Application(import.meta.url, {
4559
- "share": "./yosys-share.json"
4560
- }, {
4561
- "yosys.core.wasm": "./yosys.core.wasm",
4562
- "yosys.core2.wasm": "./yosys.core2.wasm",
4563
- "yosys.core3.wasm": "./yosys.core3.wasm",
4564
- "yosys.core4.wasm": "./yosys.core4.wasm"
4565
- }, instantiate, "yowasp-yosys");
4608
+ var resourceFileURL = new URL("./resources-yosys.js", import.meta.url);
4609
+ var yosys = new Application(resourceFileURL, instantiate, "yowasp-yosys");
4566
4610
  var runYosys = yosys.run.bind(yosys);
4611
+ var commands = { "yosys": runYosys };
4567
4612
  export {
4568
4613
  Exit,
4569
- runYosys as "cmd:yosys",
4614
+ commands,
4570
4615
  runYosys
4571
4616
  };