Merge pull request #2 from Minres/develop

Merge for patch release
This commit is contained in:
Eyck Jentzsch 2017-10-05 07:21:02 +00:00 committed by GitHub
commit 126046430d
23 changed files with 1932 additions and 391 deletions

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: RDL Editor Bundle-Name: RDL Editor
Bundle-SymbolicName: com.minres.rdl.product;singleton:=true Bundle-SymbolicName: com.minres.rdl.product;singleton:=true
Bundle-Version: 1.1.0.qualifier Bundle-Version: 1.1.1.qualifier
Bundle-Vendor: MINRES Bundle-Vendor: MINRES
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0" Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0"

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?> <?pde version="3.5"?>
<product name="RDL" uid="com.minres.rdl.product.product" id="com.minres.rdl.product.product" application="org.eclipse.ui.ide.workbench" version="1.0.0.qualifier" useFeatures="true" includeLaunchers="true"> <product name="RDL" uid="com.minres.rdl.product.product" id="com.minres.rdl.product.product" application="org.eclipse.ui.ide.workbench" version="1.1.1.qualifier" useFeatures="true" includeLaunchers="true">
<configIni use="default"> <configIni use="default">
</configIni> </configIni>
@ -14,14 +13,13 @@
<windowImages/> <windowImages/>
<launcher> <launcher name="rdl-editor">
<solaris/> <solaris/>
<win useIco="false"> <win useIco="false">
<bmp/> <bmp/>
</win> </win>
</launcher> </launcher>
<vm> <vm>
</vm> </vm>

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>com.minres.rdl.product</artifactId> <artifactId>com.minres.rdl.product</artifactId>
<packaging>eclipse-application</packaging> <packaging>eclipse-application</packaging>
@ -18,4 +18,5 @@
</plugins> </plugins>
</build> </build>
<version>1.1.1-SNAPSHOT</version>
</project> </project>

View File

@ -168,6 +168,7 @@
<parent> <parent>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<version>1.1.1-SNAPSHOT</version>
</project> </project>

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>com.minres.rdl.target</artifactId> <artifactId>com.minres.rdl.target</artifactId>
<packaging>eclipse-target-definition</packaging> <packaging>eclipse-target-definition</packaging>

View File

@ -0,0 +1 @@
/plugin.xml_gen

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: com.minres.rdl.ui Bundle-Name: com.minres.rdl.ui
Bundle-Vendor: My Company Bundle-Vendor: My Company
Bundle-Version: 1.1.0.qualifier Bundle-Version: 1.1.1.qualifier
Bundle-SymbolicName: com.minres.rdl.ui; singleton:=true Bundle-SymbolicName: com.minres.rdl.ui; singleton:=true
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Require-Bundle: com.minres.rdl, Require-Bundle: com.minres.rdl,

View File

@ -3,5 +3,6 @@ source.. = src/,\
xtend-gen/ xtend-gen/
bin.includes = .,\ bin.includes = .,\
META-INF/,\ META-INF/,\
plugin.xml plugin.xml,\
icons/
bin.excludes = **/*.xtend bin.excludes = **/*.xtend

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>com.minres.rdl.ui</artifactId> <artifactId>com.minres.rdl.ui</artifactId>
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
@ -18,4 +18,5 @@
</plugins> </plugins>
</build> </build>
<version>1.1.1-SNAPSHOT</version>
</project> </project>

View File

@ -0,0 +1,4 @@
/Run RDL Generator DBT-RISCV (test).launch
/Run RDL Generator DBT-RISCV.launch
/Run RDL Generator SC-Components-Test.launch
/plugin.xml_gen

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>com.minres.rdl</artifactId> <artifactId>com.minres.rdl</artifactId>
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
@ -146,4 +146,5 @@
</pluginManagement> </pluginManagement>
</build> </build>
<version>1.1.0-SNAPSHOT</version>
</project> </project>

View File

@ -2,6 +2,8 @@ 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.ComponentDefinitionType
class AddrmapGenerator extends RdlBaseGenerator { class AddrmapGenerator extends RdlBaseGenerator {
@ -15,10 +17,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.byteSize)»},
«ENDFOR»
«ENDFOR»
}}; }};
#endif /* _E300_PLAT_MAP_H_ */ #endif /* _E300_PLAT_MAP_H_ */
@ -29,4 +33,5 @@ class AddrmapGenerator extends RdlBaseGenerator {
'' ''
} }
} }

View File

