Skip to content

Commit

Permalink
[98] Variable modifications
Browse files Browse the repository at this point in the history
Remove possibility to create variables using unicode caracters (greek
alphabet, sum, prod and sqrt).
Generated code and LaTeX view are unchanged or equivalent.

Bug: cea-hpc#98
Signed-off-by: Vincent BLAIN <vincent.blain@obeosoft.com>
  • Loading branch information
vblainobeo committed Oct 6, 2022
1 parent 09091bc commit 646694e
Show file tree
Hide file tree
Showing 50 changed files with 383 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
package fr.cea.nabla.ide.contentassist

import com.google.inject.Inject
import fr.cea.nabla.ir.transformers.ReplaceUtf8Chars
import fr.cea.nabla.services.NablaGrammarAccess
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider

Expand All @@ -30,23 +28,10 @@ class NablaIdeContentProposalProvider extends IdeContentProposalProvider
case simpleVarRule,
case connectivityVarRule:
{
buildGrecLetterProposals(context, acceptor)
}
default:
super._createProposals(ruleCall, context, acceptor)
}
}

private def void buildGrecLetterProposals(ContentAssistContext context, IIdeContentProposalAcceptor acceptor)
{
for (p : ReplaceUtf8Chars.UTF8Chars.keySet)
{
val trueEntry = new ContentAssistEntry => [
prefix = context.prefix
proposal = p
]
acceptor.accept(trueEntry, proposalPriorities.getDefaultPriority(trueEntry))
}
}

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/*******************************************************************************
* Copyright (c) 2022 CEA
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* Contributors: see AUTHORS file
*******************************************************************************/
package fr.cea.nabla.ir.generator.java

import fr.cea.nabla.ir.IrUtils
import fr.cea.nabla.ir.ir.ExecuteTimeLoopJob
import fr.cea.nabla.ir.ir.IrRoot
import fr.cea.nabla.ir.ir.Job

import static extension fr.cea.nabla.ir.JobCallerExtensions.*
import static extension fr.cea.nabla.ir.generator.Utils.*
import static extension fr.cea.nabla.ir.generator.java.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.java.InstructionContentProvider.*

/*******************************************************************************
* Copyright (c) 2022 CEA
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* Contributors: see AUTHORS file
*******************************************************************************/
package fr.cea.nabla.ir.generator.java

import fr.cea.nabla.ir.IrUtils
import fr.cea.nabla.ir.ir.ExecuteTimeLoopJob
import fr.cea.nabla.ir.ir.IrRoot
import fr.cea.nabla.ir.ir.Job

import static extension fr.cea.nabla.ir.JobCallerExtensions.*
import static extension fr.cea.nabla.ir.generator.Utils.*
import static extension fr.cea.nabla.ir.generator.java.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.java.InstructionContentProvider.*

