robot-factory converts a Corewar source file (.s) into a valid Corewar bytecode file (.cor).
This project focuses on correctness, deterministic output, and clear internal architecture:
- strict header parsing (
.name,.comment) - instruction and parameter decoding
- label storage and relative resolution
- big-endian binary encoding (
header_t+ instruction stream)
- It provides a complete assembler workflow from raw text to binary output.
- It is testable with both unit tests and functional binary comparisons.
- It includes tooling to debug memory safety (
valgrind) and quality (coverage).
make
./robot-factory Utilities/G-CPE-200_champions/abel.sGenerated output:
- input:
abel.s - output:
abel.cor
- Parse full source content via
openatorand tokenization helpers. - Validate required header fields and length constraints.
- Build internal representation using:
robotfactory_tas root contextinstr_tlinked list for ordered instructionsnode_tlist oflabel_tfor label positions
- Encode instructions with proper coding byte rules.
- Write Corewar header and instruction payload in big-endian format.
Robot_Factory/
├── Makefile
├── Src/
│ ├── main.c
│ ├── op.c
│ ├── Headers/
│ │ ├── op.h
│ │ └── robotfactory.h
│ ├── Parser/
│ │ ├── parser.c
│ │ ├── parser_body.c
│ │ ├── is_header_line.c
│ │ ├── get_opcode.c
│ │ ├── get_instr_size.c
│ │ └── free_robotfactory.c
│ ├── Encoder/
│ │ └── encoder.c
│ └── Tools/
│ └── shifter.c
├── lib/my/
├── tests/
│ ├── Makefile
│ ├── unit_tests_lib.c
│ ├── unit_tests_robotfactory.c
│ └── run_tests.sh
└── Doc/
├── README.md
├── schem.mmd
└── POLICY/
Use:
make helpMain targets:
make/make all: buildrobot-factorymake run: run with defaultARGUMENTSmake run ARGUMENTS="path/to/file.s": run custom sourcemake debug: debug build + valgrindmake valgrind: memory analysis on currentARGUMENTSmake unit_tests: build Criterion unit testsmake tests_run: run unit testsmake functional_tests: run functional shell testsmake coverage: coverage reportmake clean,make fclean,make re
mainvalidates CLI and callsparse.parsereads file, tokenizes lines, fills header, then parses body.get_bodystores labels and instructions inrobotfactory_t.write_corserializes header + instructions to.cor.free_robotfactoryreleases all dynamic parser structures.
Detailed architecture graph is in Doc/schem.mmd.
- Unit tests:
make tests_run - Functional tests:
make functional_tests - Valgrind:
make valgrind
Doc/POLICY/COMMIT_POLICY.mdDoc/POLICY/STRUCTURE_POLICY.md