Skip to content

Commit 33fb9e6

Browse files
committed
取缔了PowerShell的使用
1 parent 8114a17 commit 33fb9e6

7 files changed

Lines changed: 305 additions & 145 deletions

File tree

src/Config.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class Config {
193193
@Type(() => FpgaConfig)
194194
fpga!: FpgaConfig;
195195
@IsNotEmpty()
196-
builtin!: { [name: string]: string };
196+
builtin!: Record<string, string>;
197197
}
198198
let config: Config | undefined = undefined;
199199

@@ -269,13 +269,12 @@ export function getConfig(): Config {
269269
return config;
270270
}
271271

272-
let builtin: { [name: string]: string } | undefined = undefined;
272+
const builtin = new Map<string, string>();
273273

274274
export function getBuiltin() {
275-
if (builtin === undefined) {
276-
builtin = {};
275+
if (builtin.size === 0) {
277276
for (const i in getConfig().builtin) {
278-
builtin[i] = fs.readFileSync(getConfig().builtin[i], "utf-8");
277+
builtin.set(i, fs.readFileSync(getConfig().builtin[i], "utf-8"));
279278
}
280279
}
281280
return builtin;

src/Spawn/Language/PlainText.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import path from "path";
22
import { getConfig } from "../../Config";
3-
import { RunOption, Language, LanguageConfigureOption, ExecType } from "./decl";
3+
import {
4+
RunOption,
5+
Language,
6+
LanguageConfigureOption,
7+
ExecType,
8+
RunType,
9+
} from "./decl";
410

511
export class PlainText extends Language {
612
private src = "src.in";
@@ -28,7 +34,7 @@ export class PlainText extends Language {
2834
}
2935

3036
pragramOptionGenerator(): RunOption {
31-
const binPath = path.join(this.compileDir, this.src);
37+
const binPath = path.join(this.runDir, this.src);
3238
return {
3339
skip: false,
3440
command: getConfig().language.cat,
@@ -39,4 +45,44 @@ export class PlainText extends Language {
3945
get judgeTimeout() {
4046
return 1000;
4147
}
48+
49+
[RunType.Synthesis] = {
50+
cacheable: true,
51+
outputFiles: [],
52+
optionGenerator(): RunOption {
53+
return { skip: true };
54+
},
55+
};
56+
57+
[RunType.Translate] = {
58+
cacheable: true,
59+
outputFiles: [],
60+
optionGenerator(): RunOption {
61+
return { skip: true };
62+
},
63+
};
64+
65+
[RunType.Map] = {
66+
cacheable: true,
67+
outputFiles: [],
68+
optionGenerator(): RunOption {
69+
return { skip: true };
70+
},
71+
};
72+
73+
[RunType.Implement] = {
74+
cacheable: true,
75+
outputFiles: [],
76+
optionGenerator(): RunOption {
77+
return { skip: true };
78+
},
79+
};
80+
81+
[RunType.Generate] = {
82+
cacheable: true,
83+
outputFiles: [],
84+
optionGenerator(): RunOption {
85+
return { skip: true };
86+
},
87+
};
4288
}

src/Spawn/Language/Verilog.ts

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { join } from "path";
2-
import { Language, RunOption } from "./decl";
2+
import { Language, RunOption, RunType } from "./decl";
33
import { getConfig } from "../../Config";
44

55
export class Verilog extends Language {
@@ -8,7 +8,7 @@ export class Verilog extends Language {
88
}
99

1010
get compiledFiles() {
11-
return [join(this.compileDir, "par.bit")];
11+
return [join(this.runDir, "par.bit")];
1212
}
1313

1414
compileOptionGenerator(): RunOption {
@@ -26,18 +26,73 @@ export class Verilog extends Language {
2626
return 1000;
2727
}
2828

29+
srcFileName = "main.v";
30+
31+
[RunType.Synthesis] = {
32+
cacheable: true,
33+
outputFiles: [join(this.runDir, "main.ngc")],
34+
optionGenerator() {
35+
return {
36+
skip: false,
37+
command: getConfig().language.xst,
38+
args: ["-ifn", "xc6slx9-2-ftg256.verilog.xst"],
39+
};
40+
},
41+
};
42+
43+
[RunType.Translate] = {
44+
cacheable: true,
45+
outputFiles: [join(this.runDir, "main.ngd")],
46+
optionGenerator() {
47+
return {
48+
skip: false,
49+
command: getConfig().language.ngdbuild,
50+
args: ["-aul", "-uc", "ax309.ucf", "main"],
51+
};
52+
},
53+
};
54+
55+
[RunType.Map] = {
56+
cacheable: true,
57+
outputFiles: [join(this.runDir, "main.ncd")],
58+
optionGenerator() {
59+
return {
60+
skip: false,
61+
command: getConfig().language.map,
62+
args: ["main"],
63+
};
64+
},
65+
};
66+
67+
[RunType.Implement] = {
68+
cacheable: true,
69+
outputFiles: [join(this.runDir, "par.ncd")],
70+
optionGenerator() {
71+
return {
72+
skip: false,
73+
command: getConfig().language.par,
74+
args: ["main", "par"],
75+
};
76+
},
77+
};
78+
79+
[RunType.Generate] = {
80+
cacheable: true,
81+
outputFiles: [join(this.runDir, "par.bit")],
82+
optionGenerator() {
83+
return {
84+
skip: false,
85+
command: getConfig().language.bitgen,
86+
args: ["par"],
87+
};
88+
},
89+
};
90+
2991
pragramOptionGenerator(): RunOption {
3092
return {
3193
skip: false,
3294
command: getConfig().language.impact,
3395
args: ["-batch", "main.cmd"],
34-
spawnOption: {
35-
timeLimit: 10000,
36-
},
3796
};
3897
}
39-
40-
get srcFileName() {
41-
return "main.v";
42-
}
4398
}

src/Spawn/Language/decl.ts

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

4+
export enum RunType {
5+
Synthesis = "synthesis",
6+
Translate = "translate",
7+
Map = "map",
8+
Implement = "implement",
9+
Generate = "generate",
10+
}
11+
412
export enum ExecType {
513
System = "system",
614
Usr = "usr",
715
Spj = "spj",
816
Interactive = "interactive",
917
}
18+
1019
export const ExecTypeArray = [
1120
ExecType.System,
1221
ExecType.Usr,
@@ -27,22 +36,33 @@ export type RunOption =
2736
export interface LanguageConfigureOption {
2837
execType: ExecType;
2938
excutable: Executable;
30-
compileDir: string;
39+
runDir: string;
40+
}
41+
42+
export interface compileOption {
43+
get cacheable(): boolean;
44+
get outputFiles(): string[];
45+
optionGenerator(): RunOption;
3146
}
3247

3348
export abstract class Language {
3449
readonly execType: ExecType;
3550
readonly excutable: Executable;
36-
compileDir: string;
51+
runDir: string;
3752
constructor(option: LanguageConfigureOption) {
3853
this.execType = option.execType;
3954
this.excutable = option.excutable;
40-
this.compileDir = option.compileDir;
55+
this.runDir = option.runDir;
4156
}
4257
abstract get compileCacheable(): boolean;
43-
abstract get srcFileName(): string;
4458
abstract get compiledFiles(): string[];
4559
abstract get judgeTimeout(): number;
4660
abstract compileOptionGenerator(): RunOption;
61+
abstract get srcFileName(): string;
62+
abstract [RunType.Synthesis]: compileOption;
63+
abstract [RunType.Translate]: compileOption;
64+
abstract [RunType.Map]: compileOption;
65+
abstract [RunType.Implement]: compileOption;
66+
abstract [RunType.Generate]: compileOption;
4767
abstract pragramOptionGenerator(): RunOption;
4868
}

src/Spawn/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface HengSpawnOption {
1616

1717
// args
1818
cwd?: string; // nsjail(get SE when cwd not mounted)
19-
env?: { [key: string]: string }; // nsjail
19+
env?: Record<string, string>; // nsjail
2020
stdio?: CompleteStdioOptions; // nsjail, meter save all fd except meterFd
2121
uid?: number; // nsjail(append root), meter
2222
gid?: number; // nsjail(append root), meter

0 commit comments

Comments
 (0)