use mulAdd for number scan
This commit is contained in:
parent
7ebfb4ca03
commit
5a6333a089
31
bin/build.js
31
bin/build.js
@ -54,15 +54,13 @@ const generate = cb => {
|
|||||||
varSizeSpan, varIdSpan, varNameSpan,
|
varSizeSpan, varIdSpan, varNameSpan,
|
||||||
idSpan,
|
idSpan,
|
||||||
commandSpan,
|
commandSpan,
|
||||||
timeSpan,
|
timeSpan
|
||||||
vectorSpan
|
|
||||||
} = `
|
} = `
|
||||||
scopeIdentifierSpan
|
scopeIdentifierSpan
|
||||||
varSizeSpan varIdSpan varNameSpan
|
varSizeSpan varIdSpan varNameSpan
|
||||||
idSpan
|
idSpan
|
||||||
commandSpan
|
commandSpan
|
||||||
timeSpan
|
timeSpan
|
||||||
vectorSpan
|
|
||||||
`
|
`
|
||||||
.trim().split(/\s+/)
|
.trim().split(/\s+/)
|
||||||
.reduce((res, n) => Object.assign(res, {[n]: p.span(p.code.span(n))}), {});
|
.reduce((res, n) => Object.assign(res, {[n]: p.span(p.code.span(n))}), {});
|
||||||
@ -78,7 +76,9 @@ const generate = cb => {
|
|||||||
inDeclaration,
|
inDeclaration,
|
||||||
simulation,
|
simulation,
|
||||||
inSimulation,
|
inSimulation,
|
||||||
simulationTime, simulationVector, simulationId
|
simulationTime,
|
||||||
|
simulationVector, simulationVectorEnd,
|
||||||
|
simulationId
|
||||||
} = `
|
} = `
|
||||||
declaration
|
declaration
|
||||||
scopeType scopeTypeEnd
|
scopeType scopeTypeEnd
|
||||||
@ -90,7 +90,9 @@ const generate = cb => {
|
|||||||
inDeclaration
|
inDeclaration
|
||||||
simulation
|
simulation
|
||||||
inSimulation
|
inSimulation
|
||||||
simulationTime simulationVector simulationId
|
simulationTime
|
||||||
|
simulationVector simulationVectorEnd
|
||||||
|
simulationId
|
||||||
`
|
`
|
||||||
.trim().split(/\s+/)
|
.trim().split(/\s+/)
|
||||||
.reduce((res, n) => Object.assign(res, {[n]: p.node(n)}), {});
|
.reduce((res, n) => Object.assign(res, {[n]: p.node(n)}), {});
|
||||||
@ -220,7 +222,7 @@ const generate = cb => {
|
|||||||
.select(cmd('0 1 x X Z'),
|
.select(cmd('0 1 x X Z'),
|
||||||
p.invoke(p.code.store('command'), idSpan.start(simulationId)))
|
p.invoke(p.code.store('command'), idSpan.start(simulationId)))
|
||||||
.select(cmd('b B r R'),
|
.select(cmd('b B r R'),
|
||||||
p.invoke(p.code.store('command'), vectorSpan.start(simulationVector)))
|
p.invoke(p.code.store('command'), simulationVector))
|
||||||
.otherwise(p.error(4, 'Expected simulation command'));
|
.otherwise(p.error(4, 'Expected simulation command'));
|
||||||
|
|
||||||
inSimulation
|
inSimulation
|
||||||
@ -231,9 +233,22 @@ const generate = cb => {
|
|||||||
.match(spaces, timeSpan.end(simulation))
|
.match(spaces, timeSpan.end(simulation))
|
||||||
.skipTo(simulationTime);
|
.skipTo(simulationTime);
|
||||||
|
|
||||||
|
const onDigit = p.code.mulAdd('value', {base: 2, signed: false});
|
||||||
|
|
||||||
simulationVector
|
simulationVector
|
||||||
.match(spaces, vectorSpan.end(idSpan.start(simulationId)))
|
.select(
|
||||||
.skipTo(simulationVector);
|
{0: 0, 1: 1, x: 2, z: 3},
|
||||||
|
p.invoke(
|
||||||
|
onDigit,
|
||||||
|
{1: p.error(1, 'Content-Length overflow')},
|
||||||
|
simulationVector
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.otherwise(simulationVectorEnd);
|
||||||
|
|
||||||
|
simulationVectorEnd
|
||||||
|
.match(spaces, idSpan.start(simulationId))
|
||||||
|
.skipTo(simulationVectorEnd);
|
||||||
|
|
||||||
simulationId
|
simulationId
|
||||||
.match(spaces, idSpan.end(simulation))
|
.match(spaces, idSpan.end(simulation))
|
||||||
|
29
vcd_spans.c
29
vcd_spans.c
@ -125,6 +125,8 @@ int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* end
|
|||||||
value = 1;
|
value = 1;
|
||||||
mask = 0;
|
mask = 0;
|
||||||
}
|
}
|
||||||
|
state->value = 0;
|
||||||
|
state->mask = 0;
|
||||||
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
|
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
|
||||||
ASSERT(undefined, napi_get_undefined(env, &undefined))
|
ASSERT(undefined, napi_get_undefined(env, &undefined))
|
||||||
ASSERT(eventName, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &eventName))
|
ASSERT(eventName, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &eventName))
|
||||||
@ -138,10 +140,29 @@ int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* end
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vectorSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
int onDigit(
|
||||||
// TODO implement proper 4-state parser
|
vcd_parser_t* state,
|
||||||
state->value = strtoul((const char *)p, (char **)&endp, 2);
|
const unsigned char* p,
|
||||||
state->mask = 0;
|
const unsigned char* endp,
|
||||||
|
int match
|
||||||
|
) {
|
||||||
|
state->value *= 2;
|
||||||
|
state->mask *= 2;
|
||||||
|
switch (match) {
|
||||||
|
case 1: {
|
||||||
|
state->value += 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
state->mask += 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
state->value += 1;
|
||||||
|
state->mask += 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user