Module Asm_targets.Asm_directives
Abstraction layer for the emission of assembly directives that conceals many intricate details differing between target systems.
val switch_to_section :
?emit_label_on_first_occurrence:bool ->
Asm_targets.Asm_section.t ->
unitEmit subsequent directives to the given section. If this function has not been called before on the particular section, a label declaration will be emitted after declaring the section. Such labels may seem strange, but they are necessary so that references (e.g. DW_FORM_ref_addr / DW_FORM_sec_offset when emitting DWARF) to places that are currently at the start of these sections get relocated correctly when those places become not at the start (e.g. during linking).
val switch_to_section_raw :
names:string list ->
flags:string option ->
args:string list ->
is_delayed:bool ->
unitEmit subsequent directives to the given section, where the section must not be one of those in type section (see above). The section is specified by the three components of a typical assembler section-switching command. This function is only intended to be used for target-specific sections.
val int8 : ?comment:string -> Numbers.Int8.t -> unitEmit an 8-bit signed integer. There is no padding or sign extension. If the comment is specified it will be put on the same line as the integer.
val int16 : ?comment:string -> Numbers.Int16.t -> unitEmit a 16-bit signed integer. There is no padding or sign extension.
val int32 : ?comment:string -> Stdlib.Int32.t -> unitEmit a 32-bit signed integer. There is no padding or sign extension.
val int64 : ?comment:string -> Stdlib.Int64.t -> unitEmit a 64-bit signed integer.
val uint8 : ?comment:string -> Numbers.Uint8.t -> unitEmit an 8-bit unsigned integer. There is no padding.
val uint16 : ?comment:string -> Numbers.Uint16.t -> unitEmit an 16-bit unsigned integer. There is no padding.
val uint32 : ?comment:string -> Numbers.Uint32.t -> unitEmit an 32-bit unsigned integer. There is no padding.
val uint64 : ?comment:string -> Numbers.Uint64.t -> unitEmit an 64-bit unsigned integer. There is no padding.
val targetint : ?comment:string -> Targetint.t -> unitEmit a signed integer whose width is that of an address on the target machine. There is no padding or sign extension.
val uleb128 : ?comment:string -> Numbers.Uint64.t -> unitEmit a 64-bit integer in unsigned LEB128 variable-length encoding (cf. DWARF debugging information standard).
val sleb128 : ?comment:string -> Stdlib.Int64.t -> unitEmit a 64-bit integer in signed LEB128 variable-length encoding.
val float32_from_bits : Stdlib.Int32.t -> unitEmit a 32-bit-wide floating point number whose bits are contained in an Int32.t.
val float64_from_bits : Stdlib.Int64.t -> unitEmit a 64-bit-wide floating point number whose bits are contained in an Int64.t.
Emit a string (directly into the current section). This function does not write a terminating null.
val cache_string :
?comment:string ->
Asm_targets.Asm_section.t ->
string ->
Asm_targets.Asm_label.tCache a string for later emission. The returned label may be used to obtain the address of the string in the section. This function does not emit anything. (See emit_cached_strings, below.) If a string is supplied to this function that is already in the cache then the previously-assigned label is returned, not a new one.
Emit the sequence of: label definition: <string><null terminator> pairs as per previous calls to cache_string with appropriate directives to switch section interspersed. This function clears the cache.
Mark the source location of the current assembly position.
Adjust the current frame address offset by the given number of bytes. This and other CFI functions will not emit anything in the case where CFI is not supported on the target.
Define the current frame address offset. This and other CFI functions will not emit anything in the case where CFI is not supported on the target.
Note that the previous value of reg is saved at offset from the current frame address.
Mark that the call stack is not to be executable at runtime. Not supported on all platforms.
val align :
fill_x86_bin_emitter:Asm_targets.Asm_directives.align_padding ->
bytes:int ->
unitLeave as much space as is required to achieve the given alignment. On x86 in the binary emitter, it is important what the space is filled with: in the text section, one would typically fill it with nop instructions and in the data section, one would typically fill it with zeros. This is controlled by the parameter fill_x86_bin_emitter.
val size :
?size_of:Asm_targets.Asm_symbol.t ->
Asm_targets.Asm_symbol.t ->
unitEmit a directive giving the displacement between the given symbol and the current position. This should only be used to state sizes of blocks (e.g. functions) emitted immediately prior into the assembly stream. size_of may be specified when the symbol used for measurement differs from that whose size is being stated (e.g. on POWER with ELF ABI v1).
val size_const : Asm_targets.Asm_symbol.t -> int64 -> unitval define_data_symbol : Asm_targets.Asm_symbol.t -> unitDefine a data ("object") symbol at the current output position. When emitting for MASM this will cause loads and stores to/from the symbol to be treated as if they are loading machine-width words (unless the instruction has an explicit width suffix).
val define_function_symbol : Asm_targets.Asm_symbol.t -> unitDefine a function symbol at the current output position. An exception will be raised if the current section is not a text section.
val define_joint_label_and_symbol :
section:Asm_targets.Asm_section.t ->
Asm_targets.Asm_symbol.t ->
unitDefine both a label and a linker symbol. The label can be obtained as Asm_label.create_label_for_local_symbol.
val define_symbol_label :
section:Asm_targets.Asm_section.t ->
Asm_targets.Asm_symbol.t ->
unitDefine a symbol as a label at the current position. No type information is emitted.
val global : Asm_targets.Asm_symbol.t -> unitMark a symbol as global.
val symbol : ?comment:string -> Asm_targets.Asm_symbol.t -> unitEmit a machine-width reference to the given symbol.
val protected : Asm_targets.Asm_symbol.t -> unitEmit a protected directive for the given symbol.
val private_extern : Asm_targets.Asm_symbol.t -> unitMark a symbol as "private extern" (see assembler documentation for details).
val extrn : Asm_targets.Asm_symbol.t -> unitMark an already encoded symbol as external.
Mark an already encoded symbol or label as hidden.
val weak : Asm_targets.Asm_symbol.t -> unitMark an already encoded symbol or label as weak.
val indirect_symbol : Asm_targets.Asm_symbol.t -> unitMarker inside the definition of a lazy symbol stub (see platform or assembler documentation for details).
val define_label : Asm_targets.Asm_label.t -> unitDefine a label at the current position in the current section. The treatment for MASM when emitting into non-text sections is as for define_symbol, above.
val label : ?comment:string -> Asm_targets.Asm_label.t -> unitEmit a machine-width reference to the given label.
val label_plus_offset :
?comment:string ->
Asm_targets.Asm_label.t ->
offset_in_bytes:Targetint.t ->
unitEmit a machine-width reference to the given label with an offset.
The type of the symbol. There are various other types, but we currently only use and support the following.
val symbol_type_to_string : Asm_targets.Asm_directives.symbol_type -> stringThe string representation, architecture dependent at the moment.
val type_symbol :
Asm_targets.Asm_symbol.t ->
ty:Asm_targets.Asm_directives.symbol_type ->
unitval type_label :
Asm_targets.Asm_label.t ->
ty:Asm_targets.Asm_directives.symbol_type ->
unitval symbol_plus_offset :
Asm_targets.Asm_symbol.t ->
offset_in_bytes:Targetint.t ->
unitEmit a machine-width reference to the address formed by adding the given byte offset to the address of the given symbol. The symbol may be in a compilation unit and/or section different from the current one.
val between_symbols_in_current_unit :
upper:Asm_targets.Asm_symbol.t ->
lower:Asm_targets.Asm_symbol.t ->
unitEmit a machine-width reference giving the displacement between two given symbols. To obtain a positive result the symbol at the lower address should be the second argument, as for normal subtraction. The symbols must be in the current compilation unit and in the same section.
val between_labels_16_bit :
?comment:string ->
upper:Asm_targets.Asm_label.t ->
lower:Asm_targets.Asm_label.t ->
unit ->
unitLike between_symbols, but for two labels, emitting a 16-bit-wide reference. The behaviour upon overflow is unspecified. The labels must be in the same section.
val between_labels_32_bit :
?comment:string ->
upper:Asm_targets.Asm_label.t ->
lower:Asm_targets.Asm_label.t ->
unit ->
unitLike between_symbols, but for two labels, emitting a 32-bit-wide reference. The behaviour upon overflow is unspecified. The labels must be in the same section.
val between_labels_64_bit :
?comment:string ->
upper:Asm_targets.Asm_label.t ->
lower:Asm_targets.Asm_label.t ->
unit ->
unitLike between_symbols, but for two labels, emitting a 64-bit-wide reference. The labels must be in the same section.
val between_labels_64_bit_with_offsets :
?comment:string ->
upper:Asm_targets.Asm_label.t ->
upper_offset:Targetint.t ->
lower:Asm_targets.Asm_label.t ->
lower_offset:Targetint.t ->
unit ->
unitLike between_symbols, but for two labels with additional offsets, emitting a 64-bit-wide reference. The labels must be in the same section.
val between_this_and_label_offset_32bit_expr :
upper:Asm_targets.Asm_label.t ->
offset_upper:Targetint.t ->
unitEmit a 32-bit-wide label expression giving the displacement obtained by subtracting the current assembly location from the sum of the address of the given label plus the given offset. The label must be in the same section as the assembler is currently emitting into.
val between_symbol_in_current_unit_and_label_offset :
?comment:string ->
upper:Asm_targets.Asm_label.t ->
lower:Asm_targets.Asm_symbol.t ->
offset_upper:Targetint.t ->
unit ->
unitEmit a machine-width reference giving the displacement between the lower symbol and the sum of the address of the upper label plus offset_upper. The lower symbol must be in the current compilation unit. The upper label must be in the same section as the lower symbol.
val offset_into_dwarf_section_label :
?comment:string ->
width:Dwarf_flags.dwarf_format ->
Asm_targets.Asm_section.dwarf_section ->
Asm_targets.Asm_label.t ->
unitEmit an offset into a DWARF section given a label identifying the place within such section.
val offset_into_dwarf_section_symbol :
?comment:string ->
width:Dwarf_flags.dwarf_format ->
Asm_targets.Asm_section.dwarf_section ->
Asm_targets.Asm_symbol.t ->
unitEmit an offset into a DWARF section given a symbol identifying the place within such section. The symbol may only be in a compilation unit different from the current one if the supplied section is Debug_info. The symbol must always be in the given section.
val reloc_x86_64_plt32 :
offset_from_this:int64 ->
target_symbol:Asm_targets.Asm_symbol.t ->
rel_offset_from_next:int64 ->
unitmodule Directive : sig ... endval initialize :
big_endian:bool ->
emit_assembly_comments:bool ->
emit:(Asm_targets.Asm_directives.Directive.t -> unit) ->
unitTo be called by the emitter at the very start of code generation. big_endian should always be Arch.big_endian. Calling the functions in this module will cause directives to be passed to the given emit function (a typical implementation of which will just call Directive.print on its parameter). This function _does not_ switch sections. If Dwarf debug information is supposed to be produced, additionally debug_header should be called, which will switch to the text section after emitting some debug section labels.
val unsafe_set_internal_section_ref : Asm_targets.Asm_section.t -> unitDirectly set the internal section ref. Use this function with caution. It only makes sense when you manually switch directly to a section.