Initial checkin

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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.launch/

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.coredsl.json.parent</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<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"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="GROOVY_SUPPORT"/>
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,2 @@
/target/
/.settings/

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.coredsl.json.repository</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,95 @@
import static groovy.io.FileType.FILES
import java.nio.file.Files
import java.nio.file.Paths
import java.util.zip.ZipEntry
def needed_jars = [
/org\.eclipse\.xtext/,
/org\.eclipse\.emf\.ecore\.xmi/,
/org\.eclipse\.emf\.ecore/,
/org\.eclipse\.emf\.common/,
/org\.antlr\.runtime/,
/com\.google\.inject/,
/org\.eclipse\.emf\.mwe\.core/,
/org\.apache\.commons\.cli/,
/org\.eclipse\.emf\.mwe2\.runtime/,
/org\.eclipse\.emf\.mwe\.utils/,
/org\.eclipse\.xtext\.util/,
/com\.google\.guava/,
/javax\.inject/,
/org\.eclipse\.xtext\.xbase/,
/org\.eclipse\.xtext\.common\.types/,
/org\.eclipse\.xtend\.lib/,
/org\.eclipse\.xtext\.xbase\.lib/,
/org\.eclipse\.xtend\.lib\.macro/,
/org\.eclipse\.equinox\.common/,
/eclipse-trace/,
/groovy-eclipse/,
/ivy-2\.5\.0\.jar/,
/groovy-3\.0\.\d-indy/,
/groovy-templates-3\.0\.\d/,
/org\.eclipse\.xtext\.xtext\.generator/,
/org\.eclipse\.emf\.codegen\.ecore/,
/org\.eclipse\.emf\.codegen/,
/org\.eclipse\.emf\.mwe2\.launch/,
/org\.eclipse\.emf\.mwe2\.language/,
/org\.eclipse\.emf\.mwe2\.lib/,
/org\.objectweb\.asm/,
/org\.apache\.commons\.logging/,
/org\.apache\.log4j/,
/com\.ibm\.icu/,
/com\.minres\.coredsl/,
/com\.minres\.coredsl\.json\.dbt_rise/
]
// Collect all jars.
def jars = []
def root = new File(project.getBasedir(), 'target/classes')
def libs = new File(project.getBasedir(), 'target/classes/lib')
def meta_inf = new File(project.getBasedir(), 'target/classes/META-INF')
libs.eachFileRecurse (FILES) { file ->
if(file.name =~/org\.codehaus\.groovy_/) { // we need to unpack this one sinc it is already jar in jar
println("Unpacking ${file}")
def zipFile = new java.util.zip.ZipFile(file)
zipFile.entries().findAll {ZipEntry entry -> !entry.directory && entry.name =~/\.jar$/}.each {ZipEntry entry ->
def outFile = new File(libs, entry.name.split(/\//)[-1])
println "Extracting file ${entry.name} to ${outFile.path} with size ${entry.size}bytes (${entry.compressedSize}bytes)"
Files.copy(zipFile.getInputStream(entry), outFile.toPath())
}
}
}
libs.eachFileRecurse (FILES) { file ->
def fileName = file.name.split("/")[-1]
if(needed_jars.find{fileName =~ it}) {
println "Adding $file to the included jars"
jars << root.toURI().relativize(file.toURI()).toString()
} else {
file.delete()
}
}
def zipFile = new java.util.zip.ZipFile(new File(project.getBasedir(), 'jar-in-jar-loader.zip'))
zipFile.entries().each {ZipEntry it ->
def path = Paths.get("${root}/", it.name)
if(it.directory){
Files.createDirectories(path)
} else {
def parentDir = path.getParent()
if (!Files.exists(parentDir)) {
Files.createDirectories(parentDir)
}
Files.deleteIfExists(path)
println "Extracting file ${it.name} to ${path} with size ${it.size}bytes (${it.compressedSize}bytes)"
Files.copy(zipFile.getInputStream(it), path)
}
}
// Write the manifest file.
Files.createDirectories( Paths.get(meta_inf.absolutePath))
def mf = new File(project.getBasedir(), 'target/classes/META-INF/MANIFEST.MF')
mf.write ''
mf << 'Manifest-Version: 1.0\n'
mf << 'Rsrc-Class-Path: ./ ' + jars.join(' ') + '\n'
mf << 'Rsrc-Main-Class: com.minres.coredsl.json.Main\n'
mf << 'Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\n'

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="com.minres.coredsl"/>
<bundle id="com.minres.coredsl.json"/>
</site>

View File

@ -0,0 +1,109 @@
<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>
<artifactId>com.minres.coredsl.json.parent</artifactId>
<groupId>com.minres.coredsl</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>com.minres.coredsl.json.standalone</artifactId>
<packaging>eclipse-repository</packaging>
<properties>
<jarinjarloader.version>1.5-SNAPSHOT</jarinjarloader.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/repository/plugins</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.alexecollins.maven.plugin</groupId>
<artifactId>script-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<language>groovy</language>
<scriptFile>assemble.groovy</scriptFile>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-bsf</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar manifest="${project.build.directory}/classes/META-INF/MANIFEST.MF"
destfile="${project.build.directory}/com.minres.coredsl.json-${project.version}.jar">
<fileset dir="${project.build.directory}/classes" />
</jar>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jcenter-bintray</id>
<name>Bintray JCenter Maven Repository</name>
<layout>default</layout>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@ -0,0 +1 @@
/.settings/

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.coredsl.json.target</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="com.minres.coredsl.json.target" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.feature.group" version="0.0.0"/>
<unit id="org.eclipse.platform.feature.group" version="0.0.0"/>
<unit id="org.eclipse.pde.feature.group" version="0.0.0"/>
<unit id="org.eclipse.draw2d.feature.group" version="0.0.0"/>
<unit id="org.eclipse.emf.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2020-06"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.emf.mwe2.launcher.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/modeling/emft/mwe/updates/releases/2.11.3/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/modeling/tmf/xtext/updates/releases/2.22.0/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="com.google.gson" version="2.8.2.v20180104-1110"/>
<unit id="org.antlr.runtime" version="3.2.0.v201101311130"/>
<unit id="org.junit" version="4.12.0.v201504281640"/>
<unit id="org.junit.jupiter.api" version="5.6.0.v20200203-2009"/>
<unit id="org.junit.jupiter.engine" version="5.6.0.v20200203-2009"/>
<unit id="org.junit.platform.commons" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.engine" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.launcher" version="1.6.0.v20200203-2009"/>
<unit id="org.junit.platform.runner" version="1.6.0.v20200203-2009"/>
<unit id="org.opentest4j" version="1.2.0.v20190826-0900"/>
<unit id="org.objectweb.asm" version="8.0.1.v20200420-1007"/>
<unit id="org.objectweb.asm.tree" version="8.0.1.v20200420-1007"/>
<unit id="io.github.classgraph" version="4.8.35.v20190528-1517"/>
<repository location="https://download.eclipse.org/tools/orbit/downloads/2020-06"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://dist.springsource.org/release/GRECLIPSE/e4.16"/>
<unit id="org.codehaus.groovy25.feature.feature.group" version="0.0.0"/>
<unit id="org.codehaus.groovy30.feature.feature.group" version="0.0.0"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://minres.com/download/repository/BundlePool"/>
<unit id="groovy-templates" version="3.0.7"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20201130205003/repository"/>
<unit id="org.json" version="1.0.0.v201011060100"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://artifactory.minres.com/artifactory/eclipse/CoreDSL-2.0.1"/>
<unit id="com.minres.coredsl.feature.feature.group" version="2.0.1.202109251203"/>
<unit id="com.minres.coredsl.feature.source.feature.group" version="2.0.1.202109251203"/>
</location>
</locations>
</target>

View File

@ -0,0 +1,16 @@
<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.target</artifactId>
<packaging>eclipse-target-definition</packaging>
<dependencies>
</dependencies>
</project>

View File

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

View File

@ -0,0 +1,7 @@
/target/
*._trace
*.xtendbin
*.xtextbin
/.settings/
/output/
/xtend-gen/

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.coredsl.json.tests</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,16 @@
Manifest-Version: 1.0
Automatic-Module-Name: com.minres.coredsl.json.dbt_rise.tests
Bundle-ManifestVersion: 2
Bundle-Vendor: MINRES Technologies GmbH
Bundle-Version: 2.0.0.qualifier
Bundle-SymbolicName: com.minres.coredsl.json.tests;singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: com.minres.coredsl.json;bundle-version="1.0.0",
com.minres.coredsl,
org.eclipse.xtext.xbase.lib;bundle-version="2.14.0",
org.junit.jupiter.api;bundle-version="[5.0.0,6.0.0)",
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.json;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: com.minres.coredsl.json.tests;x-internal=true

View File

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

View File

@ -0,0 +1,69 @@
Core TGC_X {
architectural_state {
unsigned int XLEN=32, FLEN=32;
unsigned CSR_SIZE = 4096;
unsigned REG_FILE_SIZE=32;
unsigned fencei=1;
register unsigned PC [[is_pc]];
register unsigned X[REG_FILE_SIZE];
extern char MEM[1<<XLEN];
extern unsigned CSR[CSR_SIZE];
extern unsigned<XLEN> FENCE;
}
instructions {
ADDI [[hls]] {
encoding: imm[11:0] :: rs1[4:0] :: 0b000 :: rd[4:0] :: 0b0010011;
behavior: {
X[rd] = X[rs1] + imm;
}
}
SLTI {
encoding: imm[11:0] :: rs1[4:0] :: 0b010 :: rd[4:0] :: 0b0010011;
behavior: {
X[rd] = X[rs1] < imm? 1 : 0;
}
}
SW {
encoding: imm[11:5] :: rs2[4:0] :: rs1[4:0] :: 0b010 :: imm[4:0] :: 0b0100011;
behavior: {
int offset = X[rs1] + imm;
MEM[offset] = X[rs2];
}
}
LW {
encoding: imm[11:0] :: rs1[4:0] :: 0b010 :: rd[4:0] :: 0b0000011;
args_disass:"{name(rd)}, {imm}({name(rs1)})";
behavior: if(rd!=0) X[rd]=(int)MEM[X[rs1] + imm];
}
LB {
encoding: imm[11:0] :: rs1[4:0] :: 0b000 :: rd[4:0] :: 0b0000011;
args_disass:"{name(rd)}, {imm}({name(rs1)})";
behavior: if(rd!=0) X[rd]=MEM[X[rs1] + imm];
}
LBU {
encoding: imm[11:0] :: rs1[4:0] :: 0b100 :: rd[4:0] :: 0b0000011;
args_disass:"{name(rd)}, {imm}({name(rs1)})";
behavior: if(rd!=0) X[rd]=(unsigned char)MEM[X[rs1] + imm];
}
JAL[[no_cont]] {
encoding:imm[20:20] :: imm[10:1] :: imm[11:11] :: imm[19:12] :: rd[4:0] :: 0b1101111;
behavior: {
if(rd!=0) X[rd] = (unsigned)PC;
PC = PC+imm;
}
}
CSRRCI {
encoding: csr[11:0] :: zimm[4:0] :: 0b111 :: rd[4:0] :: 0b1110011;
args_disass:"{name(rd)}, {csr}, {zimm:#0x}";
behavior: {
unsigned<XLEN> res = CSR[csr];
if(rd!=0) X[rd] = res;
if(zimm!=0) CSR[csr] = res & ~((unsigned<XLEN>)zimm);
}
}
FENCE_I[[flush]] {
encoding: imm[11:0] :: rs1[4:0] :: 0b001 :: rd[4:0] :: 0b0001111 ;
behavior: FENCE[fencei] = imm;
}
}
}

View File

@ -0,0 +1,47 @@
InstructionSet RV32I {
architectural_state {
unsigned int XLEN=32, FLEN=32;
unsigned CSR_SIZE = 4096;
unsigned REG_FILE_SIZE=32;
unsigned fencei=1;
register unsigned PC [[is_pc]];
register unsigned X[REG_FILE_SIZE];
extern char MEM[1<<XLEN];
extern unsigned CSR[CSR_SIZE];
extern unsigned<XLEN> FENCE;
}
instructions [[hls]]{
ADDI [[flush]]{
encoding: imm[11:0] :: rs1[4:0] :: 0b000 :: rd[4:0] :: 0b0010011;
behavior: {
X[rd] = X[rs1] + imm;
}
}
SLTI {
encoding: imm[11:0] :: rs1[4:0] :: 0b010 :: rd[4:0] :: 0b0010011;
behavior: {
X[rd] = X[rs1] < imm? 1 : 0;
}
}
SLTIU {
encoding: imm[11:0] :: rs1[4:0] :: 0b011 :: rd[4:0] :: 0b0010011;
behavior: {
X[rd] = X[rs1] < imm? 1 : 0;
}
}
SW {
encoding: imm[11:5] :: rs2[4:0] :: rs1[4:0] :: 0b010 :: imm[4:0] :: 0b0100011;
behavior: {
int offset = X[rs1] + imm;
MEM[offset] = X[rs2];
}
}
JAL[[no_cont]] {
encoding:imm[20:20] :: imm[10:1] :: imm[11:11] :: imm[19:12] :: rd[4:0] :: 0b1101111;
behavior: {
if(rd!=0) X[rd] = (unsigned)PC;
PC = PC+imm;
}
}
}
}

View File

@ -0,0 +1,22 @@
<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.tests</artifactId>
<packaging>eclipse-test-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

View File

@ -0,0 +1,171 @@
package com.minres.coredsl.json.tests
import com.google.inject.Inject
import com.minres.coredsl.coreDsl.CoreDef
import com.minres.coredsl.coreDsl.DescriptionContent
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.generator.IGenerator2
import org.eclipse.xtext.generator.InMemoryFileSystemAccess
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.util.CancelIndicator
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
import static extension com.google.common.io.CharStreams.*
import com.minres.coredsl.coreDsl.InstructionSet
import java.io.FileReader
import org.eclipse.xtext.testing.validation.ValidationTestHelper
@RunWith(XtextRunner)
@InjectWith(CoreDslInjectorProvider)
class CoreDslGenerationTest{
@Inject IGenerator2 generator
@Inject extension ParseHelper<DescriptionContent> parseHelper
@Inject ValidationTestHelper validator
val isa_rv32i = '''
Core RV32I {
constants {
unsigned int XLEN, FLEN;
unsigned CSR_SIZE = 4096;
unsigned REG_FILE_SIZE=32;
}
registers {
[[is_pc]] int PC ;
int X[REG_FILE_SIZE];
}
address_spaces {
char MEM[1<<XLEN];
unsigned CSR[CSR_SIZE];
}
instructions {
ADDI {
encoding: imm[11:0]s :: rs1[4:0] :: b000 :: rd[4:0] :: b0010011;
behavior: {
X[rd] = X[rs1] + imm;
}
}
SLTI {
encoding: imm[11:0]s :: rs1[4:0] :: b010 :: rd[4:0] :: b0010011;
behavior: {
X[rd] = X[rs1] < imm? 1 : 0;
}
}
SLTIU {
encoding: imm[11:0]s :: rs1[4:0] :: b011 :: rd[4:0] :: b0010011;
behavior: {
X[rd] = X[rs1] < imm? 1 : 0;
}
}
SW {
encoding: imm[11:5]s :: rs2[4:0] :: rs1[4:0] :: b010 :: imm[4:0]s :: b0100011;
behavior: {
int offset = X[rs1] + imm;
MEM[offset] = X[rs2];
}
}
JAL[[no_cont]] {
encoding:imm[20:20]s :: imm[10:1]s :: imm[11:11]s :: imm[19:12]s :: rd[4:0] :: b1101111;
behavior: {
if(rd!=0) X[rd] = (unsigned)PC;
PC = PC+imm;
}
}
}
}
'''
@Test
def void loadSimpleModel() {
val content = new FileReader('inputs/isa_1.core_desc').readLines.join('\n').parse
validator.assertNoErrors(content)
val InstructionSet result = content.definitions.get(0) as InstructionSet
assertNotNull(result)
assertEquals("RV32I", result.name)
assertNull(result.superType)
assertEquals(4, result.declarations.size())
assertNotNull(result.instructions)
assertEquals(5, result.instructions.size)
val i0 = result.instructions.get(0);
assertEquals("ADDI", i0.name)
assertEquals(5, i0.encoding.fields.size)
val i1 = result.instructions.get(1);
assertEquals("SLTI", i1.name)
assertEquals(5, i1.encoding.fields.size)
val i2 = result.instructions.get(2);
assertEquals("SLTIU", i2.name)
assertEquals(5, i2.encoding.fields.size)
val i3 = result.instructions.get(3);
assertEquals("SW", i3.name)
assertEquals(6, i3.encoding.fields.size)
}
@Test
def void generateCpp() {
val content = parseHelper.parse(isa_rv32i)
assertNotNull(content)
assertEquals(1, content.definitions.size)
val resource = content.eResource
EcoreUtil.resolveAll(resource);
assertEquals(0, resource.errors.size)
assertEquals(0, resource.warnings.size)
val fsa = new InMemoryFileSystemAccess()
generator.doGenerate(content.eResource, fsa, new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
])
println(fsa.textFiles)
assertEquals(1,fsa.textFiles.size)
assertTrue(fsa.textFiles.containsKey("DEFAULT_OUTPUTRV32I.txt"))
// assertEquals(
// '''
// public class Alice {
//
// }
// '''.toString, fsa.textFiles.get(IFileSystemAccess::DEFAULT_OUTPUT+"Alice.java").toString
// )
}
@Test
def void expandCppFile() {
val content = parseHelper.parse(isa_rv32i)
assertNotNull(content)
val resource = content.eResource
EcoreUtil.resolveAll(resource);
assertEquals(0, resource.errors.size)
assertEquals(0, resource.warnings.size)
val CoreDef model = content.definitions.get(0) as CoreDef
assertNotNull(model)
val fsa = new InMemoryFileSystemAccess()
val quote1 = '<27><>'
val quote2 = '<27><>'
fsa.generateFile("vm_" + model.name.toLowerCase + ".in.cpp", "vm-out", '''
/* <20><>quote1<65><31>start generated code<64><65>quote2<65><32> */
InstructionDesriptor instr_descr[0] = {};
/* <20><>quote1<65><31>end generated code<64><65>quote2<65><32> */
''')
generator.doGenerate(model.eResource, fsa, new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
])
println(fsa.textFiles)
assertEquals(2,fsa.textFiles.size)
assertTrue(fsa.textFiles.containsKey("DEFAULT_OUTPUTRV32I.txt"))
// assertEquals(
// '''
// public class Bob {
//
// }
// '''.toString, fsa.textFiles.get(IFileSystemAccess::DEFAULT_OUTPUT+"Bob.java").toString)
}
}

