Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMADL2CPP
Commits
df8e63c8
Commit
df8e63c8
authored
Jan 22, 2019
by
Christopher Jan-Steffen Brix
Browse files
Moved code to better location
parent
b50aa9ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/emadl/generator/EMADLGenerator.java
View file @
df8e63c8
...
...
@@ -123,11 +123,65 @@ public class EMADLGenerator {
}
public
void
generateFiles
(
TaggingResolver
taggingResolver
,
ExpandedComponentInstanceSymbol
componentSymbol
,
Scope
symtab
)
throws
IOException
{
List
<
FileContent
>
fileContents
=
generateStrings
(
taggingResolver
,
componentSymbol
,
symtab
);
Set
<
ExpandedComponentInstanceSymbol
>
allInstances
=
new
HashSet
<>();
List
<
FileContent
>
fileContents
=
generateStrings
(
taggingResolver
,
componentSymbol
,
symtab
,
allInstances
);
for
(
FileContent
fileContent
:
fileContents
)
{
emamGen
.
generateFile
(
fileContent
);
}
// train
Map
<
String
,
String
>
fileContentMap
=
new
HashMap
<>();
for
(
FileContent
f
:
fileContents
)
{
fileContentMap
.
put
(
f
.
getFileName
(),
f
.
getFileContent
());
}
for
(
ExpandedComponentInstanceSymbol
componentInstance
:
allInstances
)
{
ComponentSymbol
component
=
componentInstance
.
getComponentType
().
getReferencedSymbol
();
Optional
<
ArchitectureSymbol
>
architecture
=
component
.
getSpannedScope
().
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
if
(!
architecture
.
isPresent
())
{
continue
;
}
String
fullName
=
componentInstance
.
getFullName
().
replaceAll
(
"\\."
,
"_"
);
String
creatorScriptName
=
"CNNCreator_"
+
fullName
+
".py"
;
String
creatorScript
=
fileContentMap
.
get
(
creatorScriptName
);
int
creatorScriptHash
=
creatorScript
.
hashCode
();
String
parsedFullName
=
fullName
.
substring
(
0
,
1
).
toLowerCase
()
+
fullName
.
substring
(
1
);
String
trainerScriptName
=
"CNNTrainer_"
+
parsedFullName
+
".py"
;
System
.
out
.
println
(
"CNNTrainer file: "
+
trainerScriptName
);
String
trainerScript
=
fileContentMap
.
get
(
trainerScriptName
);
int
trainerScriptHash
=
trainerScript
.
hashCode
();
// This is not the real path to the training data! Adapt accordingly once sub-task 4 is solved
String
trainConfigFilename
=
"NOT_FOUND"
;
String
componentConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
);
String
instanceConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
)
+
"_"
+
component
.
getName
();
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
instanceConfigFilename
+
".cnnt"
)))
{
trainConfigFilename
=
instanceConfigFilename
;
}
else
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
componentConfigFilename
+
".cnnt"
))){
trainConfigFilename
=
componentConfigFilename
;
}
Path
dataPath
=
Paths
.
get
(
getModelsPath
()
+
trainConfigFilename
+
".data"
);
byte
[]
dataHash
=
checksum
(
dataPath
);
String
trainingHash
=
creatorScriptHash
+
"-"
+
trainerScriptHash
+
"-"
+
convertByteArrayToHexString
(
dataHash
);
System
.
out
.
println
(
trainingHash
);
boolean
alreadyTrained
=
isAlreadyTrained
(
trainingHash
,
componentInstance
);
if
(
alreadyTrained
)
{
System
.
out
.
println
(
"Already trained"
);
}
else
{
System
.
out
.
println
(
"Not trained yet"
);
}
fileContents
.
add
(
new
FileContent
(
trainingHash
,
componentConfigFilename
+
".training_hash"
));
}
}
private
static
String
convertByteArrayToHexString
(
byte
[]
arrayBytes
)
{
...
...
@@ -181,67 +235,15 @@ public class EMADLGenerator {
}
}
public
List
<
FileContent
>
generateStrings
(
TaggingResolver
taggingResolver
,
ExpandedComponentInstanceSymbol
componentInstanceSymbol
,
Scope
symtab
){
public
List
<
FileContent
>
generateStrings
(
TaggingResolver
taggingResolver
,
ExpandedComponentInstanceSymbol
componentInstanceSymbol
,
Scope
symtab
,
Set
<
ExpandedComponentInstanceSymbol
>
allInstances
)
{
List
<
FileContent
>
fileContents
=
new
ArrayList
<>();
Set
<
ExpandedComponentInstanceSymbol
>
allInstances
=
new
HashSet
<>();
generateComponent
(
fileContents
,
allInstances
,
taggingResolver
,
componentInstanceSymbol
,
symtab
);
String
instanceName
=
componentInstanceSymbol
.
getComponentType
().
getFullName
().
replaceAll
(
"\\."
,
"_"
);
fileContents
.
addAll
(
generateCNNTrainer
(
allInstances
,
instanceName
));
Map
<
String
,
String
>
fileContentMap
=
new
HashMap
<>();
for
(
FileContent
f
:
fileContents
)
{
fileContentMap
.
put
(
f
.
getFileName
(),
f
.
getFileContent
());
}
for
(
ExpandedComponentInstanceSymbol
componentInstance
:
allInstances
)
{
ComponentSymbol
component
=
componentInstance
.
getComponentType
().
getReferencedSymbol
();
Optional
<
ArchitectureSymbol
>
architecture
=
component
.
getSpannedScope
().
resolve
(
""
,
ArchitectureSymbol
.
KIND
);
if
(!
architecture
.
isPresent
())
{
continue
;
}
String
fullName
=
componentInstance
.
getFullName
().
replaceAll
(
"\\."
,
"_"
);
String
creatorScriptName
=
"CNNCreator_"
+
fullName
+
".py"
;
String
creatorScript
=
fileContentMap
.
get
(
creatorScriptName
);
int
creatorScriptHash
=
creatorScript
.
hashCode
();
String
parsedFullName
=
fullName
.
substring
(
0
,
1
).
toLowerCase
()
+
fullName
.
substring
(
1
);
String
trainerScriptName
=
"CNNTrainer_"
+
parsedFullName
+
".py"
;
String
trainerScript
=
fileContentMap
.
get
(
trainerScriptName
);
int
trainerScriptHash
=
trainerScript
.
hashCode
();
// This is not the real path to the training data! Adapt accordingly once sub-task 4 is solved
String
trainConfigFilename
=
"NOT_FOUND"
;
String
componentConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
);
String
instanceConfigFilename
=
component
.
getFullName
().
replaceAll
(
"\\."
,
"/"
)
+
"_"
+
component
.
getName
();
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
instanceConfigFilename
+
".cnnt"
)))
{
trainConfigFilename
=
instanceConfigFilename
;
}
else
if
(
Files
.
exists
(
Paths
.
get
(
getModelsPath
()
+
componentConfigFilename
+
".cnnt"
))){
trainConfigFilename
=
componentConfigFilename
;
}
Path
dataPath
=
Paths
.
get
(
getModelsPath
()
+
trainConfigFilename
+
".data"
);
byte
[]
dataHash
=
checksum
(
dataPath
);
String
trainingHash
=
creatorScriptHash
+
"-"
+
trainerScriptHash
+
"-"
+
convertByteArrayToHexString
(
dataHash
);
System
.
out
.
println
(
trainingHash
);
boolean
alreadyTrained
=
isAlreadyTrained
(
trainingHash
,
componentInstance
);
if
(
alreadyTrained
)
{
System
.
out
.
println
(
"Already trained"
);
}
else
{
System
.
out
.
println
(
"Not trained yet"
);
}
fileContents
.
add
(
new
FileContent
(
trainingHash
,
componentConfigFilename
+
".training_hash"
));
}
fileContents
.
add
(
ArmadilloHelper
.
getArmadilloHelperFileContent
());
TypesGeneratorCPP
tg
=
new
TypesGeneratorCPP
();
fileContents
.
addAll
(
tg
.
generateTypes
(
TypeConverter
.
getTypeSymbols
()));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment