duh-ipxact
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -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( |
252
lib/ml2on.js
@@ -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). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24314
10
435
7
24
2
1
+ Addedajv@^6.10.2
+ Addedconcat-stream@^2.0.0
+ Addedduh-schema@^0.6.0
+ Addedyargs@^14.0.0
+ Addedajv@6.12.6(transitive)
+ Addedansi-regex@4.1.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@5.0.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-stream@2.0.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedduh-schema@0.6.0(transitive)
+ Addedemoji-regex@7.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@3.1.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@5.1.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@14.2.3(transitive)
+ Addedyargs-parser@15.0.3(transitive)
Updatedfs-extra@^8.1.0