View File

@ -0,0 +1,117 @@
package com.minres.coredsl.json.tests
import com.google.inject.Inject
import com.minres.coredsl.coreDsl.DescriptionContent
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.generator.IGenerator2
import org.eclipse.xtext.generator.InMemoryFileSystemAccess
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.eclipse.xtext.util.CancelIndicator
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
import org.json.JSONObject
import org.json.JSONTokener
import org.json.JSONArray
@RunWith(XtextRunner)
@InjectWith(CoreDslInjectorProvider)
class CoreDslGenerationUnitTest{
@Inject IGenerator2 generator
@Inject extension ParseHelper<DescriptionContent> parseHelper
@Inject ValidationTestHelper validator
def CharSequence addInstructionContext(CharSequence str)'''
InstructionSet TestISA {
architectural_state {
unsigned XLEN;
const unsigned FLEN=32;
register unsigned<32> PC [[is_pc]];
register unsigned<32> X[32];
}
instructions {
«str»
}
}
Core TestCore provides TestISA {
architectural_state {
XLEN=32;
}
}
'''
@Test
def void genDisabledInstr() {
val content = '''
CLI {
encoding: 0b010 :: imm[5:5] :: rd[4:0] :: imm[4:0] :: 0b01;
behavior: {
if(rd == 0) //rd==0 is a hint, so no trap
X[rd] = (unsigned<32>)(signed)imm;
}
}
'''.addInstructionContext.parse
validator.assertNoErrors(content)
val ref = '''
void CLI(){
{
if(rd == 0) *(X+rd) = (uint32_t)(int32_t)sext<6>(imm);
}
}
'''
val fsa = new InMemoryFileSystemAccess()
generator.doGenerate(content.eResource, fsa, new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
])
val res = fsa.textFiles
res.forEach[name, text|
val jsonTokener = new JSONTokener(text.toString)
val json = new JSONObject(jsonTokener);
assertNotNull(json.get("instructions"))
assertTrue(json.get("instructions") instanceof JSONArray)
val instructions = json.get("instructions") as JSONArray
assertEquals(0, instructions.length)
]
}
@Test
def void genEnabledInstr() {
val content = '''
CLI [[hls]]{
encoding: 0b010 :: imm[5:5] :: rd[4:0] :: imm[4:0] :: 0b01;
behavior: {
if(rd == 0) //rd==0 is a hint, so no trap
X[rd] = (unsigned<32>)(signed)imm;
}
}
'''.addInstructionContext.parse
validator.assertNoErrors(content)
val ref = '''
void CLI(){
{
if(rd == 0) *(X+rd) = (uint32_t)(int32_t)sext<6>(imm);
}
}
'''
val fsa = new InMemoryFileSystemAccess()
generator.doGenerate(content.eResource, fsa, new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
])
val res = fsa.textFiles
res.forEach[name, text|
val jsonTokener = new JSONTokener(text.toString)
val json = new JSONObject(jsonTokener);
assertNotNull(json.get("instructions"))
assertTrue(json.get("instructions") instanceof JSONArray)
val instructions = json.get("instructions") as JSONArray
assertEquals(1, instructions.length)
]
}
}

