Skip to content

Commit

Permalink
Improve cli and config interface
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 4, 2024
1 parent 50ca933 commit 95514b3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
15 changes: 3 additions & 12 deletions src/cli/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ async function main() {
return emit(await getCoreAst(config.index));
}

if (config.emitModuleAst) {
return emit(await getModuleAst(config.index));
}

if (config.emitMacroAst) {
return emit(await getMacroAst(config.index));
if (config.emitIrAst) {
return emit(await getIrAST(config.index));
}

if (config.emitWasmText) {
Expand Down Expand Up @@ -60,12 +56,7 @@ async function getCoreAst(index: string) {
return await getParserAst(index);
}

async function getModuleAst(index: string) {
const module = await parseModuleFromSrc(index);
return processSemantics(module);
}

async function getMacroAst(index: string) {
async function getIrAST(index: string) {
const module = await parseModuleFromSrc(index);
return processSemantics(module);
}
Expand Down
8 changes: 2 additions & 6 deletions src/lib/config/cli.ts → src/lib/config/arg-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ const options: ParseArgsConfig["options"] = {
"emit-core-ast": {
type: "boolean",
},
"emit-module-ast": {
type: "boolean",
},
"emit-macro-ast": {
"emit-ir-ast": {
type: "boolean",
},
"emit-wasm": {
Expand Down Expand Up @@ -53,8 +50,7 @@ export const getConfigFromCli = (): VoidConfig => {
index,
emitParserAst: values["emit-parser-ast"] as boolean,
emitCoreAst: values["emit-core-ast"] as boolean,
emitModuleAst: values["emit-module-ast"] as boolean,
emitMacroAst: values["emit-macro-ast"] as boolean,
emitIrAst: values["emit-ir-ast"] as boolean,
emitWasm: values["emit-wasm"] as boolean,
emitWasmText: values["emit-wasm-text"] as boolean,
runBinaryenOptimizationPass: values["opt"] as boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConfigFromCli } from "./cli.js";
import { getConfigFromCli } from "./arg-parser.js";
import { VoidConfig } from "./types.js";

let config: VoidConfig | undefined = undefined;
Expand Down
6 changes: 2 additions & 4 deletions src/lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ export type VoidConfig = {
emitParserAst?: boolean;
/** Write desurfaced AST to stdout */
emitCoreAst?: boolean;
/** Emit full AST with all resolved file modules */
emitModuleAst?: boolean;
/** Emit ast with regular macros expanded */
emitMacroAst?: boolean;
/** Emit ast ir expanded (post semantic phases) */
emitIrAst?: boolean;
/** Write wasm bytecode to stdout */
emitWasm?: boolean;
/** Write wasm bytecode to stdout (binaryen flavor) */
Expand Down

0 comments on commit 95514b3

Please sign in to comment.