mirror of
https://github.com/Minres/RDL-Editor.git
synced 2025-07-01 13:33:27 +02:00
Changed grammar and added code generator
* changed the grammar to ease code generation * added a code generator and a standalone setup to generate SystemC code using SC-Components lib
This commit is contained in:
2
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/.gitignore
vendored
Normal file
2
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/RDLRuntimeModule.java
|
||||
/RDLStandaloneSetup.java
|
4
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/converter/.gitignore
vendored
Normal file
4
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/converter/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/IDValueConverter.java
|
||||
/NUMValueConverter.java
|
||||
/RdlTerminalConverters.java
|
||||
/STRValueConverter.java
|
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/formatting/.gitignore
vendored
Normal file
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/formatting/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/RDLFormatter.java
|
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/.gitignore
vendored
Normal file
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/generator/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/RDLGenerator.java
|
@ -0,0 +1,47 @@
|
||||
package com.minres.rdl.generator;
|
||||
|
||||
import com.minres.rdl.generator.RdlBaseGenerator;
|
||||
import com.minres.rdl.rdl.ComponentDefinition;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class AddrmapGenerator extends RdlBaseGenerator {
|
||||
private final ComponentDefinition componentDefinition;
|
||||
|
||||
public AddrmapGenerator(final ComponentDefinition definition) {
|
||||
this.componentDefinition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateHeader() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#ifndef _E300_PLAT_MAP_H_");
|
||||
_builder.newLine();
|
||||
_builder.append("#define _E300_PLAT_MAP_H_");
|
||||
_builder.newLine();
|
||||
_builder.append("// need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191");
|
||||
_builder.newLine();
|
||||
_builder.append("const std::array<sysc::target_memory_map_entry<32>, 3> e300_plat_map = {{");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("{&i_gpio, 0x10012000, 0x1000},");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("{&i_uart, 0x10013000, 0x1000},");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("{&i_spi, 0x10014000, 0x1000}");
|
||||
_builder.newLine();
|
||||
_builder.append("}};");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("#endif /* _E300_PLAT_MAP_H_ */");
|
||||
_builder.newLine();
|
||||
return _builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSource() {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,265 @@
|
||||
package com.minres.rdl.generator;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.minres.rdl.RDLStandaloneSetup;
|
||||
import java.lang.reflect.MalformedParametersException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.mwe.utils.ProjectMapping;
|
||||
import org.eclipse.emf.mwe.utils.StandaloneSetup;
|
||||
import org.eclipse.xtext.generator.GeneratorContext;
|
||||
import org.eclipse.xtext.generator.GeneratorDelegate;
|
||||
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
|
||||
import org.eclipse.xtext.generator.OutputConfiguration;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.resource.XtextResourceSet;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.validation.CheckMode;
|
||||
import org.eclipse.xtext.validation.IResourceValidator;
|
||||
import org.eclipse.xtext.validation.Issue;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
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.Pair;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class Main {
|
||||
public static class Option {
|
||||
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) {
|
||||
boolean _isEmpty = ((List<String>)Conversions.doWrapArray(args)).isEmpty();
|
||||
if (_isEmpty) {
|
||||
System.err.println("Aborting: no path to EMF resource provided!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final Injector injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration();
|
||||
injector.<Main>getInstance(Main.class).run(args);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof MalformedParametersException) {
|
||||
final MalformedParametersException e = (MalformedParametersException)_t;
|
||||
String _message = e.getMessage();
|
||||
String _plus = ("Command line error " + _message);
|
||||
InputOutput.<String>print(_plus);
|
||||
} else if (_t instanceof IllegalArgumentException) {
|
||||
final IllegalArgumentException e_1 = (IllegalArgumentException)_t;
|
||||
String _message_1 = e_1.getMessage();
|
||||
String _plus_1 = ("generation error " + _message_1);
|
||||
InputOutput.<String>print(_plus_1);
|
||||
e_1.printStackTrace();
|
||||
} else if (_t instanceof ParseException) {
|
||||
final ParseException e_2 = (ParseException)_t;
|
||||
String _message_2 = e_2.getMessage();
|
||||
String _plus_2 = ("parse problem " + _message_2);
|
||||
String _plus_3 = (_plus_2 + " (");
|
||||
int _errorOffset = e_2.getErrorOffset();
|
||||
String _plus_4 = (_plus_3 + Integer.valueOf(_errorOffset));
|
||||
String _plus_5 = (_plus_4 + ")");
|
||||
InputOutput.<String>print(_plus_5);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private Provider<ResourceSet> resourceSetProvider;
|
||||
|
||||
@Inject
|
||||
private IResourceValidator validator;
|
||||
|
||||
@Inject
|
||||
private GeneratorDelegate generator;
|
||||
|
||||
@Inject
|
||||
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) {
|
||||
this.parseOptions(args);
|
||||
final Function1<Main.Option, Boolean> _function = (Main.Option it) -> {
|
||||
return Boolean.valueOf(Objects.equal(it.flag, "repository"));
|
||||
};
|
||||
final Main.Option repo = IterableExtensions.<Main.Option>findFirst(this.optsList, _function);
|
||||
if ((repo != null)) {
|
||||
final ProjectMapping projectMapping = new ProjectMapping();
|
||||
projectMapping.setProjectName("RDL Repository");
|
||||
projectMapping.setPath(repo.value);
|
||||
new StandaloneSetup().addProjectMapping(projectMapping);
|
||||
}
|
||||
final Consumer<String> _function_1 = (String it) -> {
|
||||
this.runGenerator(it);
|
||||
};
|
||||
this.argsList.forEach(_function_1);
|
||||
}
|
||||
|
||||
protected void runGenerator(final String string) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,10 +3,20 @@
|
||||
*/
|
||||
package com.minres.rdl.generator;
|
||||
|
||||
import com.minres.rdl.generator.AddrmapGenerator;
|
||||
import com.minres.rdl.generator.RdlBaseGenerator;
|
||||
import com.minres.rdl.generator.RegfileGenerator;
|
||||
import com.minres.rdl.rdl.ComponentDefinition;
|
||||
import com.minres.rdl.rdl.ComponentDefinitionType;
|
||||
import org.eclipse.emf.common.notify.Notifier;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.generator.AbstractGenerator;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.generator.IGeneratorContext;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
|
||||
/**
|
||||
* Generates code from your model files on save.
|
||||
@ -17,5 +27,65 @@ import org.eclipse.xtext.generator.IGeneratorContext;
|
||||
public class RDLGenerator extends AbstractGenerator {
|
||||
@Override
|
||||
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
|
||||
final Function1<Notifier, Boolean> _function = (Notifier it) -> {
|
||||
return Boolean.valueOf((it instanceof ComponentDefinition));
|
||||
};
|
||||
final Function1<Notifier, ComponentDefinition> _function_1 = (Notifier it) -> {
|
||||
return ((ComponentDefinition) it);
|
||||
};
|
||||
final Procedure1<ComponentDefinition> _function_2 = (ComponentDefinition it) -> {
|
||||
final RdlBaseGenerator gen = this.fileGenerator(it);
|
||||
if ((gen != null)) {
|
||||
final String header = gen.generateHeader();
|
||||
if (((header != null) && (header.length() > 0))) {
|
||||
String _name = it.getName();
|
||||
String _plus = (_name + ".h");
|
||||
fsa.generateFile(_plus, this.outputConfig(fsa, "incl-out"), header);
|
||||
}
|
||||
final String source = gen.generateSource();
|
||||
if (((source != null) && (source.length() > 0))) {
|
||||
String _name_1 = it.getName();
|
||||
String _plus_1 = (_name_1 + ".cpp");
|
||||
fsa.generateFile(_plus_1, this.outputConfig(fsa, "src-out"), source);
|
||||
}
|
||||
}
|
||||
};
|
||||
IteratorExtensions.<ComponentDefinition>forEach(IteratorExtensions.<Notifier, ComponentDefinition>map(IteratorExtensions.<Notifier>filter(resource.getResourceSet().getAllContents(), _function), _function_1), _function_2);
|
||||
}
|
||||
|
||||
public RdlBaseGenerator fileGenerator(final ComponentDefinition definition) {
|
||||
RdlBaseGenerator _switchResult = null;
|
||||
ComponentDefinitionType _type = definition.getType();
|
||||
if (_type != null) {
|
||||
switch (_type) {
|
||||
case REGFILE:
|
||||
_switchResult = new RegfileGenerator(definition);
|
||||
break;
|
||||
case ADDRMAP:
|
||||
_switchResult = new AddrmapGenerator(definition);
|
||||
break;
|
||||
default:
|
||||
_switchResult = null;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_switchResult = null;
|
||||
}
|
||||
return _switchResult;
|
||||
}
|
||||
|
||||
public String outputConfig(final IFileSystemAccess2 fsa, final String string) {
|
||||
String output_config = string;
|
||||
try {
|
||||
fsa.getURI("", output_config);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Exception) {
|
||||
final Exception e = (Exception)_t;
|
||||
output_config = "DEFAULT_OUTPUT";
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
return output_config;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,167 @@
|
||||
package com.minres.rdl.generator;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.minres.rdl.IntegerWithRadix;
|
||||
import com.minres.rdl.rdl.ComponentDefinition;
|
||||
import com.minres.rdl.rdl.ComponentDefinitionType;
|
||||
import com.minres.rdl.rdl.EnumDefinition;
|
||||
import com.minres.rdl.rdl.ExplicitPropertyAssignment;
|
||||
import com.minres.rdl.rdl.InstancePropertyRef;
|
||||
import com.minres.rdl.rdl.Instantiation;
|
||||
import com.minres.rdl.rdl.PropertyAssignment;
|
||||
import com.minres.rdl.rdl.PropertyAssignmentRhs;
|
||||
import com.minres.rdl.rdl.PropertyEnum;
|
||||
import com.minres.rdl.rdl.RValue;
|
||||
import com.minres.rdl.rdl.RValueConstant;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public abstract class RdlBaseGenerator {
|
||||
public long accessWidth(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.ACCESSWIDTH)));
|
||||
};
|
||||
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) {
|
||||
final ComponentDefinition componentDef = this.definingComponent(instantiation);
|
||||
ComponentDefinitionType _type = componentDef.getType();
|
||||
if (_type != null) {
|
||||
switch (_type) {
|
||||
case REG:
|
||||
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(componentDef.getPropertyAssignments(), _function);
|
||||
if ((pa != null)) {
|
||||
String _effectiveValue = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs());
|
||||
final IntegerWithRadix sz = new IntegerWithRadix(_effectiveValue);
|
||||
return sz.value;
|
||||
}
|
||||
return 32L;
|
||||
case FIELD:
|
||||
final Function1<PropertyAssignment, Boolean> _function_1 = (PropertyAssignment pa_1) -> {
|
||||
return Boolean.valueOf(((pa_1 instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa_1).getName(), PropertyEnum.FIELDWIDTH)));
|
||||
};
|
||||
final PropertyAssignment pa_1 = IterableExtensions.<PropertyAssignment>findFirst(componentDef.getPropertyAssignments(), _function_1);
|
||||
if ((pa_1 != null)) {
|
||||
String _effectiveValue_1 = this.effectiveValue(((ExplicitPropertyAssignment) pa_1).getRhs());
|
||||
final IntegerWithRadix sz_1 = new IntegerWithRadix(_effectiveValue_1);
|
||||
return sz_1.value;
|
||||
}
|
||||
return 1L;
|
||||
default:
|
||||
return 0L;
|
||||
}
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public String effectiveName(final ComponentDefinition definition) {
|
||||
String _xifexpression = null;
|
||||
String _name = definition.getName();
|
||||
boolean _tripleNotEquals = (_name != null);
|
||||
if (_tripleNotEquals) {
|
||||
_xifexpression = definition.getName();
|
||||
} else {
|
||||
String _xblockexpression = null;
|
||||
{
|
||||
final Function1<PropertyAssignment, Boolean> _function = (PropertyAssignment pa) -> {
|
||||
return Boolean.valueOf(((pa instanceof ExplicitPropertyAssignment) && Objects.equal(((ExplicitPropertyAssignment) pa).getName(), PropertyEnum.NAME)));
|
||||
};
|
||||
final PropertyAssignment pa = IterableExtensions.<PropertyAssignment>findFirst(definition.getPropertyAssignments(), _function);
|
||||
_xblockexpression = this.effectiveValue(((ExplicitPropertyAssignment) pa).getRhs());
|
||||
}
|
||||
_xifexpression = _xblockexpression;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
public String effectiveValue(final PropertyAssignmentRhs rhs) {
|
||||
String _xifexpression = null;
|
||||
RValue _value = rhs.getValue();
|
||||
boolean _tripleNotEquals = (_value != null);
|
||||
if (_tripleNotEquals) {
|
||||
_xifexpression = this.effectiveValue(rhs.getValue());
|
||||
} else {
|
||||
String _xifexpression_1 = null;
|
||||
InstancePropertyRef _instPropRef = rhs.getInstPropRef();
|
||||
boolean _tripleNotEquals_1 = (_instPropRef != null);
|
||||
if (_tripleNotEquals_1) {
|
||||
_xifexpression_1 = this.effectiveValue(rhs.getInstPropRef());
|
||||
} else {
|
||||
String _xifexpression_2 = null;
|
||||
EnumDefinition _enumRef = rhs.getEnumRef();
|
||||
boolean _tripleNotEquals_2 = (_enumRef != null);
|
||||
if (_tripleNotEquals_2) {
|
||||
_xifexpression_2 = rhs.getEnumRef().getName();
|
||||
}
|
||||
_xifexpression_1 = _xifexpression_2;
|
||||
}
|
||||
_xifexpression = _xifexpression_1;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
public String effectiveValue(final RValue rvalue) {
|
||||
String _xifexpression = null;
|
||||
String _str = rvalue.getStr();
|
||||
boolean _tripleNotEquals = (_str != null);
|
||||
if (_tripleNotEquals) {
|
||||
_xifexpression = rvalue.getStr();
|
||||
} else {
|
||||
String _xifexpression_1 = null;
|
||||
RValueConstant _val = rvalue.getVal();
|
||||
boolean _notEquals = (!Objects.equal(_val, RValueConstant.UNDEFINED));
|
||||
if (_notEquals) {
|
||||
_xifexpression_1 = rvalue.getVal().getLiteral();
|
||||
} else {
|
||||
String _xifexpression_2 = null;
|
||||
Object _num = rvalue.getNum();
|
||||
boolean _tripleNotEquals_1 = (_num != null);
|
||||
if (_tripleNotEquals_1) {
|
||||
String _xblockexpression = null;
|
||||
{
|
||||
Object _num_1 = rvalue.getNum();
|
||||
final IntegerWithRadix num = ((IntegerWithRadix) _num_1);
|
||||
_xblockexpression = num.toString();
|
||||
}
|
||||
_xifexpression_2 = _xblockexpression;
|
||||
}
|
||||
_xifexpression_1 = _xifexpression_2;
|
||||
}
|
||||
_xifexpression = _xifexpression_1;
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
public String effectiveValue(final InstancePropertyRef ref) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComponentDefinition definingComponent(final Instantiation instantiation) {
|
||||
ComponentDefinition _xifexpression = null;
|
||||
ComponentDefinition _componentRef = instantiation.getComponentRef();
|
||||
boolean _tripleNotEquals = (_componentRef != null);
|
||||
if (_tripleNotEquals) {
|
||||
_xifexpression = instantiation.getComponentRef();
|
||||
} else {
|
||||
_xifexpression = instantiation.getComponent();
|
||||
}
|
||||
return _xifexpression;
|
||||
}
|
||||
|
||||
public abstract String generateHeader();
|
||||
|
||||
public abstract String generateSource();
|
||||
}
|
@ -0,0 +1,504 @@
|
||||
package com.minres.rdl.generator;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.minres.rdl.IntegerWithRadix;
|
||||
import com.minres.rdl.generator.RdlBaseGenerator;
|
||||
import com.minres.rdl.rdl.ComponentDefinition;
|
||||
import com.minres.rdl.rdl.ComponentDefinitionType;
|
||||
import com.minres.rdl.rdl.ComponentInstance;
|
||||
import com.minres.rdl.rdl.Instantiation;
|
||||
import com.minres.rdl.rdl.Range;
|
||||
import java.util.Date;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function2;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class RegfileGenerator extends RdlBaseGenerator {
|
||||
private final ComponentDefinition componentDefinition;
|
||||
|
||||
public RegfileGenerator(final ComponentDefinition definition) {
|
||||
this.componentDefinition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateHeader() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("////////////////////////////////////////////////////////////////////////////////");
|
||||
_builder.newLine();
|
||||
_builder.append("// Copyright (C) 2017, MINRES Technologies GmbH");
|
||||
_builder.newLine();
|
||||
_builder.append("// All rights reserved.");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// Redistribution and use in source and binary forms, with or without");
|
||||
_builder.newLine();
|
||||
_builder.append("// modification, are permitted provided that the following conditions are met:");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// 1. Redistributions of source code must retain the above copyright notice,");
|
||||
_builder.newLine();
|
||||
_builder.append("// this list of conditions and the following disclaimer.");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// 2. Redistributions in binary form must reproduce the above copyright notice,");
|
||||
_builder.newLine();
|
||||
_builder.append("// this list of conditions and the following disclaimer in the documentation");
|
||||
_builder.newLine();
|
||||
_builder.append("// and/or other materials provided with the distribution.");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// 3. Neither the name of the copyright holder nor the names of its contributors");
|
||||
_builder.newLine();
|
||||
_builder.append("// may be used to endorse or promote products derived from this software");
|
||||
_builder.newLine();
|
||||
_builder.append("// without specific prior written permission.");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"");
|
||||
_builder.newLine();
|
||||
_builder.append("// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE");
|
||||
_builder.newLine();
|
||||
_builder.append("// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE");
|
||||
_builder.newLine();
|
||||
_builder.append("// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
|
||||
_builder.newLine();
|
||||
_builder.append("// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
|
||||
_builder.newLine();
|
||||
_builder.append("// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
|
||||
_builder.newLine();
|
||||
_builder.append("// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS");
|
||||
_builder.newLine();
|
||||
_builder.append("// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
|
||||
_builder.newLine();
|
||||
_builder.append("// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)");
|
||||
_builder.newLine();
|
||||
_builder.append("// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE");
|
||||
_builder.newLine();
|
||||
_builder.append("// POSSIBILITY OF SUCH DAMAGE.");
|
||||
_builder.newLine();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("// Created on: ");
|
||||
Date _date = new Date();
|
||||
_builder.append(_date);
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append("// * ");
|
||||
String _name = this.componentDefinition.getName();
|
||||
_builder.append(_name);
|
||||
_builder.append(".h Author: <RDL Generator>");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append("//");
|
||||
_builder.newLine();
|
||||
_builder.append("////////////////////////////////////////////////////////////////////////////////");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("#ifndef _");
|
||||
String _upperCase = this.componentDefinition.getName().toUpperCase();
|
||||
_builder.append(_upperCase);
|
||||
_builder.append("_H_");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append("#define _");
|
||||
String _upperCase_1 = this.componentDefinition.getName().toUpperCase();
|
||||
_builder.append(_upperCase_1);
|
||||
_builder.append("_H_");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.newLine();
|
||||
_builder.append("#include <sysc/utilities.h>");
|
||||
_builder.newLine();
|
||||
_builder.append("#include <util/bit_field.h>");
|
||||
_builder.newLine();
|
||||
_builder.append("#include <sysc/register.h>");
|
||||
_builder.newLine();
|
||||
_builder.append("#include <sysc/tlm_target.h>");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("namespace sysc {");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("class ");
|
||||
String _name_1 = this.componentDefinition.getName();
|
||||
_builder.append(_name_1);
|
||||
_builder.append(" :");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
_builder.append("public sc_core::sc_module,");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("public sysc::resetable");
|
||||
_builder.newLine();
|
||||
_builder.append("{");
|
||||
_builder.newLine();
|
||||
_builder.append("protected:");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("// storage declarations");
|
||||
_builder.newLine();
|
||||
{
|
||||
EList<ComponentDefinition> _componentDefinitions = this.componentDefinition.getComponentDefinitions();
|
||||
for(final ComponentDefinition cdef : _componentDefinitions) {
|
||||
{
|
||||
ComponentDefinitionType _type = cdef.getType();
|
||||
boolean _equals = Objects.equal(_type, ComponentDefinitionType.REG);
|
||||
if (_equals) {
|
||||
_builder.append(" ");
|
||||
_builder.append("BEGIN_BF_DECL(");
|
||||
String _effectiveName = this.effectiveName(cdef);
|
||||
_builder.append(_effectiveName, " ");
|
||||
_builder.append("+\'_t\'», uint");
|
||||
_builder.append(cdef, " ");
|
||||
_builder.append("_t);");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
String _genFieldDeclarations = this.genFieldDeclarations(cdef);
|
||||
_builder.append(_genFieldDeclarations, " ");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
_builder.append("END_BF_DECL();");
|
||||
_builder.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
EList<Instantiation> _instantiations = this.componentDefinition.getInstantiations();
|
||||
for(final Instantiation instantiation : _instantiations) {
|
||||
{
|
||||
if (((instantiation.getComponentRef() != null) && Objects.equal(instantiation.getComponentRef().getType(), ComponentDefinitionType.REG))) {
|
||||
_builder.append(" ");
|
||||
String _effectiveName_1 = this.effectiveName(instantiation.getComponentRef());
|
||||
_builder.append(_effectiveName_1, " ");
|
||||
_builder.append("+\'_t\' ");
|
||||
final Function1<ComponentInstance, String> _function = (ComponentInstance it) -> {
|
||||
return it.getName();
|
||||
};
|
||||
String _join = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function), ", ");
|
||||
_builder.append(_join, " ");
|
||||
_builder.append(";");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (((instantiation.getComponent() != null) && Objects.equal(instantiation.getComponent().getType(), ComponentDefinitionType.REG))) {
|
||||
{
|
||||
boolean _isFilledByField = this.isFilledByField(instantiation);
|
||||
if (_isFilledByField) {
|
||||
_builder.append(" ");
|
||||
_builder.append("uint");
|
||||
long _size = this.getSize(instantiation);
|
||||
_builder.append(_size, " ");
|
||||
_builder.append("_t ");
|
||||
final Function1<ComponentInstance, String> _function_1 = (ComponentInstance it) -> {
|
||||
String _name_2 = it.getName();
|
||||
return ("r_" + _name_2);
|
||||
};
|
||||
String _join_1 = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function_1), ", ");
|
||||
_builder.append(_join_1, " ");
|
||||
_builder.append(";");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
{
|
||||
boolean _isFilledByField_1 = this.isFilledByField(instantiation);
|
||||
boolean _not = (!_isFilledByField_1);
|
||||
if (_not) {
|
||||
_builder.append(" ");
|
||||
_builder.append("BEGIN_BF_DECL(");
|
||||
String _effectiveName_2 = this.effectiveName(instantiation.getComponent());
|
||||
_builder.append(_effectiveName_2, " ");
|
||||
_builder.append("_t, uint");
|
||||
long _size_1 = this.getSize(instantiation);
|
||||
_builder.append(_size_1, " ");
|
||||
_builder.append("_t);");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
_builder.append(" ");
|
||||
String _genFieldDeclarations_1 = this.genFieldDeclarations(this.definingComponent(instantiation));
|
||||
_builder.append(_genFieldDeclarations_1, " ");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
_builder.append("END_BF_DECL() ");
|
||||
final Function1<ComponentInstance, String> _function_2 = (ComponentInstance it) -> {
|
||||
String _name_2 = it.getName();
|
||||
return ("r_" + _name_2);
|
||||
};
|
||||
String _join_2 = IterableExtensions.join(ListExtensions.<ComponentInstance, String>map(instantiation.getComponentInstances(), _function_2), ", ");
|
||||
_builder.append(_join_2, " ");
|
||||
_builder.append(";");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
_builder.append(" ");
|
||||
_builder.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_builder.append(" ");
|
||||
_builder.append("// register declarations");
|
||||
_builder.newLine();
|
||||
{
|
||||
EList<Instantiation> _instantiations_1 = this.componentDefinition.getInstantiations();
|
||||
for(final Instantiation instantiation_1 : _instantiations_1) {
|
||||
{
|
||||
EList<ComponentInstance> _componentInstances = instantiation_1.getComponentInstances();
|
||||
for(final ComponentInstance instance : _componentInstances) {
|
||||
{
|
||||
boolean _isFilledByField_2 = this.isFilledByField(instantiation_1);
|
||||
if (_isFilledByField_2) {
|
||||
_builder.append(" ");
|
||||
_builder.append("sysc::sc_register<uint");
|
||||
long _size_2 = this.getSize(instantiation_1);
|
||||
_builder.append(_size_2, " ");
|
||||
_builder.append("_t> ");
|
||||
String _name_2 = instance.getName();
|
||||
_builder.append(_name_2, " ");
|
||||
_builder.append(";");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
{
|
||||
boolean _isFilledByField_3 = this.isFilledByField(instantiation_1);
|
||||
boolean _not_1 = (!_isFilledByField_3);
|
||||
if (_not_1) {
|
||||
_builder.append(" ");
|
||||
_builder.append("sysc::sc_register<typename ");
|
||||
String _effectiveName_3 = this.effectiveName(instantiation_1.getComponent());
|
||||
_builder.append(_effectiveName_3, " ");
|
||||
_builder.append("_t::StorageType> ");
|
||||
String _name_3 = instance.getName();
|
||||
_builder.append(_name_3, " ");
|
||||
_builder.append(";");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_builder.append(" ");
|
||||
_builder.newLine();
|
||||
_builder.append("public:");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
String _name_4 = this.componentDefinition.getName();
|
||||
_builder.append(_name_4, " ");
|
||||
_builder.append("(sc_core::sc_module_name nm);");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("template<unsigned BUSWIDTH=32>");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("void registerResources(sysc::tlm_target<BUSWIDTH>& target);");
|
||||
_builder.newLine();
|
||||
_builder.append("};");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("//////////////////////////////////////////////////////////////////////////////");
|
||||
_builder.newLine();
|
||||
_builder.append("// member functions");
|
||||
_builder.newLine();
|
||||
_builder.append("//////////////////////////////////////////////////////////////////////////////");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("inline sysc::");
|
||||
String _name_5 = this.componentDefinition.getName();
|
||||
_builder.append(_name_5);
|
||||
_builder.append("::");
|
||||
String _name_6 = this.componentDefinition.getName();
|
||||
_builder.append(_name_6);
|
||||
_builder.append("(sc_core::sc_module_name nm)");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(": sc_core::sc_module(nm)");
|
||||
_builder.newLine();
|
||||
{
|
||||
EList<Instantiation> _instantiations_2 = this.componentDefinition.getInstantiations();
|
||||
for(final Instantiation instantiation_2 : _instantiations_2) {
|
||||
{
|
||||
EList<ComponentInstance> _componentInstances_1 = instantiation_2.getComponentInstances();
|
||||
for(final ComponentInstance instance_1 : _componentInstances_1) {
|
||||
_builder.append(", NAMED(");
|
||||
String _name_7 = instance_1.getName();
|
||||
_builder.append(_name_7);
|
||||
_builder.append(", r_");
|
||||
String _name_8 = instance_1.getName();
|
||||
_builder.append(_name_8);
|
||||
_builder.append(", 0, *this)");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_builder.append("{");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("template<unsigned BUSWIDTH>");
|
||||
_builder.newLine();
|
||||
_builder.append("inline void sysc::");
|
||||
String _name_9 = this.componentDefinition.getName();
|
||||
_builder.append(_name_9);
|
||||
_builder.append("::registerResources(sysc::tlm_target<BUSWIDTH>& target) {");
|
||||
_builder.newLineIfNotEmpty();
|
||||
{
|
||||
EList<Instantiation> _instantiations_3 = this.componentDefinition.getInstantiations();
|
||||
for(final Instantiation instantiation_3 : _instantiations_3) {
|
||||
{
|
||||
EList<ComponentInstance> _componentInstances_2 = instantiation_3.getComponentInstances();
|
||||
for(final ComponentInstance instance_2 : _componentInstances_2) {
|
||||
_builder.append(" ");
|
||||
_builder.append("target.addResource(");
|
||||
String _name_10 = instance_2.getName();
|
||||
_builder.append(_name_10, " ");
|
||||
_builder.append(", 0x");
|
||||
Object _address = instance_2.getAddress();
|
||||
String _hexString = Long.toHexString(((IntegerWithRadix) _address).value);
|
||||
_builder.append(_hexString, " ");
|
||||
_builder.append("UL, 0x");
|
||||
long _size_3 = this.getSize(instantiation_3);
|
||||
long _plus = (_size_3 + 7);
|
||||
long _divide = (_plus / 8);
|
||||
String _hexString_1 = Long.toHexString(_divide);
|
||||
_builder.append(_hexString_1, " ");
|
||||
_builder.append("UL);");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("#endif // _");
|
||||
String _upperCase_2 = this.componentDefinition.getName().toUpperCase();
|
||||
_builder.append(_upperCase_2);
|
||||
_builder.append("_H_");
|
||||
_builder.newLineIfNotEmpty();
|
||||
return _builder.toString();
|
||||
}
|
||||
|
||||
public boolean isFilledByField(final Instantiation instantiation) {
|
||||
final int fieldCount = this.instanceCountOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD);
|
||||
if ((fieldCount == 1)) {
|
||||
final long instSize = this.getSize(instantiation);
|
||||
final Instantiation field = ((Instantiation[])Conversions.unwrapArray(this.instantiationsOfType(instantiation.getComponent(), ComponentDefinitionType.FIELD), Instantiation.class))[0];
|
||||
final ComponentInstance inst = field.getComponentInstances().get(0);
|
||||
final Range range = inst.getRange();
|
||||
if ((range == null)) {
|
||||
long _size = this.getSize(field);
|
||||
return (instSize == _size);
|
||||
}
|
||||
Object _size_1 = range.getSize();
|
||||
boolean _tripleNotEquals = (_size_1 != null);
|
||||
if (_tripleNotEquals) {
|
||||
Object _size_2 = range.getSize();
|
||||
return (instSize == ((IntegerWithRadix) _size_2).value);
|
||||
} else {
|
||||
Object _left = range.getLeft();
|
||||
final long left = ((IntegerWithRadix) _left).value;
|
||||
Object _right = range.getRight();
|
||||
final long right = ((IntegerWithRadix) _right).value;
|
||||
long _xifexpression = (long) 0;
|
||||
if ((left > right)) {
|
||||
_xifexpression = ((left - right) + 1);
|
||||
} else {
|
||||
_xifexpression = ((right - left) + 1);
|
||||
}
|
||||
final long size = _xifexpression;
|
||||
return (instSize == size);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int instanceCountOfType(final ComponentDefinition definition, final ComponentDefinitionType type) {
|
||||
final Function1<Instantiation, Integer> _function = (Instantiation it) -> {
|
||||
return Integer.valueOf(it.getComponentInstances().size());
|
||||
};
|
||||
final Function2<Integer, Integer, Integer> _function_1 = (Integer p1, Integer p2) -> {
|
||||
return Integer.valueOf(((p1).intValue() + (p1).intValue()));
|
||||
};
|
||||
return (int) IterableExtensions.<Integer>reduce(IterableExtensions.<Instantiation, Integer>map(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
|
||||
public String generateSource() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String genFieldDeclarations(final ComponentDefinition componentDef) {
|
||||
String _xblockexpression = null;
|
||||
{
|
||||
long i = 0L;
|
||||
String res = "";
|
||||
EList<Instantiation> _instantiations = componentDef.getInstantiations();
|
||||
for (final Instantiation inst : _instantiations) {
|
||||
EList<ComponentInstance> _componentInstances = inst.getComponentInstances();
|
||||
for (final ComponentInstance compInst : _componentInstances) {
|
||||
Object _size = compInst.getRange().getSize();
|
||||
boolean _tripleNotEquals = (_size != null);
|
||||
if (_tripleNotEquals) {
|
||||
String _res = res;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("BF_FIELD(");
|
||||
String _name = compInst.getName();
|
||||
_builder.append(_name);
|
||||
_builder.append(", ");
|
||||
_builder.append(i);
|
||||
_builder.append(", ");
|
||||
Object _size_1 = compInst.getRange().getSize();
|
||||
_builder.append(((IntegerWithRadix) _size_1).value);
|
||||
_builder.append(");");
|
||||
_builder.newLineIfNotEmpty();
|
||||
res = (_res + _builder);
|
||||
long _i = i;
|
||||
Object _size_2 = compInst.getRange().getSize();
|
||||
i = (_i + ((IntegerWithRadix) _size_2).value);
|
||||
} else {
|
||||
Object _left = compInst.getRange().getLeft();
|
||||
final long start = ((IntegerWithRadix) _left).value;
|
||||
Object _right = compInst.getRange().getRight();
|
||||
final long end = ((IntegerWithRadix) _right).value;
|
||||
String _res_1 = res;
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("BF_FIELD(");
|
||||
String _name_1 = compInst.getName();
|
||||
_builder_1.append(_name_1);
|
||||
_builder_1.append(", ");
|
||||
_builder_1.append(end);
|
||||
_builder_1.append(", ");
|
||||
_builder_1.append(((start - end) + 1));
|
||||
_builder_1.append(");");
|
||||
_builder_1.newLineIfNotEmpty();
|
||||
res = (_res_1 + _builder_1);
|
||||
long _max = Math.max(start, end);
|
||||
long _plus = (_max + 1);
|
||||
i = _plus;
|
||||
}
|
||||
}
|
||||
}
|
||||
_xblockexpression = res;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
}
|
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/messages/.gitignore
vendored
Normal file
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/messages/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/RDLSyntaxErrorMessageProvider.java
|
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/scoping/.gitignore
vendored
Normal file
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/scoping/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/RDLScopeProvider.java
|
@ -5,16 +5,10 @@ package com.minres.rdl.scoping;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.minres.rdl.rdl.ComponentDefinition;
|
||||
import com.minres.rdl.rdl.ComponentInstance;
|
||||
import com.minres.rdl.rdl.Entity;
|
||||
import com.minres.rdl.rdl.EnumDefinition;
|
||||
import com.minres.rdl.rdl.Include;
|
||||
import com.minres.rdl.rdl.NamedInstantiation;
|
||||
import com.minres.rdl.rdl.Root;
|
||||
import com.minres.rdl.scoping.AbstractRDLScopeProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
@ -52,81 +46,6 @@ public class RDLScopeProvider extends AbstractRDLScopeProvider {
|
||||
return Scopes.scopeFor(compDefs);
|
||||
}
|
||||
|
||||
protected IScope _getScopeWithInstancesAndEnums(final ComponentDefinition componentDef) {
|
||||
ArrayList<ComponentInstance> res = new ArrayList<ComponentInstance>();
|
||||
EList<NamedInstantiation> _namedInstantiations = componentDef.getNamedInstantiations();
|
||||
for (final NamedInstantiation inst : _namedInstantiations) {
|
||||
int _size = inst.getComponentInstances().size();
|
||||
boolean _greaterThan = (_size > 0);
|
||||
if (_greaterThan) {
|
||||
res.addAll(inst.getComponentInstances());
|
||||
}
|
||||
}
|
||||
EList<ComponentDefinition> _componentDefinitions = componentDef.getComponentDefinitions();
|
||||
for (final ComponentDefinition definition : _componentDefinitions) {
|
||||
if (((definition.getImmediateInstantiation() != null) && (definition.getImmediateInstantiation().getComponentInstances().size() > 0))) {
|
||||
res.addAll(definition.getImmediateInstantiation().getComponentInstances());
|
||||
}
|
||||
}
|
||||
EList<EnumDefinition> _enumDefinitions = componentDef.getEnumDefinitions();
|
||||
Iterable<Entity> _plus = Iterables.<Entity>concat(res, _enumDefinitions);
|
||||
return Scopes.scopeFor(_plus, this.getScopeWithInstancesAndEnums(componentDef.eContainer()));
|
||||
}
|
||||
|
||||
protected IScope _getScopeWithInstancesAndEnums(final Root root) {
|
||||
ArrayList<ComponentInstance> res = new ArrayList<ComponentInstance>();
|
||||
EList<NamedInstantiation> _namedInstantiations = root.getNamedInstantiations();
|
||||
for (final NamedInstantiation instantiation : _namedInstantiations) {
|
||||
int _size = instantiation.getComponentInstances().size();
|
||||
boolean _greaterThan = (_size > 0);
|
||||
if (_greaterThan) {
|
||||
res.addAll(instantiation.getComponentInstances());
|
||||
}
|
||||
}
|
||||
EList<ComponentDefinition> _componentDefinitions = root.getComponentDefinitions();
|
||||
for (final ComponentDefinition definition : _componentDefinitions) {
|
||||
if (((definition.getImmediateInstantiation() != null) && (definition.getImmediateInstantiation().getComponentInstances().size() > 0))) {
|
||||
res.addAll(definition.getImmediateInstantiation().getComponentInstances());
|
||||
}
|
||||
}
|
||||
List<EnumDefinition> enums = EcoreUtil2.<EnumDefinition>getAllContentsOfType(root, EnumDefinition.class);
|
||||
EList<Include> _includes = root.getIncludes();
|
||||
for (final Include incl : _includes) {
|
||||
{
|
||||
final Resource resource = EcoreUtil2.getResource(root.eResource(), incl.getImportURI());
|
||||
EObject _head = IterableExtensions.<EObject>head(resource.getContents());
|
||||
List<EnumDefinition> _allContentsOfType = EcoreUtil2.<EnumDefinition>getAllContentsOfType(((Root) _head), EnumDefinition.class);
|
||||
Iterables.<EnumDefinition>addAll(enums, _allContentsOfType);
|
||||
}
|
||||
}
|
||||
Iterable<Entity> _plus = Iterables.<Entity>concat(res, enums);
|
||||
return Scopes.scopeFor(_plus);
|
||||
}
|
||||
|
||||
private Root root(final EObject definition) {
|
||||
EObject container = definition.eContainer();
|
||||
while ((!(container instanceof Root))) {
|
||||
container = container.eContainer();
|
||||
}
|
||||
return ((Root) container);
|
||||
}
|
||||
|
||||
private ComponentDefinition componentDefinition(final EObject obj) {
|
||||
EObject container = obj.eContainer();
|
||||
while ((!(container instanceof Root))) {
|
||||
{
|
||||
if ((container instanceof NamedInstantiation)) {
|
||||
return ((NamedInstantiation)container).getComponent();
|
||||
}
|
||||
if ((container instanceof ComponentDefinition)) {
|
||||
return ((ComponentDefinition)container);
|
||||
}
|
||||
container = container.eContainer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IScope getScopeWithComponentDefinition(final EObject componentDef) {
|
||||
if (componentDef instanceof ComponentDefinition) {
|
||||
return _getScopeWithComponentDefinition((ComponentDefinition)componentDef);
|
||||
@ -137,15 +56,4 @@ public class RDLScopeProvider extends AbstractRDLScopeProvider {
|
||||
Arrays.<Object>asList(componentDef).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public IScope getScopeWithInstancesAndEnums(final EObject componentDef) {
|
||||
if (componentDef instanceof ComponentDefinition) {
|
||||
return _getScopeWithInstancesAndEnums((ComponentDefinition)componentDef);
|
||||
} else if (componentDef instanceof Root) {
|
||||
return _getScopeWithInstancesAndEnums((Root)componentDef);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " +
|
||||
Arrays.<Object>asList(componentDef).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/validation/.gitignore
vendored
Normal file
1
com.minres.rdl.parent/com.minres.rdl/xtend-gen/com/minres/rdl/validation/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/RDLValidator.java
|
Reference in New Issue
Block a user