create temputils to satisfy compileWithDebug requirement from web

This commit is contained in:
Theis Pieter Hollebeek 2024-12-12 10:47:25 +01:00
parent 613b57f40f
commit 9840269ab7
2 changed files with 33 additions and 0 deletions

View File

@ -3,3 +3,5 @@ export * from "./ast.ts";
export * from "./arch.ts";
export * from "./lexer.ts";
export * from "./token.ts";
export * from "./temputils.ts";

31
compiler/temputils.ts Normal file
View File

@ -0,0 +1,31 @@
import { Checker } from "./checker.ts";
import { Reporter } from "./info.ts";
import { Lexer } from "./lexer.ts";
import { Lowerer } from "./lowerer.ts";
import { Parser } from "./parser.ts";
import { Resolver } from "./resolver.ts";
/// TODO: find a better place for this function
export async function compileWithDebug(path: string): Promise<number[]> {
const text = await Deno.readTextFile(path);
const reporter = new Reporter();
const lexer = new Lexer(text, reporter);
const parser = new Parser(lexer, reporter);
const ast = parser.parseStmts();
new Resolver(reporter).resolve(ast);
new Checker(reporter).check(ast);
if (reporter.errorOccured()) {
console.error("Errors occurred, stopping compilation.");
}
const lowerer = new Lowerer();
lowerer.lower(ast);
lowerer.printProgram();
const program = lowerer.finish();
return program;
}