Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

duh-ipxact

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duh-ipxact - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

bin/duh-ipxact.js

7

bin/import.js

@@ -34,9 +34,8 @@ #!/usr/bin/env node

const sdoc = JSON5.stringify(odoc, null, 2);
fs.outputFile(path.resolve(opath, dirname, basename + '.json5'), sdoc)
fs.outputFile(path.resolve(opath, dirname, basename + '.json5'), sdoc);
}
} else
{
} else {
console.log('???:');
}
};
};

@@ -43,0 +42,0 @@ walker(

@@ -9,3 +9,12 @@ 'use strict';

for (let i = 2; i < arr.length; i++) {
res = Object.assign(res, arr[i]);
const ai = arr[i];
Object.keys(ai).map(key => {
if (res[key] === undefined) {
res[key] = ai[key];
} else if (Array.isArray(res[key])) {
res[key] = res[key].concat(ai[key]);
} else {
res[key] = ai[key];
}
});
}

@@ -15,86 +24,207 @@ return res;

const portsReduce = node => {
let res = {};
const arr = node.full;
for (let i = 2; i < arr.length; i++) {
const port = arr[i].port;
res[port.logicalName] = port;
const toNumber = str => {
const m16 = str.match('\'h([0-9a-zA-Z]+)');
if (m16) {
return Number('0x' + m16[1].trim());
}
return res;
const m2 = str.match('\'b([01]+)');
if (m2) {
return Number('0b' + m2[1].trim());
}
const m10 = str.match('\'d([0-9]+)');
if (m10) {
return Number(m2[1].trim());
}
return Number(str);
};
const toNumber = val => {
const num = Number(val);
return (isNaN(num) || ((num |0) !== num)) ? val : num;
};
// const portsReduce = node => {
// let res = {};
// const arr = node.full;
// for (let i = 2; i < arr.length; i++) {
// const port = arr[i].port;
// res[port.logicalName] = port;
// }
// return res;
// };
//
// const toNumber = val => {
// const num = Number(val);
// return (isNaN(num) || ((num |0) !== num)) ? val : num;
// };
const objList = [
'vendor',
'library',
'name',
'version',
'presence',
'direction',
'logicalName',
'description'
];
const luter = str =>
str.trim().split(/\s+/).reduce((res, e) => {
res[e] = true;
return res;
}, {});
const boolList = [
'isClock',
'isReset',
'isAddress',
'isData',
'isAddressable',
'directConnection',
'requiresDriver'
];
const boolList = luter(`
volatile
isClock isReset isAddress isData isAddressable
directConnection
requiresDriver
`);
/*
*/
const numList = luter(`
width
bitOffset
bitWidth
value
defaultValue
baseAddress
range
addressOffset
size
resetValue
left right
clockPeriod clockPulseOffset clockPulseValue clockPulseDuration
`);
/*
*/
const objList = luter(`
vendor library name version
description displayName
fileType
presence
direction
logicalName
access
busSignalName
componentSignalName
fileSetRef
modelName
moduleName
localName
envIdentifier
language
`);
/*
abstractionRef
memoryMaps
*/
const mergeList = luter(`
onMaster onSlave
wire
port
abstractionDefinition
busDefinition
ports
values
slave
clockDriver
hwModel
`);
/*
component
*/
const namedProps = luter(`
logicalPort physicalPort
`);
/*
*/
const mergeArray = luter(`
reset
enumeratedValue
field
register
register
signalName
memoryMap
file
fileSet
choice
signal
portMap
view
addressBlock
`);
/*
abstractionType
busInterface
*/
const mergeSkip = luter(`
resets
enumeratedValues
qualifier
signalMap
fileSets
choices
signals
views
memoryMaps
portMaps
`);
/*
abstractionTypes
busInterfaces
*/
let ns, ns1;
module.exports = obj => {
ns = obj[0].split(':')[0] + ':';
ns1 = (ns === 'spirit:') ? ns : '';
let res = ['root', {}, obj];
onml.traverse(res, {
leave: function (node) {
const name = node.name.split(':')[1] || node.name;
objList.some(e => {
if (node.name === ('spirit:' + e)) {
const iter = (lut, cb, newname) => {
if (lut[name]) {
const res = {};
res[e] = node.full[2];
res[newname || name] = cb();
this.replace(res);
return true;
}
});
};
boolList.some(e => {
if (node.name === ('spirit:' + e)) {
const res = {};
res[e] = (node.full[2] === 'true');
this.replace(res);
return true;
}
});
if (iter(boolList, () => node.full[2] === 'true')) return;
if (iter(numList, () => toNumber(node.full[2]))) return;
if (iter(objList, () => node.full[2])) return;
if (iter(mergeList, () => mergeTail(node))) return;
if (iter(namedProps, () => node.full[2].name)) return;
if (iter(mergeArray, () => [mergeTail(node)], name + 's')) return;
if (mergeSkip[name]) {
this.replace(mergeTail(node));
return;
}
switch (node.name) {
case 'spirit:busType':
case ns + 'busType':
this.replace({
busType: {
vendor: node.attr['spirit:vendor'],
library: node.attr['spirit:library'],
name: node.attr['spirit:name'],
version: node.attr['spirit:version']
}
vendor: node.attr[ns1 + 'vendor'],
library: node.attr[ns1 + 'library'],
name: node.attr[ns1 + 'name'],
version: node.attr[ns1 + 'version']
},
interfaceMode: 'slave'
});
break;
case 'spirit:width': this.replace({width: Number(node.full[2])}); break;
case 'spirit:defaultValue': this.replace({defaultValue: toNumber(node.full[2])}); break;
case 'spirit:vendorExtensions': this.replace({vendorExtensions: []}); break;
// case ns + 'vendorExtensions': this.replace({vendorExtensions: []}); break;
case 'spirit:onMaster': this.replace({onMaster: mergeTail(node)}); break;
case 'spirit:onSlave': this.replace({onSlave: mergeTail(node)}); break;
case 'spirit:qualifier': this.replace(mergeTail(node)); break;
case 'spirit:wire': this.replace({wire: mergeTail(node)}); break;
case 'spirit:port': this.replace({port: mergeTail(node)}); break;
case 'spirit:abstractionDefinition': this.replace({abstractionDefinition: mergeTail(node)}); break;
case 'spirit:busDefinition': this.replace({busDefinition: mergeTail(node)}); break;
// case 'spirit:memoryMaps': this.replace(mergeTail(node)); break;
// case 'spirit:busInterfaces': this.replace(mergeTail(node)); break;
// case 'spirit:fileSet': this.replace(mergeTail(node)); break;
// case 'spirit:signals': this.replace(mergeTail(node)); break;
case 'spirit:ports': this.replace({ports: portsReduce(node)}); break;
// case ns + 'parameter': this.replace({parameters: [{attr: node.full[1], value: node.full[2]}]}); break;
// case ns + 'enumeration': this.replace({enumerations: [{attr: node.full[1], value: node.full[2]}]}); break;
// case 'spirit:signal': this.replace({signals: [mergeTail(node)]}); break;
// case 'spirit:signalMap': this.replace(mergeTail(node)); break;
}

@@ -105,1 +235,3 @@ }

};
/* eslint complexity:1 */
{
"name": "duh-ipxact",
"version": "0.2.0",
"version": "0.3.0",
"description": "IP-XACT import / export package",

@@ -9,3 +9,3 @@ "author": "SiFive",

"bin": {
"duh-import-ipxact": "bin/import.js"
"duh-ipxact": "bin/duh-ipxact.js"
},

@@ -30,5 +30,9 @@ "directories": {

"dependencies": {
"fs-extra": "^8.0.1",
"ajv": "^6.10.2",
"concat-stream": "^2.0.0",
"duh-schema": "^0.6.0",
"fs-extra": "^8.1.0",
"json5": "^2.1.0",
"onml": "^1.0.0"
"onml": "^1.0.0",
"yargs": "^14.0.0"
},

@@ -39,3 +43,3 @@ "devDependencies": {

"eslint": "^5.16.0",
"mocha": "^6.1.4",
"mocha": "^6.2.0",
"nyc": "^14.1.1"

@@ -42,0 +46,0 @@ },

@@ -8,20 +8,17 @@ [![NPM version](https://img.shields.io/npm/v/duh-ipxact.svg)](https://www.npmjs.org/package/duh-ipxact)

### DUH -> SPIRIT
```
npm i duh-ipxact
```
npx duh-ipxact duh2spirit myDuh.json5 mySpirit.xml
```bash
duh-import-ipxact -i <input> -o <output>
```
## API
### IPXACT -> DUH
TBD
```
npx duh-ipxact ipxact2duh myIpxact.xml myDuh.json5
## Testing
```
npm test
```
## License
Apache 2.0 [LICENSE](LICENSE).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc