extends configurability of generator

This commit is contained in:
Eyck Jentzsch 2022-10-24 20:18:49 +02:00
parent 1c9c0ee340
commit 1d2384257e
19 changed files with 826 additions and 684 deletions

View File

@ -100,7 +100,7 @@
<page category="com.minres.rdl.RDL"
class="com.minres.rdl.ui.RDLExecutableExtensionFactory:com.minres.rdl.ui.preferences.RdlPreferencePage"
id="com.minres.rdl.RDL.preferences"
name="Generator">
name="Output Configuration">
<keywordReference id="com.minres.rdl.ui.keyword_RDL"/>
</page>
</extension>
@ -264,11 +264,6 @@
<keywordReference id="com.minres.rdl.ui.keyword_RDL"/>
</page>
</extension>
<extension point="org.eclipse.xtext.builder.participant">
<participant
class="com.minres.rdl.ui.RDLExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant"
fileExtensions="rdl"/>
</extension>
<extension point="org.eclipse.ui.preferencePages">
<page
category="com.minres.rdl.RDL"
@ -463,4 +458,53 @@
<newWizardShortcut id="com.minres.rdl.ui.wizard.RDLNewProjectWizard"/>
</perspectiveExtension>
</extension>
<!-- <extension point="org.eclipse.xtext.builder.participant">
<participant
class="com.minres.rdl.ui.RDLExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant"
fileExtensions="rdl"/>
</extension>-->
<extension
point="org.eclipse.ui.handlers">
<handler
class="com.minres.rdl.ui.RDLExecutableExtensionFactory:com.minres.rdl.ui.builder.GenerationHandler"
commandId="com.minres.rdl.ui.handler.GenerationCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command name="Generate Code from RDL"
id="com.minres.rdl.ui.handler.GenerationCommand">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
<command
commandId="com.minres.rdl.ui.handler.GenerationCommand"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.name"
value="*.rdl"/>
</adapt>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=additions">
<command
commandId="com.minres.rdl.ui.handler.GenerationCommand"
style="push">
<visibleWhen checkEnabled="false">
<reference
definitionId="com.minres.rdl.RDL.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
</plugin>

View File

@ -3,8 +3,8 @@
*/
package com.minres.rdl.ui
import com.minres.structural.ui.hyperlink.MyHyperlinkHelper
import com.minres.structural.ui.hyperlink.MyXtextHyperlink
import com.minres.rdl.ui.hyperlink.RdlHyperlinkHelper
import com.minres.rdl.ui.hyperlink.RdlXtextHyperlink
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider
@ -36,11 +36,11 @@ class RDLUiModule extends AbstractRDLUiModule {
}
def Class<? extends HyperlinkHelper> bindHyperlinkHelper() {
return MyHyperlinkHelper
return RdlHyperlinkHelper
}
def Class<? extends XtextHyperlink> bindHyperlink() {
return MyXtextHyperlink
return RdlXtextHyperlink
}
}

View File

