-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathindex.ts
More file actions
54 lines (43 loc) · 1.63 KB
/
index.ts
File metadata and controls
54 lines (43 loc) · 1.63 KB
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
import { Buffer } from 'buffer';
import * as debugAPI from 'debug';
import * as frontend from 'llparse-frontend';
import { IStructStateFields } from '../../compiler/struct-state-fields-builder'
import { Compilation } from './compilation';
import { CONTAINER_KEY } from './constants';
import code from './code';
import node from './node';
import { Node } from './node';
import transform from './transform';
import { ExecuteBuilder } from './helpers/execute-builder';
import { InitBuilder } from './helpers/init-builder';
const debug = debugAPI('llparse:bitcode');
export interface IBitcodeCompilerOptions {
readonly debug?: string;
}
export class BitcodeCompiler {
constructor(container: frontend.Container,
private readonly options: IBitcodeCompilerOptions) {
container.add(CONTAINER_KEY, { code, node, transform });
}
public compile(fields: IStructStateFields, info: frontend.IFrontendResult): Buffer {
// Compile to bitcode
const compilation = new Compilation(info.prefix, fields, info.properties,
this.options);
debug('building root');
const root = info.root as frontend.ContainerWrap<frontend.node.Node>;
const initFn = root.get<Node<frontend.node.Node>>(CONTAINER_KEY)
.build(compilation);
debug('building match sequence');
compilation.buildMatchSequence();
debug('building init');
const ib = new InitBuilder();
ib.build(compilation, initFn);
debug('building execute');
const eb = new ExecuteBuilder();
eb.build(compilation, info);
debug('building bitcode');
const bitcode = compilation.buildBitcode(initFn);
debug('done');
return bitcode;
}
}