genopcodes command generates Go source code for Hermes bytecode opcode definitions from .def files in the Hermes source repository. This is used to add support for new Hermes bytecode versions.
Usage
Flags
Download the latest opcode definition files from the Hermes repository before generating Go code.When enabled, this runs the download script to fetch bytecode definition files for all supported Hermes versions.
Examples
Generate Opcodes from Existing Definitions
Generate Go opcode files from previously downloaded.def files:
- Reads
.deffiles frompkg/hbc/types/opcodes/bcvXX/directories - Parses opcode definitions, operand types, and instruction formats
- Generates type-safe Go structs and constants
- Writes to
pkg/hbc/types/opcodes/bcvXX/generated.go
Download and Generate
Fetch the latest Hermes definitions and generate Go code:- Runs
pkg/utils/download_all.shto fetch.deffiles from Hermes GitHub releases - Downloads definitions for all supported bytecode versions (v61-v96)
- Generates Go opcode files for each version
How It Works
Step 1: Download Hermes Definitions (with --update)
The download script fetches bytecode definition files:
BytecodeList.def- Opcode definitionsBytecodeFileFormat.h- File format constants- Version-specific operand definitions
Step 2: Parse Definition Files
The generator parses.def files which contain macro definitions like:
Step 3: Generate Go Code
For each opcode, generates: Opcode constants:Adding Support for a New Hermes Version
When a new Hermes version is released:1. Download Definitions
Run the download script or manually fetch the.def file:
2. Generate Go Code
Run the generator:3. Register the Parser
Add the new version topkg/hbc/bytecode_parser.go in the GetParser method:
4. Implement the Parser
Createpkg/hbc/bytecode_parser_v97.go:
5. Test
Test the new parser with an HBC file compiled with the new Hermes version:Output Structure
The generator creates onegenerated.go file per bytecode version:
generated.go contains:
- Opcode constants
- Instruction definitions with operand types
- Operand size calculations
- Instruction lookup tables
Common Use Cases
Update All Opcodes
Refresh all opcode definitions from upstream Hermes:Regenerate After Manual Edit
If you manually edit a.def file:
Add New Bytecode Version
When Hermes releases a new version:Supported Bytecode Versions
Currently supports Hermes bytecode versions 61 through 96:| Bytecode Version | Hermes Version | React Native Version |
|---|---|---|
| 84 | 0.9.0 | 0.66-0.67 |
| 90 | 0.10.0 | 0.68 |
| 93 | 0.11.0 | 0.69-0.70 |
| 94 | 0.12.0 | 0.71 |
| 95 | 0.12.1 | 0.72 |
| 96 | 0.13.0 | 0.73+ |
Notes
- The generator is idempotent - running it multiple times produces the same output
- Generated files should not be manually edited (they’ll be overwritten)
- The download script requires
curland internet access - Definition files are sourced from the official Hermes GitHub repository
- Each bytecode version may have different opcodes, operand types, and instruction formats
Troubleshooting
”Failed to download definitions”
Check network connectivity and GitHub availability:“Parse error in definition file”
Definition files must follow the Hermes macro format. If you manually created a.def file, ensure it matches the expected structure:
“Generated file missing”
Ensure the output directory exists:“Unsupported bytecode version”
After generating opcodes, you must register the parser inbytecode_parser.go (see “Adding Support for a New Hermes Version” above).