update target platform incl. XText/Xtend

This commit is contained in:
Eyck Jentzsch 2022-02-13 12:40:21 +01:00
parent 564977ed54
commit c827f261ff
41 changed files with 1310 additions and 651 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ com.minres.rdl.parent/*/target
*.xtextbin
*.xtendbin
*._trace
/.envrc
/*.py
/*.txt

View File

@ -16,8 +16,6 @@ import org.eclipse.xtext.ide.editor.contentassist.antlr.AntlrProposalConflictHel
import org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser;
import org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer;
import org.eclipse.xtext.ide.refactoring.IRenameStrategy2;
import org.eclipse.xtext.ide.server.rename.IRenameService;
import org.eclipse.xtext.ide.server.rename.RenameService;
/**
* Manual modifications go to {@link RDLIdeModule}.
@ -47,11 +45,6 @@ public abstract class AbstractRDLIdeModule extends DefaultIdeModule {
return FQNPrefixMatcher.class;
}
// contributed by org.eclipse.xtext.xtext.generator.ui.refactoring.RefactorElementNameFragment2
public Class<? extends IRenameService> bindIRenameService() {
return RenameService.class;
}
// contributed by org.eclipse.xtext.xtext.generator.ui.refactoring.RefactorElementNameFragment2
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
return IRenameStrategy2.DefaultImpl.class;

View File

@ -3,8 +3,6 @@
*/
package com.minres.rdl.ide;
import com.minres.rdl.ide.AbstractRDLIdeModule;
/**
* Use this class to register ide components.
*/

View File

@ -7,7 +7,6 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.minres.rdl.RDLRuntimeModule;
import com.minres.rdl.RDLStandaloneSetup;
import com.minres.rdl.ide.RDLIdeModule;
import org.eclipse.xtext.util.Modules2;
/**

View File

@ -1,25 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="com.minres.rdl.target" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.draw2d.feature.group" version="0.0.0"/>
<unit id="org.eclipse.emf.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
<unit id="org.eclipse.jdt.feature.group" version="0.0.0"/>
<unit id="org.eclipse.pde.feature.group" version="0.0.0"/>
<unit id="org.eclipse.platform.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xpand" version="0.0.0"/>
<unit id="org.eclipse.xtend" version="0.0.0"/>
<unit id="org.eclipse.xtend.typesystem.emf" version="0.0.0"/>
<repository location="http://download.eclipse.org/releases/photon"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.emf.mwe2.launcher.feature.group" version="0.0.0"/>
<repository location="http://download.eclipse.org/modeling/emft/mwe/updates/releases/2.9.1/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.sdk.feature.group" version="0.0.0"/>
<repository location="http://download.eclipse.org/modeling/tmf/xtext/updates/releases/2.14.0/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.feature.group" version="0.0.0"/>
<unit id="org.eclipse.platform.feature.group" version="0.0.0"/>
<unit id="org.eclipse.pde.feature.group" version="0.0.0"/>
<unit id="org.eclipse.draw2d.feature.group" version="0.0.0"/>
<unit id="org.eclipse.emf.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2020-06"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.emf.mwe2.launcher.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/modeling/emft/mwe/updates/releases/2.11.3/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/modeling/tmf/xtext/updates/releases/2.22.0/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="com.google.gson" version="2.8.2.v20180104-1110"/>
<unit id="org.antlr.runtime" version="3.2.0.v201101311130"/>
<unit id="org.junit" version="4.12.0.v201504281640"/>
<unit id="org.junit.jupiter.api" version="5.6.0.v20200203-2009"/>
<unit id="org.junit.jupiter.engine" version="5.6.0.v20200203-2009"/>
<unit id="org.junit.platform.commons" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.engine" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.launcher" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.runner" version="1.6.0.v20200203-2009"/>
<unit id="org.opentest4j" version="1.2.0.v20190826-0900"/>
<unit id="org.objectweb.asm" version="8.0.1.v20200420-1007"/>
<unit id="org.objectweb.asm.tree" version="8.0.1.v20200420-1007"/>
<unit id="io.github.classgraph" version="4.8.35.v20190528-1517"/>
<repository location="https://download.eclipse.org/tools/orbit/downloads/2020-06"/>
</location>
</locations>
</target>

View File

@ -5,7 +5,6 @@ package com.minres.rdl.tests;
import com.google.inject.Inject;
import com.minres.rdl.rdl.Root;
import com.minres.rdl.tests.RDLInjectorProvider;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend2.lib.StringConcatenation;

View File

@ -43,7 +43,10 @@ class RDLLabelProvider extends DefaultEObjectLabelProvider {
val pa = e.propertyAssignments.findFirst[PropertyAssignment pa |
pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.NAME
]
e.type.literal+' '+ text((pa as ExplicitPropertyAssignment).rhs)
if(pa!== null)
e.type.literal+' '+ text((pa as ExplicitPropertyAssignment).rhs)
else
e.type.literal
}
}

View File

@ -3,9 +3,6 @@
*/
package com.minres.rdl.ui;
import com.minres.rdl.ui.AbstractRDLUiModule;
import com.minres.rdl.ui.RDLEObjectDocumentationProvider;
import com.minres.rdl.ui.RDLEObjectHoverProvider;
import com.minres.structural.ui.hyperlink.MyHyperlinkHelper;
import com.minres.structural.ui.hyperlink.MyXtextHyperlink;
import org.eclipse.ui.plugin.AbstractUIPlugin;

View File

@ -3,8 +3,6 @@
*/
package com.minres.rdl.ui.contentassist;
import com.minres.rdl.ui.contentassist.AbstractRDLProposalProvider;
/**
* See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist
* on how to customize the content assistant.

View File

@ -58,10 +58,16 @@ public class RDLLabelProvider extends DefaultEObjectLabelProvider {
return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.NAME)));
};
final PropertyAssignment pa = IterableExtensions.<PropertyAssignment>findFirst(e.getPropertyAssignments(), _function);
String _literal_1 = e.getType().getLiteral();
String _plus_1 = (_literal_1 + " ");
Object _text = this.text(((ExplicitPropertyAssignment) pa).getRhs());
_xblockexpression = (_plus_1 + _text);
String _xifexpression_1 = null;
if ((pa != null)) {
String _literal_1 = e.getType().getLiteral();
String _plus_1 = (_literal_1 + " ");
Object _text = this.text(((ExplicitPropertyAssignment) pa).getRhs());
_xifexpression_1 = (_plus_1 + _text);
} else {
_xifexpression_1 = e.getType().getLiteral();
}
_xblockexpression = _xifexpression_1;
}
_xifexpression = _xblockexpression;
}

View File

@ -3,7 +3,6 @@
*/
package com.minres.rdl.ui.wizard;
import com.minres.rdl.ui.wizard.RdlProject;
import org.eclipse.xtext.ui.wizard.template.AbstractProjectTemplate;
import org.eclipse.xtext.ui.wizard.template.IProjectTemplateProvider;

View File

@ -1,7 +1,6 @@
package com.minres.structural.ui.hyperlink;
import com.google.inject.Inject;
import com.minres.structural.ui.hyperlink.MyXtextHyperlink;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;

View File

@ -4,7 +4,6 @@
package com.minres.rdl.web;
import com.google.inject.Injector;
import com.minres.rdl.web.RDLWebSetup;
import javax.servlet.annotation.WebServlet;
import org.eclipse.xtext.util.DisposableRegistry;
import org.eclipse.xtext.web.servlet.XtextServlet;

View File

@ -3,8 +3,6 @@
*/
package com.minres.rdl.web;
import com.minres.rdl.web.AbstractRDLWebModule;
/**
* Use this class to register additional components to be used within the web application.
*/

View File

