diff --git a/Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts b/Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts index b60077d42..a27edd75d 100644 --- a/Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts +++ b/Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts @@ -4,15 +4,16 @@ import { JavaClasses } from "lara-js/api/lara/util/JavaTypes.js"; import Query from "lara-js/api/weaver/Query.js"; import Weaver from "lara-js/api/weaver/Weaver.js"; import Clava from "../..//clava/Clava.js"; -import { Pragma, Program } from "../../Joinpoints.js"; +import { Joinpoint, Pragma, Program } from "../../Joinpoints.js"; import CMaker from "../../clava/cmake/CMaker.js"; +import ClavaJoinPoints from "../../clava/ClavaJoinPoints.js"; /** * Instance of a Clava benchmark. * * Implements _compilePrivate and .getKernel(). */ -export default class ClavaBenchmarkInstance extends BenchmarkInstance { +export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance { /** * The output folder for this BenchmarkInstance. */ @@ -51,9 +52,36 @@ export default class ClavaBenchmarkInstance extends BenchmarkInstance { return exe; } - protected loadPrivate(): void {} - protected closePrivate(): void {} + + + /** + * Speciallized implementation for Clava that automatically saves and restores the AST, extending classes just need to implement addCode() and loadPrologue(). + */ + protected loadPrivate(): void { + // Execute configuration for current instance + this.loadPrologue(); + + // Pust an empty AST to the top of the stack + Clava.pushAst(ClavaJoinPoints.program()); + + // Add code + this.addCode(); + + // Rebuild + Clava.rebuild(); + } + + + protected closePrivate(): void { + // Restore any necessary configurations + this.closeEpilogue(); + + // Restore previous AST + Clava.popAst(); + } + + protected loadCached(astFile: JavaClasses.File) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call @@ -78,4 +106,23 @@ export default class ClavaBenchmarkInstance extends BenchmarkInstance { return $pragma.target; } + + + /*** FUNCTIONS TO IMPLEMENT ***/ + + /** + * Configuration that is required by the benchmarks (e.g., setting the standard) + */ + protected abstract loadPrologue(): void; + + /** + * Adds the code to the AST, can assume the AST is empty. + */ + protected abstract addCode(): void; + + /** + * + */ + protected abstract closeEpilogue(): void; + } diff --git a/ClavaLaraApi/src-lara/clava/lara/benchmark/ClavaBenchmarkInstance.js b/ClavaLaraApi/src-lara/clava/lara/benchmark/ClavaBenchmarkInstance.js index aa5ca0af7..9b2ec4798 100644 --- a/ClavaLaraApi/src-lara/clava/lara/benchmark/ClavaBenchmarkInstance.js +++ b/ClavaLaraApi/src-lara/clava/lara/benchmark/ClavaBenchmarkInstance.js @@ -5,6 +5,7 @@ import Weaver from "lara-js/api/weaver/Weaver.js"; import Clava from "../..//clava/Clava.js"; import { Pragma } from "../../Joinpoints.js"; import CMaker from "../../clava/cmake/CMaker.js"; +import ClavaJoinPoints from "../../clava/ClavaJoinPoints.js"; /** * Instance of a Clava benchmark. * @@ -40,8 +41,25 @@ export default class ClavaBenchmarkInstance extends BenchmarkInstance { } return exe; } - loadPrivate() { } - closePrivate() { } + /** + * Speciallized implementation for Clava that automatically saves and restores the AST, extending classes just need to implement addCode() and loadPrologue(). + */ + loadPrivate() { + // Execute configuration for current instance + this.loadPrologue(); + // Pust an empty AST to the top of the stack + Clava.pushAst(ClavaJoinPoints.program()); + // Add code + this.addCode(); + // Rebuild + Clava.rebuild(); + } + closePrivate() { + // Restore any necessary configurations + this.closeEpilogue(); + // Restore previous AST + Clava.popAst(); + } loadCached(astFile) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call console.log(`Loading cached AST from file ${astFile.getAbsolutePath()}...`);