Skip to content

Commit

Permalink
[Clava-JS] Several fixes related to CMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobispo committed Aug 9, 2024
1 parent 2db6ba3 commit babeb72
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
13 changes: 10 additions & 3 deletions Clava-JS/src-api/clava/cmake/CMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,27 @@ export default class CMaker extends BenchmarkCompilationEngine {
const builderFolderpath = Io.mkdir(builderFolder).getAbsolutePath();

// Execute CMake
let cmakeCmd = ["cmake", `"${cmakeFile.getParentFile().getAbsolutePath()}"`];
let cmakeCmd = [
"cmake",
`"${cmakeFile.getParentFile().getAbsolutePath()}"`,
];
if (cmakeFlags !== undefined) {
cmakeCmd.push(cmakeFlags);
}

if (this.generator !== undefined) {
cmakeCmd.push(`-G "${this.generator}"`);
cmakeCmd.push(`-G`);
cmakeCmd.push(`"${this.generator}"`);
}

if (this.compiler !== undefined) {
cmakeCmd.push(this.compiler.getCommandArgs());
}

debug(() =>`Executing CMake, calling '${cmakeCmd.join(" ")}' at '${builderFolderpath}'`);
debug(
() =>
`Executing CMake, calling '${cmakeCmd.join(" ")}' at '${builderFolderpath}'`
);
const cmakeOutput = new ProcessExecutor();

cmakeOutput
Expand Down
54 changes: 34 additions & 20 deletions Clava-JS/src-api/lara/benchmark/ClavaBenchmarkInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ import ClavaJoinPoints from "../../clava/ClavaJoinPoints.js";
* Implements _compilePrivate and .getKernel().
*/
export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
cmaker: CMaker | undefined;
cmakerProvider: () => CMaker;

constructor(name: string) {
super(name);

this.cmaker = undefined;
this.cmakerProvider = () => new CMaker(name);
}

setCMakerProvider(cmakerProvider: () => CMaker): void {
this.cmakerProvider = cmakerProvider;

// New provider set, remove CMaker
this.cmaker = undefined;
}

/**
* The output folder for this BenchmarkInstance.
*/
Expand All @@ -26,20 +43,25 @@ export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
}

/**
* For compatibility reasons.
*
* @param name
* @returns
* Allows to customize the CMake options used during compilation.
*
* @param name
* @returns
*/
protected getCMaker(name: string): CMaker {
return this.compilationEngineProvider(name);
protected getCMaker(): CMaker {
if (this.cmaker === undefined) {
this.cmaker = this.cmakerProvider();
}

return this.cmaker;
}

protected compilePrivate(): JavaClasses.File | undefined {
const folder = this.getOutputFolder();
Clava.writeCode(folder);

const cmaker = this.getCompilationEngine() as CMaker;
//const cmaker = this.getCompilationEngine() as CMaker;
const cmaker = this.getCMaker();

cmaker.addCurrentAst();

Expand All @@ -52,9 +74,6 @@ export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
return exe;
}




/**
* Speciallized implementation for Clava that automatically saves and restores the AST, extending classes just need to implement addCode() and loadPrologue().
*/
Expand All @@ -72,17 +91,14 @@ export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
Clava.rebuild();
}


protected closePrivate(): void {
// Restore any necessary configurations
this.closeEpilogue();
// Restore any necessary configurations
this.closeEpilogue();

// Restore previous AST
Clava.popAst();
// Restore previous AST
Clava.popAst();
}



protected loadCached(astFile: JavaClasses.File) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
console.log(`Loading cached AST from file ${astFile.getAbsolutePath()}...`);
Expand All @@ -107,7 +123,6 @@ export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
return $pragma.target;
}


/*** FUNCTIONS TO IMPLEMENT ***/

/**
Expand All @@ -121,8 +136,7 @@ export default abstract class ClavaBenchmarkInstance extends BenchmarkInstance {
protected abstract addCode(): void;

/**
*
*
*/
protected abstract closeEpilogue(): void;

}
8 changes: 6 additions & 2 deletions ClavaLaraApi/src-lara/clava/clava/cmake/CMaker.js

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

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

0 comments on commit babeb72

Please sign in to comment.