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.generator.RdlBaseGenerator
import com.minres.rdl.rdl.ComponentDefinition 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 { class AddrmapGenerator extends RdlBaseGenerator {
@ -15,10 +18,12 @@ class AddrmapGenerator extends RdlBaseGenerator {
#ifndef _E300_PLAT_MAP_H_ #ifndef _E300_PLAT_MAP_H_
#define _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 // 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 = {{ const std::array<sysc::target_memory_map_entry<32>, «componentDefinition.instanceCount(ComponentDefinitionType.REGFILE)»> e300_plat_map = {{
{&i_gpio, 0x10012000, 0x1000}, «FOR instantiation : componentDefinition.instantiationsOfType(ComponentDefinitionType.REGFILE)»
{&i_uart, 0x10013000, 0x1000}, «FOR instance : instantiation.componentInstances»
{&i_spi, 0x10014000, 0x1000} {&i_«instance.name», 0x«Long.toHexString((instance.address as IntegerWithRadix).value)», 0x«Long.toHexString(instantiation.occupiedSize)»},
«ENDFOR»
«ENDFOR»
}}; }};
#endif /* _E300_PLAT_MAP_H_ */ #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,10 +19,11 @@ import org.eclipse.xtext.validation.IResourceValidator
import java.text.ParseException import java.text.ParseException
import com.minres.rdl.generator.Options.Multiplicity import com.minres.rdl.generator.Options.Multiplicity
import com.minres.rdl.generator.Options.Separator import com.minres.rdl.generator.Options.Separator
import org.eclipse.xtext.generator.IFileSystemAccess
class Main { 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) { def static main(String[] args) {
if (args.empty) { if (args.empty) {
@ -59,9 +60,7 @@ class Main {
val opt = new Options(args, 0, Integer.MAX_VALUE); val opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet().addOption("h", Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("h", Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("v", 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("o", 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); opt.getSet().addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (!opt.check(false, false)) { // Print usage hints if (!opt.check(false, false)) { // Print usage hints
System.err.println("Usage is: " + USAGE_STR); System.err.println("Usage is: " + USAGE_STR);
@ -82,15 +81,19 @@ class Main {
} }
// Configure and start the generator // Configure and start the generator
fileAccess.outputPath = 'src-gen/' fileAccess.outputPath = 'src-gen/'
#{'incl-out' -> false, 'src-out' -> false, 'gen-out' -> true}.forEach[p1, p2| if(opt.getSet().isSet('o')){
if(opt.getSet().isSet(p1.substring(0, 1))) fileAccess.outputPath = opt.getSet().getOption('o').getResultValue(0)
fileAccess.setOutputPath(p1, opt.getSet().getOption(p1.substring(0, 1)).getResultValue(0)+'/') fileAccess.outputConfigurations.get(IFileSystemAccess.DEFAULT_OUTPUT)?.setOverrideExistingResources(true)
else }
fileAccess.setOutputPath(p1, 'src-gen/') // #{'incl-out' -> false, 'src-out' -> false, 'gen-out' -> true}.forEach[p1, p2|
fileAccess.outputConfigurations.get(p1)?.setOverrideExistingResources(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 | opt.getSet().getData().forEach [ String string |
if(verbose) println("Reading " + string); if(verbose) println("Processing " + string);
// Load the resource // Load the resource
val resourceSet = resourceSetProvider.get as XtextResourceSet val resourceSet = resourceSetProvider.get as XtextResourceSet
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
@ -106,16 +109,16 @@ class Main {
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl] val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
generator.generate(resource, fileAccess, context) generator.generate(resource, fileAccess, context)
if(verbose) print('Code generation for ' + string + ' finished, ') if(verbose) println('Code generation for ' + string + ' finished')
try { try {
if(verbose) print('includes are in ' + fileAccess.getURI('', 'incl-out') + ', ') if(verbose) println('includes are in ' + fileAccess.getURI('', 'incl-out'))
} catch (Exception e) { } catch (Exception e) {
print('includes are in ' + fileAccess.getURI('') + ', ') println('includes are in ' + fileAccess.getURI(''))
} }
try { try {
if(verbose) println('sources are in ' + fileAccess.getURI('', 'src-out') + ', ') if(verbose) println('sources are in ' + fileAccess.getURI('', 'src-out'))
} catch (Exception e) { } catch (Exception e) {
println('sources are in ' + fileAccess.getURI('') + ', ') 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.ComponentInstance
import com.minres.rdl.rdl.Instantiation import com.minres.rdl.rdl.Instantiation
import java.util.Date import java.util.Date
import com.minres.rdl.rdl.Range
class RegfileGenerator extends RdlBaseGenerator{ class RegfileGenerator extends RdlBaseGenerator{
@ -80,12 +81,18 @@ class RegfileGenerator extends RdlBaseGenerator{
«ENDIF» «ENDIF»
«IF instantiation.component !== null && instantiation.component.type == ComponentDefinitionType.REG» «IF instantiation.component !== null && instantiation.component.type == ComponentDefinitionType.REG»
«IF instantiation.isFilledByField» «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» «ENDIF»
«IF !instantiation.isFilledByField» «IF !instantiation.isFilledByField»
BEGIN_BF_DECL(«instantiation.component.effectiveName»_t, uint«instantiation.size»_t); BEGIN_BF_DECL(«instantiation.component.effectiveName»_t, uint«instantiation.size»_t);
«instantiation.definingComponent.genFieldDeclarations» «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»
«ENDIF» «ENDIF»
@ -93,11 +100,21 @@ class RegfileGenerator extends RdlBaseGenerator{
// register declarations // register declarations
«FOR instantiation : componentDefinition.instantiations» «FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances» «FOR instance : instantiation.componentInstances»
«IF instance.range===null»
«IF instantiation.isFilledByField» «IF instantiation.isFilledByField»
sysc::sc_register<uint«instantiation.size»_t> «instance.name»; sysc::sc_register<uint«instantiation.size»_t> «instance.name»;
«ENDIF» «ENDIF»
«IF !instantiation.isFilledByField» «IF !instantiation.isFilledByField»
sysc::sc_register<typename «instantiation.component.effectiveName»_t::StorageType> «instance.name»; sysc::sc_register<«instantiation.component.effectiveName»_t> «instance.name»;
«ENDIF»
«ENDIF»
«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» «ENDIF»
«ENDFOR» «ENDFOR»
«ENDFOR» «ENDFOR»
@ -127,7 +144,7 @@ class RegfileGenerator extends RdlBaseGenerator{
inline void sysc::«componentDefinition.name»::registerResources(sysc::tlm_target<BUSWIDTH>& target) { inline void sysc::«componentDefinition.name»::registerResources(sysc::tlm_target<BUSWIDTH>& target) {
«FOR instantiation : componentDefinition.instantiations» «FOR instantiation : componentDefinition.instantiations»
«FOR instance : instantiation.componentInstances» «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»
«ENDFOR» «ENDFOR»
} }
@ -135,6 +152,13 @@ class RegfileGenerator extends RdlBaseGenerator{
#endif // _«componentDefinition.name.toUpperCase»_H_ #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){ def boolean isFilledByField(Instantiation instantiation){
val fieldCount = instantiation.component.instanceCountOfType(ComponentDefinitionType.FIELD) val fieldCount = instantiation.component.instanceCountOfType(ComponentDefinitionType.FIELD)
if(fieldCount==1) { if(fieldCount==1) {

View File

@ -1,8 +1,17 @@
package com.minres.rdl.generator; 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.generator.RdlBaseGenerator;
import com.minres.rdl.rdl.ComponentDefinition; 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.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") @SuppressWarnings("all")
public class AddrmapGenerator extends RdlBaseGenerator { public class AddrmapGenerator extends RdlBaseGenerator {
@ -21,17 +30,34 @@ public class AddrmapGenerator extends RdlBaseGenerator {
_builder.newLine(); _builder.newLine();
_builder.append("// need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191"); _builder.append("// need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191");
_builder.newLine(); _builder.newLine();
_builder.append("const std::array<sysc::target_memory_map_entry<32>, 3> e300_plat_map = {{"); _builder.append("const std::array<sysc::target_memory_map_entry<32>, ");
_builder.newLine(); 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(" ");
_builder.append("{&i_gpio, 0x10012000, 0x1000},"); _builder.append("{&i_");
_builder.newLine(); String _name = instance.getName();
_builder.append(" "); _builder.append(_name, " ");
_builder.append("{&i_uart, 0x10013000, 0x1000},"); _builder.append(", 0x");
_builder.newLine(); Object _address = instance.getAddress();
_builder.append(" "); String _hexString = Long.toHexString(((IntegerWithRadix) _address).value);
_builder.append("{&i_spi, 0x10014000, 0x1000}"); _builder.append(_hexString, " ");
_builder.newLine(); _builder.append(", 0x");
String _hexString_1 = Long.toHexString(this.occupiedSize(instantiation));
_builder.append(_hexString_1, " ");
_builder.append("},");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("}};"); _builder.append("}};");
_builder.newLine(); _builder.newLine();
_builder.newLine(); _builder.newLine();
@ -44,4 +70,26 @@ public class AddrmapGenerator extends RdlBaseGenerator {
public String generateSource() { public String generateSource() {
return ""; 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 com.minres.rdl.generator.Options;
import java.lang.reflect.MalformedParametersException; import java.lang.reflect.MalformedParametersException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource; 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.emf.mwe.utils.StandaloneSetup;
import org.eclipse.xtext.generator.GeneratorContext; import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.GeneratorDelegate; import org.eclipse.xtext.generator.GeneratorDelegate;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess; import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.generator.OutputConfiguration; import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.resource.XtextResource; 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.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator; import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue; 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.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.ObjectExtensions; import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all") @SuppressWarnings("all")
public class Main { 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) { public static void main(final String[] args) {
boolean _isEmpty = ((List<String>)Conversions.doWrapArray(args)).isEmpty(); 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); final Options opt = new Options(args, 0, Integer.MAX_VALUE);
opt.getSet().addOption("h", Options.Multiplicity.ZERO_OR_ONE); opt.getSet().addOption("h", Options.Multiplicity.ZERO_OR_ONE);
opt.getSet().addOption("v", 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("o", 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("I", 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 _check = opt.check(false, false);
boolean _not = (!_check); boolean _not = (!_check);
@ -126,31 +121,21 @@ public class Main {
new StandaloneSetup().addProjectMapping(projectMapping); new StandaloneSetup().addProjectMapping(projectMapping);
} }
this.fileAccess.setOutputPath("src-gen/"); this.fileAccess.setOutputPath("src-gen/");
Pair<String, Boolean> _mappedTo = Pair.<String, Boolean>of("incl-out", Boolean.valueOf(false)); boolean _isSet_3 = opt.getSet().isSet("o");
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) { if (_isSet_3) {
String _resultValue = opt.getSet().getOption(p1.substring(0, 1)).getResultValue(0); this.fileAccess.setOutputPath(opt.getSet().getOption("o").getResultValue(0));
String _plus = (_resultValue + "/"); OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT);
this.fileAccess.setOutputPath(p1, _plus);
} else {
this.fileAccess.setOutputPath(p1, "src-gen/");
}
OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(p1);
if (_get!=null) { 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 = (String string) -> {
final Consumer<String> _function_1 = (String string) -> {
try { try {
if (verbose) { if (verbose) {
InputOutput.<String>println(("Reading " + string)); InputOutput.<String>println(("Processing " + string));
} }
ResourceSet _get = this.resourceSetProvider.get(); ResourceSet _get_1 = this.resourceSetProvider.get();
final XtextResourceSet resourceSet = ((XtextResourceSet) _get); final XtextResourceSet resourceSet = ((XtextResourceSet) _get_1);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
final Resource resource = resourceSet.getResource(URI.createFileURI(string), true); final Resource resource = resourceSet.getResource(URI.createFileURI(string), true);
final List<Issue> issues = this.validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); final List<Issue> issues = this.validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
@ -160,38 +145,36 @@ public class Main {
URI _uRI = resource.getURI(); URI _uRI = resource.getURI();
String _plus = ("Error validating " + _uRI); String _plus = ("Error validating " + _uRI);
System.err.println(_plus); System.err.println(_plus);
final Consumer<Issue> _function_2 = (Issue it) -> { final Consumer<Issue> _function_1 = (Issue it) -> {
System.err.println(it); System.err.println(it);
}; };
issues.forEach(_function_2); issues.forEach(_function_1);
URI _uRI_1 = resource.getURI(); URI _uRI_1 = resource.getURI();
String _plus_1 = ("error validating " + _uRI_1); String _plus_1 = ("error validating " + _uRI_1);
int _size = issues.size(); int _size = issues.size();
throw new ParseException(_plus_1, _size); throw new ParseException(_plus_1, _size);
} }
GeneratorContext _generatorContext = new GeneratorContext(); GeneratorContext _generatorContext = new GeneratorContext();
final Procedure1<GeneratorContext> _function_3 = (GeneratorContext it) -> { final Procedure1<GeneratorContext> _function_2 = (GeneratorContext it) -> {
it.setCancelIndicator(CancelIndicator.NullImpl); 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); this.generator.generate(resource, this.fileAccess, context);
if (verbose) { if (verbose) {
InputOutput.<String>print((("Code generation for " + string) + " finished, ")); InputOutput.<String>println((("Code generation for " + string) + " finished"));
} }
try { try {
if (verbose) { if (verbose) {
URI _uRI_2 = this.fileAccess.getURI("", "incl-out"); URI _uRI_2 = this.fileAccess.getURI("", "incl-out");
String _plus_2 = ("includes are in " + _uRI_2); String _plus_2 = ("includes are in " + _uRI_2);
String _plus_3 = (_plus_2 + ", "); InputOutput.<String>println(_plus_2);
InputOutput.<String>print(_plus_3);
} }
} catch (final Throwable _t) { } catch (final Throwable _t) {
if (_t instanceof Exception) { if (_t instanceof Exception) {
final Exception e = (Exception)_t; final Exception e = (Exception)_t;
URI _uRI_3 = this.fileAccess.getURI(""); URI _uRI_3 = this.fileAccess.getURI("");
String _plus_4 = ("includes are in " + _uRI_3); String _plus_3 = ("includes are in " + _uRI_3);
String _plus_5 = (_plus_4 + ", "); InputOutput.<String>println(_plus_3);
InputOutput.<String>print(_plus_5);
} else { } else {
throw Exceptions.sneakyThrow(_t); throw Exceptions.sneakyThrow(_t);
} }
@ -199,17 +182,15 @@ public class Main {
try { try {
if (verbose) { if (verbose) {
URI _uRI_4 = this.fileAccess.getURI("", "src-out"); URI _uRI_4 = this.fileAccess.getURI("", "src-out");
String _plus_6 = ("sources are in " + _uRI_4); String _plus_4 = ("sources are in " + _uRI_4);
String _plus_7 = (_plus_6 + ", "); InputOutput.<String>println(_plus_4);
InputOutput.<String>println(_plus_7);
} }
} catch (final Throwable _t_1) { } catch (final Throwable _t_1) {
if (_t_1 instanceof Exception) { if (_t_1 instanceof Exception) {
final Exception e_1 = (Exception)_t_1; final Exception e_1 = (Exception)_t_1;
URI _uRI_5 = this.fileAccess.getURI(""); URI _uRI_5 = this.fileAccess.getURI("");
String _plus_8 = ("sources are in " + _uRI_5); String _plus_5 = ("sources are in " + _uRI_5);
String _plus_9 = (_plus_8 + ", "); InputOutput.<String>println(_plus_5);
InputOutput.<String>println(_plus_9);
} else { } else {
throw Exceptions.sneakyThrow(_t_1); throw Exceptions.sneakyThrow(_t_1);
} }
@ -218,6 +199,6 @@ public class Main {
throw Exceptions.sneakyThrow(_e); 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); long _size = this.getSize(instantiation);
_builder.append(_size, " "); _builder.append(_size, " ");
_builder.append("_t "); _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(); String _name_2 = it.getName();
return ("r_" + _name_2); 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(_join_1, " ");
_builder.append(";"); _builder.append(";");
_builder.newLineIfNotEmpty(); _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()); String _effectiveName_2 = this.effectiveName(instantiation.getComponent());
_builder.append(_effectiveName_2, " "); _builder.append(_effectiveName_2, " ");
_builder.append("_t, uint"); _builder.append("_t, uint");
long _size_1 = this.getSize(instantiation); long _size_2 = this.getSize(instantiation);
_builder.append(_size_1, " "); _builder.append(_size_2, " ");
_builder.append("_t);"); _builder.append("_t);");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
_builder.append(" "); _builder.append(" ");
@ -227,14 +252,39 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
_builder.append(" "); _builder.append(" ");
_builder.append("END_BF_DECL() "); _builder.append("END_BF_DECL() ");
final Function1<ComponentInstance, String> _function_2 = (ComponentInstance it) -> { final Function1<ComponentInstance, Boolean> _function_4 = (ComponentInstance it) -> {
String _name_2 = it.getName(); Range _range = it.getRange();
return ("r_" + _name_2); 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(_join_2, " ");
_builder.append(";"); _builder.append(";");
_builder.newLineIfNotEmpty(); _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(" "); _builder.append(" ");
@ -252,16 +302,20 @@ public class RegfileGenerator extends RdlBaseGenerator {
{ {
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances(); EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
for(final ComponentInstance instance : _componentInstances) { for(final ComponentInstance instance : _componentInstances) {
{
Range _range = instance.getRange();
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
{ {
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1); boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
if (_isFilledByField_2) { if (_isFilledByField_2) {
_builder.append(" "); _builder.append(" ");
_builder.append("sysc::sc_register<uint"); _builder.append("sysc::sc_register<uint");
long _size_2 = this.getSize(instantiation_1); long _size_3 = this.getSize(instantiation_1);
_builder.append(_size_2, " "); _builder.append(_size_3, " ");
_builder.append("_t> "); _builder.append("_t> ");
String _name_2 = instance.getName(); String _name_4 = instance.getName();
_builder.append(_name_2, " "); _builder.append(_name_4, " ");
_builder.append(";"); _builder.append(";");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
} }
@ -271,18 +325,61 @@ public class RegfileGenerator extends RdlBaseGenerator {
boolean _not_1 = (!_isFilledByField_3); boolean _not_1 = (!_isFilledByField_3);
if (_not_1) { if (_not_1) {
_builder.append(" "); _builder.append(" ");
_builder.append("sysc::sc_register<typename "); _builder.append("sysc::sc_register<");
String _effectiveName_3 = this.effectiveName(instantiation_1.getComponent()); String _effectiveName_4 = this.effectiveName(instantiation_1.getComponent());
_builder.append(_effectiveName_3, " "); _builder.append(_effectiveName_4, " ");
_builder.append("_t::StorageType> "); _builder.append("_t> ");
String _name_3 = instance.getName(); String _name_5 = instance.getName();
_builder.append(_name_3, " "); _builder.append(_name_5, " ");
_builder.append(";"); _builder.append(";");
_builder.newLineIfNotEmpty(); _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();
}
}
}
}
}
}
} }
} }
_builder.append(" "); _builder.append(" ");
@ -290,8 +387,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.append("public:"); _builder.append("public:");
_builder.newLine(); _builder.newLine();
_builder.append(" "); _builder.append(" ");
String _name_4 = this.componentDefinition.getName(); String _name_8 = this.componentDefinition.getName();
_builder.append(_name_4, " "); _builder.append(_name_8, " ");
_builder.append("(sc_core::sc_module_name nm);"); _builder.append("(sc_core::sc_module_name nm);");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
_builder.newLine(); _builder.newLine();
@ -313,11 +410,11 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine(); _builder.newLine();
_builder.newLine(); _builder.newLine();
_builder.append("inline sysc::"); _builder.append("inline sysc::");
String _name_5 = this.componentDefinition.getName(); String _name_9 = this.componentDefinition.getName();
_builder.append(_name_5); _builder.append(_name_9);
_builder.append("::"); _builder.append("::");
String _name_6 = this.componentDefinition.getName(); String _name_10 = this.componentDefinition.getName();
_builder.append(_name_6); _builder.append(_name_10);
_builder.append("(sc_core::sc_module_name nm)"); _builder.append("(sc_core::sc_module_name nm)");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
_builder.append(": sc_core::sc_module(nm)"); _builder.append(": sc_core::sc_module(nm)");
@ -329,11 +426,11 @@ public class RegfileGenerator extends RdlBaseGenerator {
EList<ComponentInstance> _componentInstances_1 = instantiation_2.getComponentInstances(); EList<ComponentInstance> _componentInstances_1 = instantiation_2.getComponentInstances();
for(final ComponentInstance instance_1 : _componentInstances_1) { for(final ComponentInstance instance_1 : _componentInstances_1) {
_builder.append(", NAMED("); _builder.append(", NAMED(");
String _name_7 = instance_1.getName(); String _name_11 = instance_1.getName();
_builder.append(_name_7); _builder.append(_name_11);
_builder.append(", r_"); _builder.append(", r_");
String _name_8 = instance_1.getName(); String _name_12 = instance_1.getName();
_builder.append(_name_8); _builder.append(_name_12);
_builder.append(", 0, *this)"); _builder.append(", 0, *this)");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
} }
@ -348,8 +445,8 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.append("template<unsigned BUSWIDTH>"); _builder.append("template<unsigned BUSWIDTH>");
_builder.newLine(); _builder.newLine();
_builder.append("inline void sysc::"); _builder.append("inline void sysc::");
String _name_9 = this.componentDefinition.getName(); String _name_13 = this.componentDefinition.getName();
_builder.append(_name_9); _builder.append(_name_13);
_builder.append("::registerResources(sysc::tlm_target<BUSWIDTH>& target) {"); _builder.append("::registerResources(sysc::tlm_target<BUSWIDTH>& target) {");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
{ {
@ -360,18 +457,12 @@ public class RegfileGenerator extends RdlBaseGenerator {
for(final ComponentInstance instance_2 : _componentInstances_2) { for(final ComponentInstance instance_2 : _componentInstances_2) {
_builder.append(" "); _builder.append(" ");
_builder.append("target.addResource("); _builder.append("target.addResource(");
String _name_10 = instance_2.getName(); String _name_14 = instance_2.getName();
_builder.append(_name_10, " "); _builder.append(_name_14, " ");
_builder.append(", 0x"); _builder.append(", 0x");
Object _address = instance_2.getAddress(); Object _address = instance_2.getAddress();
String _hexString = Long.toHexString(((IntegerWithRadix) _address).value); String _hexString = Long.toHexString(((IntegerWithRadix) _address).value);
_builder.append(_hexString, " "); _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.append("UL);");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
} }
@ -389,6 +480,20 @@ public class RegfileGenerator extends RdlBaseGenerator {
return _builder.toString(); 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) { public boolean isFilledByField(final Instantiation instantiation) {
final int fieldCount = this.instanceCountOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD); final int fieldCount = this.instanceCountOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD);
if ((fieldCount == 1)) { if ((fieldCount == 1)) {