Skip to content

Commit 5703289

Browse files
committed
Reimplementable calls now being generated
1 parent 838e7e1 commit 5703289

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ vitis-examples/async-static-multiple/async-static-multiple_vadd/vadd/
142142
build/
143143

144144
tools/header-to-json/woven_code/
145+
146+
tools/json-to-c/output/
147+
148+
tools/json-to-c/woven_code/

tools/json-to-c/src/Entrypoint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import Io from "@specs-feup/lara/api/lara/Io.js";
33

44
const json = Io.readJson("../intermediate-data/all_signatures.json");
55

6-
const converter = new JsonToCConverter("hls_");
6+
const converter = new JsonToCConverter();
77
const success = converter.convert(json);
88
console.log(success ? "Conversion successful" : "Conversion failed");

tools/json-to-c/src/JsonToCConverter.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import Clava from "@specs-feup/clava/api/clava/Clava.js";
22
import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
3-
import { SynthesizableHandler } from "./SignatureTypeHandlers.js";
3+
import { ReimplementableHandler, SynthesizableHandler } from "./SignatureTypeHandlers.js";
44

55
export class JsonToCConverter {
6-
private prefix: string;
7-
8-
constructor(prefix: string = '') {
9-
this.prefix = prefix;
6+
constructor() {
107
Clava.pushAst(ClavaJoinPoints.program());
118
}
129

1310
public convert(json: Record<string, any>): boolean {
1411
const synthHandler = new SynthesizableHandler();
12+
const reimpHandler = new ReimplementableHandler();
1513

1614
for (const [key, value] of Object.entries(json)) {
1715
const type = value["type"];
@@ -21,6 +19,9 @@ export class JsonToCConverter {
2119
if (type == "synthesizable") {
2220
synthHandler.handle(value);
2321
}
22+
if (type == "reimplementable") {
23+
reimpHandler.handle(value);
24+
}
2425
}
2526
Clava.writeCode("output");
2627
return true;

tools/json-to-c/src/SignatureTypeHandlers.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,39 @@ abstract class AHandler {
6161
return newFun;
6262
}
6363

64+
protected abstract buildFunctionImpl(signature: Record<string, any>, newSig: FunctionJp): FunctionJp;
65+
}
66+
67+
export class SynthesizableHandler extends AHandler {
68+
constructor() {
69+
super("hls-libc-synthesizable");
70+
}
71+
6472
protected buildFunctionImpl(signature: Record<string, any>, newSig: FunctionJp): FunctionJp {
6573
const newFun = newSig.copy() as FunctionJp;
6674

6775
const args = newFun.params.map(param => param.varref());
6876
const call = ClavaJoinPoints.callFromName(signature["name"], newFun.returnType, ...args);
6977
const retExpr = ClavaJoinPoints.returnStmt(call);
70-
const scope = ClavaJoinPoints.scope(retExpr);
7178

79+
const scope = ClavaJoinPoints.scope(retExpr);
7280
newFun.setBody(scope);
7381
return newFun;
7482
}
7583
}
7684

77-
export class SynthesizableHandler extends AHandler {
85+
export class ReimplementableHandler extends AHandler {
7886
constructor() {
79-
super("hls-libc-synthesizable");
87+
super("hls-libc-reimplemented");
88+
}
89+
90+
protected buildFunctionImpl(signature: Record<string, any>, newSig: FunctionJp): FunctionJp {
91+
const newFun = newSig.copy() as FunctionJp;
92+
93+
const comment = ClavaJoinPoints.comment("TODO: Implement this function");
94+
95+
const scope = ClavaJoinPoints.scope(comment);
96+
newFun.setBody(scope);
97+
return newFun;
8098
}
8199
}

0 commit comments

Comments
 (0)