2017-09-19 18:08:17 +02:00
package com.minres.rdl.generator ;
2017-09-20 22:36:20 +02:00
import com.minres.rdl.IntegerWithRadix ;
2018-06-04 20:55:10 +02:00
import com.minres.rdl.RdlUtil ;
2017-09-19 18:08:17 +02:00
import com.minres.rdl.rdl.ComponentDefinition ;
2017-09-20 22:36:20 +02:00
import com.minres.rdl.rdl.ComponentDefinitionType ;
import com.minres.rdl.rdl.ComponentInstance ;
import com.minres.rdl.rdl.Instantiation ;
import org.eclipse.emf.common.util.EList ;
2017-09-19 18:08:17 +02:00
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
2022-02-13 12:40:21 +01:00
public boolean getOverwrite ( ) {
return true ;
}
@Override
public String generateHeader ( final String namespace ) {
2017-09-19 18:08:17 +02:00
StringConcatenation _builder = new StringConcatenation ( ) ;
2018-06-04 20:55:10 +02:00
_builder . append ( " #ifndef _ " ) ;
String _upperCase = RdlUtil . effectiveName ( this . componentDefinition ) . toUpperCase ( ) ;
_builder . append ( _upperCase ) ;
_builder . append ( " _MAP_H_ " ) ;
_builder . newLineIfNotEmpty ( ) ;
_builder . append ( " #define _ " ) ;
String _upperCase_1 = RdlUtil . effectiveName ( this . componentDefinition ) . toUpperCase ( ) ;
_builder . append ( _upperCase_1 ) ;
_builder . append ( " _MAP_H_ " ) ;
_builder . newLineIfNotEmpty ( ) ;
2017-09-19 18:08:17 +02:00
_builder . append ( " // need double braces, see https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list#6894191 " ) ;
_builder . newLine ( ) ;
2022-02-13 12:40:21 +01:00
_builder . append ( " const std::array<scc::target_memory_map_entry<32>, " ) ;
2018-06-04 20:55:10 +02:00
int _instanceCount = RdlUtil . instanceCount ( this . componentDefinition , ComponentDefinitionType . REGFILE ) ;
2017-09-20 22:36:20 +02:00
_builder . append ( _instanceCount ) ;
2018-06-04 20:55:10 +02:00
_builder . append ( " > " ) ;
String _effectiveName = RdlUtil . effectiveName ( this . componentDefinition ) ;
_builder . append ( _effectiveName ) ;
_builder . append ( " _map = {{ " ) ;
2017-09-20 22:36:20 +02:00
_builder . newLineIfNotEmpty ( ) ;
{
2018-06-04 20:55:10 +02:00
Iterable < Instantiation > _instantiationsOfType = RdlUtil . instantiationsOfType ( this . componentDefinition , ComponentDefinitionType . REGFILE ) ;
2017-09-20 22:36:20 +02:00
for ( final Instantiation instantiation : _instantiationsOfType ) {
{
EList < ComponentInstance > _componentInstances = instantiation . getComponentInstances ( ) ;
for ( final ComponentInstance instance : _componentInstances ) {
_builder . append ( " " ) ;
2022-02-13 12:40:21 +01:00
_builder . append ( " {i_ " ) ;
2017-09-20 22:36:20 +02:00
String _name = instance . getName ( ) ;
_builder . append ( _name , " " ) ;
2022-02-13 12:40:21 +01:00
_builder . append ( " .socket, " ) ;
2018-06-04 20:55:10 +02:00
IntegerWithRadix _addressValue = RdlUtil . addressValue ( instance ) ;
_builder . append ( _addressValue , " " ) ;
2017-09-20 22:36:20 +02:00
_builder . append ( " , 0x " ) ;
2018-06-04 20:55:10 +02:00
String _hexString = Long . toHexString ( RdlUtil . byteSize ( instantiation ) ) ;
2017-09-20 22:36:20 +02:00
_builder . append ( _hexString , " " ) ;
_builder . append ( " }, " ) ;
_builder . newLineIfNotEmpty ( ) ;
}
}
}
}
2017-09-19 18:08:17 +02:00
_builder . append ( " }}; " ) ;
_builder . newLine ( ) ;
_builder . newLine ( ) ;
2018-06-04 20:55:10 +02:00
_builder . append ( " #endif /* _ " ) ;
String _upperCase_2 = RdlUtil . effectiveName ( this . componentDefinition ) . toUpperCase ( ) ;
_builder . append ( _upperCase_2 ) ;
_builder . append ( " _MAP_H_ */ " ) ;
_builder . newLineIfNotEmpty ( ) ;
2017-09-19 18:08:17 +02:00
return _builder . toString ( ) ;
}
@Override
2022-02-13 12:40:21 +01:00
public String generateSource ( final String namespace ) {
2017-09-19 18:08:17 +02:00
return " " ;
}
}