Skip to content

Extract the assembler into a reusable xasm library - #15

Merged
pfusik merged 16 commits into
pfusik:masterfrom
epi:epi/libxasm
Sep 2, 2026
Merged

pfusik merged 16 commits into
pfusik:masterfrom
epi:epi/libxasm

Conversation

@epi

@epi epi commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactors xasm so the assembler core can be used as a library (libxasm) from any D program, not just through the xasm command-line tool. xebin is going to be its first user.
All the assembly logic previously living in source/app.d now sits behind an Assembler class in a new source/xasm/package.d module. app.d becomes a thin CLI frontend that drives that class.

What changed

  • New xasm module (source/xasm/package.d): the assembler implementation, moved out of app.d verbatim and wrapped in an Assembler class with a private implementation and a small public surface.
  • I/O is fully decoupled via delegates — the library performs no direct file access or console output. Callers supply:
    • SourceReader / BinaryReader — read source and binary-include files
    • DiagnosticSink — receive warnings and errors as structured Diagnostic values (Severity, filename, line, source line, message)
    • ListingSink — receive the assembly listing and label table line by line
  • Object code is staged through a buffer, exposed via assembler.object, instead of being written straight to a file.
  • Public API documented with ddoc; make libxasm.html generates the library reference. Label is now a struct, and the module carries a documented usage example (runnable as a unittest).

Notes

  • No changes to the assembler's behavior or output for CLI users; this is a structural refactor only.
  • Man page HISTORY section notes that xasm can now be used as a library, without assigning a concrete version number.

@pfusik pfusik left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this! Generally LGTM with a few nits, and I think -i got broken.

Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/app.d Outdated
Comment thread source/xasm/package.d Outdated
Comment thread source/xasm/package.d
@epi

epi commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

-i is ok. Added a unittest to confirm.

Comment thread source/app.d Outdated
Comment thread source/xasm/package.d Outdated

@pfusik pfusik left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM kurwa

@pfusik
pfusik merged commit d431fc1 into pfusik:master Sep 2, 2026
4 checks passed
@peterdell

Copy link
Copy Markdown
Collaborator

Huge respect to Epi for this epic rework. And to fix it for fighting through it. Very interesting, and "LGTM kurwa" made my day :-)

pfusik added a commit that referenced this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants