Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/runar-cli/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ program
.option('-o, --output <dir>', 'output directory', './artifacts')
.option('--ir', 'include IR in artifact')
.option('--asm', 'print ASM to stdout')
.option('--sx', 'emit BitcoinSX (.sx) text output')
.option('--disable-constant-folding', 'disable ANF constant folding pass')
.action(compileCommand);

Expand Down
12 changes: 10 additions & 2 deletions packages/runar-cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface CompileOptions {
output: string;
ir?: boolean;
asm?: boolean;
sx?: boolean;
disableConstantFolding?: boolean;
}

Expand Down Expand Up @@ -56,7 +57,7 @@ export async function compileCommand(

// Dynamically import the compiler to avoid hard failures if it's not
// yet fully built (the compiler package may still be under development).
type CompileFn = (source: string, options?: { fileName?: string; disableConstantFolding?: boolean }) => unknown;
type CompileFn = (source: string, options?: { fileName?: string; disableConstantFolding?: boolean; emitSX?: boolean }) => unknown;
let compile: CompileFn | null = null;
try {
// In monorepo/dev mode, prefer the source entry so conformance and CLI
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function compileCommand(

let compileResult: CompileResultLike;
try {
compileResult = compile(source, { fileName: resolvedPath, disableConstantFolding: options.disableConstantFolding }) as CompileResultLike;
compileResult = compile(source, { fileName: resolvedPath, disableConstantFolding: options.disableConstantFolding, emitSX: options.sx }) as CompileResultLike;
} catch (err) {
console.error(` Compilation error: ${(err as Error).message}`);
errorCount++;
Expand Down Expand Up @@ -154,6 +155,13 @@ export async function compileCommand(
);
console.log(` Artifact written: ${artifactPath}`);

// Write SX file if requested
if (options.sx && typeof artifact['sx'] === 'string') {
const sxPath = path.join(outputDir, `${baseName}.sx`);
fs.writeFileSync(sxPath, artifact['sx'] + '\n');
console.log(` SX written: ${sxPath}`);
}

// Print ASM if requested
if (options.asm && typeof artifact['asm'] === 'string') {
console.log('');
Expand Down
Loading
Loading