@ -0,0 +1,134 @@
package com.minres.rdl.ui.builder;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;
import org.eclipse.xtext.generator.IGenerator2;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.minres.rdl.generator.RdlGeneratorContext;
import com.minres.rdl.preferences.PreferenceConstants;
public class GenerationHandler extends AbstractHandler implements IHandler {
@Inject
private IGenerator2 generator;
@Inject
private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;
@Inject
IResourceDescriptions resourceDescriptions;
@Inject
IResourceSetProvider resourceSetProvider;
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
@Override
public Object execute(ExecutionEvent event) {
RdlGeneratorContext context = new RdlGeneratorContext();
context.cancelIndicator = CancelIndicator.NullImpl;
context.namespace = preferences.get(PreferenceConstants.P_NAMESPACE, "sysc");
context.forceOverwrite=preferences.getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
String whatToGenerate = preferences.get(PreferenceConstants.P_FILETYPES_TO_GENERATE, "all");
if(whatToGenerate=="sc-comp") {
context.generateFw=false;
} else if(whatToGenerate=="fw") {
context.generateSc=false;
}
context.forceOverwrite=preferences.getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
context.fwPathModifier=preferences.get(PreferenceConstants.P_FIRMWARE_PATH, "");
context.scPathModifier=preferences.get(PreferenceConstants.P_COMPONENT_PATH, "");
String outputDir = preferences.get("outlet.DEFAULT_OUTPUT.directory", "src-gen");
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activeEditor instanceof XtextEditor && activeEditor == activePart) {
IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
if (file != null) {
final EclipseResourceFileSystemAccess2 fsa = getFsa(outputDir, file, context.fwPathModifier, context.scPathModifier);
((XtextEditor)activeEditor).getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {
@Override
public Boolean exec(XtextResource state) throws Exception {
generator.doGenerate(state, fsa, context);
return Boolean.TRUE;
}
});
}
} else {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
for (Object element : structuredSelection) {
if (element instanceof IFile) {
IFile file = (IFile) element;
final EclipseResourceFileSystemAccess2 fsa = getFsa(outputDir, file, context.fwPathModifier, context.scPathModifier);
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource r = resourceSetProvider.get(file.getProject()).getResource(uri, true);
try {
generator.doGenerate(r, fsa, context);
} finally {}
}
}
}
}
return null;
}
private EclipseResourceFileSystemAccess2 getFsa(String outputDir, IFile file, String fwPath, String scPath) {
IProject project = file.getProject();
IFolder srcGenFolder = project.getFolder(outputDir);
createIfNotExists(srcGenFolder);
if(fwPath.length()>0) createIfNotExists(srcGenFolder.getFolder(fwPath));
if(scPath.length()>0) createIfNotExists(srcGenFolder.getFolder(scPath));
final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
fsa.setOutputPath("src-gen");
String scGenFolderPath = (fwPath.length()>0? srcGenFolder.getFolder(scPath) : srcGenFolder).getProjectRelativePath().toString();
fsa.setOutputPath("sc-incl-out", scGenFolderPath);
fsa.setOutputPath("sc-src-out", scGenFolderPath);
String fwGenFolderPath = (fwPath.length()>0? srcGenFolder.getFolder(fwPath) : srcGenFolder).getProjectRelativePath().toString();
fsa.setOutputPath("fw-incl-out", fwGenFolderPath);
fsa.setOutputPath("fw-src-out", fwGenFolderPath);
fsa.setProject(project);
fsa.setMonitor(new NullProgressMonitor());
return fsa;
}
private void createIfNotExists(IFolder srcGenFolder) {
if (!srcGenFolder.exists()) {
try {
srcGenFolder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) { }
}
}
@Override
public boolean isEnabled() {
return true;
}
}

View File

