Skip to content

Commit 5ec5960

Browse files
committed
允许在Web端指定动态文件
1 parent 8f14b62 commit 5ec5960

6 files changed

Lines changed: 104 additions & 25 deletions

File tree

src/Config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export class JudgeFactoryConfig {
100100
remoteFileCacheBytes!: number;
101101
}
102102
export class FpgaConfig {
103+
@IsString()
104+
@IsNotEmpty()
105+
constraints!: string;
106+
@IsString()
107+
@IsNotEmpty()
108+
program!: string;
109+
@IsString()
110+
@IsNotEmpty()
111+
package!: string;
103112
@ArrayNotEmpty()
104113
@ArrayUnique()
105114
@IsHexadecimal({

src/Spawn/Language/Verilog.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { DynamicFile } from "heng-protocol";
12
import { join } from "path";
23
import { getConfig } from "../../Config";
34
import { Language, RunOption, RunType } from "./decl";
5+
import { getPrj, getXst } from "./XilinxSynthesisTechnology";
46

57
export class Verilog extends Language {
6-
srcFileName = "main.v";
8+
static srcFileName = "main.v";
9+
static modifyDynamicFile(files: DynamicFile[] = []) {
10+
return [getPrj(this.srcFileName, files), getXst(), ...files];
11+
}
12+
13+
srcFileName = Verilog.srcFileName;
714

815
[RunType.Synthesis] = {
916
cacheable: true,
@@ -12,7 +19,7 @@ export class Verilog extends Language {
1219
return {
1320
skip: false,
1421
command: getConfig().language.xst,
15-
args: ["-ifn", "xc6slx9-2-ftg256.verilog.xst"],
22+
args: ["-ifn", "main.xst"],
1623
};
1724
},
1825
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { DynamicFile } from "heng-protocol";
2+
import { getConfig } from "../../Config";
3+
4+
export function getXst(
5+
input = "main.prj",
6+
output = "main",
7+
fpga = getConfig().fpga.package,
8+
top = "main",
9+
name = "main.xst"
10+
): DynamicFile {
11+
return {
12+
file: {
13+
content: `run -ifn ${input} -ofn ${output} -p ${fpga} -top ${top}`,
14+
type: "direct",
15+
},
16+
name,
17+
type: "remote",
18+
};
19+
}
20+
21+
function getPrjLine(name: string) {
22+
if (name.endsWith(".v")) {
23+
return `verilog work ${name}`;
24+
}
25+
if (name.endsWith(".vhd")) {
26+
return `vhdl work ${name}`;
27+
}
28+
return "";
29+
}
30+
31+
export function getPrj(
32+
srcFileName: string,
33+
files: DynamicFile[] = [],
34+
name = "main.prj"
35+
): DynamicFile {
36+
return {
37+
file: {
38+
content: files.reduce(
39+
(content, { name }) => `${content}\n${getPrjLine(name)}`,
40+
getPrjLine(srcFileName)
41+
),
42+
type: "direct",
43+
},
44+
name,
45+
type: "remote",
46+
};
47+
}

src/Spawn/Language/decl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Executable } from "heng-protocol";
1+
import { DynamicFile, Executable } from "heng-protocol";
22
import { HengSpawnOption } from "..";
33

44
export enum RunType {
@@ -55,6 +55,9 @@ export abstract class Language {
5555
this.runDir = option.runDir;
5656
}
5757
abstract get srcFileName(): string;
58+
static modifyDynamicFile(files: DynamicFile[] = []) {
59+
return files;
60+
}
5861
abstract [RunType.Synthesis]: compileOption;
5962
abstract [RunType.Translate]: compileOption;
6063
abstract [RunType.Map]: compileOption;

src/Spawn/Language/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ export function getConfiguredLanguage(
1919
break;
2020
}
2121
}
22+
23+
export function getLanguage(lang: string): typeof Language {
24+
lang = lang.toLowerCase();
25+
switch (lang) {
26+
case "verilog":
27+
return Verilog;
28+
case "plaintext":
29+
return PlainText;
30+
default:
31+
throw new Error("Unrecognized language");
32+
}
33+
}

src/Utilities/Judge.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { SerialPort } from "serialport";
2020
import { getConfig } from "../Config";
2121
import { Controller } from "../controller";
2222
import { Tests } from "../SelfTest";
23+
import { getLanguage } from "../Spawn/Language";
2324
import { ExecType, RunType } from "../Spawn/Language/decl";
2425
import { MeterResult } from "../Spawn/Meter";
2526
import { ExecutableAgent, runLogName } from "./ExecutableAgent";
@@ -238,24 +239,11 @@ export abstract class JudgeAgent {
238239
}
239240
): Promise<[ExecutableAgent, JudgeResult | undefined]> {
240241
this.checkInit();
241-
const executableAgent = new ExecutableAgent(execType, executable, [
242-
{
243-
name: "ax309.ucf",
244-
type: "builtin",
245-
},
246-
{
247-
name: "main.cmd",
248-
type: "builtin",
249-
},
250-
{
251-
name: "verilog.prj",
252-
type: "builtin",
253-
},
254-
{
255-
name: "xc6slx9-2-ftg256.verilog.xst",
256-
type: "builtin",
257-
},
258-
]);
242+
const executableAgent = new ExecutableAgent(
243+
execType,
244+
executable,
245+
this.judge.dynamicFiles
246+
);
259247
this.ExecutableAgents.push(executableAgent);
260248
await executableAgent.init();
261249
await executableAgent.releaseFile();
@@ -286,14 +274,14 @@ export abstract class JudgeAgent {
286274
statistics.tick(this.judge.id);
287275
await this.init();
288276
const ret = await this.getResult();
289-
// await this.clean();
277+
await this.clean();
290278
statistics.finish(this.judge.id);
291279
return ret;
292280
} catch (err) {
293281
this.logger.fatal(err);
294-
// await this.clean().catch((error) => {
295-
// this.logger.fatal(error);
296-
// });
282+
await this.clean().catch((error) => {
283+
this.logger.fatal(error);
284+
});
297285
statistics.finish(this.judge.id);
298286
const e = {
299287
kind: JudgeResultKind.SystemError,
@@ -568,6 +556,19 @@ export class JudgeFactory {
568556
) {}
569557

570558
getJudgerAgent(judgeInfo: CreateJudgeArgs): JudgeAgent {
559+
judgeInfo.dynamicFiles = [
560+
{
561+
type: "builtin",
562+
name: getConfig().fpga.constraints,
563+
},
564+
{
565+
type: "builtin",
566+
name: getConfig().fpga.program,
567+
},
568+
...getLanguage(
569+
judgeInfo.judge.user.environment.language
570+
).modifyDynamicFile(judgeInfo.dynamicFiles),
571+
];
571572
judgeInfo.judge.user.limit.compiler.cpuTime = Math.ceil(
572573
judgeInfo.judge.user.limit.compiler.cpuTime / this.timeRatio
573574
);

0 commit comments

Comments
 (0)