diff --git a/sbc/asm_gen.ts b/sbc/asm_gen.ts index 464d203..27063a7 100644 --- a/sbc/asm_gen.ts +++ b/sbc/asm_gen.ts @@ -299,15 +299,15 @@ export class AsmGen { } } - private relative(offset: number): string { - return `[rbp${offset >= 0 ? `+${offset}` : `${offset}`}]`; - } - private kill(reg: lir.Reg) { this.liveRegs.delete(reg); this.regSelect.delete(reg); } + private relative(offset: number): string { + return `[rbp${offset >= 0 ? `+${offset}` : `${offset}`}]`; + } + private writeIns(ins: string) { this.writer.writeln(` ${ins}`); } diff --git a/sbc/lir_optimize.ts b/sbc/lir_optimize.ts index 3b227bc..175209b 100644 --- a/sbc/lir_optimize.ts +++ b/sbc/lir_optimize.ts @@ -9,8 +9,8 @@ import { } from "./lir.ts"; export function optimizeLir(program: Program) { - //console.log("=== BEFORE OPTIMIZATION ==="); - //console.log(new ProgramStringifyer(program).stringify()); + console.log("=== BEFORE OPTIMIZATION ==="); + console.log(new ProgramStringifyer(program).stringify()); let sizeBefore = program.fns .reduce((acc, fn) => acc + fn.lines.length, 0); @@ -34,8 +34,8 @@ export function optimizeLir(program: Program) { sizeHistory.add(sizeBefore); } - //console.log("=== AFTER OPTIMIZATION ==="); - //console.log(new ProgramStringifyer(program).stringify()); + console.log("=== AFTER OPTIMIZATION ==="); + console.log(new ProgramStringifyer(program).stringify()); } function eliminatePushPop(fn: Fn) { diff --git a/sbc/program.sbl b/sbc/program.sbl index 4fc59ac..c725eef 100644 --- a/sbc/program.sbl +++ b/sbc/program.sbl @@ -6,15 +6,28 @@ fn notice() -> int {} fn print_int(value: int) -> int {} - - #[c_function("println")] fn println(value: *str) -> int {} +fn add(a: int, b: int) -> int { return a + b; } +fn compute() -> int { return 0; } +fn consume(value: int) -> int { return 0; } + #[c_export("sbc_main")] fn main() -> int { - println("hello_world"); + let i = 0; + + loop { + if 10 < i + 1 { + break; + } + + println("hello\ world"); + + i = i + 1; + } + return 0; }