Initial checkin

This commit is contained in:
2021-09-25 16:22:15 +02:00
commit 07831ef4fc
41 changed files with 19782 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

6
com.minres.coredsl.json/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
target
*.java_trace
*.java._trace
*.xtendbin
/xtend-gen/
/.settings/

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.coredsl.json</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,21 @@
Manifest-Version: 1.0
Automatic-Module-Name: com.minres.coredsl.json
Bundle-ManifestVersion: 2
Bundle-Vendor: MINRES Technologies GmbH
Bundle-Version: 2.0.0.qualifier
Bundle-SymbolicName: com.minres.coredsl.json;singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: com.minres.coredsl;bundle-version="1.0.0",
org.eclipse.equinox.common;bundle-version="3.5.0",
org.eclipse.emf.ecore,
org.eclipse.emf.common,
org.eclipse.equinox.preferences;bundle-version="3.8.0",
org.eclipse.xtend.lib;bundle-version="2.14.0",
org.eclipse.xtext;bundle-version="2.22.0",
org.apache.commons.logging;bundle-version="1.2.0",
org.json;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: com.minres.coredsl.json,
com.minres.coredsl.json.preferences,
picocli
Import-Package: org.apache.log4j

View File

@@ -0,0 +1,5 @@
source.. = src/,\
xtend-gen/
bin.includes = .,\
META-INF/
bin.excludes = **/*.xtend

View File

@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>com.minres.coredsl</groupId>
<artifactId>com.minres.coredsl.json.parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>com.minres.coredsl.json</artifactId>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets combine.children="append">
<fileset>
<directory>xtend-gen/</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,32 @@
package com.minres.coredsl.json
import com.google.inject.Binder
import com.google.inject.Provider
import com.minres.coredsl.CoreDslRuntimeModule
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGenerator2
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.xtext.generator.IOutputConfigurationProvider
import javax.inject.Singleton
import com.minres.coredsl.json.GeneratorOutputConfigurationProvider
/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
@SuppressWarnings("all") class CoreDslGeneratorModule extends CoreDslRuntimeModule {
override void configure(Binder binder) {
super.configure(binder);
//binder.bind(TemplateEngine).to(SimpleTemplateEngine);
binder.bind(IOutputConfigurationProvider)
.to(GeneratorOutputConfigurationProvider)
.in(Singleton);
binder.bind(IFileSystemAccess2)
.to(JavaIoFileSystemAccess)
}
def Class<? extends IGenerator2> bindIGenerator2() {
// return DummyGenerator.class;
return typeof(CoreDslJsonGenerator)
}
}

View File

@@ -0,0 +1,17 @@
/*
* generated by Xtext 2.22.0
*/
package com.minres.coredsl.json
import com.google.inject.Injector
import com.google.inject.Guice
/**
* Initialization support for running Xtext languages without Equinox extension registry.
*/
class CoreDslGeneratorStandaloneSetup extends com.minres.coredsl.CoreDslStandaloneSetupGenerated {
override Injector createInjector() {
return Guice.createInjector(new CoreDslGeneratorModule());
}
}

View File