@ -8,7 +8,6 @@ import com.google.inject.Injector;
import com.minres.rdl.RDLRuntimeModule;
import com.minres.rdl.RDLStandaloneSetup;
import com.minres.rdl.ide.RDLIdeModule;
import com.minres.rdl.web.RDLWebModule;
import org.eclipse.xtext.util.Modules2;
/**

View File

@ -30,6 +30,7 @@ Workflow {
encoding = "UTF-8"
lineDelimiter = "\n"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
preferXtendStubs = false
}
}
language = StandardLanguage {
@ -53,8 +54,10 @@ Workflow {
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
// Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage
generateDeprecationValidation = true
}
generator = {
@ -64,6 +67,9 @@ Workflow {
projectWizard = {
generate = true
}
junitSupport = {
junitVersion = "5"
}
}
}
}

View File

@ -11,6 +11,7 @@ import com.minres.rdl.rdl.PropertyAssignmentRhs
import com.minres.rdl.rdl.RValue
import com.minres.rdl.rdl.RValueConstant
import com.minres.rdl.rdl.InstancePropertyRef
import com.minres.rdl.rdl.Range
class RdlUtil {
@ -153,5 +154,44 @@ class RdlUtil {
componentSize = subInstantiation.byteSize(componentSize)
return componentSize
}
static def ComponentDefinition getComponentDefinition(Instantiation instantiation) {
if(instantiation.component!==null) instantiation.component else instantiation.componentRef
}
static 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
}
static def boolean isFilledByField(Instantiation instantiation){
val fieldCount = instantiation.componentDefinition.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
}
static def int instanceCountOfType(ComponentDefinition definition, ComponentDefinitionType type){
val insts = definition.instantiationsOfType(type)
if(insts.size>0) {
insts.map[it.componentInstances.size].reduce[p1, p2| p1+p2]
} else
0
}
}

View File

@ -13,14 +13,18 @@ class AddrmapGenerator extends RdlBaseGenerator {
componentDefinition=definition
}
override generateHeader() {'''
override boolean getOverwrite(){
true
}
override generateHeader(String namespace) {'''
#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<sysc::target_memory_map_entry<32>, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> «componentDefinition.effectiveName»_map = {{
const std::array<scc::target_memory_map_entry<32>, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> «componentDefinition.effectiveName»_map = {{
«FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»
«FOR instance : instantiation.componentInstances»
{&i_«instance.name», «instance.addressValue», 0x«Long.toHexString(instantiation.byteSize)»},
{i_«instance.name».socket, «instance.addressValue», 0x«Long.toHexString(instantiation.byteSize)»},
«ENDFOR»
«ENDFOR»
}};
@ -29,7 +33,7 @@ class AddrmapGenerator extends RdlBaseGenerator {
'''
}
override generateSource() {
override generateSource(String namespace) {
''
}

View File

@ -16,9 +16,13 @@ class FwAddrmapGenerator extends RdlBaseGenerator {
val nameMap = newLinkedHashSet()
override generateHeader() {'''
override boolean getOverwrite(){
true
}
override generateHeader(String namespace) {'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020, MINRES Technologies GmbH
// Copyright (C) 2020-2022, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -57,10 +61,10 @@ class FwAddrmapGenerator extends RdlBaseGenerator {
«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)»
#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)»
#include "«instantiation.componentRef.name».h"«nameMap.add(instantiation.componentRef.name)?"":""»
«ENDIF»
«ENDFOR»
@ -80,7 +84,7 @@ class FwAddrmapGenerator extends RdlBaseGenerator {
'''
}
override generateSource() {
override generateSource(String namespace) {
''
}
}

View File

@ -6,7 +6,6 @@ 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.*
@ -18,9 +17,13 @@ class FwRegfileGenerator extends RdlBaseGenerator{
componentDefinition=definition
}
override String generateHeader()'''
override boolean getOverwrite(){
true
}
override String generateHeader(String namespace)'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020, MINRES Technologies GmbH
// Copyright (C) 2020-2022, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -117,40 +120,8 @@ class FwRegfileGenerator extends RdlBaseGenerator{
#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() {
override generateSource(String namespace) {
''
}

View File

@ -23,7 +23,7 @@ import org.eclipse.xtext.generator.IFileSystemAccess
class Main {
val USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
val USAGE_STR = "RDL2code [-h] [-v] [-f] [-n <namespace>] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
def static main(String[] args) {
if (args.empty) {
@ -60,6 +60,8 @@ class Main {
val opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet().addOption("h", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("v", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("f", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("n", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("o", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(false, false)) { // Print usage hints
@ -106,7 +108,10 @@ class Main {
throw new ParseException("error validating " + resource.URI, issues.size)
}
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
val context = new RdlGeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
context.forceOverwrite= opt.getSet().isSet('f')
if(opt.getSet().isSet('n'))
context.namespace=opt.getSet().getOption('n').getResultValue(0)
generator.generate(resource, fileAccess, context)
if(verbose) println('Code generation for ' + string + ' finished')

View File

@ -0,0 +1,107 @@
package com.minres.rdl.generator
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ComponentDefinitionType
import static extension com.minres.rdl.RdlUtil.*
class ModuleGenerator extends RdlBaseGenerator {
val ComponentDefinition componentDefinition
new(ComponentDefinition definition) {
componentDefinition=definition
}
override boolean getOverwrite(){
false
}
override generateHeader(String namespace){
if(componentDefinition.type!=ComponentDefinitionType.REGFILE) return ''
val addrMaps = componentDefinition.eResource.resourceSet.allContents
.filter[ it instanceof ComponentDefinition]
.map[it as ComponentDefinition]
.filter[it.type == ComponentDefinitionType.ADDRMAP]
.filter[def | def.instantiations.filter[it.componentRef==componentDefinition].size>0]
if(addrMaps.size==0) return ''
'''
#ifndef _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_
#define _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_
#include <scc/tlm_target.h>
namespace «namespace» {
namespace gen {
class «componentDefinition.effectiveName»_regs;
}
class «componentDefinition.effectiveName» : public sc_core::sc_module, public scc::tlm_target<> {
public:
sc_core::sc_in<sc_core::sc_time> clk_i{"clk_i"};
sc_core::sc_in<bool> rst_i{"rst_i"};
«componentDefinition.effectiveName»(sc_core::sc_module_name nm);
virtual ~«componentDefinition.effectiveName»() override;
protected:
void clock_cb();
void reset_cb();
sc_core::sc_time clk;
std::unique_ptr<gen::«componentDefinition.effectiveName»_regs> regs;
};
} /* namespace «namespace» */
#endif /* _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_ */
'''
}
override generateSource(String namespace) {
if(componentDefinition.type!=ComponentDefinitionType.REGFILE) return ''
val addrMaps = componentDefinition.eResource.resourceSet.allContents
.filter[ it instanceof ComponentDefinition]
.map[it as ComponentDefinition]
.filter[it.type == ComponentDefinitionType.ADDRMAP]
.filter[def | def.instantiations.filter[it.componentRef==componentDefinition].size>0]
if(addrMaps.size==0) return ''
'''
/*
* Copyright (c) 2019 -2022 MINRES Technologies GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "«componentDefinition.effectiveName».h"
#include "gen/«componentDefinition.effectiveName».h"
#include <scc/utilities.h>
namespace «namespace» {
SC_HAS_PROCESS(«componentDefinition.effectiveName»);// NOLINT
«componentDefinition.effectiveName»::«componentDefinition.effectiveName»(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
, scc::tlm_target<>(clk)
, NAMEDD(regs, gen::«componentDefinition.effectiveName»_regs) {
regs->registerResources(*this);
SC_METHOD(clock_cb);
sensitive << clk_i;
SC_METHOD(reset_cb);
sensitive << rst_i;
}
«componentDefinition.effectiveName»::~«componentDefinition.effectiveName»() {} // NOLINT
void «componentDefinition.effectiveName»::clock_cb() { this->clk = clk_i.read(); }
void «componentDefinition.effectiveName»::reset_cb() {
if (rst_i.read()) {
regs->reset_start();
} else {
regs->reset_stop();
}
}
} /* namespace «namespace» */
'''
}
}

View File

@ -18,25 +18,35 @@ import java.util.Map
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class RDLGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val force = if(context instanceof RdlGeneratorContext) context.forceOverwrite else false
val namespace = if(context instanceof RdlGeneratorContext) context.namespace else "sysc"
resource.resourceSet.allContents.filter[ it instanceof ComponentDefinition].map[it as ComponentDefinition].forEach[
val genMap = it.fileGenerator
if(genMap!==null) genMap.forEach[p1, gen |
val header = gen.generateHeader
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(p1+'/'+it.effectiveName+'.cpp', fsa.outputConfig('src-out'), source)
val header = gen.generateHeader(namespace)
val inclFileName = p1+'/'+it.effectiveName+'.h'
val inclCfg = fsa.outputConfig('incl-out')
if((force || !fsa.isFile(inclFileName, inclCfg) || gen.overwrite) && header!==null && header.length>0)
fsa.generateFile(inclFileName, inclCfg, header)
val source = gen.generateSource(namespace)
val srcFileName = p1+'/'+it.effectiveName+'.cpp'
val srcCfg = fsa.outputConfig('src-out')
if((force || !fsa.isFile(srcFileName, srcCfg) || gen.overwrite) && source!==null && source.length>0)
fsa.generateFile(srcFileName, srcCfg, source)
]
]
}
def Map<String, RdlBaseGenerator> fileGenerator(ComponentDefinition definition){
switch(definition.type){
case ComponentDefinitionType.REGFILE: #{'vp' -> new RegfileGenerator(definition), 'fw' -> new FwRegfileGenerator(definition)}
case ComponentDefinitionType.ADDRMAP: #{'vp' -> new AddrmapGenerator(definition), 'fw' -> new FwAddrmapGenerator(definition)}
case ComponentDefinitionType.REGFILE: #{
'gen' -> new RegfileGenerator(definition),
'fw' -> new FwRegfileGenerator(definition),
'.' -> new ModuleGenerator(definition)}
case ComponentDefinitionType.ADDRMAP: #{
'gen' -> new AddrmapGenerator(definition),
'fw' -> new FwAddrmapGenerator(definition)}
default: null
}
}

View File

@ -2,8 +2,10 @@ package com.minres.rdl.generator
abstract class RdlBaseGenerator {
def String generateHeader()
def String generateHeader(String namespace)
def String generateSource()
def String generateSource(String namespace)
def boolean getOverwrite()
}

View File

@ -0,0 +1,8 @@
package com.minres.rdl.generator
import org.eclipse.xtext.generator.GeneratorContext
class RdlGeneratorContext extends GeneratorContext {
public boolean forceOverwrite = false
public String namespace ="scc"
}

View File

@ -6,7 +6,6 @@ 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.*
@ -18,9 +17,13 @@ class RegfileGenerator extends RdlBaseGenerator{
componentDefinition=definition
}
override String generateHeader()'''
override boolean getOverwrite(){
true
}
override String generateHeader(String namespace)'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017, MINRES Technologies GmbH
// Copyright (C) 2017-2022, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -50,26 +53,34 @@ class RegfileGenerator extends RdlBaseGenerator{
// POSSIBILITY OF SUCH DAMAGE.
//
// Created on: «new Date»
// * «componentDefinition.name».h Author: <RDL Generator>
// * «componentDefinition.effectiveName».h Author: <RDL Generator>
//
////////////////////////////////////////////////////////////////////////////////
#ifndef _«componentDefinition.name.toUpperCase»_H_
#define _«componentDefinition.name.toUpperCase»_H_
#ifndef _«namespace.toUpperCase»_GEN_«componentDefinition.effectiveName.toUpperCase»_H_
#define _«namespace.toUpperCase»_GEN_«componentDefinition.effectiveName.toUpperCase»_H_
#include <sysc/utilities.h>
#include <scc/utilities.h>
#include <util/bit_field.h>
#include <sysc/register.h>
#include <sysc/tlm_target.h>
#include <scc/register.h>
#include <scc/tlm_target.h>
«FOR instantiation : componentDefinition.instantiations»
«IF instantiation.componentDefinition.type == ComponentDefinitionType.REGFILE»
#include "«instantiation.componentDefinition.effectiveName».h"
«ENDIF»
«ENDFOR»
namespace sysc {
namespace «namespace» {
namespace gen {
class «componentDefinition.name» :
class «componentDefinition.effectiveName»_regs :
public sc_core::sc_module,
public sysc::resetable
public scc::resetable
{
public:
//////////////////////////////////////////////////////////////////////////////
// storage declarations
//////////////////////////////////////////////////////////////////////////////
«FOR cdef : componentDefinition.componentDefinitions»
«IF cdef.type == ComponentDefinitionType.REG»
BEGIN_BF_DECL(«cdef.effectiveName»+'_t'», uint«cdef»_t);
@ -78,10 +89,11 @@ class RegfileGenerator extends RdlBaseGenerator{
«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.componentDefinition.type == ComponentDefinitionType.REGFILE»
«FOR instance : instantiation.componentInstances»
«instantiation.componentDefinition.effectiveName»_regs i_«instance.name»{"«instance.name»"};
«ENDFOR»
«ELSEIF instantiation.componentDefinition.type == ComponentDefinitionType.REG»
«IF instantiation.isFilledByField»
«IF instantiation.componentInstances.filter[it.range===null].size>0»
uint«instantiation.size»_t «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»;
@ -89,8 +101,14 @@ class RegfileGenerator extends RdlBaseGenerator{
«FOR componentInstance : instantiation.componentInstances.filter[it.range!==null]»
std::array<uint«instantiation.size»_t, «componentInstance.range.absSize»> r_«componentInstance.name»;
«ENDFOR»
«ENDIF»
«IF !instantiation.isFilledByField»
«ELSEIF instantiation.componentDefinition.instantiations.size==0»
«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<uint«instantiation.size»_t, «componentInstance.range.absSize»> r_«componentInstance.name»;
«ENDFOR»
«ELSE»
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(', ')»;
@ -98,96 +116,79 @@ class RegfileGenerator extends RdlBaseGenerator{
std::array<«instantiation.component.effectiveName»_t, «componentInstance.range.absSize»> r_«componentInstance.name»;
«ENDFOR»
«ENDIF»
«ENDIF»
«ENDFOR»
//////////////////////////////////////////////////////////////////////////////
// register declarations
//////////////////////////////////////////////////////////////////////////////
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
«IF instance.range===null»
«IF instantiation.isFilledByField»
sysc::sc_register<uint«instantiation.size»_t> «instance.name»;
«ENDIF»
«IF !instantiation.isFilledByField»
sysc::sc_register<«instantiation.component.effectiveName»_t> «instance.name»;
«ENDIF»
«ENDIF»
«IF instance.range!==null»
«IF instantiation.isFilledByField»
sysc::sc_register_indexed<uint«instantiation.size»_t, «instance.range.absSize»> «instance.name»;
«ENDIF»
«IF !instantiation.isFilledByField»
sysc::sc_register_indexed<«instantiation.component.effectiveName»_t, «instance.range.absSize»> «instance.name»;
«IF instantiation.componentDefinition.type == ComponentDefinitionType.REGFILE»
// scc::sc_register_file<«instantiation.componentDefinition.effectiveName»_regs> «instance.name»;
«ELSEIF instantiation.componentDefinition.type == ComponentDefinitionType.REG»
«IF instance.range===null»
«IF instantiation.componentDefinition.instantiations.size==0»
scc::sc_register<uint«instantiation.size»_t> «instance.name»;
«ELSEIF instantiation.isFilledByField»
scc::sc_register<uint«instantiation.size»_t> «instance.name»;
«ELSE»
scc::sc_register<«instantiation.componentDefinition.effectiveName»_t> «instance.name»;
«ENDIF»
«ELSE»
«IF instantiation.componentDefinition.instantiations.size==0»
scc::sc_register_indexed<uint«instantiation.size»_t, «instance.range.absSize»> «instance.name»;
«ELSEIF instantiation.isFilledByField»
scc::sc_register_indexed<uint«instantiation.size»_t, «instance.range.absSize»> «instance.name»;
«ELSE»
scc::sc_register_indexed<«instantiation.component.effectiveName»_t, «instance.range.absSize»> «instance.name»;
«ENDIF»
«ENDIF»
«ENDIF»
«ENDFOR»
«ENDFOR»
«componentDefinition.name»(sc_core::sc_module_name nm);
«componentDefinition.effectiveName»_regs(sc_core::sc_module_name nm);
template<unsigned BUSWIDTH=32>
void registerResources(sysc::tlm_target<BUSWIDTH>& target);
void registerResources(scc::tlm_target<BUSWIDTH>& target, uint64_t offset=0);
};
}
} // namespace gen
} // namespace «namespace»
//////////////////////////////////////////////////////////////////////////////
// member functions
//////////////////////////////////////////////////////////////////////////////
inline sysc::«componentDefinition.name»::«componentDefinition.name»(sc_core::sc_module_name nm)
inline «namespace»::gen::«componentDefinition.effectiveName»_regs::«componentDefinition.effectiveName»_regs(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
, NAMED(«instance.name», r_«instance.name», 0, *this)
«IF instantiation.componentDefinition.type == ComponentDefinitionType.REGFILE»
// , NAMED(«instance.name», i_«instance.name», 0, *this)
«ELSEIF instantiation.componentDefinition.type == ComponentDefinitionType.REG»
, NAMED(«instance.name», r_«instance.name», 0, *this)
«ENDIF»
«ENDFOR»
«ENDFOR»
{
}
template<unsigned BUSWIDTH>
inline void sysc::«componentDefinition.name»::registerResources(sysc::tlm_target<BUSWIDTH>& target) {
inline void «namespace»::gen::«componentDefinition.effectiveName»_regs::registerResources(scc::tlm_target<BUSWIDTH>& target, uint64_t offset) {
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
target.addResource(«instance.name», «instance.addressValue»UL);
«IF instantiation.componentDefinition.type == ComponentDefinitionType.REGFILE»
i_«instance.name».registerResources(target, «instance.addressValue»UL+offset);
«ELSEIF instantiation.componentDefinition.type == ComponentDefinitionType.REG»
target.addResource(«instance.name», «instance.addressValue»UL);
«ENDIF»
«ENDFOR»
«ENDFOR»
}
#endif // _«componentDefinition.name.toUpperCase»_H_
#endif // _«namespace.toUpperCase»_GEN_«componentDefinition.effectiveName.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() {
override generateSource(String namespace) {
''
}

View File

@ -5,7 +5,6 @@ package com.minres.rdl;
import com.google.inject.Binder;
import com.google.inject.name.Names;
import com.minres.rdl.AbstractRDLRuntimeModule;
import com.minres.rdl.converter.RdlTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverterService;
import org.eclipse.xtext.scoping.IGlobalScopeProvider;

View File

@ -3,8 +3,6 @@
*/
package com.minres.rdl;
import com.minres.rdl.RDLStandaloneSetupGenerated;
/**
* Initialization support for running Xtext languages without Equinox extension registry.
*/

View File

@ -1,7 +1,6 @@
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;
@ -14,7 +13,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 com.minres.rdl.rdl.Range;
import org.eclipse.emf.common.util.EList;
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;
@ -260,4 +261,87 @@ public class RdlUtil {
}
return componentSize;
}
public static ComponentDefinition getComponentDefinition(final Instantiation instantiation) {
ComponentDefinition _xifexpression = null;
ComponentDefinition _component = instantiation.getComponent();
boolean _tripleNotEquals = (_component != null);
if (_tripleNotEquals) {
_xifexpression = instantiation.getComponent();
} else {
_xifexpression = instantiation.getComponentRef();
}
return _xifexpression;
}
public static 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 static boolean isFilledByField(final Instantiation instantiation) {
final int fieldCount = RdlUtil.instanceCountOfType(RdlUtil.getComponentDefinition(instantiation), 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 static int instanceCountOfType(final ComponentDefinition definition, final ComponentDefinitionType type) {
Integer _xblockexpression = null;
{
final Iterable<Instantiation> insts = RdlUtil.instantiationsOfType(definition, type);
Integer _xifexpression = null;
int _size = IterableExtensions.size(insts);
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
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() + (p2).intValue()));
};
_xifexpression = IterableExtensions.<Integer>reduce(IterableExtensions.<Instantiation, Integer>map(insts, _function), _function_1);
} else {
_xifexpression = Integer.valueOf(0);
}
_xblockexpression = _xifexpression;
}
return (_xblockexpression).intValue();
}
}

View File

@ -2,9 +2,6 @@ package com.minres.rdl.converter;
import com.google.inject.Inject;
import com.minres.rdl.IntegerWithRadix;
import com.minres.rdl.converter.IDValueConverter;
import com.minres.rdl.converter.NUMValueConverter;
import com.minres.rdl.converter.STRValueConverter;
import org.eclipse.xtext.common.services.DefaultTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;

View File

@ -2,7 +2,6 @@ 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;
@ -19,7 +18,12 @@ public class AddrmapGenerator extends RdlBaseGenerator {
}
@Override
public String generateHeader() {
public boolean getOverwrite() {
return true;
}
@Override
public String generateHeader(final String namespace) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("#ifndef _");
String _upperCase = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
@ -33,7 +37,7 @@ public class AddrmapGenerator extends RdlBaseGenerator {
_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<sysc::target_memory_map_entry<32>, ");
_builder.append("const std::array<scc::target_memory_map_entry<32>, ");
int _instanceCount = RdlUtil.instanceCount(this.componentDefinition, ComponentDefinitionType.REGFILE);
_builder.append(_instanceCount);
_builder.append("> ");
@ -48,10 +52,10 @@ public class AddrmapGenerator extends RdlBaseGenerator {
EList<ComponentInstance> _componentInstances = instantiation.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
_builder.append(" ");
_builder.append("{&i_");
_builder.append("{i_");
String _name = instance.getName();
_builder.append(_name, " ");
_builder.append(", ");
_builder.append(".socket, ");
IntegerWithRadix _addressValue = RdlUtil.addressValue(instance);
_builder.append(_addressValue, " ");
_builder.append(", 0x");
@ -75,7 +79,7 @@ public class AddrmapGenerator extends RdlBaseGenerator {
}
@Override
public String generateSource() {
public String generateSource(final String namespace) {
return "";
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -24,11 +23,16 @@ public class FwAddrmapGenerator extends RdlBaseGenerator {
private final LinkedHashSet<Object> nameMap = CollectionLiterals.<Object>newLinkedHashSet();
@Override
public String generateHeader() {
public boolean getOverwrite() {
return true;
}
@Override
public String generateHeader(final String namespace) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// Copyright (C) 2020, MINRES Technologies GmbH");
_builder.append("// Copyright (C) 2020-2022, MINRES Technologies GmbH");
_builder.newLine();
_builder.append("// All rights reserved.");
_builder.newLine();
@ -120,8 +124,14 @@ public class FwAddrmapGenerator extends RdlBaseGenerator {
String _name_1 = instantiation.getComponent().getName();
_builder.append(_name_1);
_builder.append(".h\"");
String _xifexpression = null;
boolean _add = this.nameMap.add(instantiation.getComponent().getName());
_builder.append(_add);
if (_add) {
_xifexpression = "";
} else {
_xifexpression = "";
}
_builder.append(_xifexpression);
_builder.newLineIfNotEmpty();
}
}
@ -131,8 +141,14 @@ public class FwAddrmapGenerator extends RdlBaseGenerator {
String _name_2 = instantiation.getComponentRef().getName();
_builder.append(_name_2);
_builder.append(".h\"");
String _xifexpression_1 = null;
boolean _add_1 = this.nameMap.add(instantiation.getComponentRef().getName());
_builder.append(_add_1);
if (_add_1) {
_xifexpression_1 = "";
} else {
_xifexpression_1 = "";
}
_builder.append(_xifexpression_1);
_builder.newLineIfNotEmpty();
}
}
@ -194,7 +210,7 @@ public class FwAddrmapGenerator extends RdlBaseGenerator {
}
@Override
public String generateSource() {
public String generateSource(final String namespace) {
return "";
}
}

View File

@ -3,7 +3,6 @@ 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;
@ -12,9 +11,7 @@ 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;
@ -27,11 +24,16 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
}
@Override
public String generateHeader() {
public boolean getOverwrite() {
return true;
}
@Override
public String generateHeader(final String namespace) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// Copyright (C) 2020, MINRES Technologies GmbH");
_builder.append("// Copyright (C) 2020-2022, MINRES Technologies GmbH");
_builder.newLine();
_builder.append("// All rights reserved.");
_builder.newLine();
@ -176,7 +178,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
{
if (((instantiation.getComponent() != null) && Objects.equal(instantiation.getComponent().getType(), ComponentDefinitionType.REG))) {
{
boolean _isFilledByField = this.isFilledByField(instantiation);
boolean _isFilledByField = RdlUtil.isFilledByField(instantiation);
boolean _not = (!_isFilledByField);
if (_not) {
_builder.append(" ");
@ -228,7 +230,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
{
boolean _isFilledByField_1 = this.isFilledByField(instantiation_1);
boolean _isFilledByField_1 = RdlUtil.isFilledByField(instantiation_1);
if (_isFilledByField_1) {
_builder.append(" ");
_builder.append("static inline uint");
@ -255,7 +257,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
}
}
{
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
boolean _isFilledByField_2 = RdlUtil.isFilledByField(instantiation_1);
boolean _not_1 = (!_isFilledByField_2);
if (_not_1) {
_builder.append(" ");
@ -289,14 +291,14 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
boolean _tripleNotEquals = (_range_1 != null);
if (_tripleNotEquals) {
{
boolean _isFilledByField_3 = this.isFilledByField(instantiation_1);
boolean _isFilledByField_3 = RdlUtil.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());
long _absSize = RdlUtil.absSize(instance.getRange());
_builder.append(_absSize, " ");
_builder.append(">& ");
String _name_7 = instance.getName();
@ -309,7 +311,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
long _size_3 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_3, " ");
_builder.append("_t, ");
long _absSize_1 = this.absSize(instance.getRange());
long _absSize_1 = RdlUtil.absSize(instance.getRange());
_builder.append(_absSize_1, " ");
_builder.append(">*>(BASE_ADDR+");
IntegerWithRadix _addressValue_2 = RdlUtil.addressValue(instance);
@ -322,7 +324,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
}
}
{
boolean _isFilledByField_4 = this.isFilledByField(instantiation_1);
boolean _isFilledByField_4 = RdlUtil.isFilledByField(instantiation_1);
boolean _not_2 = (!_isFilledByField_4);
if (_not_2) {
_builder.append(" ");
@ -330,7 +332,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
String _name_8 = instance.getName();
_builder.append(_name_8, " ");
_builder.append("_t, ");
long _absSize_2 = this.absSize(instance.getRange());
long _absSize_2 = RdlUtil.absSize(instance.getRange());
_builder.append(_absSize_2, " ");
_builder.append(">& ");
String _name_9 = instance.getName();
@ -343,7 +345,7 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
String _name_10 = instance.getName();
_builder.append(_name_10, " ");
_builder.append("_t, ");
long _absSize_3 = this.absSize(instance.getRange());
long _absSize_3 = RdlUtil.absSize(instance.getRange());
_builder.append(_absSize_3, " ");
_builder.append(">*>(BASE_ADDR+");
IntegerWithRadix _addressValue_3 = RdlUtil.addressValue(instance);
@ -372,66 +374,8 @@ public class FwRegfileGenerator extends RdlBaseGenerator {
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() {
public String generateSource(final String namespace) {
return "";
}

View File

@ -4,7 +4,6 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.minres.rdl.RDLStandaloneSetup;
import com.minres.rdl.generator.Options;
import java.lang.reflect.MalformedParametersException;
import java.text.ParseException;
import java.util.List;
@ -14,7 +13,6 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.mwe.utils.ProjectMapping;
import org.eclipse.emf.mwe.utils.StandaloneSetup;
import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.GeneratorDelegate;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
@ -33,7 +31,7 @@ import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class Main {
private final String USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
private final String USAGE_STR = "RDL2code [-h] [-v] [-f] [-n <namespace>] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
public static void main(final String[] args) {
boolean _isEmpty = ((List<String>)Conversions.doWrapArray(args)).isEmpty();
@ -91,6 +89,8 @@ public class Main {
final Options opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet().addOption("h", Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("v", Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("f", Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("n", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("o", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("I", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
boolean _check = opt.check(false, false);
@ -154,11 +154,16 @@ public class Main {
int _size = issues.size();
throw new ParseException(_plus_1, _size);
}
GeneratorContext _generatorContext = new GeneratorContext();
final Procedure1<GeneratorContext> _function_2 = (GeneratorContext it) -> {
RdlGeneratorContext _rdlGeneratorContext = new RdlGeneratorContext();
final Procedure1<RdlGeneratorContext> _function_2 = (RdlGeneratorContext it) -> {
it.setCancelIndicator(CancelIndicator.NullImpl);
};
final GeneratorContext context = ObjectExtensions.<GeneratorContext>operator_doubleArrow(_generatorContext, _function_2);
final RdlGeneratorContext context = ObjectExtensions.<RdlGeneratorContext>operator_doubleArrow(_rdlGeneratorContext, _function_2);
context.forceOverwrite = opt.getSet().isSet("f");
boolean _isSet_4 = opt.getSet().isSet("n");
if (_isSet_4) {
context.namespace = opt.getSet().getOption("n").getResultValue(0);
}
this.generator.generate(resource, this.fileAccess, context);
if (verbose) {
InputOutput.<String>println((("Code generation for " + string) + " finished"));

View File

@ -0,0 +1,310 @@
package com.minres.rdl.generator;
import com.google.common.base.Objects;
import com.minres.rdl.RdlUtil;
import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.ComponentDefinitionType;
import com.minres.rdl.rdl.Instantiation;
import java.util.Iterator;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
@SuppressWarnings("all")
public class ModuleGenerator extends RdlBaseGenerator {
private final ComponentDefinition componentDefinition;
public ModuleGenerator(final ComponentDefinition definition) {
this.componentDefinition = definition;
}
@Override
public boolean getOverwrite() {
return false;
}
@Override
public String generateHeader(final String namespace) {
String _xblockexpression = null;
{
ComponentDefinitionType _type = this.componentDefinition.getType();
boolean _notEquals = (!Objects.equal(_type, ComponentDefinitionType.REGFILE));
if (_notEquals) {
return "";
}
final Function1<Notifier, Boolean> _function = (Notifier it) -> {
return Boolean.valueOf((it instanceof ComponentDefinition));
};
final Function1<Notifier, ComponentDefinition> _function_1 = (Notifier it) -> {
return ((ComponentDefinition) it);
};
final Function1<ComponentDefinition, Boolean> _function_2 = (ComponentDefinition it) -> {
ComponentDefinitionType _type_1 = it.getType();
return Boolean.valueOf(Objects.equal(_type_1, ComponentDefinitionType.ADDRMAP));
};
final Function1<ComponentDefinition, Boolean> _function_3 = (ComponentDefinition def) -> {
final Function1<Instantiation, Boolean> _function_4 = (Instantiation it) -> {
ComponentDefinition _componentRef = it.getComponentRef();
return Boolean.valueOf(Objects.equal(_componentRef, this.componentDefinition));
};
int _size = IterableExtensions.size(IterableExtensions.<Instantiation>filter(def.getInstantiations(), _function_4));
return Boolean.valueOf((_size > 0));
};
final Iterator<ComponentDefinition> addrMaps = IteratorExtensions.<ComponentDefinition>filter(IteratorExtensions.<ComponentDefinition>filter(IteratorExtensions.<Notifier, ComponentDefinition>map(IteratorExtensions.<Notifier>filter(this.componentDefinition.eResource().getResourceSet().getAllContents(), _function), _function_1), _function_2), _function_3);
int _size = IteratorExtensions.size(addrMaps);
boolean _equals = (_size == 0);
if (_equals) {
return "";
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("#ifndef _");
String _upperCase = namespace.toUpperCase();
_builder.append(_upperCase);
_builder.append("_");
String _upperCase_1 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_1);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.append("#define _");
String _upperCase_2 = namespace.toUpperCase();
_builder.append(_upperCase_2);
_builder.append("_");
String _upperCase_3 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_3);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.append("#include <scc/tlm_target.h>");
_builder.newLine();
_builder.newLine();
_builder.append("namespace ");
_builder.append(namespace);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("namespace gen {");
_builder.newLine();
_builder.append("class ");
String _effectiveName = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName);
_builder.append("_regs;");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class ");
String _effectiveName_1 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_1);
_builder.append(" : public sc_core::sc_module, public scc::tlm_target<> {");
_builder.newLineIfNotEmpty();
_builder.append("public:");
_builder.newLine();
_builder.append(" ");
_builder.append("sc_core::sc_in<sc_core::sc_time> clk_i{\"clk_i\"};");
_builder.newLine();
_builder.append(" ");
_builder.append("sc_core::sc_in<bool> rst_i{\"rst_i\"};");
_builder.newLine();
_builder.append(" ");
String _effectiveName_2 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_2, " ");
_builder.append("(sc_core::sc_module_name nm);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("virtual ~");
String _effectiveName_3 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_3, " ");
_builder.append("() override;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("protected:");
_builder.newLine();
_builder.append(" ");
_builder.append("void clock_cb();");
_builder.newLine();
_builder.append(" ");
_builder.append("void reset_cb();");
_builder.newLine();
_builder.append(" ");
_builder.append("sc_core::sc_time clk;");
_builder.newLine();
_builder.append(" ");
_builder.append("std::unique_ptr<gen::");
String _effectiveName_4 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_4, " ");
_builder.append("_regs> regs;");
_builder.newLineIfNotEmpty();
_builder.append("};");
_builder.newLine();
_builder.newLine();
_builder.append("} /* namespace ");
_builder.append(namespace);
_builder.append(" */");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#endif /* _");
String _upperCase_4 = namespace.toUpperCase();
_builder.append(_upperCase_4);
_builder.append("_");
String _upperCase_5 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_5);
_builder.append("_H_ */");
_builder.newLineIfNotEmpty();
_xblockexpression = _builder.toString();
}
return _xblockexpression;
}
@Override
public String generateSource(final String namespace) {
String _xblockexpression = null;
{
ComponentDefinitionType _type = this.componentDefinition.getType();
boolean _notEquals = (!Objects.equal(_type, ComponentDefinitionType.REGFILE));
if (_notEquals) {
return "";
}
final Function1<Notifier, Boolean> _function = (Notifier it) -> {
return Boolean.valueOf((it instanceof ComponentDefinition));
};
final Function1<Notifier, ComponentDefinition> _function_1 = (Notifier it) -> {
return ((ComponentDefinition) it);
};
final Function1<ComponentDefinition, Boolean> _function_2 = (ComponentDefinition it) -> {
ComponentDefinitionType _type_1 = it.getType();
return Boolean.valueOf(Objects.equal(_type_1, ComponentDefinitionType.ADDRMAP));
};
final Function1<ComponentDefinition, Boolean> _function_3 = (ComponentDefinition def) -> {
final Function1<Instantiation, Boolean> _function_4 = (Instantiation it) -> {
ComponentDefinition _componentRef = it.getComponentRef();
return Boolean.valueOf(Objects.equal(_componentRef, this.componentDefinition));
};
int _size = IterableExtensions.size(IterableExtensions.<Instantiation>filter(def.getInstantiations(), _function_4));
return Boolean.valueOf((_size > 0));
};
final Iterator<ComponentDefinition> addrMaps = IteratorExtensions.<ComponentDefinition>filter(IteratorExtensions.<ComponentDefinition>filter(IteratorExtensions.<Notifier, ComponentDefinition>map(IteratorExtensions.<Notifier>filter(this.componentDefinition.eResource().getResourceSet().getAllContents(), _function), _function_1), _function_2), _function_3);
int _size = IteratorExtensions.size(addrMaps);
boolean _equals = (_size == 0);
if (_equals) {
return "";
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Copyright (c) 2019 -2022 MINRES Technologies GmbH");
_builder.newLine();
_builder.append(" ");
_builder.append("*");
_builder.newLine();
_builder.append(" ");
_builder.append("* SPDX-License-Identifier: Apache-2.0");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.newLine();
_builder.append("#include \"");
String _effectiveName = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.append("#include \"gen/");
String _effectiveName_1 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_1);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#include <scc/utilities.h>");
_builder.newLine();
_builder.newLine();
_builder.append("namespace ");
_builder.append(namespace);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("SC_HAS_PROCESS(");
String _effectiveName_2 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_2);
_builder.append(");// NOLINT");
_builder.newLineIfNotEmpty();
_builder.newLine();
String _effectiveName_3 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_3);
_builder.append("::");
String _effectiveName_4 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_4);
_builder.append("(sc_core::sc_module_name nm)");
_builder.newLineIfNotEmpty();
_builder.append(": sc_core::sc_module(nm)");
_builder.newLine();
_builder.append(", scc::tlm_target<>(clk)");
_builder.newLine();
_builder.append(", NAMEDD(regs, gen::");
String _effectiveName_5 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_5);
_builder.append("_regs) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("regs->registerResources(*this);");
_builder.newLine();
_builder.append(" ");
_builder.append("SC_METHOD(clock_cb);");
_builder.newLine();
_builder.append(" ");
_builder.append("sensitive << clk_i;");
_builder.newLine();
_builder.append(" ");
_builder.append("SC_METHOD(reset_cb);");
_builder.newLine();
_builder.append(" ");
_builder.append("sensitive << rst_i;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
String _effectiveName_6 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_6);
_builder.append("::~");
String _effectiveName_7 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_7);
_builder.append("() {} // NOLINT");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("void ");
String _effectiveName_8 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_8);
_builder.append("::clock_cb() { this->clk = clk_i.read(); }");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("void ");
String _effectiveName_9 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_9);
_builder.append("::reset_cb() {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("if (rst_i.read()) {");
_builder.newLine();
_builder.append(" ");
_builder.append("regs->reset_start();");
_builder.newLine();
_builder.append(" ");
_builder.append("} else {");
_builder.newLine();
_builder.append(" ");
_builder.append("regs->reset_stop();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("} /* namespace ");
_builder.append(namespace);
_builder.append(" */");
_builder.newLineIfNotEmpty();
_xblockexpression = _builder.toString();
}
return _xblockexpression;
}
}

View File

@ -4,11 +4,6 @@
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;
@ -35,6 +30,20 @@ import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
public class RDLGenerator extends AbstractGenerator {
@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
boolean _xifexpression = false;
if ((context instanceof RdlGeneratorContext)) {
_xifexpression = ((RdlGeneratorContext)context).forceOverwrite;
} else {
_xifexpression = false;
}
final boolean force = _xifexpression;
String _xifexpression_1 = null;
if ((context instanceof RdlGeneratorContext)) {
_xifexpression_1 = ((RdlGeneratorContext)context).namespace;
} else {
_xifexpression_1 = "sysc";
}
final String namespace = _xifexpression_1;
final Function1<Notifier, Boolean> _function = (Notifier it) -> {
return Boolean.valueOf((it instanceof ComponentDefinition));
};
@ -45,19 +54,21 @@ public class RDLGenerator extends AbstractGenerator {
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 header = gen.generateHeader(namespace);
String _effectiveName = RdlUtil.effectiveName(it);
String _plus = ((p1 + "/") + _effectiveName);
final String inclFileName = (_plus + ".h");
final String inclCfg = this.outputConfig(fsa, "incl-out");
if (((((force || (!fsa.isFile(inclFileName, inclCfg))) || gen.getOverwrite()) && (header != null)) && (header.length() > 0))) {
fsa.generateFile(inclFileName, inclCfg, 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);
final String source = gen.generateSource(namespace);
String _effectiveName_1 = RdlUtil.effectiveName(it);
String _plus_1 = ((p1 + "/") + _effectiveName_1);
final String srcFileName = (_plus_1 + ".cpp");
final String srcCfg = this.outputConfig(fsa, "src-out");
if (((((force || (!fsa.isFile(srcFileName, srcCfg))) || gen.getOverwrite()) && (source != null)) && (source.length() > 0))) {
fsa.generateFile(srcFileName, srcCfg, source);
}
};
genMap.forEach(_function_3);
@ -73,17 +84,19 @@ public class RDLGenerator extends AbstractGenerator {
switch (_type) {
case REGFILE:
RegfileGenerator _regfileGenerator = new RegfileGenerator(definition);
Pair<String, RegfileGenerator> _mappedTo = Pair.<String, RegfileGenerator>of("vp", _regfileGenerator);
Pair<String, RegfileGenerator> _mappedTo = Pair.<String, RegfileGenerator>of("gen", _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));
ModuleGenerator _moduleGenerator = new ModuleGenerator(definition);
Pair<String, ModuleGenerator> _mappedTo_2 = Pair.<String, ModuleGenerator>of(".", _moduleGenerator);
_switchResult = Collections.<String, RdlBaseGenerator>unmodifiableMap(CollectionLiterals.<String, RdlBaseGenerator>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2));
break;
case ADDRMAP:
AddrmapGenerator _addrmapGenerator = new AddrmapGenerator(definition);
Pair<String, AddrmapGenerator> _mappedTo_2 = Pair.<String, AddrmapGenerator>of("vp", _addrmapGenerator);
Pair<String, AddrmapGenerator> _mappedTo_3 = Pair.<String, AddrmapGenerator>of("gen", _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));
Pair<String, FwAddrmapGenerator> _mappedTo_4 = Pair.<String, FwAddrmapGenerator>of("fw", _fwAddrmapGenerator);
_switchResult = Collections.<String, RdlBaseGenerator>unmodifiableMap(CollectionLiterals.<String, RdlBaseGenerator>newHashMap(_mappedTo_3, _mappedTo_4));
break;
default:
_switchResult = null;

View File

@ -2,7 +2,9 @@ package com.minres.rdl.generator;
@SuppressWarnings("all")
public abstract class RdlBaseGenerator {
public abstract String generateHeader();
public abstract String generateHeader(final String namespace);
public abstract String generateSource();
public abstract String generateSource(final String namespace);
public abstract boolean getOverwrite();
}

View File

@ -0,0 +1,10 @@
package com.minres.rdl.generator;
import org.eclipse.xtext.generator.GeneratorContext;
@SuppressWarnings("all")
public class RdlGeneratorContext extends GeneratorContext {
public boolean forceOverwrite = false;
public String namespace = "scc";
}

View File

@ -3,7 +3,6 @@ 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;
@ -12,11 +11,8 @@ 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 RegfileGenerator extends RdlBaseGenerator {
@ -27,11 +23,16 @@ public class RegfileGenerator extends RdlBaseGenerator {
}
@Override
public String generateHeader() {
public boolean getOverwrite() {
return true;
}
@Override
public String generateHeader(final String namespace) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("////////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// Copyright (C) 2017, MINRES Technologies GmbH");
_builder.append("// Copyright (C) 2017-2022, MINRES Technologies GmbH");
_builder.newLine();
_builder.append("// All rights reserved.");
_builder.newLine();
@ -94,8 +95,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.append(_date);
_builder.newLineIfNotEmpty();
_builder.append("// * ");
String _name = this.componentDefinition.getName();
_builder.append(_name);
String _effectiveName = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName);
_builder.append(".h Author: <RDL Generator>");
_builder.newLineIfNotEmpty();
_builder.append("//");
@ -104,57 +105,89 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine();
_builder.newLine();
_builder.append("#ifndef _");
String _upperCase = this.componentDefinition.getName().toUpperCase();
String _upperCase = namespace.toUpperCase();
_builder.append(_upperCase);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.append("#define _");
String _upperCase_1 = this.componentDefinition.getName().toUpperCase();
_builder.append("_GEN_");
String _upperCase_1 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_1);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.append("#define _");
String _upperCase_2 = namespace.toUpperCase();
_builder.append(_upperCase_2);
_builder.append("_GEN_");
String _upperCase_3 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_3);
_builder.append("_H_");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#include <sysc/utilities.h>");
_builder.append("#include <scc/utilities.h>");
_builder.newLine();
_builder.append("#include <util/bit_field.h>");
_builder.newLine();
_builder.append("#include <sysc/register.h>");
_builder.append("#include <scc/register.h>");
_builder.newLine();
_builder.append("#include <sysc/tlm_target.h>");
_builder.append("#include <scc/tlm_target.h>");
_builder.newLine();
{
EList<Instantiation> _instantiations = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation : _instantiations) {
{
ComponentDefinitionType _type = RdlUtil.getComponentDefinition(instantiation).getType();
boolean _equals = Objects.equal(_type, ComponentDefinitionType.REGFILE);
if (_equals) {
_builder.append("#include \"");
String _effectiveName_1 = RdlUtil.effectiveName(RdlUtil.getComponentDefinition(instantiation));
_builder.append(_effectiveName_1);
_builder.append(".h\"");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append("namespace sysc {");
_builder.append("namespace ");
_builder.append(namespace);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("namespace gen {");
_builder.newLine();
_builder.newLine();
_builder.append("class ");
String _name_1 = this.componentDefinition.getName();
_builder.append(_name_1);
_builder.append(" :");
String _effectiveName_2 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_2);
_builder.append("_regs :");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public sc_core::sc_module,");
_builder.newLine();
_builder.append(" ");
_builder.append("public sysc::resetable");
_builder.append("public scc::resetable");
_builder.newLine();
_builder.append("{");
_builder.newLine();
_builder.append("public:");
_builder.newLine();
_builder.append(" ");
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append(" ");
_builder.append("// storage declarations");
_builder.newLine();
_builder.append(" ");
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_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) {
ComponentDefinitionType _type_1 = cdef.getType();
boolean _equals_1 = Objects.equal(_type_1, ComponentDefinitionType.REG);
if (_equals_1) {
_builder.append(" ");
_builder.append("BEGIN_BF_DECL(");
String _effectiveName = RdlUtil.effectiveName(cdef);
_builder.append(_effectiveName, " ");
String _effectiveName_3 = RdlUtil.effectiveName(cdef);
_builder.append(_effectiveName_3, " ");
_builder.append("+\'_t\'», uint");
_builder.append(cdef, " ");
_builder.append("_t);");
@ -170,221 +203,186 @@ public class RegfileGenerator extends RdlBaseGenerator {
}
}
}
{
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);
if (_isFilledByField) {
{
final Function1<ComponentInstance, Boolean> _function_1 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
int _size = IterableExtensions.size(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_1));
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append(" ");
_builder.append("uint");
long _size_1 = RdlUtil.getSize(instantiation);
_builder.append(_size_1, " ");
_builder.append("_t ");
final Function1<ComponentInstance, Boolean> _function_2 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_3 = (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_2), _function_3), ", ");
_builder.append(_join_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
final Function1<ComponentInstance, Boolean> _function_4 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_4);
for(final ComponentInstance componentInstance : _filter) {
_builder.append(" ");
_builder.append("std::array<uint");
long _size_2 = RdlUtil.getSize(instantiation);
_builder.append(_size_2, " ");
_builder.append("_t, ");
long _absSize = this.absSize(componentInstance.getRange());
_builder.append(_absSize, " ");
_builder.append("> r_");
String _name_2 = componentInstance.getName();
_builder.append(_name_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
{
boolean _isFilledByField_1 = this.isFilledByField(instantiation);
boolean _not = (!_isFilledByField_1);
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_3 = RdlUtil.getSize(instantiation);
_builder.append(_size_3, " ");
_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_5 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_6 = (ComponentInstance it) -> {
String _name_3 = it.getName();
return ("r_" + _name_3);
};
String _join_2 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_5), _function_6), ", ");
_builder.append(_join_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
{
final Function1<ComponentInstance, Boolean> _function_7 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter_1 = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_7);
for(final ComponentInstance componentInstance_1 : _filter_1) {
_builder.append(" ");
_builder.append("std::array<");
String _effectiveName_3 = RdlUtil.effectiveName(instantiation.getComponent());
_builder.append(_effectiveName_3, " ");
_builder.append("_t, ");
long _absSize_1 = this.absSize(componentInstance_1.getRange());
_builder.append(_absSize_1, " ");
_builder.append("> r_");
String _name_3 = componentInstance_1.getName();
_builder.append(_name_3, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append(" ");
_builder.newLine();
}
}
}
}
_builder.append(" ");
_builder.append("// register declarations");
_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) {
ComponentDefinitionType _type_2 = RdlUtil.getComponentDefinition(instantiation_1).getType();
boolean _equals_2 = Objects.equal(_type_2, ComponentDefinitionType.REGFILE);
if (_equals_2) {
{
Range _range = instance.getRange();
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
{
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
if (_isFilledByField_2) {
_builder.append(" ");
_builder.append("sysc::sc_register<uint");
long _size_4 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_4, " ");
_builder.append("_t> ");
String _name_4 = instance.getName();
_builder.append(_name_4, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isFilledByField_3 = this.isFilledByField(instantiation_1);
boolean _not_1 = (!_isFilledByField_3);
if (_not_1) {
_builder.append(" ");
_builder.append("sysc::sc_register<");
String _effectiveName_4 = RdlUtil.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_4, " ");
_builder.append("_t> ");
String _name_5 = instance.getName();
_builder.append(_name_5, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
_builder.append(" ");
String _effectiveName_4 = RdlUtil.effectiveName(RdlUtil.getComponentDefinition(instantiation_1));
_builder.append(_effectiveName_4, " ");
_builder.append("_regs i_");
String _name = instance.getName();
_builder.append(_name, " ");
_builder.append("{\"");
String _name_1 = instance.getName();
_builder.append(_name_1, " ");
_builder.append("\"};");
_builder.newLineIfNotEmpty();
}
}
{
Range _range_1 = instance.getRange();
boolean _tripleNotEquals = (_range_1 != null);
if (_tripleNotEquals) {
{
boolean _isFilledByField_4 = this.isFilledByField(instantiation_1);
if (_isFilledByField_4) {
_builder.append(" ");
_builder.append("sysc::sc_register_indexed<uint");
long _size_5 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_5, " ");
_builder.append("_t, ");
long _absSize_2 = this.absSize(instance.getRange());
_builder.append(_absSize_2, " ");
_builder.append("> ");
String _name_6 = instance.getName();
_builder.append(_name_6, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
ComponentDefinitionType _type_3 = RdlUtil.getComponentDefinition(instantiation_1).getType();
boolean _equals_3 = Objects.equal(_type_3, ComponentDefinitionType.REG);
if (_equals_3) {
{
boolean _isFilledByField = RdlUtil.isFilledByField(instantiation_1);
if (_isFilledByField) {
{
final Function1<ComponentInstance, Boolean> _function = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
int _size = IterableExtensions.size(IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function));
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append(" ");
_builder.append("uint");
long _size_1 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_1, " ");
_builder.append("_t ");
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 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_1), _function_2), ", ");
_builder.append(_join, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
{
boolean _isFilledByField_5 = this.isFilledByField(instantiation_1);
boolean _not_2 = (!_isFilledByField_5);
if (_not_2) {
{
final Function1<ComponentInstance, Boolean> _function_3 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter = IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_3);
for(final ComponentInstance componentInstance : _filter) {
_builder.append(" ");
_builder.append("std::array<uint");
long _size_2 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_2, " ");
_builder.append("_t, ");
long _absSize = RdlUtil.absSize(componentInstance.getRange());
_builder.append(_absSize, " ");
_builder.append("> r_");
String _name_2 = componentInstance.getName();
_builder.append(_name_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
} else {
int _size_3 = RdlUtil.getComponentDefinition(instantiation_1).getInstantiations().size();
boolean _equals_4 = (_size_3 == 0);
if (_equals_4) {
{
final Function1<ComponentInstance, Boolean> _function_4 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
int _size_4 = IterableExtensions.size(IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_4));
boolean _greaterThan_1 = (_size_4 > 0);
if (_greaterThan_1) {
_builder.append(" ");
_builder.append("uint");
long _size_5 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_5, " ");
_builder.append("_t ");
final Function1<ComponentInstance, Boolean> _function_5 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_6 = (ComponentInstance it) -> {
String _name_3 = it.getName();
return ("r_" + _name_3);
};
String _join_1 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_5), _function_6), ", ");
_builder.append(_join_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
final Function1<ComponentInstance, Boolean> _function_7 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter_1 = IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_7);
for(final ComponentInstance componentInstance_1 : _filter_1) {
_builder.append(" ");
_builder.append("std::array<uint");
long _size_6 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_6, " ");
_builder.append("_t, ");
long _absSize_1 = RdlUtil.absSize(componentInstance_1.getRange());
_builder.append(_absSize_1, " ");
_builder.append("> r_");
String _name_3 = componentInstance_1.getName();
_builder.append(_name_3, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
} else {
_builder.append(" ");
_builder.append("sysc::sc_register_indexed<");
_builder.append("BEGIN_BF_DECL(");
String _effectiveName_5 = RdlUtil.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_5, " ");
_builder.append("_t, ");
long _absSize_3 = this.absSize(instance.getRange());
_builder.append(_absSize_3, " ");
_builder.append("> ");
String _name_7 = instance.getName();
_builder.append(_name_7, " ");
_builder.append("_t, uint");
long _size_7 = RdlUtil.getSize(instantiation_1);
_builder.append(_size_7, " ");
_builder.append("_t);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
String _genFieldDeclarations_1 = this.genFieldDeclarations(RdlUtil.definingComponent(instantiation_1));
_builder.append(_genFieldDeclarations_1, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("END_BF_DECL() ");
final Function1<ComponentInstance, Boolean> _function_8 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_9 = (ComponentInstance it) -> {
String _name_4 = it.getName();
return ("r_" + _name_4);
};
String _join_2 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_8), _function_9), ", ");
_builder.append(_join_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
{
final Function1<ComponentInstance, Boolean> _function_10 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter_2 = IterableExtensions.<ComponentInstance>filter(instantiation_1.getComponentInstances(), _function_10);
for(final ComponentInstance componentInstance_2 : _filter_2) {
_builder.append(" ");
_builder.append("std::array<");
String _effectiveName_6 = RdlUtil.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_6, " ");
_builder.append("_t, ");
long _absSize_2 = RdlUtil.absSize(componentInstance_2.getRange());
_builder.append(_absSize_2, " ");
_builder.append("> r_");
String _name_4 = componentInstance_2.getName();
_builder.append(_name_4, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
}
@ -394,54 +392,209 @@ public class RegfileGenerator extends RdlBaseGenerator {
}
}
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
String _name_8 = this.componentDefinition.getName();
_builder.append(_name_8, " ");
_builder.append("(sc_core::sc_module_name nm);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("template<unsigned BUSWIDTH=32>");
_builder.newLine();
_builder.append(" ");
_builder.append("void registerResources(sysc::tlm_target<BUSWIDTH>& target);");
_builder.newLine();
_builder.append("};");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// member functions");
_builder.append(" ");
_builder.append("// register declarations");
_builder.newLine();
_builder.append(" ");
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.newLine();
_builder.append("inline sysc::");
String _name_9 = this.componentDefinition.getName();
_builder.append(_name_9);
_builder.append("::");
String _name_10 = this.componentDefinition.getName();
_builder.append(_name_10);
_builder.append("(sc_core::sc_module_name nm)");
_builder.newLineIfNotEmpty();
_builder.append(": sc_core::sc_module(nm)");
_builder.newLine();
{
EList<Instantiation> _instantiations_2 = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation_2 : _instantiations_2) {
{
EList<ComponentInstance> _componentInstances_1 = instantiation_2.getComponentInstances();
for(final ComponentInstance instance_1 : _componentInstances_1) {
_builder.append(", NAMED(");
String _name_11 = instance_1.getName();
_builder.append(_name_11);
_builder.append(", r_");
String _name_12 = instance_1.getName();
_builder.append(_name_12);
_builder.append(", 0, *this)");
_builder.newLineIfNotEmpty();
{
ComponentDefinitionType _type_4 = RdlUtil.getComponentDefinition(instantiation_2).getType();
boolean _equals_5 = Objects.equal(_type_4, ComponentDefinitionType.REGFILE);
if (_equals_5) {
_builder.append(" ");
_builder.append("// scc::sc_register_file<");
String _effectiveName_7 = RdlUtil.effectiveName(RdlUtil.getComponentDefinition(instantiation_2));
_builder.append(_effectiveName_7, " ");
_builder.append("_regs> ");
String _name_5 = instance_1.getName();
_builder.append(_name_5, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
ComponentDefinitionType _type_5 = RdlUtil.getComponentDefinition(instantiation_2).getType();
boolean _equals_6 = Objects.equal(_type_5, ComponentDefinitionType.REG);
if (_equals_6) {
{
Range _range = instance_1.getRange();
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
{
int _size_8 = RdlUtil.getComponentDefinition(instantiation_2).getInstantiations().size();
boolean _equals_7 = (_size_8 == 0);
if (_equals_7) {
_builder.append(" ");
_builder.append("scc::sc_register<uint");
long _size_9 = RdlUtil.getSize(instantiation_2);
_builder.append(_size_9, " ");
_builder.append("_t> ");
String _name_6 = instance_1.getName();
_builder.append(_name_6, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
boolean _isFilledByField_1 = RdlUtil.isFilledByField(instantiation_2);
if (_isFilledByField_1) {
_builder.append(" ");
_builder.append("scc::sc_register<uint");
long _size_10 = RdlUtil.getSize(instantiation_2);
_builder.append(_size_10, " ");
_builder.append("_t> ");
String _name_7 = instance_1.getName();
_builder.append(_name_7, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append(" ");
_builder.append("scc::sc_register<");
String _effectiveName_8 = RdlUtil.effectiveName(RdlUtil.getComponentDefinition(instantiation_2));
_builder.append(_effectiveName_8, " ");
_builder.append("_t> ");
String _name_8 = instance_1.getName();
_builder.append(_name_8, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
} else {
{
int _size_11 = RdlUtil.getComponentDefinition(instantiation_2).getInstantiations().size();
boolean _equals_8 = (_size_11 == 0);
if (_equals_8) {
_builder.append(" ");
_builder.append("scc::sc_register_indexed<uint");
long _size_12 = RdlUtil.getSize(instantiation_2);
_builder.append(_size_12, " ");
_builder.append("_t, ");
long _absSize_3 = RdlUtil.absSize(instance_1.getRange());
_builder.append(_absSize_3, " ");
_builder.append("> ");
String _name_9 = instance_1.getName();
_builder.append(_name_9, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
boolean _isFilledByField_2 = RdlUtil.isFilledByField(instantiation_2);
if (_isFilledByField_2) {
_builder.append(" ");
_builder.append("scc::sc_register_indexed<uint");
long _size_13 = RdlUtil.getSize(instantiation_2);
_builder.append(_size_13, " ");
_builder.append("_t, ");
long _absSize_4 = RdlUtil.absSize(instance_1.getRange());
_builder.append(_absSize_4, " ");
_builder.append("> ");
String _name_10 = instance_1.getName();
_builder.append(_name_10, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append(" ");
_builder.append("scc::sc_register_indexed<");
String _effectiveName_9 = RdlUtil.effectiveName(instantiation_2.getComponent());
_builder.append(_effectiveName_9, " ");
_builder.append("_t, ");
long _absSize_5 = RdlUtil.absSize(instance_1.getRange());
_builder.append(_absSize_5, " ");
_builder.append("> ");
String _name_11 = instance_1.getName();
_builder.append(_name_11, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
}
}
}
}
}
}
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
String _effectiveName_10 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_10, " ");
_builder.append("_regs(sc_core::sc_module_name nm);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("template<unsigned BUSWIDTH=32>");
_builder.newLine();
_builder.append(" ");
_builder.append("void registerResources(scc::tlm_target<BUSWIDTH>& target, uint64_t offset=0);");
_builder.newLine();
_builder.append("};");
_builder.newLine();
_builder.append("} // namespace gen");
_builder.newLine();
_builder.append("} // namespace ");
_builder.append(namespace);
_builder.newLineIfNotEmpty();
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.append("// member functions");
_builder.newLine();
_builder.append("//////////////////////////////////////////////////////////////////////////////");
_builder.newLine();
_builder.newLine();
_builder.append("inline ");
_builder.append(namespace);
_builder.append("::gen::");
String _effectiveName_11 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_11);
_builder.append("_regs::");
String _effectiveName_12 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_12);
_builder.append("_regs(sc_core::sc_module_name nm)");
_builder.newLineIfNotEmpty();
_builder.append(": sc_core::sc_module(nm)");
_builder.newLine();
{
EList<Instantiation> _instantiations_3 = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation_3 : _instantiations_3) {
{
EList<ComponentInstance> _componentInstances_2 = instantiation_3.getComponentInstances();
for(final ComponentInstance instance_2 : _componentInstances_2) {
{
ComponentDefinitionType _type_6 = RdlUtil.getComponentDefinition(instantiation_3).getType();
boolean _equals_9 = Objects.equal(_type_6, ComponentDefinitionType.REGFILE);
if (_equals_9) {
_builder.append("// , NAMED(");
String _name_12 = instance_2.getName();
_builder.append(_name_12);
_builder.append(", i_");
String _name_13 = instance_2.getName();
_builder.append(_name_13);
_builder.append(", 0, *this)");
_builder.newLineIfNotEmpty();
} else {
ComponentDefinitionType _type_7 = RdlUtil.getComponentDefinition(instantiation_3).getType();
boolean _equals_10 = Objects.equal(_type_7, ComponentDefinitionType.REG);
if (_equals_10) {
_builder.append(", NAMED(");
String _name_14 = instance_2.getName();
_builder.append(_name_14);
_builder.append(", r_");
String _name_15 = instance_2.getName();
_builder.append(_name_15);
_builder.append(", 0, *this)");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
@ -453,26 +606,48 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine();
_builder.append("template<unsigned BUSWIDTH>");
_builder.newLine();
_builder.append("inline void sysc::");
String _name_13 = this.componentDefinition.getName();
_builder.append(_name_13);
_builder.append("::registerResources(sysc::tlm_target<BUSWIDTH>& target) {");
_builder.append("inline void ");
_builder.append(namespace);
_builder.append("::gen::");
String _effectiveName_13 = RdlUtil.effectiveName(this.componentDefinition);
_builder.append(_effectiveName_13);
_builder.append("_regs::registerResources(scc::tlm_target<BUSWIDTH>& target, uint64_t offset) {");
_builder.newLineIfNotEmpty();
{
EList<Instantiation> _instantiations_3 = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation_3 : _instantiations_3) {
EList<Instantiation> _instantiations_4 = this.componentDefinition.getInstantiations();
for(final Instantiation instantiation_4 : _instantiations_4) {
{
EList<ComponentInstance> _componentInstances_2 = instantiation_3.getComponentInstances();
for(final ComponentInstance instance_2 : _componentInstances_2) {
_builder.append(" ");
_builder.append("target.addResource(");
String _name_14 = instance_2.getName();
_builder.append(_name_14, " ");
_builder.append(", ");
IntegerWithRadix _addressValue = RdlUtil.addressValue(instance_2);
_builder.append(_addressValue, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
EList<ComponentInstance> _componentInstances_3 = instantiation_4.getComponentInstances();
for(final ComponentInstance instance_3 : _componentInstances_3) {
{
ComponentDefinitionType _type_8 = RdlUtil.getComponentDefinition(instantiation_4).getType();
boolean _equals_11 = Objects.equal(_type_8, ComponentDefinitionType.REGFILE);
if (_equals_11) {
_builder.append(" ");
_builder.append("i_");
String _name_16 = instance_3.getName();
_builder.append(_name_16, " ");
_builder.append(".registerResources(target, ");
IntegerWithRadix _addressValue = RdlUtil.addressValue(instance_3);
_builder.append(_addressValue, " ");
_builder.append("UL+offset);");
_builder.newLineIfNotEmpty();
} else {
ComponentDefinitionType _type_9 = RdlUtil.getComponentDefinition(instantiation_4).getType();
boolean _equals_12 = Objects.equal(_type_9, ComponentDefinitionType.REG);
if (_equals_12) {
_builder.append(" ");
_builder.append("target.addResource(");
String _name_17 = instance_3.getName();
_builder.append(_name_17, " ");
_builder.append(", ");
IntegerWithRadix _addressValue_1 = RdlUtil.addressValue(instance_3);
_builder.append(_addressValue_1, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
@ -481,73 +656,18 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine();
_builder.newLine();
_builder.append("#endif // _");
String _upperCase_2 = this.componentDefinition.getName().toUpperCase();
_builder.append(_upperCase_2);
String _upperCase_4 = namespace.toUpperCase();
_builder.append(_upperCase_4);
_builder.append("_GEN_");
String _upperCase_5 = RdlUtil.effectiveName(this.componentDefinition).toUpperCase();
_builder.append(_upperCase_5);
_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() {
public String generateSource(final String namespace) {
return "";
}

View File

@ -7,7 +7,6 @@ import com.google.common.collect.Iterables;
import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.Include;
import com.minres.rdl.rdl.Root;
import com.minres.rdl.scoping.AbstractRDLScopeProvider;
import java.util.Arrays;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;

View File

@ -3,8 +3,6 @@
*/
package com.minres.rdl.validation;
import com.minres.rdl.validation.AbstractRDLValidator;
/**
* This class contains custom validation rules.
*