@ -1,4 +1,4 @@
package com.minres.structural.ui.hyperlink
package com.minres.rdl.ui.hyperlink
import com.google.inject.Inject
import org.eclipse.emf.common.util.URI
@ -13,7 +13,7 @@ import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor
import org.eclipse.xtext.util.TextRegion
import org.eclipse.jface.text.IRegion
class MyHyperlinkHelper extends HyperlinkHelper {
class RdlHyperlinkHelper extends HyperlinkHelper {
@Inject ImportUriResolver resolver;
@ -37,7 +37,7 @@ class MyHyperlinkHelper extends HyperlinkHelper {
result.setHyperlinkRegion(new Region(textRegion.getOffset(), textRegion.getLength()) as IRegion);
result.setURI(if(uri.isPlatformResource()) uri else resource.getResourceSet().getURIConverter().normalize(uri));
result.setHyperlinkText(labelProvider.getText(top));
if(result instanceof MyXtextHyperlink) result.selectTarget=false
if(result instanceof RdlXtextHyperlink) result.selectTarget=false
acceptor.accept(result);
}
}

View File

@ -1,10 +1,10 @@
package com.minres.structural.ui.hyperlink
package com.minres.rdl.ui.hyperlink
import com.google.inject.Inject
import org.eclipse.xtext.ui.editor.IURIEditorOpener
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink
class MyXtextHyperlink extends XtextHyperlink {
class RdlXtextHyperlink extends XtextHyperlink {
var boolean select = true

View File

@ -8,6 +8,7 @@ import com.minres.rdl.preferences.PreferenceConstants
import org.eclipse.ui.preferences.ScopedPreferenceStore
import org.eclipse.core.runtime.preferences.InstanceScope
import org.eclipse.jface.preference.ComboFieldEditor
import org.eclipse.jface.preference.StringFieldEditor
class RdlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@ -21,6 +22,11 @@ class RdlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchP
override createFieldEditors() {
addField(new BooleanFieldEditor(PreferenceConstants.P_GENERATE_CSV, "Generate CSV:", getFieldEditorParent()));
addField(new ComboFieldEditor(PreferenceConstants.P_ADDRESSUNIT, "Address unit size", #[#["Byte (8bit)","byte"], #["Word (16bit)","word"], #["DWord (32bit)","dword"]], getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_NAMESPACE, "Namespace of generated SystemC", 30, getFieldEditorParent()))
addField(new BooleanFieldEditor(PreferenceConstants.P_OVERWRITE_STUBS, "Always overwrite component stubs", getFieldEditorParent()));
addField(new ComboFieldEditor(PreferenceConstants.P_FILETYPES_TO_GENERATE, "File types to generate", #[#["All","all"], #["FW only","fw"], #["SC components","sc-comp"]], getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_COMPONENT_PATH, "relative path for SystemC files", 30, getFieldEditorParent()))
addField(new StringFieldEditor(PreferenceConstants.P_FIRMWARE_PATH, "relative path for FW files", 30, getFieldEditorParent()))
}
override init(IWorkbench workbench) {

View File

@ -26,4 +26,11 @@ class RDLRuntimeModule extends AbstractRDLRuntimeModule {
//return typeof(ResourceSetGlobalScopeProvider)
return typeof(org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider)
}
// def Class<? extends IGeneratorConfiguration> bindIGeneratorConfiguration() {
// return GeneratorConfiguration;
// }
// def IGeneratorConfiguration bindIGeneratorConfiguration() {
// return new GeneratorConfiguration();
// }
}

View File

@ -4,6 +4,7 @@ import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ComponentDefinitionType
import static extension com.minres.rdl.RdlUtil.*
import java.util.Date
class AddrmapGenerator extends RdlBaseGenerator {
@ -18,8 +19,18 @@ class AddrmapGenerator extends RdlBaseGenerator {
}
override generateHeader(String namespace) {'''
#ifndef _«componentDefinition.effectiveName.toUpperCase»_MAP_H_
#define _«componentDefinition.effectiveName.toUpperCase»_MAP_H_
/*
* Copyright (c) 2019 -2022 MINRES Technologies GmbH
*
* SPDX-License-Identifier: Apache-2.0
*
* Created on: «new Date»
* * «componentDefinition.effectiveName».h Author: <RDL Generator>
*
*/
#pragma once
// need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191
const std::array<scc::target_memory_map_entry<32>, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> «componentDefinition.effectiveName»_map = {{
«FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»

View File

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

View File

@ -22,43 +22,17 @@ class FwRegfileGenerator extends RdlBaseGenerator{
}
override String generateHeader(String namespace)'''
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020-2022, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created on: «new Date»
// * «componentDefinition.name».h Author: <RDL Generator>
//
////////////////////////////////////////////////////////////////////////////////
/*
* Copyright (c) 2019 -2022 MINRES Technologies GmbH
*
* SPDX-License-Identifier: Apache-2.0
*
* Created on: «new Date»
* * «componentDefinition.effectiveName».h Author: <RDL Generator>
*
*/
#ifndef _«componentDefinition.name.toUpperCase»_H_
#define _«componentDefinition.name.toUpperCase»_H_
#pragma once
#include <util/bit_field.h>
#include <nonstd/span.hpp>

View File

@ -23,7 +23,9 @@ import java.io.File
class Main {
val USAGE_STR = "RDL2code [-h] [-v] [-f] [-n <namespace>] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
val USAGE_STR = '''
RDL2code [-h] [-v] [-f] [-fw] [-sc [-n <namespace>]] [-I <RDL include dir] [-o <output dir>] <input file> <input file>
'''
def static main(String[] args) {
if (args.empty) {
@ -56,7 +58,6 @@ class Main {
@Inject JavaIoFileSystemAccess fileAccess
def run(String[] args) {
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);
@ -64,6 +65,8 @@ class Main {
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);
opt.getSet().addOption("fw", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("sc", Multiplicity.ZERO_OR_ONE);
if (!opt.check(false, false)) { // Print usage hints
System.err.println("Usage is: " + USAGE_STR);
throw new MalformedParametersException(opt.getCheckErrors());
@ -87,19 +90,18 @@ class Main {
fileAccess.outputPath = opt.getSet().getOption('o').getResultValue(0)
fileAccess.outputConfigurations.get(IFileSystemAccess.DEFAULT_OUTPUT)?.setOverrideExistingResources(true)
}
// #{'incl-out' -> false, 'src-out' -> false, 'gen-out' -> true}.forEach[p1, p2|
// if(opt.getSet().isSet(p1.substring(0, 1)))
// fileAccess.setOutputPath(p1, opt.getSet().getOption(p1.substring(0, 1)).getResultValue(0)+'/')
// else
// fileAccess.setOutputPath(p1, 'src-gen/')
// fileAccess.outputConfigurations.get(p1)?.setOverrideExistingResources(p2)
// ]
opt.getSet().getData().forEach [ String string |
if(verbose) println("Processing " + string);
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)
context.generateFw=opt.getSet().isSet('fw')
context.generateSc=opt.getSet().isSet('sc')
opt.getSet().getData().forEach [ String fileName |
if(verbose) println("Processing " + fileName);
// Load the resource
val resourceSet = resourceSetProvider.get as XtextResourceSet
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
val resource = resourceSet.getResource(URI.createFileURI(string), true)
val resource = resourceSet.getResource(URI.createFileURI(fileName), true)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
@ -107,22 +109,10 @@ class Main {
issues.forEach[System.err.println(it)]
throw new ParseException("error validating " + resource.URI, issues.size)
}
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')
try {
if(verbose) println('includes are in ' + fileAccess.getURI('', 'incl-out'))
} catch (Exception e) {
if(verbose) {
println('Code generation for ' + fileName + ' finished')
println('includes are in ' + fileAccess.getURI(''))
}
try {
if(verbose) println('sources are in ' + fileAccess.getURI('', 'src-out'))
} catch (Exception e) {
println('sources are in ' + fileAccess.getURI(''))
}
]

View File

@ -1,58 +0,0 @@
/*
* generated by Xtext 2.14.0
*/
package com.minres.rdl.generator
import com.google.inject.Inject
import com.google.inject.Provider
import com.minres.rdl.RDLStandaloneSetup
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.generator.GeneratorDelegate
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.validation.CheckMode
import org.eclipse.xtext.validation.IResourceValidator
class Main {
def static main(String[] args) {
if (args.empty) {
System::err.println('Aborting: no path to EMF resource provided!')
return
}
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration
val main = injector.getInstance(Main)
main.runGenerator(args.get(0))
}
@Inject Provider<ResourceSet> resourceSetProvider
@Inject IResourceValidator validator
@Inject GeneratorDelegate generator
@Inject JavaIoFileSystemAccess fileAccess
def protected runGenerator(String string) {
// Load the resource
val set = resourceSetProvider.get
val resource = set.getResource(URI.createFileURI(string), true)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
issues.forEach[System.err.println(it)]
return
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
val context = new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
]
generator.generate(resource, fileAccess, context)
System.out.println('Code generation finished.')
}
}

View File

@ -22,12 +22,12 @@ class ModuleGenerator extends RdlBaseGenerator {
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 ''
// 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
@ -35,11 +35,13 @@ class ModuleGenerator extends RdlBaseGenerator {
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_
#define _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_
#pragma once
#include <scc/tlm_target.h>
namespace «namespace» {
«FOR ns : namespace.split('::')»
namespace «ns» {
«ENDFOR»
namespace gen {
class «componentDefinition.effectiveName»_regs;
}
@ -58,7 +60,9 @@ class ModuleGenerator extends RdlBaseGenerator {
std::unique_ptr<gen::«componentDefinition.effectiveName»_regs> regs;
};
} /* namespace «namespace» */
«FOR ns : namespace.split('::').reverse»
} // namespace «ns»
«ENDFOR»
#endif /* _«namespace.toUpperCase»_«componentDefinition.effectiveName.toUpperCase»_H_ */
'''
@ -66,12 +70,12 @@ class ModuleGenerator extends RdlBaseGenerator {
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 ''
// 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
@ -84,7 +88,9 @@ class ModuleGenerator extends RdlBaseGenerator {
#include <scc/utilities.h>
namespace «namespace» {
«FOR ns : namespace.split('::')»
namespace «ns» {
«ENDFOR»
SC_HAS_PROCESS(«componentDefinition.effectiveName»);// NOLINT
«componentDefinition.effectiveName»::«componentDefinition.effectiveName»(sc_core::sc_module_name nm)
@ -119,7 +125,9 @@ class ModuleGenerator extends RdlBaseGenerator {
}
}
} /* namespace «namespace» */
«FOR ns : namespace.split('::').reverse»
} // namespace «ns»
«ENDFOR»
'''
}

View File

@ -12,28 +12,28 @@ import org.eclipse.xtext.generator.IGeneratorContext
import static extension com.minres.rdl.RdlUtil.*
import java.util.Map
/**
* Generates code from your model files on save.
*
* 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"
val genFW = if(context instanceof RdlGeneratorContext) context.generateFw else true
val genSC = if(context instanceof RdlGeneratorContext) context.generateSc else true
resource.resourceSet.allContents.filter[ it instanceof ComponentDefinition].map[it as ComponentDefinition].forEach[
val genMap = it.fileGenerator
if(genMap!==null) genMap.forEach[p1, gen |
if((p1=='fw' && genFW) || (p1!='fw' && genSC)) {
val header = gen.generateHeader(namespace)
val prefix = if(p1=="fw") 'fw-' else 'sc-'
val inclFileName = p1+'/'+it.effectiveName+'.h'
val inclCfg = fsa.outputConfig('incl-out')
val inclCfg = fsa.outputConfig(prefix+'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')
val srcCfg = fsa.outputConfig(prefix+'src-out')
if((force || !fsa.isFile(srcFileName, srcCfg) || gen.overwrite) && source!==null && source.length>0)
fsa.generateFile(srcFileName, srcCfg, source)
}
]
]
}

View File

@ -1,8 +1,26 @@
package com.minres.rdl.generator
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.generator.IGeneratorContext
class RdlGeneratorContext implements IGeneratorContext {
class RdlGeneratorContext extends GeneratorContext {
public boolean forceOverwrite = false
public String namespace ="scc"
public String namespace ="sysc"
public CancelIndicator cancelIndicator;
public boolean generateFw = true;
public String fwPathModifier = ""
public boolean generateSc = true;
public String scPathModifier =""
override getCancelIndicator() {
return cancelIndicator
}
}

View File

@ -32,8 +32,7 @@ class RegfileGenerator extends RdlBaseGenerator{
*
*/
#ifndef _«namespace.toUpperCase»_GEN_«componentDefinition.effectiveName.toUpperCase»_H_
#define _«namespace.toUpperCase»_GEN_«componentDefinition.effectiveName.toUpperCase»_H_
#pragma once
#include <scc/utilities.h>
#include <util/bit_field.h>
@ -45,7 +44,9 @@ class RegfileGenerator extends RdlBaseGenerator{
«ENDIF»
«ENDFOR»
namespace «namespace» {
«FOR ns : namespace.split('::')»
namespace «ns» {
«ENDFOR»
namespace gen {
class «componentDefinition.effectiveName»_regs :
@ -128,7 +129,9 @@ class RegfileGenerator extends RdlBaseGenerator{
void registerResources(scc::tlm_target<BUSWIDTH>& target, uint64_t offset=0);
};
} // namespace gen
} // namespace «namespace»
«FOR ns : namespace.split('::').reverse»
} // namespace «ns»
«ENDFOR»
//////////////////////////////////////////////////////////////////////////////
// member functions
//////////////////////////////////////////////////////////////////////////////

View File

@ -7,10 +7,19 @@ public class PreferenceConstants {
public static final String SCOPE_NAME = "com.minres.rdl.rdl";
public static final String ADDRESSUNIT_PROP = "com.minres.rdl.addrunit";
public static final String P_GENERATE_CSV = "booleanCsvPreference";
public static final String P_ADDRESSUNIT = "choiceAddrunitPreference";
public static final String ADDRESSUNIT_PROP = "com.minres.rdl.addrunit";
public static final String P_NAMESPACE = "setNamespacePreference";
public static final String P_OVERWRITE_STUBS = "overwriteStubs";
public static final String P_FILETYPES_TO_GENERATE = "filetypesToGenerate";
public static final String P_COMPONENT_PATH = "componentPath";
public static final String P_FIRMWARE_PATH = "firmwarePath";
}

View File

@ -1,5 +1,8 @@
package com.minres.rdl.preferences;
import java.util.Arrays;
import java.util.HashSet;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@ -8,6 +11,7 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences;
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
private final HashSet<String> valid_addrunit_types = new HashSet<String>(Arrays.asList(new String[]{"byte", "word", "dword"}));
/*
* (non-Javadoc)
*
@ -18,19 +22,17 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
IEclipsePreferences store = RdlPreferences.getPreferenceStore();
store.putBoolean(PreferenceConstants.P_GENERATE_CSV, true);
String value = System.getProperty(PreferenceConstants.ADDRESSUNIT_PROP);
if(value!=null){
if("byte".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
} else if("word".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "word");
} else if("dword".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "dword");
if(valid_addrunit_types.contains(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, value);
} else {
System.err.println("Unknown configuration value: '"+value+"', using 'byte'");
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
}
} else
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
store.put(PreferenceConstants.P_NAMESPACE, "sysc");
store.putBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
store.put(PreferenceConstants.P_FILETYPES_TO_GENERATE, "all");
store.put(PreferenceConstants.P_COMPONENT_PATH, "");
store.put(PreferenceConstants.P_FIRMWARE_PATH, "");
}
}

View File

@ -5,6 +5,10 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
public class RdlPreferences {
public static IEclipsePreferences getPreferenceStore() {
return InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
}
public static boolean getGenerateCsv() {
return getPreferenceStore().getBoolean(PreferenceConstants.P_GENERATE_CSV, true);
}
@ -13,7 +17,23 @@ public class RdlPreferences {
return getPreferenceStore().get(PreferenceConstants.P_ADDRESSUNIT, System.getProperty(PreferenceConstants.ADDRESSUNIT_PROP));
}
public static IEclipsePreferences getPreferenceStore() {
return InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
public static String getNamespace() {
return getPreferenceStore().get(PreferenceConstants.P_NAMESPACE, "sysc");
}
public static boolean getOverwriteStubs() {
return getPreferenceStore().getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
}
public static int getFielTypesToGenerate() {
return getPreferenceStore().getInt(PreferenceConstants.P_FILETYPES_TO_GENERATE, 3);
}
public static String getComponentPath() {
return getPreferenceStore().get(PreferenceConstants.P_COMPONENT_PATH, "");
}
public static String getFirmwarePath() {
return getPreferenceStore().get(PreferenceConstants.P_FIRMWARE_PATH, "");
}
}