duh-ipxact
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -15,36 +15,36 @@ #!/usr/bin/env node | ||
const duh2spiritHandler = argv => { | ||
if (argv.verbose) console.log('duh2spirit'); | ||
fs.readFile(argv.duh, 'utf8') | ||
.then(duhStr => { | ||
const duhObj = json5.parse(duhStr); | ||
const spiritObj = duh2spirit(duhObj); | ||
let spiritStr; | ||
try { | ||
spiritStr = metaxml + onml.stringify(spiritObj, 2); | ||
} catch (err) { | ||
console.error(json5.stringify(spiritObj, null, 2)); | ||
} | ||
if (argv.spirit) { | ||
fs.outputFile(argv.spirit, spiritStr); | ||
} else { | ||
console.log(spiritStr); | ||
} | ||
}); | ||
const duh2spiritHandler = async argv => { | ||
if (argv.verbose) { | ||
console.log('duh2spirit'); | ||
} | ||
const duhStr = await fs.readFile(argv.duh, 'utf8'); | ||
const duhObj = json5.parse(duhStr); | ||
const spiritObj = duh2spirit(duhObj); | ||
let spiritStr; | ||
try { | ||
spiritStr = metaxml + onml.stringify(spiritObj, 2); | ||
} catch (err) { | ||
throw new Error(json5.stringify(spiritObj, null, 2)); | ||
} | ||
if (argv.spirit) { | ||
await fs.outputFile(argv.spirit, spiritStr); | ||
} else { | ||
console.log(spiritStr); | ||
} | ||
}; | ||
// ipxact -> duh | ||
const ipxact2duhHandler = argv => { | ||
if (argv.verbose) console.log('ipxact2duh'); | ||
fs.readFile(argv.ipxact, 'utf8') | ||
.then(ipxactStr => { | ||
const ipxactObj = onml.parse(ipxactStr); | ||
const duhObj = ml2on(ipxactObj); | ||
const duhStr = json5.stringify(duhObj, null, 2); | ||
if (argv.duh) { | ||
fs.outputFile(argv.duh, duhStr); | ||
} else { | ||
console.log(duhStr); | ||
} | ||
}); | ||
const ipxact2duhHandler = async argv => { | ||
if (argv.verbose) { | ||
console.log('ipxact2duh'); | ||
} | ||
const ipxactStr = await fs.readFile(argv.ipxact, 'utf8'); | ||
const ipxactObj = onml.parse(ipxactStr); | ||
const duhObj = ml2on(ipxactObj); | ||
const duhStr = json5.stringify(duhObj, null, 2); | ||
if (argv.duh) { | ||
fs.outputFile(argv.duh, duhStr); | ||
} else { | ||
console.log(duhStr); | ||
} | ||
}; | ||
@@ -51,0 +51,0 @@ |
'use strict'; | ||
const spirit = require('./spirit.js'); | ||
const ns = require('./ns.js'); | ||
@@ -19,7 +20,3 @@ const $ = spirit(); | ||
const component = p => [$.component, { | ||
'xmlns:spirit': 'http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.4', | ||
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', | ||
'xsi:schemaLocation': 'http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.4 http://www.spiritconsortium.org/XMLSchema/SPIRIT/1.4/index.xsd' | ||
}] | ||
const component = p => [$.component, ns.spirit14()] | ||
.concat(attr(p, 'vendor library name version')); | ||
@@ -53,2 +50,2 @@ | ||
component(node.component) | ||
.concat([memoryMaps(node.component.memoryMaps)]); | ||
.concat([memoryMaps(node.component.memoryMaps || [])]); |
158
lib/ml2on.js
@@ -23,7 +23,14 @@ 'use strict'; | ||
const toNumber = str => { | ||
const m16 = str.match('\'h([0-9a-zA-Z]+)'); | ||
const toNumber = node => { | ||
const str = node.full[2] || ''; | ||
if (typeof str !== 'string') { | ||
throw new Error(JSON.stringify(node.full, null, 2)); | ||
} | ||
const m16 = str.match(/^'h([0-9a-zA-Z]+)$/); | ||
if (m16) { | ||
return Number('0x' + m16[1].trim()); | ||
} | ||
const m2 = str.match('\'b([01]+)'); | ||
@@ -33,9 +40,61 @@ if (m2) { | ||
} | ||
const m10 = str.match('\'d([0-9]+)'); | ||
if (m10) { | ||
return Number(m2[1].trim()); | ||
return Number(m10[1].trim()); | ||
} | ||
return Number(str); | ||
let res = Number(str); | ||
return Number.isNaN(res) ? str : res; | ||
}; | ||
const porter = node => { | ||
let info = mergeTail(node); | ||
let width; | ||
let vector = info.wire.vector; | ||
if (vector === undefined) { | ||
width = 1; | ||
} else { | ||
if (Number.isInteger(vector.left) && (vector.right === 0)) { | ||
width = vector.left + 1; | ||
} else { | ||
throw new Error(JSON.stringify(info, null, 2)); | ||
} | ||
} | ||
let res; | ||
if (info.wire.direction === 'out') { | ||
res = -width; | ||
} else | ||
if (info.wire.direction === 'in') { | ||
res = width; | ||
} else | ||
if (info.wire.direction === 'inout') { | ||
res = { | ||
direction: 'inout', | ||
width: width | ||
}; | ||
} else { | ||
throw new Error(JSON.stringify(info, null, 2)); | ||
} | ||
return { | ||
[info.name]: res | ||
}; | ||
}; | ||
const portMapper = node => { | ||
const arr = node.full; | ||
let res = {}; | ||
for (let i = 2; i < arr.length; i++) { | ||
const portMap = arr[i].portMap; | ||
res[portMap.logicalPort] = portMap.physicalPort; | ||
} | ||
return {abstractionTypes: [{ | ||
viewRef: 'RTLview', | ||
portMaps: res | ||
}]}; | ||
}; | ||
// const portsReduce = node => { | ||
@@ -62,2 +121,3 @@ // let res = {}; | ||
// ['foo', {}, 'true'] -> {foot: true} | ||
const boolList = luter(` | ||
@@ -68,6 +128,6 @@ volatile | ||
requiresDriver | ||
testable | ||
`); | ||
/* | ||
*/ | ||
// ['foo', {}, '42'] -> {foo: 42} | ||
const numList = luter(` | ||
@@ -78,2 +138,3 @@ width | ||
value | ||
mask | ||
defaultValue | ||
@@ -83,2 +144,3 @@ baseAddress | ||
addressOffset | ||
addressUnitBits | ||
size | ||
@@ -89,5 +151,4 @@ resetValue | ||
`); | ||
/* | ||
*/ | ||
// ['foo', {}, 'bar'] -> 'bar' | ||
const objList = luter(` | ||
@@ -115,16 +176,22 @@ vendor library name version | ||
// ['ns:foo', {}, {a:1}, {b:2}] -> {foo: {a:1, b:2}} | ||
const mergeList = luter(` | ||
onMaster onSlave | ||
wire | ||
port | ||
abstractionDefinition | ||
busDefinition | ||
ports | ||
values | ||
slave | ||
vector | ||
clockDriver | ||
hwModel | ||
ports | ||
model | ||
portMap | ||
component | ||
fileSets | ||
`); | ||
/* | ||
component | ||
master | ||
slave | ||
port | ||
*/ | ||
@@ -138,2 +205,4 @@ | ||
// ['foo', {}, {a:1}, {b:2}] -> {foos: [{a:1, b:2}]} | ||
const mergeArray = luter(` | ||
@@ -144,16 +213,14 @@ reset | ||
register | ||
register | ||
signalName | ||
memoryMap | ||
file | ||
fileSet | ||
choice | ||
signal | ||
portMap | ||
view | ||
addressBlock | ||
busInterface | ||
`); | ||
/* | ||
portMap | ||
abstractionType | ||
busInterface | ||
*/ | ||
@@ -166,3 +233,2 @@ | ||
signalMap | ||
fileSets | ||
choices | ||
@@ -172,9 +238,15 @@ signals | ||
memoryMaps | ||
portMaps | ||
busInterfaces | ||
`); | ||
/* | ||
parameters | ||
fileSets | ||
portMaps | ||
abstractionTypes | ||
busInterfaces | ||
*/ | ||
const propsList = luter(` | ||
memoryMapRef | ||
`); | ||
let ns, ns1; | ||
@@ -191,2 +263,3 @@ | ||
const name = node.name.split(':')[1] || node.name; | ||
const tail = mergeTail(node); | ||
@@ -202,11 +275,13 @@ const iter = (lut, cb, newname) => { | ||
// if (iter(justList, () => true)) return; | ||
if (iter(propsList, () => node.full[1])) return; | ||
if (iter(boolList, () => node.full[2] === 'true')) return; | ||
if (iter(numList, () => toNumber(node.full[2]))) return; | ||
if (iter(numList, () => toNumber(node))) return; | ||
if (iter(objList, () => node.full[2])) return; | ||
if (iter(mergeList, () => mergeTail(node))) return; | ||
if (iter(mergeList, () => tail)) return; | ||
if (iter(namedProps, () => node.full[2].name)) return; | ||
if (iter(mergeArray, () => [mergeTail(node)], name + 's')) return; | ||
if (iter(mergeArray, () => [tail], name + 's')) return; | ||
if (mergeSkip[name]) { | ||
this.replace(mergeTail(node)); | ||
this.replace(tail); | ||
return; | ||
@@ -216,5 +291,7 @@ } | ||
switch (node.name) { | ||
case ns + 'busType': | ||
case ns + 'abstractionType': | ||
this.replace({ | ||
busType: { | ||
[name]: { | ||
vendor: node.attr[ns1 + 'vendor'], | ||
@@ -224,7 +301,36 @@ library: node.attr[ns1 + 'library'], | ||
version: node.attr[ns1 + 'version'] | ||
}, | ||
interfaceMode: 'slave' | ||
} | ||
}); | ||
break; | ||
case ns + 'port': | ||
this.replace(porter(node)); | ||
break; | ||
case ns + 'parameter': | ||
this.replace(tail); // {[tail.name]: tail.value}); | ||
break; | ||
case ns + 'parameters': | ||
this.replace((n => { | ||
let res = n.full.slice(2); | ||
return {[name]: res}; | ||
})(node)); | ||
break; | ||
case ns + 'master': | ||
this.replace({interfaceMode: 'master'}); | ||
break; | ||
case ns + 'slave': | ||
this.replace({interfaceMode: 'slave'}); | ||
break; | ||
case ns + 'fileSet': | ||
this.replace({[tail.name]: tail.files}); | ||
break; | ||
case ns + 'portMaps': | ||
this.replace(portMapper(node)); | ||
break; | ||
// case ns + 'vendorExtensions': this.replace({vendorExtensions: []}); break; | ||
@@ -231,0 +337,0 @@ |
{ | ||
"name": "duh-ipxact", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "IP-XACT import / export package", | ||
@@ -15,3 +15,3 @@ "author": "SiFive", | ||
"scripts": { | ||
"test": "eslint lib && mocha test && nyc -r=text -r=lcov mocha test" | ||
"test": "eslint lib && nyc -r=text -r=lcov mocha test" | ||
}, | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
@@ -33,7 +33,7 @@ "bugs": { | ||
"concat-stream": "^2.0.0", | ||
"duh-schema": "^0.7.0", | ||
"duh-schema": "^0.7.4", | ||
"fs-extra": "^8.1.0", | ||
"json5": "^2.1.0", | ||
"json5": "^2.1.1", | ||
"onml": "^1.0.0", | ||
"yargs": "^14.0.0" | ||
"yargs": "^15.1.0" | ||
}, | ||
@@ -43,5 +43,5 @@ "devDependencies": { | ||
"chai": "^4.2.0", | ||
"eslint": "^5.16.0", | ||
"mocha": "^6.2.0", | ||
"nyc": "^14.1.1" | ||
"eslint": "^6.8.0", | ||
"mocha": "^7.0.0", | ||
"nyc": "^15.0.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "eslintConfig": { |
[![NPM version](https://img.shields.io/npm/v/duh-ipxact.svg)](https://www.npmjs.org/package/duh-ipxact) | ||
[![Travis build Status](https://travis-ci.org/sifive/duh-ipxact.svg?branch=master)](https://travis-ci.org/sifive/duh-ipxact) | ||
[![Actions Status](https://github.com/sifive/duh-ipxact/workflows/Tests/badge.svg)](https://github.com/sifive/duh-ipxact/actions) | ||
@@ -4,0 +4,0 @@ IP-XACT import / export 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
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
27502
12
536
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removedansi-regex@4.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcliui@5.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedyargs@14.2.3(transitive)
- Removedyargs-parser@15.0.3(transitive)
Updatedduh-schema@^0.7.4
Updatedjson5@^2.1.1
Updatedyargs@^15.1.0