From f19b9ea185cde17bda0aacb2c3cb803216a9db0e Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Fri, 25 Oct 2024 13:16:37 -0700 Subject: [PATCH 1/3] small tool to index intruction yaml files --- index-unifieddb.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 index-unifieddb.js diff --git a/index-unifieddb.js b/index-unifieddb.js new file mode 100755 index 0000000000..22f25c7fd5 --- /dev/null +++ b/index-unifieddb.js @@ -0,0 +1,68 @@ +#!/usr/bin/env node +'use strict'; + +const process = require('process'); +const path = require('path'); +const fs = require('fs'); + +const { readdir } = fs.promises; + +const tree = { + arch: { + inst: { // TODO update this object to index new extension + A: {}, + B: {}, + F: {}, + H: {}, + I: {}, + M: {}, + Q: {}, + S: {}, + Svinval: {}, + V: {}, + Zabha: {}, + Zacas: {}, + Zalasr: {}, + Zawrs: {}, + Zfbfmin: {}, + Zfh: {}, + Zicbom: {}, + Zicboz: {}, + Zicfiss: {}, + Zicond: {}, + Zicsr: {}, + Zifencei: {} + } + } +}; + +const rec = async (node, branch, root) => { + const keys = Object.keys(node); + if (keys.length === 0) { + const fullPath = path.resolve(root, ...branch); + const files = await readdir(fullPath); + for (const file of files) { + const baseName = path.basename(file, '.yaml'); + node[baseName] = {$ref: path.join(...branch, file)}; + } + } else { + for (const key of keys) { + const newBranch = [...branch, key]; + await rec(node[key], newBranch, root); + } + } + return node; +}; + +const main = async () => { + const [, , root] = process.argv; + if (root === undefined) { + console.error('usage: ./index-unifieddb.js '); + return; + } + const rootPath = path.resolve('.', root); + await rec(tree, [], rootPath); + console.log(JSON.stringify(tree, null, 2)); +}; + +main(); From f68d5961b1f92ac0647d41984eeca68f7b64f828 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Fri, 25 Oct 2024 14:02:13 -0700 Subject: [PATCH 2/3] indexing all yaml/json files recurcively --- index-unifieddb.js | 63 +++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/index-unifieddb.js b/index-unifieddb.js index 22f25c7fd5..c0744d038f 100755 --- a/index-unifieddb.js +++ b/index-unifieddb.js @@ -5,50 +5,23 @@ const process = require('process'); const path = require('path'); const fs = require('fs'); -const { readdir } = fs.promises; +const { readdir, stat } = fs.promises; -const tree = { - arch: { - inst: { // TODO update this object to index new extension - A: {}, - B: {}, - F: {}, - H: {}, - I: {}, - M: {}, - Q: {}, - S: {}, - Svinval: {}, - V: {}, - Zabha: {}, - Zacas: {}, - Zalasr: {}, - Zawrs: {}, - Zfbfmin: {}, - Zfh: {}, - Zicbom: {}, - Zicboz: {}, - Zicfiss: {}, - Zicond: {}, - Zicsr: {}, - Zifencei: {} - } - } -}; - -const rec = async (node, branch, root) => { - const keys = Object.keys(node); - if (keys.length === 0) { - const fullPath = path.resolve(root, ...branch); - const files = await readdir(fullPath); - for (const file of files) { - const baseName = path.basename(file, '.yaml'); - node[baseName] = {$ref: path.join(...branch, file)}; - } - } else { - for (const key of keys) { - const newBranch = [...branch, key]; - await rec(node[key], newBranch, root); +const rec = async (branch, root) => { + const node = {}; + const localPath = path.resolve(root, ...branch); + const els = await readdir(localPath); + for (const el of els) { + const isFile = (await stat(path.resolve(localPath, el))).isFile(); + const fileExt = path.extname(el); + const baseName = path.basename(el, fileExt); + console.log(localPath, el, baseName, fileExt, isFile); + if (isFile) { + if (['.yaml', '.json'].includes(fileExt)) { + node[baseName] = {$ref: path.join(...branch, el)}; + } + } else { + node[el] = await rec([...branch, el], root); } } return node; @@ -57,11 +30,11 @@ const rec = async (node, branch, root) => { const main = async () => { const [, , root] = process.argv; if (root === undefined) { - console.error('usage: ./index-unifieddb.js '); + console.error('usage: ./index-unifieddb.js '); return; } const rootPath = path.resolve('.', root); - await rec(tree, [], rootPath); + const tree = await rec([], rootPath); console.log(JSON.stringify(tree, null, 2)); }; From 69eea11b792832ae8f4ec655d0d652165f8745d2 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Fri, 25 Oct 2024 14:11:38 -0700 Subject: [PATCH 3/3] clean the stdout --- index-unifieddb.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index-unifieddb.js b/index-unifieddb.js index c0744d038f..cdc1404d62 100755 --- a/index-unifieddb.js +++ b/index-unifieddb.js @@ -15,7 +15,6 @@ const rec = async (branch, root) => { const isFile = (await stat(path.resolve(localPath, el))).isFile(); const fileExt = path.extname(el); const baseName = path.basename(el, fileExt); - console.log(localPath, el, baseName, fileExt, isFile); if (isFile) { if (['.yaml', '.json'].includes(fileExt)) { node[baseName] = {$ref: path.join(...branch, el)};