From 0e526f811a89968876fa2f9dc958825a35d139e0 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Wed, 4 Oct 2017 10:10:36 +0200 Subject: [PATCH] Fixed size calculation and error generating std::array of plain datatypes --- .../rdl/generator/AddrmapGenerator.xtend | 14 +-- .../rdl/generator/RdlBaseGenerator.xtend | 57 +++++++++++- .../rdl/generator/RegfileGenerator.xtend | 6 +- .../rdl/generator/AddrmapGenerator.java | 28 +----- .../rdl/generator/RdlBaseGenerator.java | 92 ++++++++++++++++++- .../rdl/generator/RegfileGenerator.java | 76 ++++++++------- 6 files changed, 194 insertions(+), 79 deletions(-) diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/AddrmapGenerator.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/AddrmapGenerator.xtend index 8b1f08c..3aa455f 100644 --- a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/AddrmapGenerator.xtend +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/AddrmapGenerator.xtend @@ -3,7 +3,6 @@ package com.minres.rdl.generator import com.minres.rdl.generator.RdlBaseGenerator import com.minres.rdl.rdl.ComponentDefinition import com.minres.rdl.IntegerWithRadix -import com.minres.rdl.rdl.Instantiation import com.minres.rdl.rdl.ComponentDefinitionType class AddrmapGenerator extends RdlBaseGenerator { @@ -21,7 +20,7 @@ class AddrmapGenerator extends RdlBaseGenerator { const std::array, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> e300_plat_map = {{ «FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)» «FOR instance : instantiation.componentInstances» - {&i_«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)», 0x«Long.toHexString(instantiation.occupiedSize)»}, + {&i_«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)», 0x«Long.toHexString(instantiation.byteSize)»}, «ENDFOR» «ENDFOR» }}; @@ -34,16 +33,5 @@ class AddrmapGenerator extends RdlBaseGenerator { '' } - def int instanceCount(ComponentDefinition definition, ComponentDefinitionType type){ - definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2| p1+p2] - } - def instantiationsOfType(ComponentDefinition definition, ComponentDefinitionType type){ - definition.instantiations.filter[it.definingComponent.type == type] - } - - def long occupiedSize(Instantiation instantiation){ - return 4096 - } - } \ No newline at end of file diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RdlBaseGenerator.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RdlBaseGenerator.xtend index 547d990..413f8f0 100644 --- a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RdlBaseGenerator.xtend +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RdlBaseGenerator.xtend @@ -13,7 +13,8 @@ import com.minres.rdl.rdl.InstancePropertyRef import com.minres.rdl.rdl.ComponentDefinitionType abstract class RdlBaseGenerator { - def long accessWidth(ComponentDefinition definition){ + + def long accessWidth(ComponentDefinition definition){ var size = 32L val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.ACCESSWIDTH @@ -24,7 +25,19 @@ abstract class RdlBaseGenerator { } return size } - + + def long regWidth(ComponentDefinition definition){ + var size = 32L + val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | + pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.REGWIDTH + ] + if(pa !== null){ + val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue) + size=sz.value + } + return size + } + def long getSize(Instantiation instantiation){ val componentDef= instantiation.definingComponent switch (componentDef.type) { @@ -87,13 +100,51 @@ abstract class RdlBaseGenerator { } def String effectiveValue(InstancePropertyRef ref){ - + throw new RuntimeException() } def ComponentDefinition definingComponent(Instantiation instantiation){ if(instantiation.componentRef!==null) instantiation.componentRef else instantiation.component } + def int instanceCount(ComponentDefinition definition, ComponentDefinitionType type){ + definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2| p1+p2] + } + + def instantiationsOfType(ComponentDefinition definition, ComponentDefinitionType type){ + definition.instantiations.filter[it.definingComponent.type == type] + } + + def long byteSize(Instantiation instantiation, long start){ + val componentDefinition = instantiation.definingComponent + var long componentSize=0; + if(instantiation.definingComponent.type == ComponentDefinitionType.REG){ + componentSize=instantiation.definingComponent.regWidth/8 + } else + for(subInstantiation: componentDefinition.instantiations) + componentSize = subInstantiation.byteSize(componentSize) + + var long lastTopAddress = start + var long topAddress=start + for(componentInstance: instantiation.componentInstances ){ + val byteSize = if(componentInstance.address !== null) (componentInstance.address as IntegerWithRadix).value+componentSize else componentSize + lastTopAddress + topAddress = Math.max(topAddress, byteSize) + lastTopAddress = byteSize + } + return topAddress + } + + def long byteSize(Instantiation instantiation){ + val componentDefinition = instantiation.definingComponent + var long componentSize=0; + if(instantiation.definingComponent.type == ComponentDefinitionType.REG){ + componentSize=instantiation.definingComponent.regWidth/8 + } else + for(subInstantiation: componentDefinition.instantiations) + componentSize = subInstantiation.byteSize(componentSize) + return componentSize + } + def String generateHeader() def String generateSource() diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RegfileGenerator.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RegfileGenerator.xtend index b0994b9..1bd9b1f 100644 --- a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RegfileGenerator.xtend +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RegfileGenerator.xtend @@ -81,7 +81,9 @@ class RegfileGenerator extends RdlBaseGenerator{ «ENDIF» «IF instantiation.component !== null && instantiation.component.type == ComponentDefinitionType.REG» «IF instantiation.isFilledByField» - uint«instantiation.size»_t «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»; + «IF instantiation.componentInstances.filter[it.range===null].size>0» + uint«instantiation.size»_t «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»; + «ENDIF» «FOR componentInstance : instantiation.componentInstances.filter[it.range!==null]» std::array r_«componentInstance.name»; «ENDFOR» @@ -110,7 +112,7 @@ class RegfileGenerator extends RdlBaseGenerator{ «ENDIF» «IF instance.range!==null» «IF instantiation.isFilledByField» - sysc::sc_register_indexed<«instantiation.size»_t, «instance.range.absSize»> «instance.name»; + sysc::sc_register_indexed «instance.name»; «ENDIF» «IF !instantiation.isFilledByField» sysc::sc_register_indexed<«instantiation.component.effectiveName»_t, «instance.range.absSize»> «instance.name»; diff --git a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/AddrmapGenerator.java b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/AddrmapGenerator.java index e989aa9..45ef074 100644 --- a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/AddrmapGenerator.java +++ b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/AddrmapGenerator.java @@ -1,6 +1,5 @@ package com.minres.rdl.generator; -import com.google.common.base.Objects; import com.minres.rdl.IntegerWithRadix; import com.minres.rdl.generator.RdlBaseGenerator; import com.minres.rdl.rdl.ComponentDefinition; @@ -9,9 +8,6 @@ import com.minres.rdl.rdl.ComponentInstance; import com.minres.rdl.rdl.Instantiation; import org.eclipse.emf.common.util.EList; import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.Functions.Function2; -import org.eclipse.xtext.xbase.lib.IterableExtensions; @SuppressWarnings("all") public class AddrmapGenerator extends RdlBaseGenerator { @@ -50,7 +46,7 @@ public class AddrmapGenerator extends RdlBaseGenerator { String _hexString = Long.toHexString(((IntegerWithRadix) _address).value); _builder.append(_hexString, " "); _builder.append(", 0x"); - String _hexString_1 = Long.toHexString(this.occupiedSize(instantiation)); + String _hexString_1 = Long.toHexString(this.byteSize(instantiation)); _builder.append(_hexString_1, " "); _builder.append("},"); _builder.newLineIfNotEmpty(); @@ -70,26 +66,4 @@ public class AddrmapGenerator extends RdlBaseGenerator { public String generateSource() { return ""; } - - public int instanceCount(final ComponentDefinition definition, final ComponentDefinitionType type) { - final Function1 _function = (Instantiation it) -> { - return Integer.valueOf(it.getComponentInstances().size()); - }; - final Function2 _function_1 = (Integer p1, Integer p2) -> { - return Integer.valueOf(((p1).intValue() + (p2).intValue())); - }; - return (int) IterableExtensions.reduce(IterableExtensions.map(this.instantiationsOfType(definition, type), _function), _function_1); - } - - public Iterable instantiationsOfType(final ComponentDefinition definition, final ComponentDefinitionType type) { - final Function1 _function = (Instantiation it) -> { - ComponentDefinitionType _type = this.definingComponent(it).getType(); - return Boolean.valueOf(Objects.equal(_type, type)); - }; - return IterableExtensions.filter(definition.getInstantiations(), _function); - } - - public long occupiedSize(final Instantiation instantiation) { - return 4096; - } } diff --git a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RdlBaseGenerator.java b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RdlBaseGenerator.java index 60241d0..4117828 100644 --- a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RdlBaseGenerator.java +++ b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RdlBaseGenerator.java @@ -4,6 +4,7 @@ import com.google.common.base.Objects; import com.minres.rdl.IntegerWithRadix; import com.minres.rdl.rdl.ComponentDefinition; import com.minres.rdl.rdl.ComponentDefinitionType; +import com.minres.rdl.rdl.ComponentInstance; import com.minres.rdl.rdl.EnumDefinition; import com.minres.rdl.rdl.ExplicitPropertyAssignment; import com.minres.rdl.rdl.InstancePropertyRef; @@ -13,7 +14,9 @@ import com.minres.rdl.rdl.PropertyAssignmentRhs; import com.minres.rdl.rdl.PropertyEnum; import com.minres.rdl.rdl.RValue; import com.minres.rdl.rdl.RValueConstant; +import org.eclipse.emf.common.util.EList; import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.Functions.Function2; import org.eclipse.xtext.xbase.lib.IterableExtensions; @SuppressWarnings("all") @@ -32,6 +35,20 @@ public abstract class RdlBaseGenerator { return size; } + public long regWidth(final ComponentDefinition definition) { + long size = 32L; + final Function1 _function = (PropertyAssignment pa) -> { + return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.REGWIDTH))); + }; + final PropertyAssignment pa = IterableExtensions.findFirst(definition.getPropertyAssignments(), _function); + if ((pa != null)) { + String _effectiveValue = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); + final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue); + size = sz.value; + } + return size; + } + public long getSize(final Instantiation instantiation) { final ComponentDefinition componentDef = this.definingComponent(instantiation); ComponentDefinitionType _type = componentDef.getType(); @@ -146,7 +163,7 @@ public abstract class RdlBaseGenerator { } public String effectiveValue(final InstancePropertyRef ref) { - return null; + throw new RuntimeException(); } public ComponentDefinition definingComponent(final Instantiation instantiation) { @@ -161,6 +178,79 @@ public abstract class RdlBaseGenerator { return _xifexpression; } + public int instanceCount(final ComponentDefinition definition, final ComponentDefinitionType type) { + final Function1 _function = (Instantiation it) -> { + return Integer.valueOf(it.getComponentInstances().size()); + }; + final Function2 _function_1 = (Integer p1, Integer p2) -> { + return Integer.valueOf(((p1).intValue() + (p2).intValue())); + }; + return (int) IterableExtensions.reduce(IterableExtensions.map(this.instantiationsOfType(definition, type), _function), _function_1); + } + + public Iterable instantiationsOfType(final ComponentDefinition definition, final ComponentDefinitionType type) { + final Function1 _function = (Instantiation it) -> { + ComponentDefinitionType _type = this.definingComponent(it).getType(); + return Boolean.valueOf(Objects.equal(_type, type)); + }; + return IterableExtensions.filter(definition.getInstantiations(), _function); + } + + public long byteSize(final Instantiation instantiation, final long start) { + final ComponentDefinition componentDefinition = this.definingComponent(instantiation); + long componentSize = 0; + ComponentDefinitionType _type = this.definingComponent(instantiation).getType(); + boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG); + if (_equals) { + long _regWidth = this.regWidth(this.definingComponent(instantiation)); + long _divide = (_regWidth / 8); + componentSize = _divide; + } else { + EList _instantiations = componentDefinition.getInstantiations(); + for (final Instantiation subInstantiation : _instantiations) { + componentSize = this.byteSize(subInstantiation, componentSize); + } + } + long lastTopAddress = start; + long topAddress = start; + EList _componentInstances = instantiation.getComponentInstances(); + for (final ComponentInstance componentInstance : _componentInstances) { + { + long _xifexpression = (long) 0; + Object _address = componentInstance.getAddress(); + boolean _tripleNotEquals = (_address != null); + if (_tripleNotEquals) { + Object _address_1 = componentInstance.getAddress(); + _xifexpression = (((IntegerWithRadix) _address_1).value + componentSize); + } else { + _xifexpression = (componentSize + lastTopAddress); + } + final long byteSize = _xifexpression; + topAddress = Math.max(topAddress, byteSize); + lastTopAddress = byteSize; + } + } + return topAddress; + } + + public long byteSize(final Instantiation instantiation) { + final ComponentDefinition componentDefinition = this.definingComponent(instantiation); + long componentSize = 0; + ComponentDefinitionType _type = this.definingComponent(instantiation).getType(); + boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG); + if (_equals) { + long _regWidth = this.regWidth(this.definingComponent(instantiation)); + long _divide = (_regWidth / 8); + componentSize = _divide; + } else { + EList _instantiations = componentDefinition.getInstantiations(); + for (final Instantiation subInstantiation : _instantiations) { + componentSize = this.byteSize(subInstantiation, componentSize); + } + } + return componentSize; + } + public abstract String generateHeader(); public abstract String generateSource(); diff --git a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RegfileGenerator.java b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RegfileGenerator.java index 583e250..dfe9f6a 100644 --- a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RegfileGenerator.java +++ b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RegfileGenerator.java @@ -192,34 +192,44 @@ public class RegfileGenerator extends RdlBaseGenerator { { boolean _isFilledByField = this.isFilledByField(instantiation); if (_isFilledByField) { - _builder.append(" "); - _builder.append("uint"); - long _size = this.getSize(instantiation); - _builder.append(_size, " "); - _builder.append("_t "); - final Function1 _function_1 = (ComponentInstance it) -> { - Range _range = it.getRange(); - return Boolean.valueOf((_range == null)); - }; - final Function1 _function_2 = (ComponentInstance it) -> { - String _name_2 = it.getName(); - return ("r_" + _name_2); - }; - String _join_1 = IterableExtensions.join(IterableExtensions.map(IterableExtensions.filter(instantiation.getComponentInstances(), _function_1), _function_2), ", "); - _builder.append(_join_1, " "); - _builder.append(";"); - _builder.newLineIfNotEmpty(); { - final Function1 _function_3 = (ComponentInstance it) -> { + final Function1 _function_1 = (ComponentInstance it) -> { + Range _range = it.getRange(); + return Boolean.valueOf((_range == null)); + }; + int _size = IterableExtensions.size(IterableExtensions.filter(instantiation.getComponentInstances(), _function_1)); + boolean _greaterThan = (_size > 0); + if (_greaterThan) { + _builder.append(" "); + _builder.append("uint"); + long _size_1 = this.getSize(instantiation); + _builder.append(_size_1, " "); + _builder.append("_t "); + final Function1 _function_2 = (ComponentInstance it) -> { + Range _range = it.getRange(); + return Boolean.valueOf((_range == null)); + }; + final Function1 _function_3 = (ComponentInstance it) -> { + String _name_2 = it.getName(); + return ("r_" + _name_2); + }; + String _join_1 = IterableExtensions.join(IterableExtensions.map(IterableExtensions.filter(instantiation.getComponentInstances(), _function_2), _function_3), ", "); + _builder.append(_join_1, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + { + final Function1 _function_4 = (ComponentInstance it) -> { Range _range = it.getRange(); return Boolean.valueOf((_range != null)); }; - Iterable _filter = IterableExtensions.filter(instantiation.getComponentInstances(), _function_3); + Iterable _filter = IterableExtensions.filter(instantiation.getComponentInstances(), _function_4); for(final ComponentInstance componentInstance : _filter) { _builder.append(" "); _builder.append("std::array _function_4 = (ComponentInstance it) -> { + final Function1 _function_5 = (ComponentInstance it) -> { Range _range = it.getRange(); return Boolean.valueOf((_range == null)); }; - final Function1 _function_5 = (ComponentInstance it) -> { + final Function1 _function_6 = (ComponentInstance it) -> { String _name_3 = it.getName(); return ("r_" + _name_3); }; - String _join_2 = IterableExtensions.join(IterableExtensions.map(IterableExtensions.filter(instantiation.getComponentInstances(), _function_4), _function_5), ", "); + String _join_2 = IterableExtensions.join(IterableExtensions.map(IterableExtensions.filter(instantiation.getComponentInstances(), _function_5), _function_6), ", "); _builder.append(_join_2, " "); _builder.append(";"); _builder.newLineIfNotEmpty(); { - final Function1 _function_6 = (ComponentInstance it) -> { + final Function1 _function_7 = (ComponentInstance it) -> { Range _range = it.getRange(); return Boolean.valueOf((_range != null)); }; - Iterable _filter_1 = IterableExtensions.filter(instantiation.getComponentInstances(), _function_6); + Iterable _filter_1 = IterableExtensions.filter(instantiation.getComponentInstances(), _function_7); for(final ComponentInstance componentInstance_1 : _filter_1) { _builder.append(" "); _builder.append("std::array<"); @@ -311,8 +321,8 @@ public class RegfileGenerator extends RdlBaseGenerator { if (_isFilledByField_2) { _builder.append(" "); _builder.append("sysc::sc_register "); String _name_4 = instance.getName(); _builder.append(_name_4, " "); @@ -345,9 +355,9 @@ public class RegfileGenerator extends RdlBaseGenerator { boolean _isFilledByField_4 = this.isFilledByField(instantiation_1); if (_isFilledByField_4) { _builder.append(" "); - _builder.append("sysc::sc_register_indexed<"); - long _size_4 = this.getSize(instantiation_1); - _builder.append(_size_4, " "); + _builder.append("sysc::sc_register_indexed