View File

@ -0,0 +1,71 @@
/*
* generated by Xtext 2.22.0
*/
package com.minres.coredsl.json.tests;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.minres.coredsl.CoreDslRuntimeModule;
import com.minres.coredsl.CoreDslStandaloneSetup;
import com.minres.coredsl.json.CoreDslGeneratorModule;
import org.eclipse.xtext.testing.GlobalRegistries;
import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento;
import org.eclipse.xtext.testing.IInjectorProvider;
import org.eclipse.xtext.testing.IRegistryConfigurator;
public class CoreDslInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
protected GlobalStateMemento stateBeforeInjectorCreation;
protected GlobalStateMemento stateAfterInjectorCreation;
protected Injector injector;
static {
GlobalRegistries.initializeDefaults();
}
@Override
public Injector getInjector() {
if (injector == null) {
this.injector = internalCreateInjector();
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
}
return injector;
}
protected Injector internalCreateInjector() {
return new CoreDslStandaloneSetup() {
@Override
public Injector createInjector() {
return Guice.createInjector(createRuntimeModule());
}
}.createInjectorAndDoEMFRegistration();
}
protected CoreDslRuntimeModule createRuntimeModule() {
// make it work also with Maven/Tycho and OSGI
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672
return new CoreDslGeneratorModule() {
@Override
public ClassLoader bindClassLoaderToInstance() {
return CoreDslInjectorProvider.class
.getClassLoader();
}
};
}
@Override
public void restoreRegistry() {
stateBeforeInjectorCreation.restoreGlobalState();
stateBeforeInjectorCreation = null;
}
@Override
public void setupRegistry() {
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
if (injector == null) {
getInjector();
}
stateAfterInjectorCreation.restoreGlobalState();
}
}

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

