-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
83 lines (76 loc) · 2.29 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Statement } from './ast';
import { RegisterAgnosticTargetInfo } from './TargetInfo';
import { Type, TypeDeclaration, TypeReference } from './types';
import { FileResult } from 'fs-extra';
import { Program } from './threeAddressCode/Program';
export type Variable = {
name: string;
type: Type | TypeReference;
exported: boolean;
};
export type Function = {
statements: Statement[];
variables: Variable[];
parameters: Variable[];
returnType: Type;
};
export const getTypeOfFunction = (fn: Function): Type => {
return {
type: {
kind: 'Function',
permissions: [],
arguments: fn.parameters.map(p => p.type),
returnType: fn.returnType,
},
methods: [],
};
};
export type StringLiteralData = { id: number; value: string };
export type ExportedVariable = {
exportedName: string;
declaredName: string;
};
export type FrontendOutput = {
types: TypeDeclaration[];
functions: Map<string, Function>;
builtinFunctions: Variable[];
program: Function | ExportedVariable[];
globalDeclarations: Variable[];
stringLiterals: StringLiteralData[];
};
export type ExecutionResult =
| {
exitCode: number;
stdout: string;
executorName: string;
runInstructions: string;
debugInstructions: string;
}
| { error: string; executorName: string };
export type Assembly = {};
export type CompilationResult =
| {
source: string;
sourceFile: FileResult;
binaryFile: FileResult;
threeAddressCode?: Assembly;
threeAddressCodeFile: FileResult | undefined;
}
| { error: string; intermediateFile?: FileResult };
export type Executor = {
name: string;
execute: (exePath: string, stdinPath: string) => Promise<ExecutionResult>;
};
export type Backend = {
name: string;
compile: (
input: FrontendOutput
) => { target: string; tac: Program | undefined } | { error: string };
compileTac?: (input: Program, includeLeakCheck: boolean) => string | { error: string };
finishCompilation: (
input: string,
tac: Program | undefined
) => Promise<CompilationResult | { error: string }>;
targetInfo?: RegisterAgnosticTargetInfo;
executors: Executor[];
};