Actions
Task #5207
closed[verilog][parser][cfg] Дублирование кода и другие замечания к коду
Start date:
08/21/2014
Due date:
% Done:
0%
Estimated time:
Detected in build:
svn
Published in build:
Description
- Дублируется код, связанный с вычислением типа переменной (
onVariable
,onDeclarationBegin
). Необходимо выделить его в приватный метод. - Объект
variable
типаNodeVariable
(onDeclarationBegin
) создается, даже если он не нужен (не добавляется вCfgModel
). - Для вычисление типа данных переменной можно использовать метод
ElementType.getDataType
(onDeclarationBegin
):NodeVariable variable = new NodeVariable(new Variable(node.getName(), node.getElementType().getDataType()));
public void onVariable(NodeVariable variable) {
Reference reference = (Reference) variable.getUserData();
VariableType type;
if (reference == null || reference.getDeclaration() == null) // TODO: to be checked and removed
type = VariableType.REG;
else {
switch (reference.getDeclaration().getType()) { // TODO: find the most suitable declaration (input, output or simply register)
case INPUT: {
type = VariableType.IN;
break;
}
case OUTPUT: {
type = VariableType.OUT;
break;
}
case INOUT: {
type = VariableType.INOUT;
break;
}
case EVENT: {
type = VariableType.REG;
break;
}
case PARAMETER: {
type = VariableType.CONST;
break;
}
case SPECPARAM: {
type = VariableType.CONST;
break;
}
case LOCALPARAM: {
type = VariableType.CONST;
break;
}
case DEFPARAM: {
type = VariableType.CONST;
break;
} // TODO
case GENVAR: {
type = VariableType.REG;
break;
} // TODO
case VARIABLE: {
type = VariableType.REG;
break;
}
default:
type = VariableType.REG;
}
}
variable.setUserData(new VariableData(type));
}
public Result onDeclarationBegin(final Declaration node) {
VariableType variableType;
switch (node.getType()) {
case INPUT: {
variableType = VariableType.IN;
break;
}
case OUTPUT: {
variableType = VariableType.OUT;
break;
}
case INOUT: {
variableType = VariableType.INOUT;
break;
}
case EVENT: {
variableType = VariableType.REG;
break;
}
case PARAMETER: {
variableType = VariableType.CONST;
break;
}
case SPECPARAM: {
variableType = VariableType.CONST;
break;
}
case LOCALPARAM: {
variableType = VariableType.CONST;
break;
}
case DEFPARAM: {
variableType = VariableType.CONST;
break;
}
case GENVAR: {
variableType = VariableType.REG;
break;
}
case VARIABLE: {
variableType = VariableType.REG;
break;
}
default:
variableType = VariableType.REG;
}
//assert (node.getRange().getRanges().size() == 0); // TODO: arrays are not supported
int size = 1, lr = 0, rr = 0;
if (node.getElementType().getRange() != null) {
if (node.getElementType().getRange().getLeftExpression().isConstant())
lr = node.getElementType().getRange().getLeftExpression().evaluateInteger();
if (node.getElementType().getRange().getRightExpression().isConstant())
rr = node.getElementType().getRange().getRightExpression().evaluateInteger();
size = Math.abs(lr - rr) + 1;
}
NodeVariable variable =
new NodeVariable(new Variable(node.getName(), DataType.BIT_VECTOR(size)));
variable.setUserData(new VariableData(variableType));
final Set<Declaration> namesakes = node.getNamesakes();
if (namesakes.isEmpty() || node.isOutput() || node.isInout()) {
getCurrentModule().addVariable(variable);
getLogger().log(LogLevel.INFO, String.format("add variable %s [%d:%d] (%s) to module %s.", variable, lr, rr, variable.getData(), getCurrentModule().getName()));
}
// final ElementType type = node.getElementType();
// parameter type.isSpecified() is not used
if (node.getExpression() != null) {
if (initialProcess == null)
initialProcess = new Process(true);
Assignment assignment = new Assignment();
Reference reference = new Reference();
Path path = new Path(variable.getName());
reference.setDeclaration(node);
reference.setPath(path);
assignment.addReference(reference);
assignment.setExpression(node.getExpression());
activityType = Type.INITIAL;
parseAssignment(assignment, AssignStatement.Type.ASSIGN, true);
}
return Result.OK;
}
Updated by Alexander Kamkin over 10 years ago
- Subject changed from [verilog][parser][cfg] to [verilog][parser][cfg] Дублирование кода и другие замечания к коду
Updated by Alexander Kamkin about 10 years ago
- Status changed from Resolved to Closed
Actions