Fixed code generation to use sc_register_indexed for register arrays

This commit is contained in:
Eyck Jentzsch 2017-09-20 22:36:20 +02:00
parent 8ceb09beed
commit a973f43fe6
7 changed files with 384 additions and 205 deletions

View File

@ -0,0 +1 @@
/RdlPreferencePage.java

View File

@ -2,6 +2,9 @@ package com.minres.rdl.generator
import com.minres.rdl.generator.RdlBaseGenerator
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.IntegerWithRadix
import com.minres.rdl.rdl.Instantiation
import com.minres.rdl.rdl.ComponentDefinitionType
class AddrmapGenerator extends RdlBaseGenerator {
@ -15,10 +18,12 @@ class AddrmapGenerator extends RdlBaseGenerator {
#ifndef _E300_PLAT_MAP_H_
#define _E300_PLAT_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>, 3> e300_plat_map = {{
{&i_gpio, 0x10012000, 0x1000},
{&i_uart, 0x10013000, 0x1000},
{&i_spi, 0x10014000, 0x1000}
const std::array<sysc::target_memory_map_entry<32>, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> e300_plat_map = {{
«FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»
«FOR instance : instantiation.componentInstances»
{&i_«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)», 0x«Long.toHexString(instantiation.occupiedSize)»},
«ENDFOR»
«ENDFOR»
}};
#endif /* _E300_PLAT_MAP_H_ */
@ -29,4 +34,16 @@ class AddrmapGenerator extends RdlBaseGenerator {
''
}
def int instanceCount(ComponentDefinition definition, ComponentDefinitionType type){
definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2| p1+p2]
}
def instantiationsOfType(ComponentDefinition definition, ComponentDefinitionType type){
definition.instantiations.filter[it.definingComponent.type == type]
}
def long occupiedSize(Instantiation instantiation){
return 4096
}
}

View File