331
pom.xml Normal file
View File

@ -0,0 +1,331 @@
<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>
<groupId>com.minres.coredsl</groupId>
<version>2.0.0-SNAPSHOT</version>
<artifactId>com.minres.coredsl.json.parent</artifactId>
<packaging>pom</packaging>
<properties>
<xtextVersion>2.22.0</xtextVersion>
<mwe2Version>2.11.3</mwe2Version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- Tycho settings -->
<tycho-version>1.7.0</tycho-version>
<!-- Define overridable properties for tycho-surefire-plugin -->
<platformSystemProperties></platformSystemProperties>
<moduleProperties></moduleProperties>
<systemProperties></systemProperties>
<additionalTestArguments></additionalTestArguments>
</properties>
<modules>
<module>com.minres.coredsl.json.target</module>
<module>com.minres.coredsl.json</module>
<module>com.minres.coredsl.json.tests</module>
<module>com.minres.coredsl.json.repository</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>xtext-dev-bom</artifactId>
<version>${xtextVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-source-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>plugin-source</id>
<goals>
<goal>plugin-source</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-source-feature-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>source-feature</id>
<phase>package</phase>
<goals>
<goal>source-feature</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>attach-p2-metadata</id>
<phase>package</phase>
<goals>
<goal>p2-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<target>
<artifact>
<groupId>com.minres.coredsl</groupId>
<artifactId>com.minres.coredsl.json.target</artifactId>
<version>2.0.0-SNAPSHOT</version>
</artifact>
</target>
<environments>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.xtext.logging</id>
<versionRange>1.2.15</versionRange>
</requirement>
<!-- to get the org.eclipse.osgi.compatibility.state plugin if the target
platform is Luna or later. (backward compatible with kepler and previous
versions) see https://bugs.eclipse.org/bugs/show_bug.cgi?id=492149 -->
<requirement>
<type>eclipse-feature</type>
<id>org.eclipse.rcp</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<version>${xtextVersion}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>xtend-install-debug-info</goal>
<goal>testCompile</goal>
<goal>xtend-test-install-debug-info</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${basedir}/xtend-gen</outputDirectory>
<testOutputDirectory>${basedir}/xtend-gen</testOutputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/xtend-gen</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>
[1.9.1,)
</versionRange>
<goals>
<goal>add-resource</goal>
<goal>add-source</goal>
<goal>add-test-resource</goal>
<goal>add-test-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.eclipse.tycho
</groupId>
<artifactId>
tycho-compiler-plugin
</artifactId>
<versionRange>
[0.23.1,)
</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.eclipse.tycho
</groupId>
<artifactId>
tycho-packaging-plugin
</artifactId>
<versionRange>
[0.23.1,)
</versionRange>
<goals>
<goal>build-qualifier</goal>
<goal>build-qualifier-aggregator</goal>
<goal>validate-id</goal>
<goal>validate-version</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<!--
Can be removed after first generator execution
https://bugs.eclipse.org/bugs/show_bug.cgi?id=480097
-->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<compilerArgument>-err:-forbidden</compilerArgument>
<useProjectSettings>false</useProjectSettings>
</configuration>
</plugin>
<!-- to skip running (and compiling) tests use commandline flag: -Dmaven.test.skip
To skip tests, but still compile them, use: -DskipTests
To allow all tests in a pom to pass/fail, use commandline flag: -fae (fail
at end) -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<!-- THE FOLLOWING LINE MUST NOT BE BROKEN BY AUTOFORMATTING -->
<argLine>${platformSystemProperties} ${systemProperties} ${moduleProperties} ${additionalTestArguments}</argLine>
<failIfNoTests>false</failIfNoTests>
<useUIHarness>false</useUIHarness>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
<repository>
<id>codehaus-snapshots</id>
<name>disable dead 'Codehaus Snapshots' repository, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=481478</name>
<url>http://nexus.codehaus.org/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>codehaus-snapshots</id>
<name>disable dead 'Codehaus Snapshots' repository, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=481478</name>
<url>http://nexus.codehaus.org/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
<id>macos</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<!-- THE FOLLOWING LINE MUST NOT BE BROKEN BY AUTOFORMATTING -->
<platformSystemProperties>-XstartOnFirstThread</platformSystemProperties>
</properties>
</profile>
<profile>
<id>jdk9-or-newer</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<moduleProperties>--add-modules=ALL-SYSTEM</moduleProperties>
</properties>
</profile>
</profiles>
<dependencies>
</dependencies>
</project>