class JobContentProvider
{
static def getContent(Job it)
'''
'''
«comment»
protected void «codeName»()
{
Expand All @@ -31,45 +31,45 @@ class JobContentProvider
'''
private static def dispatch CharSequence getInnerContent(Job it)
'''
'''
«instruction.innerContent»
'''
private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
«val itVar = iterationCounter.codeName»
«val irRoot = IrUtils.getContainerOfType(it, IrRoot
«val tn = irRoot.currentTimeVariable.codeName»
«val deltat = irRoot.timeStepVariable.codeName»
«val ppInfo = irRoot.postProcessing»
«itVar» = 0;
boolean continueLoop = true;
do
{
«itVar»++;
«IF caller.main»
System.out.printf("START ITERATION «iterationCounter.name»: %5d - t: %5.5f - deltat: %5.5f\n", «itVar», «tn», «deltat»);
«IF ppInfo !== null»
if («ppInfo.periodReference.codeName» >= «ppInfo.lastDumpVariable.codeName» + «ppInfo.periodValue.codeName»)
dumpVariables(«itVar»);
«ENDIF»
«ELSE»
System.out.printf("Start iteration «iterationCounter.name»: %5d\n", «itVar»);
«ENDIF»

«FOR j : calls»
«j.callName»(); // @«j.at»
«ENDFOR»

// Evaluate loop condition with variables at time n
continueLoop = («whileCondition.content»);

«instruction.innerContent»
} while (continueLoop);
«IF caller.main»

System.out.printf("FINAL TIME: %5.5f - deltat: %5.5f\n", «tn», «deltat»);
«IF ppInfo !== null»dumpVariables(«itVar»+1);«ENDIF»
«ENDIF»
'''
private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
«val itVar = iterationCounter.codeName»
«val irRoot = IrUtils.getContainerOfType(it, IrRoot
«val tn = irRoot.currentTimeVariable.codeName»
«val delta_t = irRoot.timeStepVariable.codeName»
«val ppInfo = irRoot.postProcessing»
«itVar» = 0;
boolean continueLoop = true;
do
{
«itVar»++;
«IF caller.main»
System.out.printf("START ITERATION «iterationCounter.name»: %5d - t: %5.5f - delta_t: %5.5f\n", «itVar», «tn», «delta_t»);
«IF ppInfo !== null»
if («ppInfo.periodReference.codeName» >= «ppInfo.lastDumpVariable.codeName» + «ppInfo.periodValue.codeName»)
dumpVariables(«itVar»);
«ENDIF»
«ELSE»
System.out.printf("Start iteration «iterationCounter.name»: %5d\n", «itVar»);
«ENDIF»

«FOR j : calls»
«j.callName»(); // @«j.at»
«ENDFOR»

// Evaluate loop condition with variables at time n
continueLoop = («whileCondition.content»);

«instruction.innerContent»
} while (continueLoop);
«IF caller.main»

System.out.printf("FINAL TIME: %5.5f - delta_t: %5.5f\n", «tn», «delta_t»);
«IF ppInfo !== null»dumpVariables(«itVar»+1);«ENDIF»
«ENDIF»
'''
}
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
/*******************************************************************************
* Copyright (c) 2022 CEA
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* Contributors: see AUTHORS file
*******************************************************************************/
package fr.cea.nabla.ir.generator.python

import fr.cea.nabla.ir.IrUtils
import fr.cea.nabla.ir.generator.Utils
import fr.cea.nabla.ir.ir.ExecuteTimeLoopJob
import fr.cea.nabla.ir.ir.IrRoot
import fr.cea.nabla.ir.ir.Job
import fr.cea.nabla.ir.ir.Variable

import static extension fr.cea.nabla.ir.JobCallerExtensions.*
import static extension fr.cea.nabla.ir.generator.python.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.python.InstructionContentProvider.*

/*******************************************************************************
* Copyright (c) 2022 CEA
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* Contributors: see AUTHORS file
*******************************************************************************/
package fr.cea.nabla.ir.generator.python

import fr.cea.nabla.ir.IrUtils
import fr.cea.nabla.ir.generator.Utils
import fr.cea.nabla.ir.ir.ExecuteTimeLoopJob
import fr.cea.nabla.ir.ir.IrRoot
import fr.cea.nabla.ir.ir.Job
import fr.cea.nabla.ir.ir.Variable

import static extension fr.cea.nabla.ir.JobCallerExtensions.*
import static extension fr.cea.nabla.ir.generator.python.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.python.InstructionContentProvider.*

class JobContentProvider
{
static def getContent(Job it)
'''
"""
Job «Utils.getCodeName(it)» called @«at» in «Utils.getCodeName(caller)» method.
In variables: «FOR v : inVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
Out variables: «FOR v : outVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
"""
'''
"""
Job «Utils.getCodeName(it)» called @«at» in «Utils.getCodeName(caller)» method.
In variables: «FOR v : inVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
Out variables: «FOR v : outVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
"""
def _«Utils.getCodeName(it)»(self):
«innerContent»
'''

private static def dispatch CharSequence getInnerContent(Job it)
'''
'''
«instruction.innerContent»
'''

private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
«val itVar = Utils.getCodeName(iterationCounter
«val irRoot = IrUtils.getContainerOfType(it, IrRoot
«val tn = Utils.getCodeName(irRoot.currentTimeVariable
«val deltat = Utils.getCodeName(irRoot.timeStepVariable
«val ppInfo = irRoot.postProcessing»
self.«itVar» = 0
«IF irRoot.currentTimeVariable.needDefinition»self.«tn» = 0.0«ENDIF»
«IF irRoot.timeStepVariable.needDefinition»self.«deltat» = 0.0«ENDIF»
continueLoop = True
while continueLoop:
self.«itVar» += 1
«IF caller.main»
print("START ITERATION «iterationCounter.name»: %5d - t: %5.5f - deltat: %5.5f\n" % (selfitVar», selftn», selfdeltat»))
«IF ppInfo !== null»
if (selfUtils.getCodeName(ppInfo.periodReference)» >= self.«Utils.getCodeName(ppInfo.lastDumpVariable)» + self.«Utils.getCodeName(ppInfo.periodValue)»):
self.__dumpVariables(selfitVar»)
«ENDIF»
«ELSE»
print("Start iteration «iterationCounter.name»: %5d\n" % (selfitVar»))
«ENDIF»

«FOR j : calls»
«PythonGeneratorUtils.getCallName(j)»() # @«j.at»
«ENDFOR»

# Evaluate loop condition with variables at time n
continueLoop = («whileCondition.content»)

«instruction.innerContent»
«IF caller.main»

print("FINAL TIME: %5.5f - deltat: %5.5f\n" % (selftn», selfdeltat»))
«IF ppInfo !== null»self.__dumpVariables(selfitVar»+1);«ENDIF»
«ENDIF»
'''
private static def needDefinition(Variable v)
{
!v.option && v.defaultValue === null
}

private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
«val itVar = Utils.getCodeName(iterationCounter
«val irRoot = IrUtils.getContainerOfType(it, IrRoot
«val tn = Utils.getCodeName(irRoot.currentTimeVariable
«val delta_t = Utils.getCodeName(irRoot.timeStepVariable
«val ppInfo = irRoot.postProcessing»
self.«itVar» = 0
«IF irRoot.currentTimeVariable.needDefinition»self.«tn» = 0.0«ENDIF»
«IF irRoot.timeStepVariable.needDefinition»self.«delta_t» = 0.0«ENDIF»
continueLoop = True
while continueLoop:
self.«itVar» += 1
«IF caller.main»
print("START ITERATION «iterationCounter.name»: %5d - t: %5.5f - delta_t: %5.5f\n" % (selfitVar», selftn», selfdelta_t»))
«IF ppInfo !== null»
if (selfUtils.getCodeName(ppInfo.periodReference)» >= self.«Utils.getCodeName(ppInfo.lastDumpVariable)» + self.«Utils.getCodeName(ppInfo.periodValue)»):
self.__dumpVariables(selfitVar»)
«ENDIF»
«ELSE»
print("Start iteration «iterationCounter.name»: %5d\n" % (selfitVar»))
«ENDIF»

«FOR j : calls»
«PythonGeneratorUtils.getCallName(j)»() # @«j.at»
«ENDFOR»

# Evaluate loop condition with variables at time n
continueLoop = («whileCondition.content»)

«instruction.innerContent»
«IF caller.main»

print("FINAL TIME: %5.5f - delta_t: %5.5f\n" % (selftn», selfdelta_t»))
«IF ppInfo !== null»self.__dumpVariables(selfitVar»+1);«ENDIF»
«ENDIF»
'''
private static def needDefinition(Variable v)
{
!v.option && v.defaultValue === null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JobInterpreter

if (caller.main)
{
val log = String.format(Locale::ENGLISH, "START ITERATION %1$s: %2$5d - t: %3$.5f - deltat: %4$.5f",
val log = String.format(Locale::ENGLISH, "START ITERATION %1$s: %2$5d - t: %3$.5f - delta_t: %4$.5f",
iterationCounter.name,
iteration,
context.getReal(context.ir.currentTimeVariable),
Expand Down Expand Up @@ -96,7 +96,7 @@ class JobInterpreter
if (caller.main)
{
// force a last trace and output at the end
val log = String.format(Locale::ENGLISH, "FINAL TIME: %1$.5f - deltat: %2$.5f",
val log = String.format(Locale::ENGLISH, "FINAL TIME: %1$.5f - delta_t: %2$.5f",
context.getReal(context.ir.currentTimeVariable),
context.getReal(context.ir.timeStepVariable))
context.logFine(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class IrTransformationUtils
static def getCommonTransformation(boolean replaceAllReductions)
{
#[
new ReplaceUtf8Chars,
new ReplaceReductions(replaceAllReductions),
new ReplaceAffectations,
new CreateArrayOperators,
Expand Down
Loading

0 comments on commit 646694e

Please sign in to comment.