fix #1 'Generate register access functions for FW'

This commit is contained in:
Eyck Jentzsch 2020-10-08 08:40:04 +02:00
parent 1804692f8d
commit add1d362cc
6 changed files with 1007 additions and 26 deletions

View File

@ -0,0 +1,86 @@
package com.minres.rdl.generator
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ComponentDefinitionType
import java.util.Date
import static extension com.minres.rdl.RdlUtil.*
class FwAddrmapGenerator extends RdlBaseGenerator {
val ComponentDefinition componentDefinition
new(ComponentDefinition definition) {
componentDefinition=definition
}
val nameMap = newLinkedHashSet()
override generateHeader() {'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created on: «new Date»
// * «componentDefinition.name».h Author: <RDL Generator>
//
////////////////////////////////////////////////////////////////////////////////
#ifndef _«componentDefinition.effectiveName.toUpperCase»_MAP_H_
#define _«componentDefinition.effectiveName.toUpperCase»_MAP_H_
«FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»
«IF instantiation.component !== null && !nameMap.contains(instantiation.component.name)»
#include "«instantiation.component.name».h"«nameMap.add(instantiation.component.name)»
«ENDIF»
«IF instantiation.componentRef !== null && !nameMap.contains(instantiation.componentRef.name)»
#include "«instantiation.componentRef.name».h"«nameMap.add(instantiation.componentRef.name)»
«ENDIF»
«ENDFOR»
«FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»
«FOR instance : instantiation.componentInstances»
«IF instantiation.component !== null»
using «instance.name» = «instantiation.component.name»<«instance.addressValue»ULL>;
«ENDIF»
«IF instantiation.componentRef !== null»
using «instance.name» = «instantiation.componentRef.name»<«instance.addressValue»ULL>;
«ENDIF»
«ENDFOR»
«ENDFOR»
#endif /* _«componentDefinition.effectiveName.toUpperCase»_MAP_H_ */
'''
}
override generateSource() {
''
}
}

View File

@ -0,0 +1,179 @@
package com.minres.rdl.generator
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.Instantiation
import java.util.Date
import com.minres.rdl.rdl.Range
import static extension com.minres.rdl.RdlUtil.*
class FwRegfileGenerator extends RdlBaseGenerator{
val ComponentDefinition componentDefinition
new(ComponentDefinition definition) {
componentDefinition=definition
}
override String generateHeader()'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created on: «new Date»
// * «componentDefinition.name».h Author: <RDL Generator>
//
////////////////////////////////////////////////////////////////////////////////
#ifndef _«componentDefinition.name.toUpperCase»_H_
#define _«componentDefinition.name.toUpperCase»_H_
#include <util/bit_field.h>
#include <nonstd/span.hpp>
#include <cstdint>
template<size_t BASE_ADDR>
struct «componentDefinition.name» {
«FOR cdef : componentDefinition.componentDefinitions»
«IF cdef.type == ComponentDefinitionType.REG»
BEGIN_BF_DECL(«cdef.effectiveName»+'_t'», uint«cdef»_t);
«cdef.genFieldDeclarations»
END_BF_DECL();
«ENDIF»
«ENDFOR»
«FOR instantiation : componentDefinition.instantiations»
«IF instantiation.componentRef !==null && instantiation.componentRef.type == ComponentDefinitionType.REG»
«instantiation.componentRef.effectiveName»+'_t' «instantiation.componentInstances.map[it.name].join(', ')»;
«ENDIF»
«IF instantiation.component !== null && instantiation.component.type == ComponentDefinitionType.REG»
«IF !instantiation.isFilledByField»
BEGIN_BF_DECL(«instantiation.component.effectiveName»_t, uint«instantiation.size»_t);
«instantiation.definingComponent.genFieldDeclarations»
END_BF_DECL() «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»;
«ENDIF»
«ENDIF»
«ENDFOR»
// register access
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
«IF instance.range===null»
«IF instantiation.isFilledByField»
static inline uint«instantiation.size»_t& «instance.name»(){
return *reinterpret_cast<«instance.name»_t*>(BASE_ADDR+«instance.addressValue»UL);
}
«ENDIF»
«IF !instantiation.isFilledByField»
static inline «instance.name»_t& «instance.name»(){
return *reinterpret_cast<«instance.name»_t*>(BASE_ADDR+«instance.addressValue»UL);
}
«ENDIF»
«ENDIF»
«IF instance.range!==null»
«IF instantiation.isFilledByField»
static inline nonstd::span<uint«instantiation.size»_t, «instance.range.absSize»>& «instance.name»(){
return *reinterpret_cast<nonstd::span<uint«instantiation.size»_t, «instance.range.absSize»>*>(BASE_ADDR+«instance.addressValue»UL);
}
«ENDIF»
«IF !instantiation.isFilledByField»
static inline nonstd::span<«instance.name»_t, «instance.range.absSize»>& «instance.name»(){
return *reinterpret_cast<nonstd::span<«instance.name»_t, «instance.range.absSize»>*>(BASE_ADDR+«instance.addressValue»UL);
}
«ENDIF»
«ENDIF»
«ENDFOR»
«ENDFOR»
};
#endif // _«componentDefinition.name.toUpperCase»_H_
'''
def long absSize(Range range){
if(range.size!==null)
return (range.size as IntegerWithRadix).value
else
return Math.abs((range.left as IntegerWithRadix).value - (range.right as IntegerWithRadix).value)+1
}
def boolean isFilledByField(Instantiation instantiation){
val fieldCount = instantiation.component.instanceCountOfType(ComponentDefinitionType.FIELD)
if(fieldCount==1) {
val instSize=instantiation.size
val field = instantiation.component.instantiationsOfType(ComponentDefinitionType.FIELD).get(0)
val inst = field.componentInstances.get(0)
val range = inst.range
if(range===null)
return instSize==field.size
if(range.size !== null)
return instSize==(range.size as IntegerWithRadix).value
else {
val left=(range.left as IntegerWithRadix).value
val right=(range.right as IntegerWithRadix).value
val size = if(left>right) left-right+1 else right-left+1
return instSize==size
}
}
return false
}
def int instanceCountOfType(ComponentDefinition definition, ComponentDefinitionType type){
definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2|p1+p1]
}
override generateSource() {
''
}
def String genFieldDeclarations(ComponentDefinition componentDef){
var i=0L;
var res = ""
for( Instantiation inst: componentDef.instantiations){
for(ComponentInstance compInst : inst.componentInstances){
if(compInst.range.size!==null){
res+='''BF_FIELD(«compInst.name», «i», «(compInst.range.size as IntegerWithRadix).value»);
'''
i+=(compInst.range.size as IntegerWithRadix).value
} else {
val start =(compInst.range.left as IntegerWithRadix).value
val end = (compInst.range.right as IntegerWithRadix).value
res+='''BF_FIELD(«compInst.name», «end», «start-end+1»);
'''
i=Math.max(start, end)+1
}
}
}
res
}
}

