Skip to content

Commit

Permalink
[Clava-JS] Reformulates the ClavaBenchmarkInstance interface
Browse files Browse the repository at this point in the history
- Now is an abstract class, provides implementations for loadPrivate() and closePrivate(), and adds protected abstract methods loadPrologue(), addCode(), and closeEpilogue();
  • Loading branch information
joaobispo committed Aug 8, 2024
1 parent 5c00a1b commit a73c5cf
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
55 changes: 51 additions & 4 deletions Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -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;

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a73c5cf

Please sign in to comment.