diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/RdlUtil.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/RdlUtil.xtend new file mode 100644 index 0000000..16ac2e2 --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/RdlUtil.xtend @@ -0,0 +1,157 @@ +package com.minres.rdl + +import com.minres.rdl.rdl.ComponentInstance +import com.minres.rdl.rdl.ComponentDefinition +import com.minres.rdl.rdl.ExplicitPropertyAssignment +import com.minres.rdl.rdl.PropertyAssignment +import com.minres.rdl.rdl.Instantiation +import com.minres.rdl.rdl.ComponentDefinitionType +import com.minres.rdl.rdl.PropertyEnum +import com.minres.rdl.rdl.PropertyAssignmentRhs +import com.minres.rdl.rdl.RValue +import com.minres.rdl.rdl.RValueConstant +import com.minres.rdl.rdl.InstancePropertyRef + +class RdlUtil { + + static def IntegerWithRadix addressValue(ComponentInstance instance) { + if (instance.address !== null) + return instance.address as IntegerWithRadix + else + return new IntegerWithRadix(0) + } + + def long accessWidth(ComponentDefinition definition){ + var size = 32L + val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | + pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.ACCESSWIDTH + ] + if(pa !== null){ + val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue) + size=sz.value + } + return size + } + + static 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 + } + + static def long getSize(Instantiation instantiation){ + val componentDef= instantiation.definingComponent + switch (componentDef.type) { + case ComponentDefinitionType.REG: { + val pa = componentDef.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) + return sz.value + } + return 32L + } + case ComponentDefinitionType.FIELD:{ + val pa = componentDef.propertyAssignments.findFirst[PropertyAssignment pa | + pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.FIELDWIDTH + ] + if(pa !== null){ + val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue) + return sz.value + } + return 1L + } + default: { + return 0L; + } + } + } + + static def String effectiveName(ComponentDefinition definition){ + if(definition.name!==null){ + return definition.name.replaceAll('\\s+', '_') + } else{ + val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | + pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.NAME + ] + if(pa !== null) + return (pa as ExplicitPropertyAssignment).rhs.effectiveValue.replaceAll('\\s+', '_') + else + return ('unnamed_'+definition.type).replaceAll('\\s+', '_') + } + } + + static def String effectiveValue(PropertyAssignmentRhs rhs){ + if(rhs.value!== null) + rhs.value.effectiveValue + else if(rhs.instPropRef!==null) + rhs.instPropRef.effectiveValue + else if(rhs.enumRef!==null) + rhs.enumRef.name + } + + static def String effectiveValue(RValue rvalue){ + if(rvalue.str!==null){ + rvalue.str + } else if(rvalue.^val!=RValueConstant.UNDEFINED) + rvalue.^val.literal + else if(rvalue.num!==null){ + val num = rvalue.num as IntegerWithRadix + num.toString + } + } + + static def String effectiveValue(InstancePropertyRef ref){ + throw new RuntimeException() + } + + static def ComponentDefinition definingComponent(Instantiation instantiation){ + if(instantiation.componentRef!==null) instantiation.componentRef else instantiation.component + } + + static def int instanceCount(ComponentDefinition definition, ComponentDefinitionType type){ + definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2| p1+p2] + } + + static def instantiationsOfType(ComponentDefinition definition, ComponentDefinitionType type){ + definition.instantiations.filter[it.definingComponent.type == type] + } + + static 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 + } + + static 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 + } + +} \ No newline at end of file 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 3aa455f..b7a8652 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 @@ -4,6 +4,10 @@ import com.minres.rdl.generator.RdlBaseGenerator import com.minres.rdl.rdl.ComponentDefinition import com.minres.rdl.IntegerWithRadix import com.minres.rdl.rdl.ComponentDefinitionType +import com.minres.rdl.rdl.ComponentInstance +import com.minres.rdl.rdl.Instantiation + +import static extension com.minres.rdl.RdlUtil.* class AddrmapGenerator extends RdlBaseGenerator { @@ -14,21 +18,21 @@ class AddrmapGenerator extends RdlBaseGenerator { } override generateHeader() {''' - #ifndef _E300_PLAT_MAP_H_ - #define _E300_PLAT_MAP_H_ + #ifndef _«componentDefinition.effectiveName.toUpperCase»_MAP_H_ + #define _«componentDefinition.effectiveName.toUpperCase»_MAP_H_ // need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191 - const std::array, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> e300_plat_map = {{ + const std::array, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> «componentDefinition.effectiveName»_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.byteSize)»}, + {&i_«instance.name», «instance.addressValue», 0x«Long.toHexString(instantiation.byteSize)»}, «ENDFOR» «ENDFOR» }}; - #endif /* _E300_PLAT_MAP_H_ */ + #endif /* _«componentDefinition.effectiveName.toUpperCase»_MAP_H_ */ ''' } - + override generateSource() { '' } diff --git a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RDLGenerator.xtend b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RDLGenerator.xtend index a9c5780..ee292da 100644 --- a/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RDLGenerator.xtend +++ b/com.minres.rdl.parent/com.minres.rdl/src/com/minres/rdl/generator/RDLGenerator.xtend @@ -9,6 +9,7 @@ import org.eclipse.emf.ecore.resource.Resource import org.eclipse.xtext.generator.AbstractGenerator import org.eclipse.xtext.generator.IFileSystemAccess2 import org.eclipse.xtext.generator.IGeneratorContext +import static extension com.minres.rdl.RdlUtil.* /** * Generates code from your model files on save. @@ -22,13 +23,13 @@ class RDLGenerator extends AbstractGenerator { val gen = it.fileGenerator if(gen!==null){ val header = gen.generateHeader - if(header!==null && header.length>0) fsa.generateFile(it.name+'.h', fsa.outputConfig('incl-out'), header) + if(header!==null && header.length>0) fsa.generateFile(it.effectiveName+'.h', fsa.outputConfig('incl-out'), header) val source = gen.generateSource - if(source!==null && source.length>0) fsa.generateFile(it.name+'.cpp', fsa.outputConfig('src-out'), source) + if(source!==null && source.length>0) fsa.generateFile(it.effectiveName+'.cpp', fsa.outputConfig('src-out'), source) } ] } - + def RdlBaseGenerator fileGenerator(ComponentDefinition definition){ switch(definition.type){ case ComponentDefinitionType.REGFILE: new RegfileGenerator(definition) 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 413f8f0..933afad 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,138 +13,7 @@ import com.minres.rdl.rdl.InstancePropertyRef import com.minres.rdl.rdl.ComponentDefinitionType abstract class RdlBaseGenerator { - - def long accessWidth(ComponentDefinition definition){ - var size = 32L - val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | - pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.ACCESSWIDTH - ] - if(pa !== null){ - val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue) - size=sz.value - } - 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) { - case ComponentDefinitionType.REG: { - val pa = componentDef.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) - return sz.value - } - return 32L - } - case ComponentDefinitionType.FIELD:{ - val pa = componentDef.propertyAssignments.findFirst[PropertyAssignment pa | - pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.FIELDWIDTH - ] - if(pa !== null){ - val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue) - return sz.value - } - return 1L - } - default: { - return 0L; - } - } - } - - def String effectiveName(ComponentDefinition definition){ - if(definition.name!==null){ - definition.name - } else{ - val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | - pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.NAME - ] - (pa as ExplicitPropertyAssignment).rhs.effectiveValue - } - - } - - def String effectiveValue(PropertyAssignmentRhs rhs){ - if(rhs.value!== null) - rhs.value.effectiveValue - else if(rhs.instPropRef!==null) - rhs.instPropRef.effectiveValue - else if(rhs.enumRef!==null) - rhs.enumRef.name - } - - def String effectiveValue(RValue rvalue){ - if(rvalue.str!==null){ - rvalue.str - } else if(rvalue.^val!=RValueConstant.UNDEFINED) - rvalue.^val.literal - else if(rvalue.num!==null){ - val num = rvalue.num as IntegerWithRadix - num.toString - } - } - - 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 fc7d12e..a74635f 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 @@ -8,6 +8,8 @@ import com.minres.rdl.rdl.Instantiation import java.util.Date import com.minres.rdl.rdl.Range +import static extension com.minres.rdl.RdlUtil.* + class RegfileGenerator extends RdlBaseGenerator{ val ComponentDefinition componentDefinition @@ -145,7 +147,7 @@ class RegfileGenerator extends RdlBaseGenerator{ inline void sysc::«componentDefinition.name»::registerResources(sysc::tlm_target& target) { «FOR instantiation : componentDefinition.instantiations» «FOR instance : instantiation.componentInstances» - target.addResource(«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)»UL); + target.addResource(«instance.name», «instance.addressValue»UL); «ENDFOR» «ENDFOR» } diff --git a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/RdlUtil.java b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/RdlUtil.java new file mode 100644 index 0000000..ec144d6 --- /dev/null +++ b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/RdlUtil.java @@ -0,0 +1,263 @@ +package com.minres.rdl; + +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; +import com.minres.rdl.rdl.Instantiation; +import com.minres.rdl.rdl.PropertyAssignment; +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") +public class RdlUtil { + public static IntegerWithRadix addressValue(final ComponentInstance instance) { + Object _address = instance.getAddress(); + boolean _tripleNotEquals = (_address != null); + if (_tripleNotEquals) { + Object _address_1 = instance.getAddress(); + return ((IntegerWithRadix) _address_1); + } else { + return new IntegerWithRadix(Integer.valueOf(0)); + } + } + + public long accessWidth(final ComponentDefinition definition) { + long size = 32L; + final Function1 _function = (PropertyAssignment pa) -> { + return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.ACCESSWIDTH))); + }; + final PropertyAssignment pa = IterableExtensions.findFirst(definition.getPropertyAssignments(), _function); + if ((pa != null)) { + String _effectiveValue = RdlUtil.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); + final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue); + size = sz.value; + } + return size; + } + + public static 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 = RdlUtil.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); + final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue); + size = sz.value; + } + return size; + } + + public static long getSize(final Instantiation instantiation) { + final ComponentDefinition componentDef = RdlUtil.definingComponent(instantiation); + ComponentDefinitionType _type = componentDef.getType(); + if (_type != null) { + switch (_type) { + case REG: + final Function1 _function = (PropertyAssignment pa) -> { + return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.REGWIDTH))); + }; + final PropertyAssignment pa = IterableExtensions.findFirst(componentDef.getPropertyAssignments(), _function); + if ((pa != null)) { + String _effectiveValue = RdlUtil.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); + final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue); + return sz.value; + } + return 32L; + case FIELD: + final Function1 _function_1 = (PropertyAssignment pa_1) -> { + return Boolean.valueOf(((pa_1 instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa_1).getName(), PropertyEnum.FIELDWIDTH))); + }; + final PropertyAssignment pa_1 = IterableExtensions.findFirst(componentDef.getPropertyAssignments(), _function_1); + if ((pa_1 != null)) { + String _effectiveValue_1 = RdlUtil.effectiveValue(((ExplicitPropertyAssignment) pa_1).getRhs()); + final IntegerWithRadix sz_1 = new IntegerWithRadix(_effectiveValue_1); + return sz_1.value; + } + return 1L; + default: + return 0L; + } + } else { + return 0L; + } + } + + public static String effectiveName(final ComponentDefinition definition) { + String _name = definition.getName(); + boolean _tripleNotEquals = (_name != null); + if (_tripleNotEquals) { + return definition.getName().replaceAll("\\s+", "_"); + } else { + final Function1 _function = (PropertyAssignment pa) -> { + return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.NAME))); + }; + final PropertyAssignment pa = IterableExtensions.findFirst(definition.getPropertyAssignments(), _function); + if ((pa != null)) { + return RdlUtil.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()).replaceAll("\\s+", "_"); + } else { + ComponentDefinitionType _type = definition.getType(); + return ("unnamed_" + _type).replaceAll("\\s+", "_"); + } + } + } + + public static String effectiveValue(final PropertyAssignmentRhs rhs) { + String _xifexpression = null; + RValue _value = rhs.getValue(); + boolean _tripleNotEquals = (_value != null); + if (_tripleNotEquals) { + _xifexpression = RdlUtil.effectiveValue(rhs.getValue()); + } else { + String _xifexpression_1 = null; + InstancePropertyRef _instPropRef = rhs.getInstPropRef(); + boolean _tripleNotEquals_1 = (_instPropRef != null); + if (_tripleNotEquals_1) { + _xifexpression_1 = RdlUtil.effectiveValue(rhs.getInstPropRef()); + } else { + String _xifexpression_2 = null; + EnumDefinition _enumRef = rhs.getEnumRef(); + boolean _tripleNotEquals_2 = (_enumRef != null); + if (_tripleNotEquals_2) { + _xifexpression_2 = rhs.getEnumRef().getName(); + } + _xifexpression_1 = _xifexpression_2; + } + _xifexpression = _xifexpression_1; + } + return _xifexpression; + } + + public static String effectiveValue(final RValue rvalue) { + String _xifexpression = null; + String _str = rvalue.getStr(); + boolean _tripleNotEquals = (_str != null); + if (_tripleNotEquals) { + _xifexpression = rvalue.getStr(); + } else { + String _xifexpression_1 = null; + RValueConstant _val = rvalue.getVal(); + boolean _notEquals = (!Objects.equal(_val, RValueConstant.UNDEFINED)); + if (_notEquals) { + _xifexpression_1 = rvalue.getVal().getLiteral(); + } else { + String _xifexpression_2 = null; + Object _num = rvalue.getNum(); + boolean _tripleNotEquals_1 = (_num != null); + if (_tripleNotEquals_1) { + String _xblockexpression = null; + { + Object _num_1 = rvalue.getNum(); + final IntegerWithRadix num = ((IntegerWithRadix) _num_1); + _xblockexpression = num.toString(); + } + _xifexpression_2 = _xblockexpression; + } + _xifexpression_1 = _xifexpression_2; + } + _xifexpression = _xifexpression_1; + } + return _xifexpression; + } + + public static String effectiveValue(final InstancePropertyRef ref) { + throw new RuntimeException(); + } + + public static ComponentDefinition definingComponent(final Instantiation instantiation) { + ComponentDefinition _xifexpression = null; + ComponentDefinition _componentRef = instantiation.getComponentRef(); + boolean _tripleNotEquals = (_componentRef != null); + if (_tripleNotEquals) { + _xifexpression = instantiation.getComponentRef(); + } else { + _xifexpression = instantiation.getComponent(); + } + return _xifexpression; + } + + public static 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(RdlUtil.instantiationsOfType(definition, type), _function), _function_1); + } + + public static Iterable instantiationsOfType(final ComponentDefinition definition, final ComponentDefinitionType type) { + final Function1 _function = (Instantiation it) -> { + ComponentDefinitionType _type = RdlUtil.definingComponent(it).getType(); + return Boolean.valueOf(Objects.equal(_type, type)); + }; + return IterableExtensions.filter(definition.getInstantiations(), _function); + } + + public static long byteSize(final Instantiation instantiation, final long start) { + final ComponentDefinition componentDefinition = RdlUtil.definingComponent(instantiation); + long componentSize = 0; + ComponentDefinitionType _type = RdlUtil.definingComponent(instantiation).getType(); + boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG); + if (_equals) { + long _regWidth = RdlUtil.regWidth(RdlUtil.definingComponent(instantiation)); + long _divide = (_regWidth / 8); + componentSize = _divide; + } else { + EList _instantiations = componentDefinition.getInstantiations(); + for (final Instantiation subInstantiation : _instantiations) { + componentSize = RdlUtil.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 static long byteSize(final Instantiation instantiation) { + final ComponentDefinition componentDefinition = RdlUtil.definingComponent(instantiation); + long componentSize = 0; + ComponentDefinitionType _type = RdlUtil.definingComponent(instantiation).getType(); + boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG); + if (_equals) { + long _regWidth = RdlUtil.regWidth(RdlUtil.definingComponent(instantiation)); + long _divide = (_regWidth / 8); + componentSize = _divide; + } else { + EList _instantiations = componentDefinition.getInstantiations(); + for (final Instantiation subInstantiation : _instantiations) { + componentSize = RdlUtil.byteSize(subInstantiation, componentSize); + } + } + return componentSize; + } +} 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 45ef074..3b0f1ef 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,7 @@ package com.minres.rdl.generator; import com.minres.rdl.IntegerWithRadix; +import com.minres.rdl.RdlUtil; import com.minres.rdl.generator.RdlBaseGenerator; import com.minres.rdl.rdl.ComponentDefinition; import com.minres.rdl.rdl.ComponentDefinitionType; @@ -20,19 +21,28 @@ public class AddrmapGenerator extends RdlBaseGenerator { @Override public String generateHeader() { StringConcatenation _builder = new StringConcatenation(); - _builder.append("#ifndef _E300_PLAT_MAP_H_"); - _builder.newLine(); - _builder.append("#define _E300_PLAT_MAP_H_"); - _builder.newLine(); + _builder.append("#ifndef _"); + String _upperCase = RdlUtil.effectiveName(this.componentDefinition).toUpperCase(); + _builder.append(_upperCase); + _builder.append("_MAP_H_"); + _builder.newLineIfNotEmpty(); + _builder.append("#define _"); + String _upperCase_1 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase(); + _builder.append(_upperCase_1); + _builder.append("_MAP_H_"); + _builder.newLineIfNotEmpty(); _builder.append("// need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191"); _builder.newLine(); _builder.append("const std::array, "); - int _instanceCount = this.instanceCount(this.componentDefinition, ComponentDefinitionType.REGFILE); + int _instanceCount = RdlUtil.instanceCount(this.componentDefinition, ComponentDefinitionType.REGFILE); _builder.append(_instanceCount); - _builder.append("> e300_plat_map = {{"); + _builder.append("> "); + String _effectiveName = RdlUtil.effectiveName(this.componentDefinition); + _builder.append(_effectiveName); + _builder.append("_map = {{"); _builder.newLineIfNotEmpty(); { - Iterable _instantiationsOfType = this.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE); + Iterable _instantiationsOfType = RdlUtil.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE); for(final Instantiation instantiation : _instantiationsOfType) { { EList _componentInstances = instantiation.getComponentInstances(); @@ -41,13 +51,12 @@ public class AddrmapGenerator extends RdlBaseGenerator { _builder.append("{&i_"); String _name = instance.getName(); _builder.append(_name, " "); + _builder.append(", "); + IntegerWithRadix _addressValue = RdlUtil.addressValue(instance); + _builder.append(_addressValue, " "); _builder.append(", 0x"); - Object _address = instance.getAddress(); - String _hexString = Long.toHexString(((IntegerWithRadix) _address).value); + String _hexString = Long.toHexString(RdlUtil.byteSize(instantiation)); _builder.append(_hexString, " "); - _builder.append(", 0x"); - String _hexString_1 = Long.toHexString(this.byteSize(instantiation)); - _builder.append(_hexString_1, " "); _builder.append("},"); _builder.newLineIfNotEmpty(); } @@ -57,8 +66,11 @@ public class AddrmapGenerator extends RdlBaseGenerator { _builder.append("}};"); _builder.newLine(); _builder.newLine(); - _builder.append("#endif /* _E300_PLAT_MAP_H_ */"); - _builder.newLine(); + _builder.append("#endif /* _"); + String _upperCase_2 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase(); + _builder.append(_upperCase_2); + _builder.append("_MAP_H_ */"); + _builder.newLineIfNotEmpty(); return _builder.toString(); } diff --git a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RDLGenerator.java b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RDLGenerator.java index 026e5df..238728c 100644 --- a/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RDLGenerator.java +++ b/com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/RDLGenerator.java @@ -3,6 +3,7 @@ */ package com.minres.rdl.generator; +import com.minres.rdl.RdlUtil; import com.minres.rdl.generator.AddrmapGenerator; import com.minres.rdl.generator.RdlBaseGenerator; import com.minres.rdl.generator.RegfileGenerator; @@ -38,14 +39,14 @@ public class RDLGenerator extends AbstractGenerator { if ((gen != null)) { final String header = gen.generateHeader(); if (((header != null) && (header.length() > 0))) { - String _name = it.getName(); - String _plus = (_name + ".h"); + String _effectiveName = RdlUtil.effectiveName(it); + String _plus = (_effectiveName + ".h"); fsa.generateFile(_plus, this.outputConfig(fsa, "incl-out"), header); } final String source = gen.generateSource(); if (((source != null) && (source.length() > 0))) { - String _name_1 = it.getName(); - String _plus_1 = (_name_1 + ".cpp"); + String _effectiveName_1 = RdlUtil.effectiveName(it); + String _plus_1 = (_effectiveName_1 + ".cpp"); fsa.generateFile(_plus_1, this.outputConfig(fsa, "src-out"), source); } } 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 4117828..6e5a9ab 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 @@ -1,256 +1,7 @@ package com.minres.rdl.generator; -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; -import com.minres.rdl.rdl.Instantiation; -import com.minres.rdl.rdl.PropertyAssignment; -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") public abstract class RdlBaseGenerator { - public long accessWidth(final ComponentDefinition definition) { - long size = 32L; - final Function1 _function = (PropertyAssignment pa) -> { - return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.ACCESSWIDTH))); - }; - 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 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(); - if (_type != null) { - switch (_type) { - case REG: - final Function1 _function = (PropertyAssignment pa) -> { - return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.REGWIDTH))); - }; - final PropertyAssignment pa = IterableExtensions.findFirst(componentDef.getPropertyAssignments(), _function); - if ((pa != null)) { - String _effectiveValue = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); - final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue); - return sz.value; - } - return 32L; - case FIELD: - final Function1 _function_1 = (PropertyAssignment pa_1) -> { - return Boolean.valueOf(((pa_1 instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa_1).getName(), PropertyEnum.FIELDWIDTH))); - }; - final PropertyAssignment pa_1 = IterableExtensions.findFirst(componentDef.getPropertyAssignments(), _function_1); - if ((pa_1 != null)) { - String _effectiveValue_1 = this.effectiveValue(((ExplicitPropertyAssignment) pa_1).getRhs()); - final IntegerWithRadix sz_1 = new IntegerWithRadix(_effectiveValue_1); - return sz_1.value; - } - return 1L; - default: - return 0L; - } - } else { - return 0L; - } - } - - public String effectiveName(final ComponentDefinition definition) { - String _xifexpression = null; - String _name = definition.getName(); - boolean _tripleNotEquals = (_name != null); - if (_tripleNotEquals) { - _xifexpression = definition.getName(); - } else { - String _xblockexpression = null; - { - final Function1 _function = (PropertyAssignment pa) -> { - return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.NAME))); - }; - final PropertyAssignment pa = IterableExtensions.findFirst(definition.getPropertyAssignments(), _function); - _xblockexpression = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs()); - } - _xifexpression = _xblockexpression; - } - return _xifexpression; - } - - public String effectiveValue(final PropertyAssignmentRhs rhs) { - String _xifexpression = null; - RValue _value = rhs.getValue(); - boolean _tripleNotEquals = (_value != null); - if (_tripleNotEquals) { - _xifexpression = this.effectiveValue(rhs.getValue()); - } else { - String _xifexpression_1 = null; - InstancePropertyRef _instPropRef = rhs.getInstPropRef(); - boolean _tripleNotEquals_1 = (_instPropRef != null); - if (_tripleNotEquals_1) { - _xifexpression_1 = this.effectiveValue(rhs.getInstPropRef()); - } else { - String _xifexpression_2 = null; - EnumDefinition _enumRef = rhs.getEnumRef(); - boolean _tripleNotEquals_2 = (_enumRef != null); - if (_tripleNotEquals_2) { - _xifexpression_2 = rhs.getEnumRef().getName(); - } - _xifexpression_1 = _xifexpression_2; - } - _xifexpression = _xifexpression_1; - } - return _xifexpression; - } - - public String effectiveValue(final RValue rvalue) { - String _xifexpression = null; - String _str = rvalue.getStr(); - boolean _tripleNotEquals = (_str != null); - if (_tripleNotEquals) { - _xifexpression = rvalue.getStr(); - } else { - String _xifexpression_1 = null; - RValueConstant _val = rvalue.getVal(); - boolean _notEquals = (!Objects.equal(_val, RValueConstant.UNDEFINED)); - if (_notEquals) { - _xifexpression_1 = rvalue.getVal().getLiteral(); - } else { - String _xifexpression_2 = null; - Object _num = rvalue.getNum(); - boolean _tripleNotEquals_1 = (_num != null); - if (_tripleNotEquals_1) { - String _xblockexpression = null; - { - Object _num_1 = rvalue.getNum(); - final IntegerWithRadix num = ((IntegerWithRadix) _num_1); - _xblockexpression = num.toString(); - } - _xifexpression_2 = _xblockexpression; - } - _xifexpression_1 = _xifexpression_2; - } - _xifexpression = _xifexpression_1; - } - return _xifexpression; - } - - public String effectiveValue(final InstancePropertyRef ref) { - throw new RuntimeException(); - } - - public ComponentDefinition definingComponent(final Instantiation instantiation) { - ComponentDefinition _xifexpression = null; - ComponentDefinition _componentRef = instantiation.getComponentRef(); - boolean _tripleNotEquals = (_componentRef != null); - if (_tripleNotEquals) { - _xifexpression = instantiation.getComponentRef(); - } else { - _xifexpression = instantiation.getComponent(); - } - 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 dffa55e..4db471a 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 @@ -2,6 +2,7 @@ package com.minres.rdl.generator; import com.google.common.base.Objects; import com.minres.rdl.IntegerWithRadix; +import com.minres.rdl.RdlUtil; import com.minres.rdl.generator.RdlBaseGenerator; import com.minres.rdl.rdl.ComponentDefinition; import com.minres.rdl.rdl.ComponentDefinitionType; @@ -152,7 +153,7 @@ public class RegfileGenerator extends RdlBaseGenerator { if (_equals) { _builder.append(" "); _builder.append("BEGIN_BF_DECL("); - String _effectiveName = this.effectiveName(cdef); + String _effectiveName = RdlUtil.effectiveName(cdef); _builder.append(_effectiveName, " "); _builder.append("+\'_t\'», uint"); _builder.append(cdef, " "); @@ -175,7 +176,7 @@ public class RegfileGenerator extends RdlBaseGenerator { { if (((instantiation.getComponentRef() != null) && Objects.equal(instantiation.getComponentRef().getType(), ComponentDefinitionType.REG))) { _builder.append(" "); - String _effectiveName_1 = this.effectiveName(instantiation.getComponentRef()); + String _effectiveName_1 = RdlUtil.effectiveName(instantiation.getComponentRef()); _builder.append(_effectiveName_1, " "); _builder.append("+\'_t\' "); final Function1 _function = (ComponentInstance it) -> { @@ -202,7 +203,7 @@ public class RegfileGenerator extends RdlBaseGenerator { if (_greaterThan) { _builder.append(" "); _builder.append("uint"); - long _size_1 = this.getSize(instantiation); + long _size_1 = RdlUtil.getSize(instantiation); _builder.append(_size_1, " "); _builder.append("_t "); final Function1 _function_2 = (ComponentInstance it) -> { @@ -228,7 +229,7 @@ public class RegfileGenerator extends RdlBaseGenerator { for(final ComponentInstance componentInstance : _filter) { _builder.append(" "); _builder.append("std::array "); String _name_4 = instance.getName(); @@ -336,7 +337,7 @@ public class RegfileGenerator extends RdlBaseGenerator { if (_not_1) { _builder.append(" "); _builder.append("sysc::sc_register<"); - String _effectiveName_4 = this.effectiveName(instantiation_1.getComponent()); + String _effectiveName_4 = RdlUtil.effectiveName(instantiation_1.getComponent()); _builder.append(_effectiveName_4, " "); _builder.append("_t> "); String _name_5 = instance.getName(); @@ -356,7 +357,7 @@ public class RegfileGenerator extends RdlBaseGenerator { if (_isFilledByField_4) { _builder.append(" "); _builder.append("sysc::sc_register_indexed _function_1 = (Integer p1, Integer p2) -> { return Integer.valueOf(((p1).intValue() + (p1).intValue())); }; - return (int) IterableExtensions.reduce(IterableExtensions.map(this.instantiationsOfType(definition, type), _function), _function_1); + return (int) IterableExtensions.reduce(IterableExtensions.map(RdlUtil.instantiationsOfType(definition, type), _function), _function_1); } @Override