@ -1,11 +1,9 @@
package com.minres.rdl.generator package com.minres.rdl.generator
import com.google.inject.Inject import com.google.inject.Inject
import com.google.inject.Provider import com.google.inject.Provider
import com.minres.rdl.RDLStandaloneSetup import com.minres.rdl.RDLStandaloneSetup
import java.lang.reflect.MalformedParametersException import java.lang.reflect.MalformedParametersException
import java.util.ArrayList
import org.eclipse.emf.common.util.URI import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.emf.mwe.utils.ProjectMapping import org.eclipse.emf.mwe.utils.ProjectMapping
@ -19,34 +17,33 @@ 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 java.text.ParseException 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 { class Main {
static class Option {
String flag private val USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
String value
def Option(String flag, String value) {
this.flag = flag
this.value = value
}
}
def static main(String[] args) { def static main(String[] args) {
if (args.empty) { if (args.empty) {
System::err.println('Aborting: no path to EMF resource provided!') System::err.println('Aborting: no path to RDL file provided!')
return return
} }
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration
try { val main = injector.getInstance(Main)
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration try {
injector.getInstance(Main).run(args) main.run(args)
} catch(MalformedParametersException e){ } catch (MalformedParametersException e) {
print("Command line error "+e.message) print("Command line error " + e.message)
} catch(IllegalArgumentException e){ System.exit(1)
print("generation error "+e.message) } catch (IllegalArgumentException e) {
print("generation error " + e.message)
e.printStackTrace e.printStackTrace
} catch(ParseException e){ System.exit(2)
print("parse problem "+e.message+" ("+ e.errorOffset+")") } catch (ParseException e) {
print("parse problem " + e.message + " (" + e.errorOffset + ")")
System.exit(3)
} }
} }
@ -58,89 +55,71 @@ class Main {
@Inject JavaIoFileSystemAccess fileAccess @Inject JavaIoFileSystemAccess fileAccess
var optsList = new ArrayList<Option>(); def run(String[] args) {
var argsList = new ArrayList<String>()
val shortOptMap = newLinkedHashMap('i' -> 'incl-out', 's' -> 'src-out')
def protected parseOptions(String[] args) { val opt = new Options(args, 0, Integer.MAX_VALUE);
for (arg : args) { opt.getSet().addOption("h", Multiplicity.ZERO_OR_ONE);
switch (arg) { opt.getSet().addOption("v", Multiplicity.ZERO_OR_ONE);
case arg.startsWith('--'): { opt.getSet().addOption("o", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
if (arg.length < 3) opt.getSet().addOption("I", Separator.BLANK, Multiplicity.ZERO_OR_ONE);
throw new MalformedParametersException("not a valid argument: " + arg); if (!opt.check(false, false)) { // Print usage hints
val res = arg.substring(2).split('=') System.err.println("Usage is: " + USAGE_STR);
var opt = new Option() throw new MalformedParametersException(opt.getCheckErrors());
val longOpt = shortOptMap.values.findFirst[String s|s == res.get(0)]
if(longOpt === null) throw new IllegalArgumentException("unknown option: " + arg);
opt.flag = res.get(0)
if (res.size == 2)
opt.value = res.get(1)
optsList += opt
}
case arg.startsWith('-'): {
if (arg.length < 2)
throw new MalformedParametersException("not a valid argument: " + arg);
// -opt
var res = arg.substring(1).split('=')
val longOpt = shortOptMap.get(res.get(0))
if(longOpt === null) throw new MalformedParametersException("unknown option: " + arg);
var opt = new Option()
opt.flag = longOpt
if (res.size == 2)
opt.value = res.get(1)
optsList += opt
}
default: {
argsList += arg;
}
}
} }
// 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")) {
def run(String[] args){
parseOptions(args)
val repo = optsList.findFirst[it.flag == "repository"]
if(repo!==null){
val projectMapping = new ProjectMapping val projectMapping = new ProjectMapping
projectMapping.projectName = "RDL Repository" projectMapping.projectName = "RDL Repository"
projectMapping.path = repo.value projectMapping.path = opt.getSet().getOption("I").getResultValue(0)
new StandaloneSetup().addProjectMapping(projectMapping) new StandaloneSetup().addProjectMapping(projectMapping)
} }
argsList.forEach[runGenerator(it)]
}
def protected runGenerator(String 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)
}
// Configure and start the generator // Configure and start the generator
fileAccess.outputPath = 'src-gen/' fileAccess.outputPath = 'src-gen/'
optsList.filter[it.flag.matches('.*-out')].forEach[fileAccess.setOutputPath(it.flag, it.value)] if(opt.getSet().isSet('o')){
fileAccess.outputConfigurations.get('src-out')?.setOverrideExistingResources(true) fileAccess.outputPath = opt.getSet().getOption('o').getResultValue(0)
fileAccess.outputConfigurations.get(IFileSystemAccess.DEFAULT_OUTPUT)?.setOverrideExistingResources(true)
val context = new GeneratorContext => [ cancelIndicator = CancelIndicator.NullImpl ]
generator.generate(resource, fileAccess, context)
System.out.print('Code generation for '+string +' finished, ')
try{
System.out.print('includes are in '+fileAccess.getURI('', 'incl-out')+', ')
}catch(Exception e){
System.out.print('includes are in '+fileAccess.getURI('')+', ')
}
try{
System.out.println('sources are in '+fileAccess.getURI('', 'src-out')+', ')
}catch(Exception e){
System.out.println('sources are in '+fileAccess.getURI('')+', ')
} }
// #{'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)
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

@ -0,0 +1,275 @@
package com.minres.rdl.generator;
/**
* This class holds all the data for an option. This includes the prefix, the key, the separator
* (for value options), the multiplicity, and all the other settings describing the option. The class
* is designed to be only a data container from a user perspective, i. e. the user has read-access to
* any data determined by the {@link Options#check()}, but not access to any of the other methods
* which are used internally for the operation of the actual check.
*/
public class OptionData {
private final static String CLASS = "OptionData";
private Options.Prefix prefix = null;
private String key = null;
private boolean detail = false;
private Options.Separator separator = null;
private boolean value = false;
private Options.Multiplicity multiplicity = null;
private java.util.regex.Pattern pattern = null;
private int counter = 0;
private java.util.ArrayList<String> values = null;
private java.util.ArrayList<String> details = null;
/**
* The constructor
*/
OptionData(Options.Prefix prefix,
String key,
boolean detail,
Options.Separator separator,
boolean value,
Options.Multiplicity multiplicity) {
if (prefix == null) throw new IllegalArgumentException(CLASS + ": prefix may not be null");
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (separator == null) throw new IllegalArgumentException(CLASS + ": separator may not be null");
if (multiplicity == null) throw new IllegalArgumentException(CLASS + ": multiplicity may not be null");
//.... The data describing the option
this.prefix = prefix;
this.key = key;
this.detail = detail;
this.separator = separator;
this.value = value;
this.multiplicity = multiplicity;
//.... Create the pattern to match this option
if (value) {
if (separator == Options.Separator.BLANK) {
if (detail) {
pattern = java.util.regex.Pattern.compile(prefix.getName() + key + "((\\w|\\.)+)$");
} else {
pattern = java.util.regex.Pattern.compile(prefix.getName() + key + "$");
}
} else {
if (detail) {
pattern = java.util.regex.Pattern.compile(prefix.getName() + key + "((\\w|\\.)+)" + separator.getName() + "(.+)$");
} else {
pattern = java.util.regex.Pattern.compile(prefix.getName() + key + separator.getName() + "(.+)$");
}
}
} else {
pattern = java.util.regex.Pattern.compile(prefix.getName() + key + "$");
}
//.... Structures to hold result data
if (value) {
values = new java.util.ArrayList<String>();
if (detail)
details = new java.util.ArrayList<String>();
}
}
/**
* Getter method for <code>prefix</code> property
* <p>
* @return The value for the <code>prefix</code> property
*/
Options.Prefix getPrefix() {
return prefix;
}
/**
* Getter method for <code>key</code> property
* <p>
* @return The value for the <code>key</code> property
*/
String getKey() {
return key;
}
/**
* Getter method for <code>detail</code> property
* <p>
* @return The value for the <code>detail</code> property
*/
boolean useDetail() {
return detail;
}
/**
* Getter method for <code>separator</code> property
* <p>
* @return The value for the <code>separator</code> property
*/
Options.Separator getSeparator() {
return separator;
}
/**
* Getter method for <code>value</code> property
* <p>
* @return The value for the <code>value</code> property
*/
boolean useValue() {
return value;
}
/**
* Getter method for <code>multiplicity</code> property
* <p>
* @return The value for the <code>multiplicity</code> property
*/
Options.Multiplicity getMultiplicity() {
return multiplicity;
}
/**
* Getter method for <code>pattern</code> property
* <p>
* @return The value for the <code>pattern</code> property
*/
java.util.regex.Pattern getPattern() {
return pattern;
}
/**
* Get the number of results found for this option, which is number of times the key matched
* <p>
* @return The number of results
*/
public int getResultCount() {
if (value) {
return values.size();
} else {
return counter;
}
}
/**
* Get the value with the given index. The index can range between 0 and {@link #getResultCount()}<code> - 1</code>.
* However, only for value options, a non-<code>null</code> value will be returned. Non-value options always
* return <code>null</code>.
* <p>
* @param index The index for the desired value
* <p>
* @return The option value with the given index
* <p>
* @throws IllegalArgumentException If the value for <code>index</code> is out of bounds
*/
public String getResultValue(int index) {
if (!value) return null;
if (index < 0 || index >= getResultCount()) throw new IllegalArgumentException(CLASS + ": illegal value for index");
return values.get(index);
}
/**
* Get the detail with the given index. The index can range between 0 and {@link #getResultCount()}<code> - 1</code>.
* However, only for value options which take details, a non-<code>null</code> detail will be returned. Non-value options
* and value options which do not take details always return <code>null</code>.
* <p>
* @param index The index for the desired value
* <p>
* @return The option detail with the given index
* <p>
* @throws IllegalArgumentException If the value for <code>index</code> is out of bounds
*/
public String getResultDetail(int index) {
if (!detail) return null;
if (index < 0 || index >= getResultCount()) throw new IllegalArgumentException(CLASS + ": illegal value for index");
return details.get(index);
}
/**
* Store the data for a match found
*/
void addResult(String valueData, String detailData) {
if (value) {
if (valueData == null) throw new IllegalArgumentException(CLASS + ": valueData may not be null");
values.add(valueData);
if (detail) {
if (detailData == null) throw new IllegalArgumentException(CLASS + ": detailData may not be null");
details.add(detailData);
}
}
counter++;
}
/**
* This is the overloaded {@link Object#toString()} method, and it is provided mainly for debugging
* purposes.
* <p>
* @return A string representing the instance
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Prefix : ");
sb.append(prefix);
sb.append('\n');
sb.append("Key : ");
sb.append(key);
sb.append('\n');
sb.append("Detail : ");
sb.append(detail);
sb.append('\n');
sb.append("Separator : ");
sb.append(separator);
sb.append('\n');
sb.append("Value : ");
sb.append(value);
sb.append('\n');
sb.append("Multiplicity: ");
sb.append(multiplicity);
sb.append('\n');
sb.append("Pattern : ");
sb.append(pattern);
sb.append('\n');
sb.append("Results : ");
sb.append(counter);
sb.append('\n');
if (value) {
if (detail) {
for (int i = 0; i < values.size(); i++) {
sb.append(details.get(i));
sb.append(" / ");
sb.append(values.get(i));
sb.append('\n');
}
} else {
for (int i = 0; i < values.size(); i++) {
sb.append(values.get(i));
sb.append('\n');
}
}
}
return sb.toString();
}
}

View File

@ -0,0 +1,276 @@
package com.minres.rdl.generator;
/**
* This class holds the information for a <i>set</i> of options. A set can hold any number of
* <code>OptionData</code> instances which are checked together to determine success or failure.
* <p>
* The approach to use this class looks like this:
* <p>
* <ol>
* <li> The user uses any of the <code>Options.addSet()</code> (e. g. {@link Options#addSet(String)}) to create
* any number of sets required (or just relies on the default set, if only one set is required)
* <li> The user adds all required option definitions to each set
* <li> Using any of the <code>Options.check()</code> methods, each set can be checked whether the options
* that were specified on the command line satisfy its requirements
* <li> If the check was successful for a given set, several data items are available from this class:
* <ul>
* <li> All options defined for the set (through with e. g. values, details, and multiplicity are available)
* <li> All data items found (these are the items on the command line which do not start with the prefix,
* i. e. non-option arguments)
* <li> All unmatched arguments on the command line (these are the items on the command line which start
* with the prefix, but do not match to one of the options).
* Programs can elect to ignore these, or react with an error
* </ul>
* </ol>
*/
public class OptionSet {
private final static String CLASS = "OptionSet";
private java.util.ArrayList<OptionData> options = new java.util.ArrayList<OptionData>();
private java.util.HashMap<String, OptionData> keys = new java.util.HashMap<String, OptionData>();
private java.util.ArrayList<String> unmatched = new java.util.ArrayList<String>();
private java.util.ArrayList<String> data = new java.util.ArrayList<String>();
private String setName = null;
private int minData = 0;
private int maxData = 0;
private Options.Prefix prefix = null;
private Options.Multiplicity defaultMultiplicity = null;
/**
* Constructor
*/
OptionSet(Options.Prefix prefix, Options.Multiplicity defaultMultiplicity, String setName, int minData, int maxData) {
if (setName == null) throw new IllegalArgumentException(CLASS + ": setName may not be null");
if (minData < 0) throw new IllegalArgumentException(CLASS + ": minData must be >= 0");
if (maxData < minData) throw new IllegalArgumentException(CLASS + ": maxData must be >= minData");
this.prefix = prefix;
this.defaultMultiplicity = defaultMultiplicity;
this.setName = setName;
this.minData = minData;
this.maxData = maxData;
}
/**
* Get a list of all the options defined for this set
* <p>
* @return A list of {@link OptionData} instances defined for this set
*/
public java.util.ArrayList<OptionData> getOptionData() {
return options;
}
/**
* Get the data for a specific option, identified by its key name (which is unique)
* <p>
* @param key The key for the option
* <p>
* @return The {@link OptionData} instance
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or unknown in this set
*/
public OptionData getOption(String key) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
return keys.get(key);
}
/**
* Check whether a specific option is set, i. e. whether it was specified at least once on the command line.
* <p>
* @param key The key for the option
* <p>
* @return <code>true</code> or <code>false</code>, depending on the outcome of the check
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or unknown in this set
*/
public boolean isSet(String key) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (!keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": unknown key: " + key);
return keys.get(key).getResultCount() > 0 ? true : false;
}
/**
* Getter method for <code>setName</code> property
* <p>
* @return The value for the <code>setName</code> property
*/
public String getSetName() {
return setName;
}
/**
* Getter method for <code>minData</code> property
* <p>
* @return The value for the <code>minData</code> property
*/
public int getMinData() {
return minData;
}
/**
* Getter method for <code>maxData</code> property
* <p>
* @return The value for the <code>maxData</code> property
*/
public int getMaxData() {
return maxData;
}
/**
* Return the data items found (these are the items on the command line which do not start with the prefix, i. e. non-option arguments)
* <p>
* @return A list of strings with all data items found
*/
public java.util.ArrayList<String> getData() {
return data;
}
/**
* Return all unmatched items found (these are the items on the command line which start with the prefix, but do not
* match to one of the options)
* <p>
* @return A list of strings with all unmatched items found
*/
public java.util.ArrayList<String> getUnmatched() {
return unmatched;
}
/**
* Add a non-value option with the given key, and the default prefix and multiplicity
* <p>
* @param key The key for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
*/
public OptionSet addOption(String key) {
return addOption(key, defaultMultiplicity);
}
/**
* Add a non-value option with the given key and multiplicity, and the default prefix
* <p>
* @param key The key for the option
* @param multiplicity The multiplicity for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
* or if <code>multiplicity</code> is <code>null</code>
*/
public OptionSet addOption(String key, Options.Multiplicity multiplicity) {
return addOption(key, false, Options.Separator.NONE, false, multiplicity);
}
/**
* Add a value option with the given key and separator, no details, and the default prefix and multiplicity
* <p>
* @param key The key for the option
* @param separator The separator for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
* or if <code>separator</code> is <code>null</code>
*/
public OptionSet addOption(String key, Options.Separator separator) {
return addOption(key, false, separator, true, defaultMultiplicity);
}
/**
* Add a value option with the given key, separator, and multiplicity, no details, and the default prefix
* <p>
* @param key The key for the option
* @param separator The separator for the option
* @param multiplicity The multiplicity for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
* or if <code>separator</code> or <code>multiplicity</code> are <code>null</code>
*/
public OptionSet addOption(String key, Options.Separator separator, Options.Multiplicity multiplicity) {
return addOption(key, false, separator, true, multiplicity);
}
/**
*
* Add a value option with the given key and separator, possibly details, and the default prefix and multiplicity
* <p>
* @param key The key for the option
* @param details A boolean indicating whether details are expected for the option
* @param separator The separator for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
* or if <code>separator</code> is <code>null</code>
*/
public OptionSet addOption(String key, boolean details, Options.Separator separator) {
return addOption(key, details, separator, true, defaultMultiplicity);
}
/**
* Add a value option with the given key, separator, and multiplicity, possibly details, and the default prefix
* <p>
* @param key The key for the option
* @param details A boolean indicating whether details are expected for the option
* @param separator The separator for the option
* @param multiplicity The multiplicity for the option
* <p>
* @return The set instance itself (to support invocation chaining for <code>addOption()</code> methods)
* <p>
* @throws IllegalArgumentException If the <code>key</code> is <code>null</code> or a key with this name has already been defined
* or if <code>separator</code> or <code>multiplicity</code> are <code>null</code>
*/
public OptionSet addOption(String key, boolean details, Options.Separator separator, Options.Multiplicity multiplicity) {
return addOption(key, details, separator, true, multiplicity);
}
/**
* The master method to add an option. Since there are combinations which are not
* acceptable (like a NONE separator and a true value), this method is not public.
* Internally, we only supply acceptable combinations.
*/
OptionSet addOption(String key,
boolean details,
Options.Separator separator,
boolean value,
Options.Multiplicity multiplicity) {
if (key == null) throw new IllegalArgumentException(CLASS + ": key may not be null");
if (multiplicity == null) throw new IllegalArgumentException(CLASS + ": multiplicity may not be null");
if (separator == null) throw new IllegalArgumentException(CLASS + ": separator may not be null");
if (keys.containsKey(key)) throw new IllegalArgumentException(CLASS + ": the key "
+ key + " has already been defined for this OptionSet");
OptionData od = new OptionData(prefix, key, details, separator, value, multiplicity);
options.add(od);
keys.put(key, od);
return this;
}
}

View File

@ -0,0 +1,770 @@
package com.minres.rdl.generator;
/**
* The central class for option processing. Sets are identified by their name, but there is also
* an anonymous default set, which is very convenient if an application requieres only one set.
*/
public class Options {
private final static String CLASS = "Options";
/**
* The name used internally for the default set
*/
public final static String DEFAULT_SET = "DEFAULT_OPTION_SET";
/**
* An enum encapsulating the possible separators between value options and their actual values.
*/
public enum Separator {
/**
* Separate option and value by ":"
*/
COLON(':'),
/**
* Separate option and value by "="
*/
EQUALS('='),
/**
* Separate option and value by blank space
*/
BLANK(' '), // Or, more precisely, whitespace (as allowed by the CLI)
/**
* This is just a placeholder in case no separator is required (i. e. for non-value options)
*/
NONE('D'); // NONE is a placeholder in case no separator is required, 'D' is just an arbitrary dummy value
private char c;
private Separator(char c) {
this.c = c;
}
/**
* Return the actual separator character
* <p>
* @return The actual separator character
*/
char getName() {
return c;
}
}
/**
* An enum encapsulating the possible prefixes identifying options (and separating them from command line data items)
*/
public enum Prefix {
/**
* Options start with a "-" (typically on Unix platforms)
*/
DASH('-'),
/**
* Options start with a "/" (typically on Windows platforms)
*/
SLASH('/');
private char c;
private Prefix(char c) {
this.c = c;
}
/**
* Return the actual prefix character
* <p>
* @return The actual prefix character
*/
char getName() {
return c;
}
}
/**
* An enum encapsulating the possible multiplicities for options
*/
public enum Multiplicity {
/**
* Option needs to occur exactly once
*/
ONCE,
/**
* Option needs to occur at least once
*/
ONCE_OR_MORE,
/**
* Option needs to occur either once or not at all
*/
ZERO_OR_ONE,
/**
* Option can occur any number of times
*/
ZERO_OR_MORE;
}
private java.util.HashMap<String, OptionSet> optionSets = new java.util.HashMap<String, OptionSet>();
private Prefix prefix = null;
private Multiplicity defaultMultiplicity = null;
private String[] arguments = null;
// private boolean ignoreUnmatched = false;
private int defaultMinData = 0;
private int defaultMaxData = 0;
private StringBuffer checkErrors = null;
/**
* Constructor
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* the same time
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
* @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code>, <code>prefix</code>, or <code>defaultMultiplicity</code>
* is <code>null</code> - or if the data range values don't make sense
*/
public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity, int defMinData, int defMaxData) {
if (args == null) throw new IllegalArgumentException(CLASS + ": args may not be null");
if (prefix == null) throw new IllegalArgumentException(CLASS + ": prefix may not be null");
if (defaultMultiplicity == null) throw new IllegalArgumentException(CLASS + ": defaultMultiplicity may not be null");
if (defMinData < 0) throw new IllegalArgumentException(CLASS + ": defMinData must be >= 0");
if (defMaxData < defMinData) throw new IllegalArgumentException(CLASS + ": defMaxData must be >= defMinData");
arguments = new String[args.length];
int i = 0;
for (String s : args)
arguments[i++] = s;
this.prefix = prefix;
this.defaultMultiplicity = defaultMultiplicity;
this.defaultMinData = defMinData;
this.defaultMaxData = defMaxData;
}
/**
* Constructor
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* the same time
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code>, <code>prefix</code>, or <code>defaultMultiplicity</code>
* is <code>null</code> - or if the data range value doesn't make sense
*/
public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity, int data) {
this(args, prefix, defaultMultiplicity, data, data);
}
/**
* Constructor. The default number of data items is set to 0.
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* the same time
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* <p>
* @throws IllegalArgumentException If either <code>args</code>, <code>prefix</code>, or <code>defaultMultiplicity</code>
* is <code>null</code>
*/
public Options(String args[], Prefix prefix, Multiplicity defaultMultiplicity) {
this(args, prefix, defaultMultiplicity, 0, 0);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}.
* <p>
* @param args The command line arguments to check
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
* @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>defaultMultiplicity</code>
* is <code>null</code> - or if the data range values don't make sense
*/
public Options(String args[], Multiplicity defaultMultiplicity, int defMinData, int defMaxData) {
this(args, Prefix.DASH, defaultMultiplicity, defMinData, defMaxData);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}.
* <p>
* @param args The command line arguments to check
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>defaultMultiplicity</code>
* is <code>null</code> - or if the data range value doesn't make sense
*/
public Options(String args[], Multiplicity defaultMultiplicity, int data) {
this(args, Prefix.DASH, defaultMultiplicity, data, data);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}, and the default number of data items is set to 0.
* <p>
* @param args The command line arguments to check
* @param defaultMultiplicity The default multiplicity to use for all options (can be overridden when adding an option)
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>defaultMultiplicity</code>
* is <code>null</code>
*/
public Options(String args[], Multiplicity defaultMultiplicity) {
this(args, Prefix.DASH, defaultMultiplicity, 0, 0);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}, the default number of data items is set to 0, and
* the multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* <p>
* @throws IllegalArgumentException If <code>args</code> is <code>null</code>
*/
public Options(String args[]) {
this(args, Prefix.DASH, Multiplicity.ONCE);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}, and
* the multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If <code>args</code> is <code>null</code> - or if the data range value doesn't make sense
*/
public Options(String args[], int data) {
this(args, Prefix.DASH, Multiplicity.ONCE, data, data);
}
/**
* Constructor. The prefix is set to {@link Prefix#DASH}, and
* the multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
* @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If <code>args</code> is <code>null</code> - or if the data range values don't make sense
*/
public Options(String args[], int defMinData, int defMaxData) {
this(args, Prefix.DASH, Multiplicity.ONCE, defMinData, defMaxData);
}
/**
* Constructor. The default number of data items is set to 0, and
* the multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* the same time
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>prefix</code> is <code>null</code>
*/
public Options(String args[], Prefix prefix) {
this(args, prefix, Multiplicity.ONCE, 0, 0);
}
/**
* Constructor. The multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* @param data The default minimum and maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>prefix</code> is <code>null</code>
* - or if the data range value doesn't make sense
*/
public Options(String args[], Prefix prefix, int data) {
this(args, prefix, Multiplicity.ONCE, data, data);
}
/**
* Constructor. The multiplicity is set to {@link Multiplicity#ONCE}.
* <p>
* @param args The command line arguments to check
* @param prefix The prefix to use for all command line options. It can only be set here for all options at
* the same time
* @param defMinData The default minimum number of data items for all sets (can be overridden when adding a set)
* @param defMaxData The default maximum number of data items for all sets (can be overridden when adding a set)
* <p>
* @throws IllegalArgumentException If either <code>args</code> or <code>prefix</code> is <code>null</code>
* - or if the data range values don't make sense
*/
public Options(String args[], Prefix prefix, int defMinData, int defMaxData) {
this(args, prefix, Multiplicity.ONCE, defMinData, defMaxData);
}
/**
* Return the (first) matching set. This invocation does not ignore unmatched options and requires that
* data items are the last ones on the command line.
* <p>
* @return The first set which matches (i. e. the <code>check()</code> method returns <code>true</code>) - or
* <code>null</code>, if no set matches.
*/
public OptionSet getMatchingSet() {
return getMatchingSet(false, true);
}
/**
* Return the (first) matching set.
* <p>
* @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
* @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
* <p>
* @return The first set which matches (i. e. the <code>check()</code> method returns <code>true</code>) - or
* <code>null</code>, if no set matches.
*/
public OptionSet getMatchingSet(boolean ignoreUnmatched, boolean requireDataLast) {
for (String setName : optionSets.keySet())
if (check(setName, ignoreUnmatched, requireDataLast))
return optionSets.get(setName);
return null;
}
/**
* Add an option set.
* <p>
* @param setName The name for the set. This must be a unique identifier
* @param minData The minimum number of data items for this set
* @param maxData The maximum number of data items for this set
* <p>
* @return The new <code>Optionset</code> instance created. This is useful to allow chaining of <code>addOption()</code>
* calls right after this method
*/
public OptionSet addSet(String setName, int minData, int maxData) {
if (setName == null) throw new IllegalArgumentException(CLASS + ": setName may not be null");
if (optionSets.containsKey(setName)) throw new IllegalArgumentException(CLASS + ": a set with the name "
+ setName + " has already been defined");
OptionSet os = new OptionSet(prefix, defaultMultiplicity, setName, minData, maxData);
optionSets.put(setName, os);
return os;
}
/**
* Add an option set.
* <p>
* @param setName The name for the set. This must be a unique identifier
* @param data The minimum and maximum number of data items for this set
* <p>
* @return The new <code>Optionset</code> instance created. This is useful to allow chaining of <code>addOption()</code>
* calls right after this method
*/
public OptionSet addSet(String setName, int data) {
return addSet(setName, data, data);
}
/**
* Add an option set. The defaults for the number of data items are used.
* <p>
* @param setName The name for the set. This must be a unique identifier
* <p>
* @return The new <code>Optionset</code> instance created. This is useful to allow chaining of <code>addOption()</code>
* calls right after this method
*/
public OptionSet addSet(String setName) {
return addSet(setName, defaultMinData, defaultMaxData);
}
/**
* Return an option set - or <code>null</code>, if no set with the given name exists
* <p>
* @param setName The name for the set to retrieve
* <p>
* @return The set to retrieve (or <code>null</code>, if no set with the given name exists)
*/
public OptionSet getSet(String setName) {
return optionSets.get(setName);
}
/**
* This returns the (anonymous) default set
* <p>
* @return The default set
*/
public OptionSet getSet() {
if (getSet(DEFAULT_SET) == null)
addSet(DEFAULT_SET, defaultMinData, defaultMaxData);
return getSet(DEFAULT_SET);
}
/**
* The error messages collected during the last option check (invocation of any of the <code>check()</code> methods). This
* is useful to determine what was wrong with the command line arguments provided
* <p>
* @return A string with all collected error messages
*/
public String getCheckErrors() {
return checkErrors.toString();
}
/**
* Run the checks for the default set. <code>ignoreUnmatched</code> is set to <code>false</code>, and
* <code>requireDataLast</code> is set to <code>true</code>.
* <p>
* @return A boolean indicating whether all checks were successful or not
*/
public boolean check() {
return check(DEFAULT_SET, false, true);
}
/**
* Run the checks for the default set.
* <p>
* @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
* @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
* <p>
* @return A boolean indicating whether all checks were successful or not
*/
public boolean check(boolean ignoreUnmatched, boolean requireDataLast) {
return check(DEFAULT_SET, ignoreUnmatched, requireDataLast);
}
/**
* Run the checks for the given set. <code>ignoreUnmatched</code> is set to <code>false</code>, and
* <code>requireDataLast</code> is set to <code>true</code>.
* <p>
* @param setName The name for the set to check
* <p>
* @return A boolean indicating whether all checks were successful or not
* <p>
* @throws IllegalArgumentException If either <code>setName</code> is <code>null</code>, or the set is unknown.
*/
public boolean check(String setName) {
return check(setName, false, true);
}
/**
* Run the checks for the given set.
* <p>
* @param setName The name for the set to check
* @param ignoreUnmatched A boolean to select whether unmatched options can be ignored in the checks or not
* @param requireDataLast A boolean to indicate whether the data items have to be the last ones on the command line or not
* <p>
* @return A boolean indicating whether all checks were successful or not
* <p>
* @throws IllegalArgumentException If either <code>setName</code> is <code>null</code>, or the set is unknown.
*/
public boolean check(String setName, boolean ignoreUnmatched, boolean requireDataLast) {
if (setName == null) throw new IllegalArgumentException(CLASS + ": setName may not be null");
if (optionSets.get(setName) == null) throw new IllegalArgumentException(CLASS + ": Unknown OptionSet: " + setName);
checkErrors = new StringBuffer();
checkErrors.append("Checking set ");
checkErrors.append(setName);
checkErrors.append('\n');
//.... Access the data for the set to use
OptionSet set = optionSets.get(setName);
java.util.ArrayList<OptionData> options = set.getOptionData();
java.util.ArrayList<String> data = set.getData();
java.util.ArrayList<String> unmatched = set.getUnmatched();
//.... Catch some trivial cases
if (options.size() == 0) { // No options have been defined at all
if (arguments.length == 0) { // No arguments have been given: in this case, this is a success
return true;
} else {
checkErrors.append("No options have been defined, nothing to check\n");
return false;
}
} else if (arguments.length == 0) { // Options have been defined, but no arguments given
checkErrors.append("Options have been defined, but no arguments have been given; nothing to check\n");
return false;
}
//.... Parse all the arguments given
int ipos = 0;
int offset = 0;
java.util.regex.Matcher m = null;
String value = null;
String detail = null;
String next = null;
String key = null;
String pre = Character.toString(prefix.getName());
boolean add = true;
boolean[] matched = new boolean[arguments.length];
for (int i = 0; i < matched.length; i++) // Initially, we assume there was no match at all
matched[i] = false;
while (true) {
value = null;
detail = null;
offset = 0;
add = true;
key = arguments[ipos];
for (OptionData optionData : options) { // For each argument, we may need to check all defined options
m = optionData.getPattern().matcher(key);
if (m.lookingAt()) {
if (optionData.useValue()) { // The code section for value options
if (optionData.useDetail()) {
detail = m.group(1);
offset = 2; // required for correct Matcher.group access below
}
if (optionData.getSeparator() == Separator.BLANK) { // In this case, the next argument must be the value
if (ipos + 1 == arguments.length) { // The last argument, thus no value follows it: Error
checkErrors.append("At end of arguments - no value found following argument ");
checkErrors.append(key);
checkErrors.append('\n');
add = false;
} else {
next = arguments[ipos + 1];
if (next.startsWith(pre)) { // The next one is an argument, not a value: Error
checkErrors.append("No value found following argument ");
checkErrors.append(key);
checkErrors.append('\n');
add = false;
} else {
value = next;
matched[ipos++] = true; // Mark the key and the value
matched[ipos] = true;
}
}
} else { // The value follows the separator in this case
value = m.group(1 + offset);
matched[ipos] = true;
}
} else { // Simple, non-value options
matched[ipos] = true;
}
if (add) optionData.addResult(value, detail); // Store the result
break; // No need to check more options, we have a match
}
}
ipos++; // Advance to the next argument to check
if (ipos >= arguments.length) break; // Terminating condition for the check loop
}
//.... Identify unmatched arguments and actual (non-option) data
int first = -1; // Required later for requireDataLast
for (int i = 0; i < matched.length; i++) { // Assemble the list of unmatched options
if (!matched[i]) {
if (arguments[i].startsWith(pre)) { // This is an unmatched option
unmatched.add(arguments[i]);
checkErrors.append("No matching option found for argument ");
checkErrors.append(arguments[i]);
checkErrors.append('\n');
} else { // This is actual data
if (first < 0) first = i;
data.add(arguments[i]);
}
}
}
//.... Checks to determine overall success; start with multiplicity of options
boolean err = true;
for (OptionData optionData : options) {
key = optionData.getKey();
err = false; // Local check result for one option
switch (optionData.getMultiplicity()) {
case ONCE: if (optionData.getResultCount() != 1) err = true; break;
case ONCE_OR_MORE: if (optionData.getResultCount() == 0) err = true; break;
case ZERO_OR_ONE: if (optionData.getResultCount() > 1) err = true; break;
default:
break;
}
if (err) {
checkErrors.append("Wrong number of occurences found for argument ");
checkErrors.append(prefix.getName());
checkErrors.append(key);
checkErrors.append('\n');
return false;
}
}
//.... Check range for data
if (data.size() < set.getMinData() || data.size() > set.getMaxData()) {
checkErrors.append("Invalid number of data arguments: ");
checkErrors.append(data.size());
checkErrors.append(" (allowed range: ");
checkErrors.append(set.getMinData());
checkErrors.append(" ... ");
checkErrors.append(set.getMaxData());
checkErrors.append(")\n");
return false;
}
//.... Check for location of the data in the list of command line arguments
if (requireDataLast) {
if (first + data.size() != arguments.length) {
checkErrors.append("Invalid data specification: data arguments are not the last ones on the command line\n");
return false;
}
}
//.... Check for unmatched arguments
if (!ignoreUnmatched && unmatched.size() > 0) return false; // Don't accept unmatched arguments
//.... If we made it to here, all checks were successful
return true;
}
/**
* Add the given non-value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String)} for details.
*/
public void addOptionAllSets(String key) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, defaultMultiplicity);
}
/**
* Add the given non-value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String, Options.Multiplicity)} for details.
*/
public void addOptionAllSets(String key, Multiplicity multiplicity) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, false, Separator.NONE, false, multiplicity);
}
/**
* Add the given value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String, Options.Separator)} for details.
*/
public void addOptionAllSets(String key, Separator separator) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, false, separator, true, defaultMultiplicity);
}
/**
* Add the given value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String, Options.Separator, Options.Multiplicity)} for details.
*/
public void addOptionAllSets(String key, Separator separator, Multiplicity multiplicity) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, false, separator, true, multiplicity);
}
/**
* Add the given value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String, boolean, Options.Separator)} for details.
*/
public void addOptionAllSets(String key, boolean details, Separator separator) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, details, separator, true, defaultMultiplicity);
}
/**
* Add the given value option to <i>all</i> known sets.
* See {@link OptionSet#addOption(String, boolean, Options.Separator, Options.Multiplicity)} for details.
*/
public void addOptionAllSets(String key, boolean details, Separator separator, Multiplicity multiplicity) {
for (String setName : optionSets.keySet())
optionSets.get(setName).addOption(key, details, separator, true, multiplicity);
}
/**
* This is the overloaded {@link Object#toString()} method, and it is provided mainly for debugging
* purposes.
* <p>
* @return A string representing the instance
*/
public String toString() {
StringBuffer sb = new StringBuffer();
for (OptionSet set : optionSets.values()) {
sb.append("Set: ");
sb.append(set.getSetName());
sb.append('\n');
for (OptionData data : set.getOptionData()) {
sb.append(data.toString());
sb.append('\n');
}
}
return sb.toString();
}
}

