Skip to content

Improve QBE Backend Code Generation (Expand JS Support & IR Lowering) #2

@ronak-create

Description

@ronak-create

Description

Currently, the compiler parses string literals but does not lower them in the QBE backend. This prevents basic programs like:

console.log("hello");

from working correctly.

This issue focuses on adding basic string literal support in the QBE backend by emitting them into the .data section and referencing them in generated code.


Goal

Enable simple string output via console.log by supporting string literals in QBE code generation.


Tasks

  • Detect string literals during QBE codegen
  • Store string literals in a global table (avoid duplicates if possible)
  • Emit .data section entries in QBE IR
  • Generate labels for each string (e.g., str0, str1)
  • Replace string usage in code with label references
  • Update console.log lowering to handle string arguments

Expected Behavior

Input:

console.log("hello");

QBE IR (simplified idea):

data $str0 = { b "hello", b 0 }

export function w $main() {
@start
call $puts(l $str0)
ret 0
}


Hints

  • Look into: src/qbe/qbe_codegen.c
  • You may need:
    • A small string pool (array or hashmap)
    • A helper like: get_string_label(const char* str)
  • QBE uses null-terminated strings (b 0)

Scope

  • Only handle string literals
  • No need for:
    • String operations
    • Concatenation
    • Dynamic allocation

Why This Matters

  • Unlocks basic I/O capability
  • First step toward real JS support
  • Clean, self-contained backend improvement

Difficulty

🟢 Good First Issue


Status

Open for contribution

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions