2017-09-12 12:48:21 +02:00
|
|
|
/*
|
|
|
|
* generated by Xtext 2.12.0
|
|
|
|
*/
|
|
|
|
package com.minres.rdl.generator
|
|
|
|
|
2017-09-19 18:08:17 +02:00
|
|
|
import com.minres.rdl.rdl.ComponentDefinition
|
|
|
|
import com.minres.rdl.rdl.ComponentDefinitionType
|
2017-09-12 12:48:21 +02:00
|
|
|
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
|
2018-06-04 20:55:10 +02:00
|
|
|
import static extension com.minres.rdl.RdlUtil.*
|
2020-10-08 08:40:04 +02:00
|
|
|
import java.util.Map
|
2017-09-12 12:48:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates code from your model files on save.
|
|
|
|
*
|
|
|
|
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
|
|
|
|
*/
|
|
|
|
class RDLGenerator extends AbstractGenerator {
|
|
|
|
|
|
|
|
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
|
2017-09-19 18:08:17 +02:00
|
|
|
resource.resourceSet.allContents.filter[ it instanceof ComponentDefinition].map[it as ComponentDefinition].forEach[
|
2020-10-08 08:40:04 +02:00
|
|
|
val genMap = it.fileGenerator
|
|
|
|
if(genMap!==null) genMap.forEach[p1, gen |
|
2017-09-19 18:08:17 +02:00
|
|
|
val header = gen.generateHeader
|
2020-10-08 08:40:04 +02:00
|
|
|
if(header!==null && header.length>0)
|
|
|
|
fsa.generateFile(p1+'/'+it.effectiveName+'.h', fsa.outputConfig('incl-out'), header)
|
2017-09-19 18:08:17 +02:00
|
|
|
val source = gen.generateSource
|
2020-10-08 08:40:04 +02:00
|
|
|
if(source!==null && source.length>0)
|
|
|
|
fsa.generateFile(p1+'/'+it.effectiveName+'.cpp', fsa.outputConfig('src-out'), source)
|
|
|
|
]
|
2017-09-19 18:08:17 +02:00
|
|
|
]
|
|
|
|
}
|
2018-06-04 20:55:10 +02:00
|
|
|
|
2020-10-08 08:40:04 +02:00
|
|
|
def Map<String, RdlBaseGenerator> fileGenerator(ComponentDefinition definition){
|
2017-09-19 18:08:17 +02:00
|
|
|
switch(definition.type){
|
2020-10-08 08:40:04 +02:00
|
|
|
case ComponentDefinitionType.REGFILE: #{'vp' -> new RegfileGenerator(definition), 'fw' -> new FwRegfileGenerator(definition)}
|
|
|
|
case ComponentDefinitionType.ADDRMAP: #{'vp' -> new AddrmapGenerator(definition), 'fw' -> new FwAddrmapGenerator(definition)}
|
2017-09-19 18:08:17 +02:00
|
|
|
default: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def String outputConfig(IFileSystemAccess2 fsa, String string){
|
|
|
|
var output_config = string
|
|
|
|
try {fsa.getURI("", output_config)} catch (Exception e) {output_config ='DEFAULT_OUTPUT'}
|
|
|
|
return output_config
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|