View File

@ -10,6 +10,7 @@ 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.*
import java.util.Map
/**
* Generates code from your model files on save.
@ -20,20 +21,22 @@ class RDLGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
resource.resourceSet.allContents.filter[ it instanceof ComponentDefinition].map[it as ComponentDefinition].forEach[
val gen = it.fileGenerator
if(gen!==null){
val genMap = it.fileGenerator
if(genMap!==null) genMap.forEach[p1, gen |
val header = gen.generateHeader
if(header!==null && header.length>0) fsa.generateFile(it.effectiveName+'.h', fsa.outputConfig('incl-out'), header)
if(header!==null && header.length>0)
fsa.generateFile(p1+'/'+it.effectiveName+'.h', fsa.outputConfig('incl-out'), header)
val source = gen.generateSource
if(source!==null && source.length>0) fsa.generateFile(it.effectiveName+'.cpp', fsa.outputConfig('src-out'), source)
}
if(source!==null && source.length>0)
fsa.generateFile(p1+'/'+it.effectiveName+'.cpp', fsa.outputConfig('src-out'), source)
]
]
}
def RdlBaseGenerator fileGenerator(ComponentDefinition definition){
def Map<String, RdlBaseGenerator> fileGenerator(ComponentDefinition definition){
switch(definition.type){
case ComponentDefinitionType.REGFILE: new RegfileGenerator(definition)
case ComponentDefinitionType.ADDRMAP: new AddrmapGenerator(definition)
case ComponentDefinitionType.REGFILE: #{'vp' -> new RegfileGenerator(definition), 'fw' -> new FwRegfileGenerator(definition)}
case ComponentDefinitionType.ADDRMAP: #{'vp' -> new AddrmapGenerator(definition), 'fw' -> new FwAddrmapGenerator(definition)}
default: null
}
}

View File

@ -0,0 +1,200 @@
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;
import com.minres.rdl.rdl.ComponentInstance;
import com.minres.rdl.rdl.Instantiation;
import java.util.Date;
import java.util.LinkedHashSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
@SuppressWarnings("all")
public class FwAddrmapGenerator extends RdlBaseGenerator {
private final ComponentDefinition componentDefinition;
public FwAddrmapGenerator(final ComponentDefinition definition) {
this.componentDefinition = definition;
}
private final LinkedHashSet<Object> nameMap = CollectionLiterals.<Object>newLinkedHashSet();
@Override
public String generateHeader() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// Copyright (C) 2020, MINRES Technologies GmbH");
_builder.newLine();
_builder.append("// All rights reserved.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// Redistribution and use in source and binary forms, with or without");
_builder.newLine();
_builder.append("// modification, are permitted provided that the following conditions are met:");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 1. Redistributions of source code must retain the above copyright notice,");
_builder.newLine();
_builder.append("// this list of conditions and the following disclaimer.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 2. Redistributions in binary form must reproduce the above copyright notice,");
_builder.newLine();
_builder.append("// this list of conditions and the following disclaimer in the documentation");
_builder.newLine();
_builder.append("// and/or other materials provided with the distribution.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 3. Neither the name of the copyright holder nor the names of its contributors");
_builder.newLine();
_builder.append("// may be used to endorse or promote products derived from this software");
_builder.newLine();
_builder.append("// without specific prior written permission.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"");
_builder.newLine();
_builder.append("// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE");
_builder.newLine();
_builder.append("// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE");
_builder.newLine();
_builder.append("// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
_builder.newLine();
_builder.append("// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
_builder.newLine();
_builder.append("// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
_builder.newLine();
_builder.append("// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS");
_builder.newLine();
_builder.append("// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
_builder.newLine();
_builder.append("// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)");
_builder.newLine();
_builder.append("// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE");
_builder.newLine();
_builder.append("// POSSIBILITY OF SUCH DAMAGE.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// Created on: ");
Date _date = new Date();
_builder.append(_date);
_builder.newLineIfNotEmpty();
_builder.append("// * ");
String _name = this.componentDefinition.getName();
_builder.append(_name);
_builder.append(".h Author: <RDL Generator>");
_builder.newLineIfNotEmpty();
_builder.append("//");
_builder.newLine();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_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.newLine();
{
Iterable<Instantiation> _instantiationsOfType = RdlUtil.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE);
for(final Instantiation instantiation : _instantiationsOfType) {
{
if (((instantiation.getComponent() != null) && (!this.nameMap.contains(instantiation.getComponent().getName())))) {
_builder.append("#include \"");
String _name_1 = instantiation.getComponent().getName();
_builder.append(_name_1);
_builder.append(".h\"");
boolean _add = this.nameMap.add(instantiation.getComponent().getName());
_builder.append(_add);
_builder.newLineIfNotEmpty();
}
}
{
if (((instantiation.getComponentRef() != null) && (!this.nameMap.contains(instantiation.getComponentRef().getName())))) {
_builder.append("#include \"");
String _name_2 = instantiation.getComponentRef().getName();
_builder.append(_name_2);
_builder.append(".h\"");
boolean _add_1 = this.nameMap.add(instantiation.getComponentRef().getName());
_builder.append(_add_1);
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.newLine();
{
Iterable<Instantiation> _instantiationsOfType_1 = RdlUtil.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE);
for(final Instantiation instantiation_1 : _instantiationsOfType_1) {
{
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
{
ComponentDefinition _component = instantiation_1.getComponent();
boolean _tripleNotEquals = (_component != null);
if (_tripleNotEquals) {
_builder.append("using ");
String _name_3 = instance.getName();
_builder.append(_name_3);
_builder.append(" = ");
String _name_4 = instantiation_1.getComponent().getName();
_builder.append(_name_4);
_builder.append("<");
IntegerWithRadix _addressValue = RdlUtil.addressValue(instance);
_builder.append(_addressValue);
_builder.append("ULL>;");
_builder.newLineIfNotEmpty();
}
}
{
ComponentDefinition _componentRef = instantiation_1.getComponentRef();
boolean _tripleNotEquals_1 = (_componentRef != null);
if (_tripleNotEquals_1) {
_builder.append("using ");
String _name_5 = instance.getName();
_builder.append(_name_5);
_builder.append(" = ");
String _name_6 = instantiation_1.getComponentRef().getName();
_builder.append(_name_6);
_builder.append("<");
IntegerWithRadix _addressValue_1 = RdlUtil.addressValue(instance);
_builder.append(_addressValue_1);
_builder.append("ULL>;");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
_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();
}
@Override
public String generateSource() {
return "";
}
}

View File

@ -0,0 +1,493 @@
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;
import com.minres.rdl.rdl.ComponentInstance;
import com.minres.rdl.rdl.Instantiation;
import com.minres.rdl.rdl.Range;
import java.util.Date;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@SuppressWarnings("all")
public class FwRegfileGenerator extends RdlBaseGenerator {
private final ComponentDefinition componentDefinition;
public FwRegfileGenerator(final ComponentDefinition definition) {
this.componentDefinition = definition;
}
@Override
public String generateHeader() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// Copyright (C) 2020, MINRES Technologies GmbH");
_builder.newLine();
_builder.append("// All rights reserved.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// Redistribution and use in source and binary forms, with or without");
_builder.newLine();
_builder.append("// modification, are permitted provided that the following conditions are met:");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 1. Redistributions of source code must retain the above copyright notice,");
_builder.newLine();
_builder.append("// this list of conditions and the following disclaimer.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 2. Redistributions in binary form must reproduce the above copyright notice,");
_builder.newLine();
_builder.append("// this list of conditions and the following disclaimer in the documentation");
_builder.newLine();
_builder.append("// and/or other materials provided with the distribution.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// 3. Neither the name of the copyright holder nor the names of its contributors");
_builder.newLine();
_builder.append("// may be used to endorse or promote products derived from this software");
_builder.newLine();
_builder.append("// without specific prior written permission.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"");
_builder.newLine();
_builder.append("// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE");
_builder.newLine();
_builder.append("// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE");
_builder.newLine();
_builder.append("// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
_builder.newLine();
_builder.append("// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
_builder.newLine();
_builder.append("// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
_builder.newLine();
_builder.append("// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS");
_builder.newLine();
_builder.append("// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
_builder.newLine();
_builder.append("// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)");
_builder.newLine();
_builder.append("// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE");
_builder.newLine();
_builder.append("// POSSIBILITY OF SUCH DAMAGE.");
_builder.newLine();
_builder.append("//");
_builder.newLine();
_builder.append("// Created on: ");
Date _date = new Date();
_builder.append(_date);
_builder.newLineIfNotEmpty();
_builder.append("// * ");
String _name = this.componentDefinition.getName();
_builder.append(_name);
_builder.append(".h Author: <RDL Generator>");
_builder.newLineIfNotEmpty();
_builder.append("//");
_builder.newLine();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.newLine();
_builder.append("#ifndef _");
String _upperCase = this.componentDefinition.getName().toUpperCase();
_builder.append(_upperCase);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.append("#define _");
String _upperCase_1 = this.componentDefinition.getName().toUpperCase();
_builder.append(_upperCase_1);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#include <util/bit_field.h>");
_builder.newLine();
_builder.append("#include <nonstd/span.hpp>");
_builder.newLine();
_builder.append("#include <cstdint>");
_builder.newLine();
_builder.newLine();
_builder.append("template<size_t BASE_ADDR>");
_builder.newLine();
_builder.append("struct ");
String _name_1 = this.componentDefinition.getName();
_builder.append(_name_1);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
EList<ComponentDefinition> _componentDefinitions = this.componentDefinition.getComponentDefinitions();
for(final ComponentDefinition cdef : _componentDefinitions) {
{
ComponentDefinitionType _type = cdef.getType();
boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG);
if (_equals) {
_builder.append(" ");
_builder.append("BEGIN_BF_DECL(");
String _effectiveName = RdlUtil.effectiveName(cdef);
_builder.append(_effectiveName, " ");
_builder.append("+\'_t\'», uint");
_builder.append(cdef, " ");
_builder.append("_t);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
String _genFieldDeclarations = this.genFieldDeclarations(cdef);
_builder.append(_genFieldDeclarations, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("END_BF_DECL();");
_builder.newLine();
}
}
}
}
{
EList<Instantiation> _instantiations = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation : _instantiations) {
{
if (((instantiation.getComponentRef() != null) && Objects.equal(instantiation.getComponentRef().getType(), ComponentDefinitionType.REG))) {
_builder.append(" ");
String _effectiveName_1 = RdlUtil.effectiveName(instantiation.getComponentRef());
_builder.append(_effectiveName_1, " ");
_builder.append("+\'_t\' ");
final Function1<ComponentInstance, String> _function = (ComponentInstance it) -> {
return it.getName();
};
String _join = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function), ", ");
_builder.append(_join, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
if (((instantiation.getComponent() != null) && Objects.equal(instantiation.getComponent().getType(), ComponentDefinitionType.REG))) {
{
boolean _isFilledByField = this.isFilledByField(instantiation);
boolean _not = (!_isFilledByField);
if (_not) {
_builder.append(" ");
_builder.append("BEGIN_BF_DECL(");
String _effectiveName_2 = RdlUtil.effectiveName(instantiation.getComponent());
_builder.append(_effectiveName_2, " ");
_builder.append("_t, uint");
long _size = RdlUtil.getSize(instantiation);
_builder.append(_size, " ");
_builder.append("_t);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
String _genFieldDeclarations_1 = this.genFieldDeclarations(RdlUtil.definingComponent(instantiation));
_builder.append(_genFieldDeclarations_1, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("END_BF_DECL() ");
final Function1<ComponentInstance, Boolean> _function_1 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_2 = (ComponentInstance it) -> {
String _name_2 = it.getName();
return ("r_" + _name_2);
};
String _join_1 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_1), _function_2), ", ");
_builder.append(_join_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
}
}
}
}
}
}
_builder.append(" ");
_builder.append("// register access");
_builder.newLine();
{
EList<Instantiation> _instantiations_1 = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation_1 : _instantiations_1) {
{
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
{
Range _range = instance.getRange();
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
{
boolean _isFilledByField_1 = this.isFilledByField(instantiation_1);
if (_isFilledByField_1) {
_builder.append(" ");
_builder.append("static inline uint");
long _size_1 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_1, " ");
_builder.append("_t& ");
String _name_2 = instance.getName();
_builder.append(_name_2, " ");
_builder.append("(){");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("return *reinterpret_cast<");
String _name_3 = instance.getName();
_builder.append(_name_3, " ");
_builder.append("_t*>(BASE_ADDR+");
IntegerWithRadix _addressValue = RdlUtil.addressValue(instance);
_builder.append(_addressValue, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
{
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
boolean _not_1 = (!_isFilledByField_2);
if (_not_1) {
_builder.append(" ");
_builder.append("static inline ");
String _name_4 = instance.getName();
_builder.append(_name_4, " ");
_builder.append("_t& ");
String _name_5 = instance.getName();
_builder.append(_name_5, " ");
_builder.append("(){");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("return *reinterpret_cast<");
String _name_6 = instance.getName();
_builder.append(_name_6, " ");
_builder.append("_t*>(BASE_ADDR+");
IntegerWithRadix _addressValue_1 = RdlUtil.addressValue(instance);
_builder.append(_addressValue_1, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
}
}
{
Range _range_1 = instance.getRange();
boolean _tripleNotEquals = (_range_1 != null);
if (_tripleNotEquals) {
{
boolean _isFilledByField_3 = this.isFilledByField(instantiation_1);
if (_isFilledByField_3) {
_builder.append(" ");
_builder.append("static inline nonstd::span<uint");
long _size_2 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_2, " ");
_builder.append("_t, ");
long _absSize = this.absSize(instance.getRange());
_builder.append(_absSize, " ");
_builder.append(">& ");
String _name_7 = instance.getName();
_builder.append(_name_7, " ");
_builder.append("(){");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("return *reinterpret_cast<nonstd::span<uint");
long _size_3 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_3, " ");
_builder.append("_t, ");
long _absSize_1 = this.absSize(instance.getRange());
_builder.append(_absSize_1, " ");
_builder.append(">*>(BASE_ADDR+");
IntegerWithRadix _addressValue_2 = RdlUtil.addressValue(instance);
_builder.append(_addressValue_2, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
{
boolean _isFilledByField_4 = this.isFilledByField(instantiation_1);
boolean _not_2 = (!_isFilledByField_4);
if (_not_2) {
_builder.append(" ");
_builder.append("static inline nonstd::span<");
String _name_8 = instance.getName();
_builder.append(_name_8, " ");
_builder.append("_t, ");
long _absSize_2 = this.absSize(instance.getRange());
_builder.append(_absSize_2, " ");
_builder.append(">& ");
String _name_9 = instance.getName();
_builder.append(_name_9, " ");
_builder.append("(){");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("return *reinterpret_cast<nonstd::span<");
String _name_10 = instance.getName();
_builder.append(_name_10, " ");
_builder.append("_t, ");
long _absSize_3 = this.absSize(instance.getRange());
_builder.append(_absSize_3, " ");
_builder.append(">*>(BASE_ADDR+");
IntegerWithRadix _addressValue_3 = RdlUtil.addressValue(instance);
_builder.append(_addressValue_3, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
}
}
}
}
}
}
_builder.append("};");
_builder.newLine();
_builder.newLine();
_builder.append("#endif // _");
String _upperCase_2 = this.componentDefinition.getName().toUpperCase();
_builder.append(_upperCase_2);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
return _builder.toString();
}
public long absSize(final Range range) {
Object _size = range.getSize();
boolean _tripleNotEquals = (_size != null);
if (_tripleNotEquals) {
Object _size_1 = range.getSize();
return ((IntegerWithRadix) _size_1).value;
} else {
Object _left = range.getLeft();
Object _right = range.getRight();
long _abs = Math.abs((((IntegerWithRadix) _left).value - ((IntegerWithRadix) _right).value));
return (_abs + 1);
}
}
public boolean isFilledByField(final Instantiation instantiation) {
final int fieldCount = this.instanceCountOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD);
if ((fieldCount == 1)) {
final long instSize = RdlUtil.getSize(instantiation);
final Instantiation field = ((Instantiation[])Conversions.unwrapArray(RdlUtil.instantiationsOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD), Instantiation.class))[0];
final ComponentInstance inst = field.getComponentInstances().get(0);
final Range range = inst.getRange();
if ((range == null)) {
long _size = RdlUtil.getSize(field);
return (instSize == _size);
}
Object _size_1 = range.getSize();
boolean _tripleNotEquals = (_size_1 != null);
if (_tripleNotEquals) {
Object _size_2 = range.getSize();
return (instSize == ((IntegerWithRadix) _size_2).value);
} else {
Object _left = range.getLeft();
final long left = ((IntegerWithRadix) _left).value;
Object _right = range.getRight();
final long right = ((IntegerWithRadix) _right).value;
long _xifexpression = (long) 0;
if ((left > right)) {
_xifexpression = ((left - right) + 1);
} else {
_xifexpression = ((right - left) + 1);
}
final long size = _xifexpression;
return (instSize == size);
}
}
return false;
}
public int instanceCountOfType(final ComponentDefinition definition, final ComponentDefinitionType type) {
final Function1<Instantiation, Integer> _function = (Instantiation it) -> {
return Integer.valueOf(it.getComponentInstances().size());
};
final Function2<Integer, Integer, Integer> _function_1 = (Integer p1, Integer p2) -> {
return Integer.valueOf(((p1).intValue() + (p1).intValue()));
};
return (int) IterableExtensions.<Integer>reduce(IterableExtensions.<Instantiation, Integer>map(RdlUtil.instantiationsOfType(definition, type), _function), _function_1);
}
@Override
public String generateSource() {
return "";
}
public String genFieldDeclarations(final ComponentDefinition componentDef) {
String _xblockexpression = null;
{
long i = 0L;
String res = "";
EList<Instantiation> _instantiations = componentDef.getInstantiations();
for (final Instantiation inst : _instantiations) {
EList<ComponentInstance> _componentInstances = inst.getComponentInstances();
for (final ComponentInstance compInst : _componentInstances) {
Object _size = compInst.getRange().getSize();
boolean _tripleNotEquals = (_size != null);
if (_tripleNotEquals) {
String _res = res;
StringConcatenation _builder = new StringConcatenation();
_builder.append("BF_FIELD(");
String _name = compInst.getName();
_builder.append(_name);
_builder.append(", ");
_builder.append(i);
_builder.append(", ");
Object _size_1 = compInst.getRange().getSize();
_builder.append(((IntegerWithRadix) _size_1).value);
_builder.append(");");
_builder.newLineIfNotEmpty();
res = (_res + _builder);
long _i = i;
Object _size_2 = compInst.getRange().getSize();
i = (_i + ((IntegerWithRadix) _size_2).value);
} else {
Object _left = compInst.getRange().getLeft();
final long start = ((IntegerWithRadix) _left).value;
Object _right = compInst.getRange().getRight();
final long end = ((IntegerWithRadix) _right).value;
String _res_1 = res;
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("BF_FIELD(");
String _name_1 = compInst.getName();
_builder_1.append(_name_1);
_builder_1.append(", ");
_builder_1.append(end);
_builder_1.append(", ");
_builder_1.append(((start - end) + 1));
_builder_1.append(");");
_builder_1.newLineIfNotEmpty();
res = (_res_1 + _builder_1);
long _max = Math.max(start, end);
long _plus = (_max + 1);
i = _plus;
}
}
}
_xblockexpression = res;
}
return _xblockexpression;
}
}

View File

@ -5,18 +5,25 @@ package com.minres.rdl.generator;
import com.minres.rdl.RdlUtil;
import com.minres.rdl.generator.AddrmapGenerator;
import com.minres.rdl.generator.FwAddrmapGenerator;
import com.minres.rdl.generator.FwRegfileGenerator;
import com.minres.rdl.generator.RdlBaseGenerator;
import com.minres.rdl.generator.RegfileGenerator;
import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.ComponentDefinitionType;
import java.util.Collections;
import java.util.Map;
import java.util.function.BiConsumer;
import org.eclipse.emf.common.notify.Notifier;
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 org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
/**
@ -35,35 +42,48 @@ public class RDLGenerator extends AbstractGenerator {
return ((ComponentDefinition) it);
};
final Procedure1<ComponentDefinition> _function_2 = (ComponentDefinition it) -> {
final RdlBaseGenerator gen = this.fileGenerator(it);
if ((gen != null)) {
final String header = gen.generateHeader();
if (((header != null) && (header.length() > 0))) {
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 _effectiveName_1 = RdlUtil.effectiveName(it);
String _plus_1 = (_effectiveName_1 + ".cpp");
fsa.generateFile(_plus_1, this.outputConfig(fsa, "src-out"), source);
}
final Map<String, RdlBaseGenerator> genMap = this.fileGenerator(it);
if ((genMap != null)) {
final BiConsumer<String, RdlBaseGenerator> _function_3 = (String p1, RdlBaseGenerator gen) -> {
final String header = gen.generateHeader();
if (((header != null) && (header.length() > 0))) {
String _effectiveName = RdlUtil.effectiveName(it);
String _plus = ((p1 + "/") + _effectiveName);
String _plus_1 = (_plus + ".h");
fsa.generateFile(_plus_1, this.outputConfig(fsa, "incl-out"), header);
}
final String source = gen.generateSource();
if (((source != null) && (source.length() > 0))) {
String _effectiveName_1 = RdlUtil.effectiveName(it);
String _plus_2 = ((p1 + "/") + _effectiveName_1);
String _plus_3 = (_plus_2 + ".cpp");
fsa.generateFile(_plus_3, this.outputConfig(fsa, "src-out"), source);
}
};
genMap.forEach(_function_3);
}
};
IteratorExtensions.<ComponentDefinition>forEach(IteratorExtensions.<Notifier, ComponentDefinition>map(IteratorExtensions.<Notifier>filter(resource.getResourceSet().getAllContents(), _function), _function_1), _function_2);
}
public RdlBaseGenerator fileGenerator(final ComponentDefinition definition) {
RdlBaseGenerator _switchResult = null;
public Map<String, RdlBaseGenerator> fileGenerator(final ComponentDefinition definition) {
Map<String, RdlBaseGenerator> _switchResult = null;
ComponentDefinitionType _type = definition.getType();
if (_type != null) {
switch (_type) {
case REGFILE:
_switchResult = new RegfileGenerator(definition);
RegfileGenerator _regfileGenerator = new RegfileGenerator(definition);
Pair<String, RegfileGenerator> _mappedTo = Pair.<String, RegfileGenerator>of("vp", _regfileGenerator);
FwRegfileGenerator _fwRegfileGenerator = new FwRegfileGenerator(definition);
Pair<String, FwRegfileGenerator> _mappedTo_1 = Pair.<String, FwRegfileGenerator>of("fw", _fwRegfileGenerator);
_switchResult = Collections.<String, RdlBaseGenerator>unmodifiableMap(CollectionLiterals.<String, RdlBaseGenerator>newHashMap(_mappedTo, _mappedTo_1));
break;
case ADDRMAP:
_switchResult = new AddrmapGenerator(definition);
AddrmapGenerator _addrmapGenerator = new AddrmapGenerator(definition);
Pair<String, AddrmapGenerator> _mappedTo_2 = Pair.<String, AddrmapGenerator>of("vp", _addrmapGenerator);
FwAddrmapGenerator _fwAddrmapGenerator = new FwAddrmapGenerator(definition);
Pair<String, FwAddrmapGenerator> _mappedTo_3 = Pair.<String, FwAddrmapGenerator>of("fw", _fwAddrmapGenerator);
_switchResult = Collections.<String, RdlBaseGenerator>unmodifiableMap(CollectionLiterals.<String, RdlBaseGenerator>newHashMap(_mappedTo_2, _mappedTo_3));
break;
default:
_switchResult = null;