@@ -0,0 +1,106 @@
/*
* generated by Xtext 2.13.0
*/
package com.minres.coredsl.json
import com.google.inject.Inject
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 com.minres.coredsl.coreDsl.CoreDef
import com.minres.coredsl.coreDsl.Instruction
import com.minres.coredsl.coreDsl.InstructionSet
import org.apache.log4j.Logger
import com.minres.coredsl.coreDsl.Encoding
import com.minres.coredsl.coreDsl.BitField
import com.minres.coredsl.coreDsl.BitValue
import java.util.List
import com.minres.coredsl.coreDsl.AttributeName
import com.minres.coredsl.coreDsl.ISA
import org.json.JSONObject
import org.json.JSONArray
import com.minres.coredsl.util.BigIntegerWithRadix
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class CoreDslJsonGenerator extends AbstractGenerator {
val logger = Logger.getLogger(typeof(CoreDslJsonGenerator));
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
for (e : resource.allContents.toIterable.filter(CoreDef)) {
val root = new JSONObject()
root.put('instructions', e.compile)
fsa.generateFile(e.name + ".json", root.toString)
}
}
def Boolean isHls(Instruction inst){
val instrSet = inst.eContainer as ISA;
!(inst.attributes.filter[it.type==AttributeName.HLS].isEmpty &&
instrSet.attributes.filter[it.type==AttributeName.HLS].isEmpty)
}
def JSONArray compile(CoreDef coreDef) {
val insts = coreDef.allInstr
val enabled_insts = insts.filter[it.isHls]
val res = enabled_insts.map[ inst | inst.jsonDescr ].toList
return res.length>0?new JSONArray(res) :new JSONArray()
}
def JSONObject jsonDescr(Instruction inst){
val ret = new JSONObject();
ret.put("decoding", inst.encoding.fields.map[it.asString].join(' '))
ret.put("name", inst.name);
ret.put('disassembly', inst.disass!= null? inst.name.toLowerCase + ' ' + inst.disass.toLowerCase : inst.name)
ret.put('execution', inst.behavior.toString)
ret.put('restrictions', '')
}
def Iterable<Instruction> allInstr(CoreDef core) {
val unique = newLinkedHashMap
val instrList = if (core.contributingType.size == 0)
core.instructions
else {
val instrSets = core.contributingType?.map[InstructionSet i|i.allInstructionSets].flatten
val seen = newLinkedHashSet
seen.addAll(instrSets)
seen.map[InstructionSet i|i.instructions].flatten
}
for (Instruction i : instrList) {
if (i.eContainer instanceof InstructionSet)
logger.trace("adding instruction " + i.name + " of " + (i.eContainer as InstructionSet).name)
if (i.eContainer instanceof CoreDef)
logger.trace("adding instruction " + i.name + " of " + (i.eContainer as CoreDef).name)
unique.put(i.name, i)
}
val instLut = newLinkedHashMap()
for (Instruction i : unique.values) {
logger.trace("adding encoding " + i.encoding.bitEncoding + " for instruction " + i.name)
instLut.put(i.encoding.bitEncoding, i)
}
return instLut.values
}
def List<InstructionSet> allInstructionSets(InstructionSet core) {
val s = if(core.superType !== null) core.superType.allInstructionSets else newLinkedList
s.add(core)
return s
}
def String getBitEncoding(Encoding encoding) '''«FOR field : encoding.fields»«field.regEx»«ENDFOR»'''
def dispatch getRegEx(BitField i) '''«FOR idx : i.right.value.intValue .. i.left.value.intValue».«ENDFOR»'''
def dispatch getRegEx(BitValue i) '''«i.value.toString(2)»'''
def dispatch asString(BitField i) '''«i.name»[«i.left.value.intValue»:«i.right.value.intValue»]'''
def dispatch asString(BitValue i) {
(i.value as BigIntegerWithRadix).toCString(2)
}
}

View File

@@ -0,0 +1,31 @@
package com.minres.coredsl.json
import java.util.Set
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IOutputConfigurationProvider
import org.eclipse.xtext.generator.OutputConfiguration
class GeneratorOutputConfigurationProvider implements IOutputConfigurationProvider {
public static final String GEN_ONCE_OUTPUT = "gen-once"
/**
* @return a set of {@link OutputConfiguration} available for the generator
*/
override Set<OutputConfiguration> getOutputConfigurations() {
var OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess::DEFAULT_OUTPUT)
defaultOutput.setDescription("Output Folder")
defaultOutput.setOutputDirectory("./src-gen")
defaultOutput.setOverrideExistingResources(true)
defaultOutput.setCreateOutputDirectory(true)
defaultOutput.setCleanUpDerivedResources(true)
defaultOutput.setSetDerivedProperty(true)
var OutputConfiguration readonlyOutput = new OutputConfiguration(GEN_ONCE_OUTPUT)
readonlyOutput.setDescription("Read-only Output Folder")
readonlyOutput.setOutputDirectory("./src")
readonlyOutput.setOverrideExistingResources(false)
readonlyOutput.setCreateOutputDirectory(true)
readonlyOutput.setCleanUpDerivedResources(false)
readonlyOutput.setSetDerivedProperty(false)
return newHashSet(defaultOutput, readonlyOutput)
}
}

View File

