1 /* 2 * %CopyrightBegin% 3 * 4 * Copyright Ericsson AB 2020-2020. All Rights Reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * %CopyrightEnd% 19 */ 20 21 #ifndef _ASM_LOAD_H 22 #define _ASM_LOAD_H 23 24 /* 25 * Type for a label. 26 */ 27 typedef struct { 28 Uint value; /* Value of label (0 if not known yet). */ 29 Uint looprec_targeted; /* Non-zero if this label is the target of a 30 * loop_rec instruction. */ 31 } Label; 32 33 /* 34 * This structure associates a code offset with a source code location. 35 */ 36 37 typedef struct { 38 int pos; /* Position in code */ 39 int loc; /* Location in source code */ 40 } LineInstr; 41 42 /* This structure contains all information about the module being loaded. */ 43 struct LoaderState_ { 44 ErlDrvBinary *bin; /* Binary holding BEAM file (or NULL) */ 45 46 /* 47 * The following are used mainly for diagnostics. 48 */ 49 50 Eterm group_leader; /* Group leader (for diagnostics). */ 51 Eterm module; /* Tagged atom for module name. */ 52 Eterm function; /* Tagged atom for current function (or 0 if none). */ 53 unsigned arity; /* Arity for current function. */ 54 55 /* 56 * Used for code loading (mainly). 57 */ 58 int specific_op; /* Specific opcode (-1 if not found). */ 59 60 const BeamCodeHeader *code_hdr; /* Actual code header */ 61 BeamCodeHeader *load_hdr; /* Code header during load */ 62 63 int codev_size; /* Size of code buffer in words. */ 64 int ci; /* Current index into loaded code buffer. */ 65 Label *labels; 66 unsigned loaded_size; /* Final size of code when loaded. */ 67 int may_load_nif; /* true if NIFs may later be loaded for this module */ 68 const ErtsCodeInfo *on_load; /* Pointer to the on_load function, if any */ 69 unsigned max_opcode; /* Highest opcode used in module */ 70 71 /* 72 * Generic instructions. 73 */ 74 BeamOp *genop; /* The last generic instruction seen. */ 75 76 BifEntry **bif_imports; 77 78 /* 79 * Line table. 80 */ 81 LineInstr *line_instr; /* Line instructions */ 82 unsigned int current_li; /* Current line instruction */ 83 unsigned int *func_line; /* Mapping from function to first line instr */ 84 85 void *ba; /* Assembler used to create x86 assembly */ 86 87 const void *native_module_exec; /* Native module after codegen */ 88 void *native_module_rw; /* Native module after codegen, writable mapping */ 89 90 int function_number; 91 int last_label; 92 93 int otp_20_or_higher; 94 95 BeamOpAllocator op_allocator; 96 BeamFile beam; 97 }; 98 99 #endif 100