Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overture code generation improvements: VDM-to-C and RT-to-RMI code generators #491

Closed
18 tasks done
peterwvj opened this issue Jan 11, 2016 · 2 comments
Closed
18 tasks done
Assignees
Labels
bug Incorrect behaviour of the tool enhancement Not a bug, but nice to have
Milestone

Comments

@peterwvj
Copy link
Member

Recent development work on the VDM-to-C code generator and the RT-to-RMI code generator has given rise new suggestions for improvements that should be addressed:

VDM2C project

  • Move Java test code out into separate project due maven quirk with test jars (see https://issues.apache.org/jira/browse/MJAR-138). Based on feedback from different people I've decided not use the maven test-jar feature anymore. COMPASS experienced a similar problem and decided that the best thing to do is simply to move test code that needs to be used by multiple projects into a separate module.
  • Reorganise template structure such that AST nodes and templates are consistent. There seems to be confusion about figuring out how nodes and templates relate. This can probably be alleviated by using a more systematic naming scheme for templates - for example by using the fully qualified node name as the template name
    Example: Node: org.overture.codegen.cgast.declarations.ADefaultClassDeclCG Template: <myRoot>/org/overture/codegen/cgast/declarations/ADefaultClassDeclCG.vm
  • Now that template paths are derived (as described in the item above) it would still be convenient to be able to force or set the actual path of the template. In particular this will allow different templates to be used for the same node type.
  • Transfer all nodes in FuncTrans. The return statement is created but no source it selected for it.
  • The PCG field sourceNode should be changed from a tree field to a graph field. New version of ASTCreator now allows this feature to be done.
  • Change name of ide/plugins/codegen to ide/plugins/javagen to better describe what functionality this plugin provides
  • Add String formatting functionality to template. Similar to what was done in this commit: overturetool/vdm2c@ae1a0ef
  • Improve documentation of the isLocal method in the DeclAssistantCG class.
  • Generalise generate method such that it does things such as computing the definition table
  • Hide application of MergeVisitor and make it return a status. Also makes sure that the state of the MergeVisitor is cleared after it has been applied
  • Add expression statement node
  • Better testing of whether the isLocal property is correctly set for variable occurences
  • consNextElementCall in the transformation assistant must accept the type as a STypeCG and not a java.lang.String.
  • Update CodeGenBase with funtionality for emitting generated code.
  • Change name of AST file from cg.astv2 to ir.ast. The same for the node files.
    The ffollowing commands have been used to do the refactoring:
## Run from core/codegen root
git mv ir/src/main/resources/cg.astv2 ir/src/main/resources/ir.ast
git mv ir/src/main/resources/cg.astv2.tostring ir/src/main/resources/ir.ast.tostring
find . \( -name '*.java' -o -name '*.ast' -o -name '*.tostring' -o -name 'pom.xml' \) -exec perl -pi -e 's/cg.astv2/ir.ast/g' {} \;
git add .
git commit . -m "Rename IR specification files and references for them"
find . -type f -name "*CG*.java" -exec rename 's/CG/IR/' {} ";"
git add .
git commit . -m "Rename IR visitors"
git mv javagen/src/main/resources/JavaTemplates/org/overture/codegen/cgast/ javagen/src/main/resources/JavaTemplates/org/overture/codegen/ir/
find . \( -name '*.java' -o -name '*.ast' -o -name '*.tostring' -o -name 'pom.xml' \) -exec perl -pi -e 's/cgast/ir/g' {} \;
git add .
git commit . -m "Rename IR node packages"
find . \( -name '*.java' -o -name '*.ast' -o -name '*.tostring' \) -exec perl -pi -e 's/([A-Z\|a-z\|:\| \|%|.]+?)CG/\1IR/g' {} \;
find . \( -name '*.java' -o -name '*.ast' -o -name '*.tostring' \) -exec perl -pi -e 's/^CG/IR/g' {} \;
find . -type f -name "*CG.vm" -exec rename 's/CG/IR/' {} ";"
git add .
git commit -m "Change CG suffix to IR"
cd ../../ide/
find . -type f -exec perl -pi -e 's/cgast/ir/g' {} \;
find . \( -name '*.java' -o -name '*.ast' -o -name '*.tostring' \) -exec perl -pi -e 's/([A-Z\|a-z\|:\| \|%|.]+?)CG/\1IR/g' {} \;
git add .
git commit -m "Update IR node references in code generator plugins"
## How to avoid doing this in cpp and isa?

RT-to-RMI project

  • Update IR methods to specify what exceptions get thrown. It should be sufficient to to add a field raises to the AMethodDeclCG node.
  • Add a way for users of the JavaGen to access the System, CPU and BUS classes. Probably through interception of some event.
  • Update the template manager to allow the template reference loader to be specified for each template.
@peterwvj peterwvj added bug Incorrect behaviour of the tool enhancement Not a bug, but nice to have labels Jan 11, 2016
@peterwvj peterwvj self-assigned this Jan 11, 2016
peterwvj added a commit that referenced this issue Jan 12, 2016
@peterwvj
Copy link
Member Author

Changing the name of the codegen plugin to javagen - see 823cdd3

@peterwvj
Copy link
Member Author

These issues have now been addressed. The application of the MergeVisitor is now hidden in the CodeGenBase class, which also uses the template method design pattern to ensure that the state of the IR generator is properly initialized and necessary pre-processing of the VDM AST is done. See

/**
* The entry point of this class. This method translates a VDM AST into target language code. Use of the template
* method design pattern ensures that the state of this code generator is properly initialized and that the VDM AST
* is pre-processed in accordance with the {@link #preProcessAst(List)} method.
*
* @param ast
* The VDM AST, which can be either VDM modules or classes.
* @return The data generated from the VDM AST.
* @throws AnalysisException
* If a problem occurs during the construction of the IR.
*/
public GeneratedData generate(List<INode> ast) throws AnalysisException
{
clear();
preProcessAst(ast);
return genVdmToTargetLang(ast);
}

/**
* This method translates an IR module or class into target language code.
*
* @param mergeVisitor
* The visitor that translates the IR module or class into target language code.
* @param status
* The IR status that holds the IR node that we want to code generate.
* @return The generated code and data about what has been generated.
* @throws org.overture.codegen.cgast.analysis.AnalysisException
* If something goes wrong during the code generation process.
*/
protected GeneratedModule genIrModule(MergeVisitor mergeVisitor,
IRStatus<? extends PCG> status) throws org.overture.codegen.cgast.analysis.AnalysisException
{
if (status.canBeGenerated())
{
mergeVisitor.init();
StringWriter writer = new StringWriter();
status.getIrNode().apply(mergeVisitor, writer);
boolean isTestCase = isTestCase(status);
GeneratedModule generatedModule;
if (mergeVisitor.hasMergeErrors())
{
generatedModule = new GeneratedModule(status.getIrNodeName(), status.getIrNode(), mergeVisitor.getMergeErrors(), isTestCase);
} else if (mergeVisitor.hasUnsupportedTargLangNodes())
{
generatedModule = new GeneratedModule(status.getIrNodeName(), new HashSet<VdmNodeInfo>(), mergeVisitor.getUnsupportedInTargLang(), isTestCase);
} else
{
generatedModule = new GeneratedModule(status.getIrNodeName(), status.getIrNode(), formatCode(writer), isTestCase);
generatedModule.setTransformationWarnings(status.getTransformationWarnings());
}
return generatedModule;
} else
{
return new GeneratedModule(status.getIrNodeName(), status.getUnsupportedInIr(), new HashSet<IrNodeInfo>(), isTestCase(status));
}
}

I'm closing this issue for now.

peterwvj added a commit that referenced this issue Jan 26, 2016
@peterwvj peterwvj reopened this Jan 27, 2016
peterwvj added a commit that referenced this issue Jan 30, 2016
@peterwvj peterwvj changed the title Overture code generation improvements based on the vdm2c feedback Overture code generation improvements: VDM-to-C and RT-to-RMI code generators Jan 30, 2016
peterwvj added a commit that referenced this issue Jan 31, 2016
@peterwvj peterwvj closed this as completed Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behaviour of the tool enhancement Not a bug, but nice to have
Projects
None yet
Development

No branches or pull requests

1 participant