@@ -0,0 +1,115 @@
/*
* generated by Xtext 2.11.0
*/
package com.minres.coredsl.json
import java.io.File
import java.util.concurrent.Callable
import org.apache.log4j.Logger
import picocli.CommandLine.Parameters
import picocli.CommandLine.Option
import picocli.CommandLine
import com.google.inject.Inject
import com.google.inject.Provider
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.validation.IResourceValidator
import org.eclipse.xtext.generator.GeneratorDelegate
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.emf.mwe.utils.ProjectMapping
import org.eclipse.emf.mwe.utils.StandaloneSetup
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.emf.common.util.URI
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.validation.CheckMode
import org.eclipse.xtext.parser.ParseException
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.generator.IFileSystemAccess
import picocli.CommandLine.ITypeConverter
import java.lang.reflect.MalformedParametersException
import org.apache.log4j.Level
import org.eclipse.emf.ecore.resource.Resource
class Main implements Callable<Integer> {
@Parameters(paramLabel="input_file", arity="1..*", description="one ore more files to process")
public File[] files;
@Option(names=#["-o", "--output-file"], description="output file")
public File outputFile;
@Option(names=#["-r", "--repository"], description="repository directory")
public String repository = "";
@Option(names=#["-v", "--verbose"], description="verbose output")
public Boolean verbose = false;
def static main(String[] args) {
val ret = new CommandLine(new Main()).execute(args);
System.exit(ret)
}
override Integer call() throws Exception {
Logger.rootLogger.level = verbose?Level.DEBUG:Level.INFO
val injector = new CoreDslGeneratorStandaloneSetup().createInjectorAndDoEMFRegistration
injector.getInstance(GeneratorMain).run(this)
return 0;
}
}
class GeneratorMain {
static val logger = Logger.getLogger(typeof(GeneratorMain));
@Inject Provider<ResourceSet> resourceSetProvider
@Inject IResourceValidator validator
@Inject GeneratorDelegate generator
@Inject JavaIoFileSystemAccess fsa
def run(Main params) {
if (params.repository.length > 0) {
val projectMapping = new ProjectMapping
projectMapping.projectName = "CoreDSL Repository"
projectMapping.path = params.repository
new StandaloneSetup().addProjectMapping(projectMapping)
}
try {
for (file : params.files) {
// Load the resource
val resourceSet = resourceSetProvider.get as XtextResourceSet
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
val resource = resourceSet.getResource(URI.createFileURI(file.absolutePath), true)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
logger.error("Error validating " + resource.URI)
issues.forEach[logger.error(it)]
throw new ParseException("error validating " + resource.URI)
}
// Configure and start the generator
logger.info('Code generation for ' + file + ' finished')
}
} catch (MalformedParametersException | IllegalArgumentException | ParseException e) {
logger.error("Command line error " + e.message, e)
return -1
}
return 0
}
def runGenerator(Resource resource, File template, File outputFile){
logger.info('Running generator to generate '+outputFile+' using template '+template)
if(template !== null) System.properties.put("template", template)
if(outputFile !== null){
System.properties.put("outputFile", outputFile.name)
fsa.outputPath = outputFile.parentFile.absolutePath
} else
fsa.outputPath = './'
val outputCfg = fsa.outputConfigurations.get(IFileSystemAccess.DEFAULT_OUTPUT)
outputCfg.setOverrideExistingResources(true)
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
generator.doGenerate(resource, fsa, context)
}
}

View File

@@ -0,0 +1,15 @@
package com.minres.coredsl.json.preferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
public class CoreDSLPreferences {
public static String getTemplateDir() {
return getPreferenceStore().get(PreferenceConstants.P_TEMPLATE_DIR, System.getProperty(PreferenceConstants.P_TEMPLATE_DIR));
}
public static IEclipsePreferences getPreferenceStore() {
return InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
}
}

View File

@@ -0,0 +1,12 @@
package com.minres.coredsl.json.preferences;
/**
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
public static final String SCOPE_NAME = "com.minres.coredsl.json";
public static final String P_TEMPLATE_DIR = "booleanCsvPreference";
}

View File

@@ -0,0 +1,31 @@
package com.minres.coredsl.json.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
/**
* Class used to initialize default preference values.
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
* initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IEclipsePreferences store = getPreferenceStore();
String value = System.getProperty(PreferenceConstants.P_TEMPLATE_DIR);
if(value!=null){
store.put(PreferenceConstants.P_TEMPLATE_DIR, "byte");
} else
store.put(PreferenceConstants.P_TEMPLATE_DIR, "src/templates");
}
public static IEclipsePreferences getPreferenceStore() {
return DefaultScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
}
}

File diff suppressed because it is too large Load Diff