@ -19,104 +19,107 @@ import org.eclipse.xtext.validation.IResourceValidator
import java.text.ParseException
import com.minres.rdl.generator.Options.Multiplicity
import com.minres.rdl.generator.Options.Separator
import org.eclipse.xtext.generator.IFileSystemAccess
class Main {
private val USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-i <include output dir>] [-s <source output dir>] [-g <generated files output dir>] <input file> <input file>";
private val USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
def static main(String[] args) {
if (args.empty) {
System::err.println('Aborting: no path to RDL file provided!')
return
}
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration
val main = injector.getInstance(Main)
try {
main.run(args)
} catch (MalformedParametersException e) {
print("Command line error " + e.message)
System.exit(1)
} catch (IllegalArgumentException e) {
print("generation error " + e.message)
e.printStackTrace
System.exit(2)
} catch (ParseException e) {
print("parse problem " + e.message + " (" + e.errorOffset + ")")
System.exit(3)
}
}
def static main(String[] args) {
if (args.empty) {
System::err.println('Aborting: no path to RDL file provided!')
return
}
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration
val main = injector.getInstance(Main)
try {
main.run(args)
} catch (MalformedParametersException e) {
print("Command line error " + e.message)
System.exit(1)
} catch (IllegalArgumentException e) {
print("generation error " + e.message)
e.printStackTrace
System.exit(2)
} catch (ParseException e) {
print("parse problem " + e.message + " (" + e.errorOffset + ")")
System.exit(3)
}
}
@Inject Provider<ResourceSet> resourceSetProvider
@Inject Provider<ResourceSet> resourceSetProvider
@Inject IResourceValidator validator
@Inject IResourceValidator validator
@Inject GeneratorDelegate generator
@Inject GeneratorDelegate generator
@Inject JavaIoFileSystemAccess fileAccess
@Inject JavaIoFileSystemAccess fileAccess
def run(String[] args) {
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);
opt.getSet().addOption("i", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("s", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("g", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(false, false)) { // Print usage hints
System.err.println("Usage is: " + USAGE_STR);
throw new MalformedParametersException(opt.getCheckErrors());
}
// Normal processing
if (opt.getSet().isSet("h")) {
println("Usage: " + USAGE_STR);
return
}
val verbose = if(opt.getSet().isSet("v")) true else false;
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("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
System.err.println("Usage is: " + USAGE_STR);
throw new MalformedParametersException(opt.getCheckErrors());
}
// Normal processing
if (opt.getSet().isSet("h")) {
println("Usage: " + USAGE_STR);
return
}
val verbose = if(opt.getSet().isSet("v")) true else false;
if (opt.getSet().isSet("I")) {
val projectMapping = new ProjectMapping
projectMapping.projectName = "RDL Repository"
projectMapping.path = opt.getSet().getOption("I").getResultValue(0)
new StandaloneSetup().addProjectMapping(projectMapping)
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
#{'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("Reading " + string);
// 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)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
System.err.println("Error validating " + resource.URI)
issues.forEach[System.err.println(it)]
throw new ParseException("error validating " + resource.URI, issues.size)
}
if (opt.getSet().isSet("I")) {
val projectMapping = new ProjectMapping
projectMapping.projectName = "RDL Repository"
projectMapping.path = opt.getSet().getOption("I").getResultValue(0)
new StandaloneSetup().addProjectMapping(projectMapping)
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
if(opt.getSet().isSet('o')){
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);
// 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)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
System.err.println("Error validating " + resource.URI)
issues.forEach[System.err.println(it)]
throw new ParseException("error validating " + resource.URI, issues.size)
}
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
generator.generate(resource, fileAccess, context)
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
generator.generate(resource, fileAccess, context)
if(verbose) print('Code generation for ' + string + ' finished, ')
try {
if(verbose) print('includes are in ' + fileAccess.getURI('', 'incl-out') + ', ')
} catch (Exception e) {
print('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('') + ', ')
}
]
}
if(verbose) println('Code generation for ' + string + ' finished')
try {
if(verbose) println('includes are in ' + fileAccess.getURI('', 'incl-out'))
} catch (Exception e) {
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

@ -6,6 +6,7 @@ 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
class RegfileGenerator extends RdlBaseGenerator{
@ -80,12 +81,18 @@ class RegfileGenerator extends RdlBaseGenerator{
«ENDIF»
«IF instantiation.component !== null && instantiation.component.type == ComponentDefinitionType.REG»
«IF instantiation.isFilledByField»
uint«instantiation.size»_t «instantiation.componentInstances.map['r_'+it.name].join(', ')»;
uint«instantiation.size»_t «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»;
«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»
BEGIN_BF_DECL(«instantiation.component.effectiveName»_t, uint«instantiation.size»_t);
«instantiation.definingComponent.genFieldDeclarations»
END_BF_DECL() «instantiation.componentInstances.map['r_'+it.name].join(', ')»;
END_BF_DECL() «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»;
«FOR componentInstance : instantiation.componentInstances.filter[it.range!==null]»
std::array<«instantiation.component.effectiveName»_t, «componentInstance.range.absSize»> r_«componentInstance.name»;
«ENDFOR»
«ENDIF»
«ENDIF»
@ -93,11 +100,21 @@ class RegfileGenerator extends RdlBaseGenerator{
// register declarations
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
«IF instantiation.isFilledByField»
sysc::sc_register<uint«instantiation.size»_t> «instance.name»;
«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 !instantiation.isFilledByField»
sysc::sc_register<typename «instantiation.component.effectiveName»_t::StorageType> «instance.name»;
«IF instance.range!==null»
«IF instantiation.isFilledByField»
sysc::sc_register_indexed<«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»;
«ENDIF»
«ENDIF»
«ENDFOR»
«ENDFOR»
@ -127,7 +144,7 @@ class RegfileGenerator extends RdlBaseGenerator{
inline void sysc::«componentDefinition.name»::registerResources(sysc::tlm_target<BUSWIDTH>& target) {
«FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances»
target.addResource(«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)»UL, 0x«Long.toHexString((instantiation.size+7)/8)»UL);
target.addResource(«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)»UL);
«ENDFOR»
«ENDFOR»
}
@ -135,6 +152,13 @@ class RegfileGenerator 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) {

View File

@ -1,8 +1,17 @@
package com.minres.rdl.generator;
import com.google.common.base.Objects;
import com.minres.rdl.IntegerWithRadix;
import com.minres.rdl.generator.RdlBaseGenerator;
import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.ComponentDefinitionType;
import com.minres.rdl.rdl.ComponentInstance;
import com.minres.rdl.rdl.Instantiation;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class AddrmapGenerator extends RdlBaseGenerator {
@ -21,17 +30,34 @@ public class AddrmapGenerator extends RdlBaseGenerator {
_builder.newLine();
_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>, 3> e300_plat_map = {{");
_builder.newLine();
_builder.append(" ");
_builder.append("{&i_gpio, 0x10012000, 0x1000},");
_builder.newLine();
_builder.append(" ");
_builder.append("{&i_uart, 0x10013000, 0x1000},");
_builder.newLine();
_builder.append(" ");
_builder.append("{&i_spi, 0x10014000, 0x1000}");
_builder.newLine();
_builder.append("const std::array<sysc::target_memory_map_entry<32>, ");
int _instanceCount = this.instanceCount(this.componentDefinition, ComponentDefinitionType.REGFILE);
_builder.append(_instanceCount);
_builder.append("> e300_plat_map = {{");
_builder.newLineIfNotEmpty();
{
Iterable<Instantiation> _instantiationsOfType = this.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE);
for(final Instantiation instantiation : _instantiationsOfType) {
{
EList<ComponentInstance> _componentInstances = instantiation.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
_builder.append(" ");
_builder.append("{&i_");
String _name = instance.getName();
_builder.append(_name, " ");
_builder.append(", 0x");
Object _address = instance.getAddress();
String _hexString = Long.toHexString(((IntegerWithRadix) _address).value);
_builder.append(_hexString, " ");
_builder.append(", 0x");
String _hexString_1 = Long.toHexString(this.occupiedSize(instantiation));
_builder.append(_hexString_1, " ");
_builder.append("},");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("}};");
_builder.newLine();
_builder.newLine();
@ -44,4 +70,26 @@ public class AddrmapGenerator extends RdlBaseGenerator {
public String generateSource() {
return "";
}
public int instanceCount(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() + (p2).intValue()));
};
return (int) IterableExtensions.<Integer>reduce(IterableExtensions.<Instantiation, Integer>map(this.instantiationsOfType(definition, type), _function), _function_1);
}
public Iterable<Instantiation> instantiationsOfType(final ComponentDefinition definition, final ComponentDefinitionType type) {
final Function1<Instantiation, Boolean> _function = (Instantiation it) -> {
ComponentDefinitionType _type = this.definingComponent(it).getType();
return Boolean.valueOf(Objects.equal(_type, type));
};
return IterableExtensions.<Instantiation>filter(definition.getInstantiations(), _function);
}
public long occupiedSize(final Instantiation instantiation) {
return 4096;
}
}

View File

@ -7,9 +7,7 @@ import com.minres.rdl.RDLStandaloneSetup;
import com.minres.rdl.generator.Options;
import java.lang.reflect.MalformedParametersException;
import java.text.ParseException;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@ -18,6 +16,7 @@ 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;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.resource.XtextResource;
@ -26,17 +25,15 @@ import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
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] [-i <include output dir>] [-s <source output dir>] [-g <generated files output dir>] <input file> <input file>";
private final String USAGE_STR = "RDL2code [-h] [-v] [-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();
@ -94,9 +91,7 @@ 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("i", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("s", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("g", 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);
boolean _not = (!_check);
@ -126,31 +121,21 @@ public class Main {
new StandaloneSetup().addProjectMapping(projectMapping);
}
this.fileAccess.setOutputPath("src-gen/");
Pair<String, Boolean> _mappedTo = Pair.<String, Boolean>of("incl-out", Boolean.valueOf(false));
Pair<String, Boolean> _mappedTo_1 = Pair.<String, Boolean>of("src-out", Boolean.valueOf(false));
Pair<String, Boolean> _mappedTo_2 = Pair.<String, Boolean>of("gen-out", Boolean.valueOf(true));
final BiConsumer<String, Boolean> _function = (String p1, Boolean p2) -> {
boolean _isSet_3 = opt.getSet().isSet(p1.substring(0, 1));
if (_isSet_3) {
String _resultValue = opt.getSet().getOption(p1.substring(0, 1)).getResultValue(0);
String _plus = (_resultValue + "/");
this.fileAccess.setOutputPath(p1, _plus);
} else {
this.fileAccess.setOutputPath(p1, "src-gen/");
}
OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(p1);
boolean _isSet_3 = opt.getSet().isSet("o");
if (_isSet_3) {
this.fileAccess.setOutputPath(opt.getSet().getOption("o").getResultValue(0));
OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT);
if (_get!=null) {
_get.setOverrideExistingResources((p2).booleanValue());
_get.setOverrideExistingResources(true);
}
};
Collections.<String, Boolean>unmodifiableMap(CollectionLiterals.<String, Boolean>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)).forEach(_function);
final Consumer<String> _function_1 = (String string) -> {
}
final Consumer<String> _function = (String string) -> {
try {
if (verbose) {
InputOutput.<String>println(("Reading " + string));
InputOutput.<String>println(("Processing " + string));
}
ResourceSet _get = this.resourceSetProvider.get();
final XtextResourceSet resourceSet = ((XtextResourceSet) _get);
ResourceSet _get_1 = this.resourceSetProvider.get();
final XtextResourceSet resourceSet = ((XtextResourceSet) _get_1);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
final Resource resource = resourceSet.getResource(URI.createFileURI(string), true);
final List<Issue> issues = this.validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
@ -160,38 +145,36 @@ public class Main {
URI _uRI = resource.getURI();
String _plus = ("Error validating " + _uRI);
System.err.println(_plus);
final Consumer<Issue> _function_2 = (Issue it) -> {
final Consumer<Issue> _function_1 = (Issue it) -> {
System.err.println(it);
};
issues.forEach(_function_2);
issues.forEach(_function_1);
URI _uRI_1 = resource.getURI();
String _plus_1 = ("error validating " + _uRI_1);
int _size = issues.size();
throw new ParseException(_plus_1, _size);
}
GeneratorContext _generatorContext = new GeneratorContext();
final Procedure1<GeneratorContext> _function_3 = (GeneratorContext it) -> {
final Procedure1<GeneratorContext> _function_2 = (GeneratorContext it) -> {
it.setCancelIndicator(CancelIndicator.NullImpl);
};
final GeneratorContext context = ObjectExtensions.<GeneratorContext>operator_doubleArrow(_generatorContext, _function_3);
final GeneratorContext context = ObjectExtensions.<GeneratorContext>operator_doubleArrow(_generatorContext, _function_2);
this.generator.generate(resource, this.fileAccess, context);
if (verbose) {
InputOutput.<String>print((("Code generation for " + string) + " finished, "));
InputOutput.<String>println((("Code generation for " + string) + " finished"));
}
try {
if (verbose) {
URI _uRI_2 = this.fileAccess.getURI("", "incl-out");
String _plus_2 = ("includes are in " + _uRI_2);
String _plus_3 = (_plus_2 + ", ");
InputOutput.<String>print(_plus_3);
InputOutput.<String>println(_plus_2);
}
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception)_t;
URI _uRI_3 = this.fileAccess.getURI("");
String _plus_4 = ("includes are in " + _uRI_3);
String _plus_5 = (_plus_4 + ", ");
InputOutput.<String>print(_plus_5);
String _plus_3 = ("includes are in " + _uRI_3);
InputOutput.<String>println(_plus_3);
} else {
throw Exceptions.sneakyThrow(_t);
}
@ -199,17 +182,15 @@ public class Main {
try {
if (verbose) {
URI _uRI_4 = this.fileAccess.getURI("", "src-out");
String _plus_6 = ("sources are in " + _uRI_4);
String _plus_7 = (_plus_6 + ", ");
InputOutput.<String>println(_plus_7);
String _plus_4 = ("sources are in " + _uRI_4);
InputOutput.<String>println(_plus_4);
}
} catch (final Throwable _t_1) {
if (_t_1 instanceof Exception) {
final Exception e_1 = (Exception)_t_1;
URI _uRI_5 = this.fileAccess.getURI("");
String _plus_8 = ("sources are in " + _uRI_5);
String _plus_9 = (_plus_8 + ", ");
InputOutput.<String>println(_plus_9);
String _plus_5 = ("sources are in " + _uRI_5);
InputOutput.<String>println(_plus_5);
} else {
throw Exceptions.sneakyThrow(_t_1);
}
@ -218,6 +199,6 @@ public class Main {
throw Exceptions.sneakyThrow(_e);
}
};
opt.getSet().getData().forEach(_function_1);
opt.getSet().getData().forEach(_function);
}
}

View File

@ -197,14 +197,39 @@ public class RegfileGenerator extends RdlBaseGenerator {
long _size = this.getSize(instantiation);
_builder.append(_size, " ");
_builder.append("_t ");
final Function1<ComponentInstance, String> _function_1 = (ComponentInstance it) -> {
final Function1<ComponentInstance, Boolean> _function_1 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_2 = (ComponentInstance it) -> {
String _name_2 = it.getName();
return ("r_" + _name_2);
};
String _join_1 = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function_1), ", ");
String _join_1 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_1), _function_2), ", ");
_builder.append(_join_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
{
final Function1<ComponentInstance, Boolean> _function_3 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_3);
for(final ComponentInstance componentInstance : _filter) {
_builder.append(" ");
_builder.append("std::array<uint");
long _size_1 = this.getSize(instantiation);
_builder.append(_size_1, " ");
_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();
}
}
}
}
{
@ -216,8 +241,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
String _effectiveName_2 = this.effectiveName(instantiation.getComponent());
_builder.append(_effectiveName_2, " ");
_builder.append("_t, uint");
long _size_1 = this.getSize(instantiation);
_builder.append(_size_1, " ");
long _size_2 = this.getSize(instantiation);
_builder.append(_size_2, " ");
_builder.append("_t);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
@ -227,14 +252,39 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("END_BF_DECL() ");
final Function1<ComponentInstance, String> _function_2 = (ComponentInstance it) -> {
String _name_2 = it.getName();
return ("r_" + _name_2);
final Function1<ComponentInstance, Boolean> _function_4 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
String _join_2 = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function_2), ", ");
final Function1<ComponentInstance, String> _function_5 = (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_4), _function_5), ", ");
_builder.append(_join_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
{
final Function1<ComponentInstance, Boolean> _function_6 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter_1 = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_6);
for(final ComponentInstance componentInstance_1 : _filter_1) {
_builder.append(" ");
_builder.append("std::array<");
String _effectiveName_3 = this.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(" ");
@ -253,32 +303,79 @@ public class RegfileGenerator extends RdlBaseGenerator {
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) {
{
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
if (_isFilledByField_2) {
_builder.append(" ");
_builder.append("sysc::sc_register<uint");
long _size_2 = this.getSize(instantiation_1);
_builder.append(_size_2, " ");
_builder.append("_t> ");
String _name_2 = instance.getName();
_builder.append(_name_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
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_3 = this.getSize(instantiation_1);
_builder.append(_size_3, " ");
_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 = this.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_4, " ");
_builder.append("_t> ");
String _name_5 = instance.getName();
_builder.append(_name_5, " ");
_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<typename ");
String _effectiveName_3 = this.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_3, " ");
_builder.append("_t::StorageType> ");
String _name_3 = instance.getName();
_builder.append(_name_3, " ");
_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<");
long _size_4 = this.getSize(instantiation_1);
_builder.append(_size_4, " ");
_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();
}
}
{
boolean _isFilledByField_5 = this.isFilledByField(instantiation_1);
boolean _not_2 = (!_isFilledByField_5);
if (_not_2) {
_builder.append(" ");
_builder.append("sysc::sc_register_indexed<");
String _effectiveName_5 = this.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(";");
_builder.newLineIfNotEmpty();
}
}
}
}
}
@ -290,8 +387,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.append("public:");
_builder.newLine();
_builder.append(" ");
String _name_4 = this.componentDefinition.getName();
_builder.append(_name_4, " ");
String _name_8 = this.componentDefinition.getName();
_builder.append(_name_8, " ");
_builder.append("(sc_core::sc_module_name nm);");
_builder.newLineIfNotEmpty();
_builder.newLine();
@ -313,11 +410,11 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine();
_builder.newLine();
_builder.append("inline sysc::");
String _name_5 = this.componentDefinition.getName();
_builder.append(_name_5);
String _name_9 = this.componentDefinition.getName();
_builder.append(_name_9);
_builder.append("::");
String _name_6 = this.componentDefinition.getName();
_builder.append(_name_6);
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)");
@ -329,11 +426,11 @@ public class RegfileGenerator extends RdlBaseGenerator {
EList<ComponentInstance> _componentInstances_1 = instantiation_2.getComponentInstances();
for(final ComponentInstance instance_1 : _componentInstances_1) {
_builder.append(", NAMED(");
String _name_7 = instance_1.getName();
_builder.append(_name_7);
String _name_11 = instance_1.getName();
_builder.append(_name_11);
_builder.append(", r_");
String _name_8 = instance_1.getName();
_builder.append(_name_8);
String _name_12 = instance_1.getName();
_builder.append(_name_12);
_builder.append(", 0, *this)");
_builder.newLineIfNotEmpty();
}
@ -348,8 +445,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.append("template<unsigned BUSWIDTH>");
_builder.newLine();
_builder.append("inline void sysc::");
String _name_9 = this.componentDefinition.getName();
_builder.append(_name_9);
String _name_13 = this.componentDefinition.getName();
_builder.append(_name_13);
_builder.append("::registerResources(sysc::tlm_target<BUSWIDTH>& target) {");
_builder.newLineIfNotEmpty();
{
@ -360,18 +457,12 @@ public class RegfileGenerator extends RdlBaseGenerator {
for(final ComponentInstance instance_2 : _componentInstances_2) {
_builder.append(" ");
_builder.append("target.addResource(");
String _name_10 = instance_2.getName();
_builder.append(_name_10, " ");
String _name_14 = instance_2.getName();
_builder.append(_name_14, " ");
_builder.append(", 0x");
Object _address = instance_2.getAddress();
String _hexString = Long.toHexString(((IntegerWithRadix) _address).value);
_builder.append(_hexString, " ");
_builder.append("UL, 0x");
long _size_3 = this.getSize(instantiation_3);
long _plus = (_size_3 + 7);
long _divide = (_plus / 8);
String _hexString_1 = Long.toHexString(_divide);
_builder.append(_hexString_1, " ");
_builder.append("UL);");
_builder.newLineIfNotEmpty();
}
@ -389,6 +480,20 @@ public class RegfileGenerator 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)) {