Overview
insert_sub_program appears in the RISC-V assembly program generation flow as the function call:
insert_sub_program(sub_program[hart], instr_stream);
The call is used after sub-program instruction generation or selection, inserting the per-hart sub_program[hart] content into an instruction stream named instr_stream.
Role in the generation sequence
The documented sequence places insert_sub_program in the middle of the broader riscv_asm_program_gen program-generation flow:
- Sub-program instructions are generated or selected.
insert_sub_program(sub_program[hart], instr_stream)is called.- After main-program and sub-program generation is complete, host-interface instructions are added through
gen_section. - The host-interface section includes labels and instructions such as:
write_tohost:
sw gp, tohost, t1
_exit:
- Trap-handling setup follows, including
push_gpr_to_kernel_stack(), which pushes general-purpose registers to the stack for trap handling. gen_section()is also used to select anmtvec_handlersection containingexception_handerandinterrupt_handlerdefinitions.
Context in generated programs
The surrounding generator flow is described as producing complete RISC-V assembly programs. The gen_program() function, other functions in the same class, riscv_instruction_sequence, base-test classes, and helper classes work together to generate randomized instructions, randomized general-purpose register choices, and different instruction patterns for IP verification use cases.
Inputs visible from the call site
The visible call signature shows two arguments:
sub_program[hart]: a per-hart sub-program object or collection referenced by hart index.instr_stream: the instruction stream into which the sub-program is inserted.
No further implementation details, return value, side effects beyond insertion into the instruction stream, or error behavior are provided in the available evidence.