View File

@ -13,7 +13,8 @@ import com.minres.rdl.rdl.InstancePropertyRef
import com.minres.rdl.rdl.ComponentDefinitionType import com.minres.rdl.rdl.ComponentDefinitionType
abstract class RdlBaseGenerator { abstract class RdlBaseGenerator {
def long accessWidth(ComponentDefinition definition){
def long accessWidth(ComponentDefinition definition){
var size = 32L var size = 32L
val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa | val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa |
pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.ACCESSWIDTH pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.ACCESSWIDTH
@ -24,7 +25,19 @@ abstract class RdlBaseGenerator {
} }
return size return size
} }
def long regWidth(ComponentDefinition definition){
var size = 32L
val pa = definition.propertyAssignments.findFirst[PropertyAssignment pa |
pa instanceof ExplicitPropertyAssignment && (pa as ExplicitPropertyAssignment).name==PropertyEnum.REGWIDTH
]
if(pa !== null){
val sz = new IntegerWithRadix((pa as ExplicitPropertyAssignment).rhs.effectiveValue)
size=sz.value
}
return size
}
def long getSize(Instantiation instantiation){ def long getSize(Instantiation instantiation){
val componentDef= instantiation.definingComponent val componentDef= instantiation.definingComponent
switch (componentDef.type) { switch (componentDef.type) {
@ -87,13 +100,51 @@ abstract class RdlBaseGenerator {
} }
def String effectiveValue(InstancePropertyRef ref){ def String effectiveValue(InstancePropertyRef ref){
throw new RuntimeException()
} }
def ComponentDefinition definingComponent(Instantiation instantiation){ def ComponentDefinition definingComponent(Instantiation instantiation){
if(instantiation.componentRef!==null) instantiation.componentRef else instantiation.component if(instantiation.componentRef!==null) instantiation.componentRef else instantiation.component
} }
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 byteSize(Instantiation instantiation, long start){
val componentDefinition = instantiation.definingComponent
var long componentSize=0;
if(instantiation.definingComponent.type == ComponentDefinitionType.REG){
componentSize=instantiation.definingComponent.regWidth/8
} else
for(subInstantiation: componentDefinition.instantiations)
componentSize = subInstantiation.byteSize(componentSize)
var long lastTopAddress = start
var long topAddress=start
for(componentInstance: instantiation.componentInstances ){
val byteSize = if(componentInstance.address !== null) (componentInstance.address as IntegerWithRadix).value+componentSize else componentSize + lastTopAddress
topAddress = Math.max(topAddress, byteSize)
lastTopAddress = byteSize
}
return topAddress
}
def long byteSize(Instantiation instantiation){
val componentDefinition = instantiation.definingComponent
var long componentSize=0;
if(instantiation.definingComponent.type == ComponentDefinitionType.REG){
componentSize=instantiation.definingComponent.regWidth/8
} else
for(subInstantiation: componentDefinition.instantiations)
componentSize = subInstantiation.byteSize(componentSize)
return componentSize
}
def String generateHeader() def String generateHeader()
def String generateSource() def String generateSource()

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{
@ -65,7 +66,7 @@ class RegfileGenerator extends RdlBaseGenerator{
public sc_core::sc_module, public sc_core::sc_module,
public sysc::resetable public sysc::resetable
{ {
protected: public:
// storage declarations // storage declarations
«FOR cdef : componentDefinition.componentDefinitions» «FOR cdef : componentDefinition.componentDefinitions»
«IF cdef.type == ComponentDefinitionType.REG» «IF cdef.type == ComponentDefinitionType.REG»
@ -80,12 +81,20 @@ 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(', ')»; «IF instantiation.componentInstances.filter[it.range===null].size>0»
uint«instantiation.size»_t «instantiation.componentInstances.filter[it.range===null].map['r_'+it.name].join(', ')»;
«ENDIF»
«FOR componentInstance : instantiation.componentInstances.filter[it.range!==null]»
std::array<uint«instantiation.size»_t, «componentInstance.range.absSize»> r_«componentInstance.name»;
«ENDFOR»
«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,16 +102,25 @@ 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 instantiation.isFilledByField» «IF instance.range===null»
sysc::sc_register<uint«instantiation.size»_t> «instance.name»; «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» «ENDIF»
«IF !instantiation.isFilledByField» «IF instance.range!==null»
sysc::sc_register<typename «instantiation.component.effectiveName»_t::StorageType> «instance.name»; «IF instantiation.isFilledByField»
sysc::sc_register_indexed<uint«instantiation.size»_t, «instance.range.absSize»> «instance.name»;
«ENDIF»
«IF !instantiation.isFilledByField»
sysc::sc_register_indexed<«instantiation.component.effectiveName»_t, «instance.range.absSize»> «instance.name»;
«ENDIF»
«ENDIF» «ENDIF»
«ENDFOR» «ENDFOR»
«ENDFOR» «ENDFOR»
public:
«componentDefinition.name»(sc_core::sc_module_name nm); «componentDefinition.name»(sc_core::sc_module_name nm);
template<unsigned BUSWIDTH=32> template<unsigned BUSWIDTH=32>
@ -127,7 +145,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 +153,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) {
@ -160,10 +185,6 @@ class RegfileGenerator extends RdlBaseGenerator{
definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2|p1+p1] definition.instantiationsOfType(type).map[it.componentInstances.size].reduce[p1, p2|p1+p1]
} }
def instantiationsOfType(ComponentDefinition definition, ComponentDefinitionType type){
definition.instantiations.filter[it.definingComponent.type == type]
}
override generateSource() { override generateSource() {
'' ''
} }

View File

@ -1,7 +1,12 @@
package com.minres.rdl.generator; package com.minres.rdl.generator;
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;
@SuppressWarnings("all") @SuppressWarnings("all")
@ -21,17 +26,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(" "); _builder.append(_instanceCount);
_builder.append("{&i_gpio, 0x10012000, 0x1000},"); _builder.append("> e300_plat_map = {{");
_builder.newLine(); _builder.newLineIfNotEmpty();
_builder.append(" "); {
_builder.append("{&i_uart, 0x10013000, 0x1000},"); Iterable<Instantiation> _instantiationsOfType = this.instantiationsOfType(this.componentDefinition, ComponentDefinitionType.REGFILE);
_builder.newLine(); for(final Instantiation instantiation : _instantiationsOfType) {
_builder.append(" "); {
_builder.append("{&i_spi, 0x10014000, 0x1000}"); EList<ComponentInstance> _componentInstances = instantiation.getComponentInstances();
_builder.newLine(); 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.byteSize(instantiation));
_builder.append(_hexString_1, " ");
_builder.append("},");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("}};"); _builder.append("}};");
_builder.newLine(); _builder.newLine();
_builder.newLine(); _builder.newLine();

View File

@ -1,14 +1,12 @@
package com.minres.rdl.generator; package com.minres.rdl.generator;
import com.google.common.base.Objects;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.minres.rdl.RDLStandaloneSetup; import com.minres.rdl.RDLStandaloneSetup;
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.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.URI;
@ -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,54 +25,40 @@ 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.Functions.Function1;
import org.eclipse.xtext.xbase.lib.InputOutput; import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
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 {
public static class Option { private final String USAGE_STR = "RDL2code [-h] [-v] [-I <RDL include dir] [-o <output dir>] <input file> <input file>";
private String flag;
private String value;
public String Option(final String flag, final String value) {
String _xblockexpression = null;
{
this.flag = flag;
_xblockexpression = this.value = value;
}
return _xblockexpression;
}
}
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();
if (_isEmpty) { if (_isEmpty) {
System.err.println("Aborting: no path to EMF resource provided!"); System.err.println("Aborting: no path to RDL file provided!");
return; return;
} }
final Injector injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration();
final Main main = injector.<Main>getInstance(Main.class);
try { try {
final Injector injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration(); main.run(args);
injector.<Main>getInstance(Main.class).run(args);
} catch (final Throwable _t) { } catch (final Throwable _t) {
if (_t instanceof MalformedParametersException) { if (_t instanceof MalformedParametersException) {
final MalformedParametersException e = (MalformedParametersException)_t; final MalformedParametersException e = (MalformedParametersException)_t;
String _message = e.getMessage(); String _message = e.getMessage();
String _plus = ("Command line error " + _message); String _plus = ("Command line error " + _message);
InputOutput.<String>print(_plus); InputOutput.<String>print(_plus);
System.exit(1);
} else if (_t instanceof IllegalArgumentException) { } else if (_t instanceof IllegalArgumentException) {
final IllegalArgumentException e_1 = (IllegalArgumentException)_t; final IllegalArgumentException e_1 = (IllegalArgumentException)_t;
String _message_1 = e_1.getMessage(); String _message_1 = e_1.getMessage();
String _plus_1 = ("generation error " + _message_1); String _plus_1 = ("generation error " + _message_1);
InputOutput.<String>print(_plus_1); InputOutput.<String>print(_plus_1);
e_1.printStackTrace(); e_1.printStackTrace();
System.exit(2);
} else if (_t instanceof ParseException) { } else if (_t instanceof ParseException) {
final ParseException e_2 = (ParseException)_t; final ParseException e_2 = (ParseException)_t;
String _message_2 = e_2.getMessage(); String _message_2 = e_2.getMessage();
@ -83,6 +68,7 @@ public class Main {
String _plus_4 = (_plus_3 + Integer.valueOf(_errorOffset)); String _plus_4 = (_plus_3 + Integer.valueOf(_errorOffset));
String _plus_5 = (_plus_4 + ")"); String _plus_5 = (_plus_4 + ")");
InputOutput.<String>print(_plus_5); InputOutput.<String>print(_plus_5);
System.exit(3);
} else { } else {
throw Exceptions.sneakyThrow(_t); throw Exceptions.sneakyThrow(_t);
} }
@ -101,165 +87,118 @@ public class Main {
@Inject @Inject
private JavaIoFileSystemAccess fileAccess; private JavaIoFileSystemAccess fileAccess;
private ArrayList<Main.Option> optsList = new ArrayList<Main.Option>();
private ArrayList<String> argsList = new ArrayList<String>();
private final LinkedHashMap<String, String> shortOptMap = CollectionLiterals.<String, String>newLinkedHashMap(Pair.<String, String>of("i", "incl-out"), Pair.<String, String>of("s", "src-out"));
protected void parseOptions(final String[] args) {
for (final String arg : args) {
boolean _matched = false;
boolean _startsWith = arg.startsWith("--");
if (_startsWith) {
_matched=true;
int _length = arg.length();
boolean _lessThan = (_length < 3);
if (_lessThan) {
throw new MalformedParametersException(("not a valid argument: " + arg));
}
final String[] res = arg.substring(2).split("=");
Main.Option opt = new Main.Option();
final Function1<String, Boolean> _function = (String s) -> {
Object _get = res[0];
return Boolean.valueOf(Objects.equal(s, _get));
};
final String longOpt = IterableExtensions.<String>findFirst(this.shortOptMap.values(), _function);
if ((longOpt == null)) {
throw new IllegalArgumentException(("unknown option: " + arg));
}
opt.flag = res[0];
int _size = ((List<String>)Conversions.doWrapArray(res)).size();
boolean _equals = (_size == 2);
if (_equals) {
opt.value = res[1];
}
this.optsList.add(opt);
}
if (!_matched) {
boolean _startsWith_1 = arg.startsWith("-");
if (_startsWith_1) {
_matched=true;
int _length_1 = arg.length();
boolean _lessThan_1 = (_length_1 < 2);
if (_lessThan_1) {
throw new MalformedParametersException(("not a valid argument: " + arg));
}
String[] res_1 = arg.substring(1).split("=");
final String longOpt_1 = this.shortOptMap.get(res_1[0]);
if ((longOpt_1 == null)) {
throw new MalformedParametersException(("unknown option: " + arg));
}
Main.Option opt_1 = new Main.Option();
opt_1.flag = longOpt_1;
final String[] _converted_res_1 = (String[])res_1;
int _size_1 = ((List<String>)Conversions.doWrapArray(_converted_res_1)).size();
boolean _equals_1 = (_size_1 == 2);
if (_equals_1) {
opt_1.value = res_1[1];
}
this.optsList.add(opt_1);
}
}
if (!_matched) {
this.argsList.add(arg);
}
}
}
public void run(final String[] args) { public void run(final String[] args) {
this.parseOptions(args); final Options opt = new Options(args, 0, Integer.MAX_VALUE);
final Function1<Main.Option, Boolean> _function = (Main.Option it) -> { opt.getSet().addOption("h", Options.Multiplicity.ZERO_OR_ONE);
return Boolean.valueOf(Objects.equal(it.flag, "repository")); opt.getSet().addOption("v", Options.Multiplicity.ZERO_OR_ONE);
}; opt.getSet().addOption("o", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
final Main.Option repo = IterableExtensions.<Main.Option>findFirst(this.optsList, _function); opt.getSet().addOption("I", Options.Separator.BLANK, Options.Multiplicity.ZERO_OR_ONE);
if ((repo != null)) { boolean _check = opt.check(false, false);
boolean _not = (!_check);
if (_not) {
System.err.println(("Usage is: " + this.USAGE_STR));
String _checkErrors = opt.getCheckErrors();
throw new MalformedParametersException(_checkErrors);
}
boolean _isSet = opt.getSet().isSet("h");
if (_isSet) {
InputOutput.<String>println(("Usage: " + this.USAGE_STR));
return;
}
boolean _xifexpression = false;
boolean _isSet_1 = opt.getSet().isSet("v");
if (_isSet_1) {
_xifexpression = true;
} else {
_xifexpression = false;
}
final boolean verbose = _xifexpression;
boolean _isSet_2 = opt.getSet().isSet("I");
if (_isSet_2) {
final ProjectMapping projectMapping = new ProjectMapping(); final ProjectMapping projectMapping = new ProjectMapping();
projectMapping.setProjectName("RDL Repository"); projectMapping.setProjectName("RDL Repository");
projectMapping.setPath(repo.value); projectMapping.setPath(opt.getSet().getOption("I").getResultValue(0));
new StandaloneSetup().addProjectMapping(projectMapping); new StandaloneSetup().addProjectMapping(projectMapping);
} }
final Consumer<String> _function_1 = (String it) -> { this.fileAccess.setOutputPath("src-gen/");
this.runGenerator(it); boolean _isSet_3 = opt.getSet().isSet("o");
}; if (_isSet_3) {
this.argsList.forEach(_function_1); this.fileAccess.setOutputPath(opt.getSet().getOption("o").getResultValue(0));
} OutputConfiguration _get = this.fileAccess.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT);
if (_get!=null) {
protected void runGenerator(final String string) { _get.setOverrideExistingResources(true);
try {
ResourceSet _get = this.resourceSetProvider.get();
final XtextResourceSet resourceSet = ((XtextResourceSet) _get);
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);
boolean _isEmpty = issues.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
URI _uRI = resource.getURI();
String _plus = ("Error validating " + _uRI);
System.err.println(_plus);
final Consumer<Issue> _function = (Issue it) -> {
System.err.println(it);
};
issues.forEach(_function);
URI _uRI_1 = resource.getURI();
String _plus_1 = ("error validating " + _uRI_1);
int _size = issues.size();
throw new ParseException(_plus_1, _size);
} }
this.fileAccess.setOutputPath("src-gen/");
final Function1<Main.Option, Boolean> _function_1 = (Main.Option it) -> {
return Boolean.valueOf(it.flag.matches(".*-out"));
};
final Consumer<Main.Option> _function_2 = (Main.Option it) -> {
this.fileAccess.setOutputPath(it.flag, it.value);
};
IterableExtensions.<Main.Option>filter(this.optsList, _function_1).forEach(_function_2);
OutputConfiguration _get_1 = this.fileAccess.getOutputConfigurations().get("src-out");
if (_get_1!=null) {
_get_1.setOverrideExistingResources(true);
}
GeneratorContext _generatorContext = new GeneratorContext();
final Procedure1<GeneratorContext> _function_3 = (GeneratorContext it) -> {
it.setCancelIndicator(CancelIndicator.NullImpl);
};
final GeneratorContext context = ObjectExtensions.<GeneratorContext>operator_doubleArrow(_generatorContext, _function_3);
this.generator.generate(resource, this.fileAccess, context);
System.out.print((("Code generation for " + string) + " finished, "));
try {
URI _uRI_2 = this.fileAccess.getURI("", "incl-out");
String _plus_2 = ("includes are in " + _uRI_2);
String _plus_3 = (_plus_2 + ", ");
System.out.print(_plus_3);
} 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 + ", ");
System.out.print(_plus_5);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
try {
URI _uRI_4 = this.fileAccess.getURI("", "src-out");
String _plus_6 = ("sources are in " + _uRI_4);
String _plus_7 = (_plus_6 + ", ");
System.out.println(_plus_7);
} 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 + ", ");
System.out.println(_plus_9);
} else {
throw Exceptions.sneakyThrow(_t_1);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
} }
final Consumer<String> _function = (String string) -> {
try {
if (verbose) {
InputOutput.<String>println(("Processing " + string));
}
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);
boolean _isEmpty = issues.isEmpty();
boolean _not_1 = (!_isEmpty);
if (_not_1) {
URI _uRI = resource.getURI();
String _plus = ("Error validating " + _uRI);
System.err.println(_plus);
final Consumer<Issue> _function_1 = (Issue it) -> {
System.err.println(it);
};
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_2 = (GeneratorContext it) -> {
it.setCancelIndicator(CancelIndicator.NullImpl);
};
final GeneratorContext context = ObjectExtensions.<GeneratorContext>operator_doubleArrow(_generatorContext, _function_2);
this.generator.generate(resource, this.fileAccess, context);
if (verbose) {
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);
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_3 = ("includes are in " + _uRI_3);
InputOutput.<String>println(_plus_3);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
try {
if (verbose) {
URI _uRI_4 = this.fileAccess.getURI("", "src-out");
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_5 = ("sources are in " + _uRI_5);
InputOutput.<String>println(_plus_5);
} else {
throw Exceptions.sneakyThrow(_t_1);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
opt.getSet().getData().forEach(_function);
} }
} }

View File

@ -4,6 +4,7 @@ import com.google.common.base.Objects;
import com.minres.rdl.IntegerWithRadix; import com.minres.rdl.IntegerWithRadix;
import com.minres.rdl.rdl.ComponentDefinition; import com.minres.rdl.rdl.ComponentDefinition;
import com.minres.rdl.rdl.ComponentDefinitionType; import com.minres.rdl.rdl.ComponentDefinitionType;
import com.minres.rdl.rdl.ComponentInstance;
import com.minres.rdl.rdl.EnumDefinition; import com.minres.rdl.rdl.EnumDefinition;
import com.minres.rdl.rdl.ExplicitPropertyAssignment; import com.minres.rdl.rdl.ExplicitPropertyAssignment;
import com.minres.rdl.rdl.InstancePropertyRef; import com.minres.rdl.rdl.InstancePropertyRef;
@ -13,7 +14,9 @@ import com.minres.rdl.rdl.PropertyAssignmentRhs;
import com.minres.rdl.rdl.PropertyEnum; import com.minres.rdl.rdl.PropertyEnum;
import com.minres.rdl.rdl.RValue; import com.minres.rdl.rdl.RValue;
import com.minres.rdl.rdl.RValueConstant; import com.minres.rdl.rdl.RValueConstant;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all") @SuppressWarnings("all")
@ -32,6 +35,20 @@ public abstract class RdlBaseGenerator {
return size; return size;
} }
public long regWidth(final ComponentDefinition definition) {
long size = 32L;
final Function1<PropertyAssignment, Boolean> _function = (PropertyAssignment pa) -> {
return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.REGWIDTH)));
};
final PropertyAssignment pa = IterableExtensions.<PropertyAssignment>findFirst(definition.getPropertyAssignments(), _function);
if ((pa != null)) {
String _effectiveValue = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs());
final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue);
size = sz.value;
}
return size;
}
public long getSize(final Instantiation instantiation) { public long getSize(final Instantiation instantiation) {
final ComponentDefinition componentDef = this.definingComponent(instantiation); final ComponentDefinition componentDef = this.definingComponent(instantiation);
ComponentDefinitionType _type = componentDef.getType(); ComponentDefinitionType _type = componentDef.getType();
@ -146,7 +163,7 @@ public abstract class RdlBaseGenerator {
} }
public String effectiveValue(final InstancePropertyRef ref) { public String effectiveValue(final InstancePropertyRef ref) {
return null; throw new RuntimeException();
} }
public ComponentDefinition definingComponent(final Instantiation instantiation) { public ComponentDefinition definingComponent(final Instantiation instantiation) {
@ -161,6 +178,79 @@ public abstract class RdlBaseGenerator {
return _xifexpression; return _xifexpression;
} }
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 byteSize(final Instantiation instantiation, final long start) {
final ComponentDefinition componentDefinition = this.definingComponent(instantiation);
long componentSize = 0;
ComponentDefinitionType _type = this.definingComponent(instantiation).getType();
boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG);
if (_equals) {
long _regWidth = this.regWidth(this.definingComponent(instantiation));
long _divide = (_regWidth / 8);
componentSize = _divide;
} else {
EList<Instantiation> _instantiations = componentDefinition.getInstantiations();
for (final Instantiation subInstantiation : _instantiations) {
componentSize = this.byteSize(subInstantiation, componentSize);
}
}
long lastTopAddress = start;
long topAddress = start;
EList<ComponentInstance> _componentInstances = instantiation.getComponentInstances();
for (final ComponentInstance componentInstance : _componentInstances) {
{
long _xifexpression = (long) 0;
Object _address = componentInstance.getAddress();
boolean _tripleNotEquals = (_address != null);
if (_tripleNotEquals) {
Object _address_1 = componentInstance.getAddress();
_xifexpression = (((IntegerWithRadix) _address_1).value + componentSize);
} else {
_xifexpression = (componentSize + lastTopAddress);
}
final long byteSize = _xifexpression;
topAddress = Math.max(topAddress, byteSize);
lastTopAddress = byteSize;
}
}
return topAddress;
}
public long byteSize(final Instantiation instantiation) {
final ComponentDefinition componentDefinition = this.definingComponent(instantiation);
long componentSize = 0;
ComponentDefinitionType _type = this.definingComponent(instantiation).getType();
boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG);
if (_equals) {
long _regWidth = this.regWidth(this.definingComponent(instantiation));
long _divide = (_regWidth / 8);
componentSize = _divide;
} else {
EList<Instantiation> _instantiations = componentDefinition.getInstantiations();
for (final Instantiation subInstantiation : _instantiations) {
componentSize = this.byteSize(subInstantiation, componentSize);
}
}
return componentSize;
}
public abstract String generateHeader(); public abstract String generateHeader();
public abstract String generateSource(); public abstract String generateSource();

View File

@ -138,7 +138,7 @@ public class RegfileGenerator extends RdlBaseGenerator {
_builder.newLine(); _builder.newLine();
_builder.append("{"); _builder.append("{");
_builder.newLine(); _builder.newLine();
_builder.append("protected:"); _builder.append("public:");
_builder.newLine(); _builder.newLine();
_builder.append(" "); _builder.append(" ");
_builder.append("// storage declarations"); _builder.append("// storage declarations");
@ -192,19 +192,54 @@ public class RegfileGenerator extends RdlBaseGenerator {
{ {
boolean _isFilledByField = this.isFilledByField(instantiation); boolean _isFilledByField = this.isFilledByField(instantiation);
if (_isFilledByField) { if (_isFilledByField) {
_builder.append(" "); {
_builder.append("uint"); final Function1<ComponentInstance, Boolean> _function_1 = (ComponentInstance it) -> {
long _size = this.getSize(instantiation); Range _range = it.getRange();
_builder.append(_size, " "); return Boolean.valueOf((_range == null));
_builder.append("_t "); };
final Function1<ComponentInstance, String> _function_1 = (ComponentInstance it) -> { int _size = IterableExtensions.size(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_1));
String _name_2 = it.getName(); boolean _greaterThan = (_size > 0);
return ("r_" + _name_2); if (_greaterThan) {
}; _builder.append(" ");
String _join_1 = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function_1), ", "); _builder.append("uint");
_builder.append(_join_1, " "); long _size_1 = this.getSize(instantiation);
_builder.append(";"); _builder.append(_size_1, " ");
_builder.newLineIfNotEmpty(); _builder.append("_t ");
final Function1<ComponentInstance, Boolean> _function_2 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range == null));
};
final Function1<ComponentInstance, String> _function_3 = (ComponentInstance it) -> {
String _name_2 = it.getName();
return ("r_" + _name_2);
};
String _join_1 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_2), _function_3), ", ");
_builder.append(_join_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
{
final Function1<ComponentInstance, Boolean> _function_4 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_4);
for(final ComponentInstance componentInstance : _filter) {
_builder.append(" ");
_builder.append("std::array<uint");
long _size_2 = this.getSize(instantiation);
_builder.append(_size_2, " ");
_builder.append("_t, ");
long _absSize = this.absSize(componentInstance.getRange());
_builder.append(_absSize, " ");
_builder.append("> r_");
String _name_2 = componentInstance.getName();
_builder.append(_name_2, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
} }
} }
{ {
@ -216,8 +251,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_3 = this.getSize(instantiation);
_builder.append(_size_1, " "); _builder.append(_size_3, " ");
_builder.append("_t);"); _builder.append("_t);");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
_builder.append(" "); _builder.append(" ");
@ -227,14 +262,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_5 = (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_6 = (ComponentInstance it) -> {
String _name_3 = it.getName();
return ("r_" + _name_3);
};
String _join_2 = IterableExtensions.join(IterableExtensions.<ComponentInstance, String>map(IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_5), _function_6), ", ");
_builder.append(_join_2, " "); _builder.append(_join_2, " ");
_builder.append(";"); _builder.append(";");
_builder.newLineIfNotEmpty(); _builder.newLineIfNotEmpty();
{
final Function1<ComponentInstance, Boolean> _function_7 = (ComponentInstance it) -> {
Range _range = it.getRange();
return Boolean.valueOf((_range != null));
};
Iterable<ComponentInstance> _filter_1 = IterableExtensions.<ComponentInstance>filter(instantiation.getComponentInstances(), _function_7);
for(final ComponentInstance componentInstance_1 : _filter_1) {
_builder.append(" ");
_builder.append("std::array<");
String _effectiveName_3 = 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(" ");
@ -253,32 +313,79 @@ 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) {
{ {
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1); Range _range = instance.getRange();
if (_isFilledByField_2) { boolean _tripleEquals = (_range == null);
_builder.append(" "); if (_tripleEquals) {
_builder.append("sysc::sc_register<uint"); {
long _size_2 = this.getSize(instantiation_1); boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
_builder.append(_size_2, " "); if (_isFilledByField_2) {
_builder.append("_t> "); _builder.append(" ");
String _name_2 = instance.getName(); _builder.append("sysc::sc_register<uint");
_builder.append(_name_2, " "); long _size_4 = this.getSize(instantiation_1);
_builder.append(";"); _builder.append(_size_4, " ");
_builder.newLineIfNotEmpty(); _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); Range _range_1 = instance.getRange();
boolean _not_1 = (!_isFilledByField_3); boolean _tripleNotEquals = (_range_1 != null);
if (_not_1) { if (_tripleNotEquals) {
_builder.append(" "); {
_builder.append("sysc::sc_register<typename "); boolean _isFilledByField_4 = this.isFilledByField(instantiation_1);
String _effectiveName_3 = this.effectiveName(instantiation_1.getComponent()); if (_isFilledByField_4) {
_builder.append(_effectiveName_3, " "); _builder.append(" ");
_builder.append("_t::StorageType> "); _builder.append("sysc::sc_register_indexed<uint");
String _name_3 = instance.getName(); long _size_5 = this.getSize(instantiation_1);
_builder.append(_name_3, " "); _builder.append(_size_5, " ");
_builder.append(";"); _builder.append("_t, ");
_builder.newLineIfNotEmpty(); 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();
}
}
} }
} }
} }
@ -287,11 +394,9 @@ public class RegfileGenerator extends RdlBaseGenerator {
} }
_builder.append(" "); _builder.append(" ");
_builder.newLine(); _builder.newLine();
_builder.append("public:");
_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 +418,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 +434,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 +453,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 +465,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 +488,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)) {
@ -433,14 +546,6 @@ public class RegfileGenerator extends RdlBaseGenerator {
return (int) IterableExtensions.<Integer>reduce(IterableExtensions.<Instantiation, Integer>map(this.instantiationsOfType(definition, type), _function), _function_1); 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);
}
@Override @Override
public String generateSource() { public String generateSource() {
return ""; return "";

View File

@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.minres.rdl</groupId> <groupId>com.minres.rdl</groupId>
<version>1.1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<artifactId>com.minres.rdl.parent</artifactId> <artifactId>com.minres.rdl.parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>