Skip to main content
The codegen command analyzes Xbox 360 executable files and generates recompiled C++ code, headers, and build integration files.

Usage

rexglue codegen <config.toml> [flags]

Arguments

config.toml
string
required
Path to TOML configuration fileThis file specifies the XEX input path, output directory, and codegen options. See Configuration Reference.

Flags

General Flags

--force
boolean
default:"false"
Generate output even if validation errors occurBy default, codegen aborts if it detects errors during analysis. Use --force to generate code anyway (useful for iterative development).
--enable-exception-handlers
boolean
default:"false"
Enable generation of SEH exception handler codeGenerates code for Structured Exception Handling (SEH) found in the XEX binary.

Output Control

--functions-per-file
uint32
default:"500"
Number of functions per generated .cpp fileControls file splitting to keep compilation units manageable. Range: 1-100000.
--progress-log-frequency
uint32
default:"100"
Log progress every N functionsControls how often progress messages are logged during code generation. Range: 1-100000.

Analysis Parameters

--max-discovery-iterations
uint32
default:"1000"
Maximum iterations for function discovery convergenceLimits the iterative function discovery process. Range: 1-100000.
--max-vtable-iterations
uint32
default:"100"
Maximum iterations for vtable discoveryLimits the C++ vtable discovery process. Range: 1-100000.
--max-resolve-iterations
uint32
default:"100"
Maximum iterations for call target resolutionLimits the call graph resolution process. Range: 1-100000.

Exception Handling Limits

--max-eh-states
uint32
default:"100"
Maximum C++ EH states before rejecting handlerFunctions with more exception states are skipped. Range: 1-100000.
--max-eh-try-blocks
uint32
default:"50"
Maximum try blocks before rejecting handlerFunctions with more try blocks are skipped. Range: 1-100000.
--max-eh-ip-map-entries
uint32
default:"200"
Maximum IP-to-state map entriesControls exception handler table size limits. Range: 1-100000.
--max-seh-scope-entries
uint32
default:"100"
Maximum SEH scope table entriesControls SEH handler table size limits. Range: 1-100000.

Jump Table Discovery

--backward-scan-limit
uint32
default:"64"
Maximum instructions to scan backward for jump table patternsControls how far to look back when detecting switch/jump tables. Range: 1-10000.
--max-jump-table-entries
uint32
default:"512"
Maximum entries per detected jump tablePrevents runaway jump table detection. Range: 1-100000.
--max-blocks-per-function
uint32
default:"10000"
Safety limit on basic blocks per functionPrevents analysis of pathologically large functions. Range: 1-1000000.

Examples

Basic Code Generation

rexglue codegen my_game_config.toml
Output:
ReXGlue v0.1.0 - Xbox 360 Recompilation Toolkit
Generating code with config: my_game_config.toml
[Info] Loading XEX file: assets/default.xex
[Info] Discovered 4523 functions
[Info] Resolving call targets...
[Info] Generating C++ code...
[Info] Writing output files...
Operation completed successfully in 12.456s

Enable Exception Handlers

rexglue codegen my_game_config.toml --enable-exception-handlers

Force Generation with Errors

rexglue codegen my_game_config.toml --force --log-verbose

Adjust Output File Size

rexglue codegen my_game_config.toml --functions-per-file 250
This generates more (but smaller) .cpp files, which can improve parallel compilation.

Tune Analysis for Large Binaries

rexglue codegen my_game_config.toml \
  --max-discovery-iterations 2000 \
  --max-blocks-per-function 20000 \
  --progress-log-frequency 50

Generated Output

The codegen command generates several types of files in the output directory:

Configuration Header

// generated/my_game_config.h
#define PPC_IMAGE_BASE 0x82000000ull
#define PPC_IMAGE_SIZE 0x01A3C000ull
#define PPC_CODE_BASE 0x82000200ull
#define PPC_CODE_SIZE 0x019F4800ull

Initialization Code

// generated/my_game_init.h
// Function mapping tables for runtime
extern const PPCFunctionMapping PPCFuncMappings[];

Function Implementation Files

// generated/my_game_funcs_0.cpp
#include "my_game_config.h"
#include <rex/ppc.h>

PPC_FUNC(sub_82000200) {
  // Generated recompiled code
}

CMake Integration

# generated/sources.cmake
set(GENERATED_SOURCES
    generated/my_game_funcs_0.cpp
    generated/my_game_funcs_1.cpp
    # ...
)

Integration with CMake

After running codegen, rebuild your CMake project to include the generated code:
cmake --build out/build/linux-amd64-debug
The generated sources.cmake is automatically included by the project’s CMakeLists.txt.

Custom Codegen Target

Your project includes a custom CMake target for running codegen:
cmake --build out/build/linux-amd64-debug --target my_game_codegen
This runs rexglue codegen with the correct paths automatically.

Common Errors

Missing Config File

Missing config path. Usage: rexglue codegen <config.toml>
Solution: Provide the path to your configuration file.

XEX File Not Found

Failed to load XEX file: assets/default.xex
Solution: Verify the file_path in your config matches the actual XEX location.

Validation Errors

Operation failed: Validation errors detected (took 8.234s)
Solution: Check logs for details. Use --force to generate code despite errors, or fix the issues in your configuration.

Performance Tips

  1. Use --functions-per-file to balance compilation parallelism:
    • Smaller values (250-500): More files, better parallelism, slower linking
    • Larger values (1000+): Fewer files, slower compilation per file
  2. Enable verbose logging only when debugging:
    rexglue codegen config.toml --log-verbose --log-file codegen.log
    
  3. Tune iteration limits for very large binaries (>10MB XEX):
    • Increase --max-discovery-iterations if function discovery doesn’t converge
    • Increase --max-blocks-per-function if you have very large functions

Next Steps

Build docs developers (and LLMs) love