libyasm
arch.h
Go to the documentation of this file.
1 
30 #ifndef YASM_ARCH_H
31 #define YASM_ARCH_H
32 
34 typedef enum yasm_arch_create_error {
39 
41 typedef enum yasm_arch_insnprefix {
46 
50 typedef enum yasm_arch_regtmod {
57 
58 #ifndef YASM_DOXYGEN
59 
62 typedef struct yasm_arch_base {
64  const struct yasm_arch_module *module;
65 } yasm_arch_base;
66 #endif
67 
74 typedef struct yasm_arch_machine {
76  const char *name;
77 
79  const char *keyword;
81 
88 typedef struct yasm_arch_module {
92  const char *name;
93 
97  const char *keyword;
98 
100  /*@null@*/ const yasm_directive *directives;
101 
106  /*@only@*/ yasm_arch * (*create) (const char *machine, const char *parser,
107  /*@out@*/ yasm_arch_create_error *error);
108 
112  void (*destroy) (/*@only@*/ yasm_arch *arch);
113 
117  const char * (*get_machine) (const yasm_arch *arch);
118 
122  unsigned int (*get_address_size) (const yasm_arch *arch);
123 
127  int (*set_var) (yasm_arch *arch, const char *var, unsigned long val);
128 
133  (yasm_arch *arch, const char *id, size_t id_len, unsigned long line,
134  /*@out@*/ /*@only@*/ yasm_bytecode **bc, /*@out@*/ uintptr_t *prefix);
135 
140  (yasm_arch *arch, const char *id, size_t id_len,
141  /*@out@*/ uintptr_t *data);
142 
146  const unsigned char ** (*get_fill) (const yasm_arch *arch);
147 
151  int (*floatnum_tobytes) (yasm_arch *arch, const yasm_floatnum *flt,
152  unsigned char *buf, size_t destsize,
153  size_t valsize, size_t shift, int warn);
154 
158  int (*intnum_tobytes) (yasm_arch *arch, const yasm_intnum *intn,
159  unsigned char *buf, size_t destsize, size_t valsize,
160  int shift, const yasm_bytecode *bc,
161  int warn);
162 
166  unsigned int (*get_reg_size) (yasm_arch *arch, uintptr_t reg);
167 
171  uintptr_t (*reggroup_get_reg) (yasm_arch *arch, uintptr_t reggroup,
172  unsigned long regindex);
173 
177  void (*reg_print) (yasm_arch *arch, uintptr_t reg, FILE *f);
178 
182  void (*segreg_print) (yasm_arch *arch, uintptr_t segreg, FILE *f);
183 
187  yasm_effaddr * (*ea_create) (yasm_arch *arch, /*@keep@*/ yasm_expr *e);
188 
192  void (*ea_destroy) (/*@only@*/ yasm_effaddr *ea);
193 
197  void (*ea_print) (const yasm_effaddr *ea, FILE *f, int indent_level);
198 
202  /*@only@*/ yasm_bytecode * (*create_empty_insn) (yasm_arch *arch,
203  unsigned long line);
204 
210 
216 
221  unsigned int wordsize;
222 
227  unsigned int min_insn_len;
229 
234 const char *yasm_arch_name(const yasm_arch *arch);
235 
240 const char *yasm_arch_keyword(const yasm_arch *arch);
241 
246 unsigned int yasm_arch_wordsize(const yasm_arch *arch);
247 
252 unsigned int yasm_arch_min_insn_len(const yasm_arch *arch);
253 
263 /*@only@*/ yasm_arch *yasm_arch_create(const yasm_arch_module *module,
264  const char *machine, const char *parser,
265  /*@out@*/ yasm_arch_create_error *error);
266 
270 void yasm_arch_destroy(/*@only@*/ yasm_arch *arch);
271 
276 const char *yasm_arch_get_machine(const yasm_arch *arch);
277 
282 unsigned int yasm_arch_get_address_size(const yasm_arch *arch);
283 
290 int yasm_arch_set_var(yasm_arch *arch, const char *var, unsigned long val);
291 
308  (yasm_arch *arch, const char *id, size_t id_len, unsigned long line,
309  /*@out@*/ /*@only@*/ yasm_bytecode **bc, /*@out@*/ uintptr_t *prefix);
310 
324  (yasm_arch *arch, const char *id, size_t id_len,
325  /*@out@*/ uintptr_t *data);
326 
332 const unsigned char **yasm_arch_get_fill(const yasm_arch *arch);
333 
349  unsigned char *buf, size_t destsize,
350  size_t valsize, size_t shift, int warn);
351 
368 int yasm_arch_intnum_tobytes(yasm_arch *arch, const yasm_intnum *intn,
369  unsigned char *buf, size_t destsize,
370  size_t valsize, int shift,
371  const yasm_bytecode *bc, int warn);
372 
378 unsigned int yasm_arch_get_reg_size(yasm_arch *arch, uintptr_t reg);
379 
388 uintptr_t yasm_arch_reggroup_get_reg(yasm_arch *arch, uintptr_t reggroup,
389  unsigned long regindex);
390 
396 void yasm_arch_reg_print(yasm_arch *arch, uintptr_t reg, FILE *f);
397 
403 void yasm_arch_segreg_print(yasm_arch *arch, uintptr_t segreg, FILE *f);
404 
410 yasm_effaddr *yasm_arch_ea_create(yasm_arch *arch, /*@keep@*/ yasm_expr *e);
411 
416 void yasm_arch_ea_destroy(yasm_arch *arch, /*@only@*/ yasm_effaddr *ea);
417 
424 void yasm_arch_ea_print(const yasm_arch *arch, const yasm_effaddr *ea,
425  FILE *f, int indent_level);
426 
434  unsigned long line);
435 
436 #ifndef YASM_DOXYGEN
437 
438 /* Inline macro implementations for arch functions */
439 
440 #define yasm_arch_name(arch) \
441  (((yasm_arch_base *)arch)->module->name)
442 #define yasm_arch_keyword(arch) \
443  (((yasm_arch_base *)arch)->module->keyword)
444 #define yasm_arch_wordsize(arch) \
445  (((yasm_arch_base *)arch)->module->wordsize)
446 #define yasm_arch_min_insn_len(arch) \
447  (((yasm_arch_base *)arch)->module->min_insn_len)
448 
449 #define yasm_arch_create(module, machine, parser, error) \
450  module->create(machine, parser, error)
451 
452 #define yasm_arch_destroy(arch) \
453  ((yasm_arch_base *)arch)->module->destroy(arch)
454 #define yasm_arch_get_machine(arch) \
455  ((yasm_arch_base *)arch)->module->get_machine(arch)
456 #define yasm_arch_get_address_size(arch) \
457  ((yasm_arch_base *)arch)->module->get_address_size(arch)
458 #define yasm_arch_set_var(arch, var, val) \
459  ((yasm_arch_base *)arch)->module->set_var(arch, var, val)
460 #define yasm_arch_parse_check_insnprefix(arch, id, id_len, line, bc, prefix) \
461  ((yasm_arch_base *)arch)->module->parse_check_insnprefix \
462  (arch, id, id_len, line, bc, prefix)
463 #define yasm_arch_parse_check_regtmod(arch, id, id_len, data) \
464  ((yasm_arch_base *)arch)->module->parse_check_regtmod \
465  (arch, id, id_len, data)
466 #define yasm_arch_get_fill(arch) \
467  ((yasm_arch_base *)arch)->module->get_fill(arch)
468 #define yasm_arch_floatnum_tobytes(arch, flt, buf, destsize, valsize, shift, \
469  warn) \
470  ((yasm_arch_base *)arch)->module->floatnum_tobytes \
471  (arch, flt, buf, destsize, valsize, shift, warn)
472 #define yasm_arch_intnum_tobytes(arch, intn, buf, destsize, valsize, shift, \
473  bc, warn) \
474  ((yasm_arch_base *)arch)->module->intnum_tobytes \
475  (arch, intn, buf, destsize, valsize, shift, bc, warn)
476 #define yasm_arch_get_reg_size(arch, reg) \
477  ((yasm_arch_base *)arch)->module->get_reg_size(arch, reg)
478 #define yasm_arch_reggroup_get_reg(arch, regg, regi) \
479  ((yasm_arch_base *)arch)->module->reggroup_get_reg(arch, regg, regi)
480 #define yasm_arch_reg_print(arch, reg, f) \
481  ((yasm_arch_base *)arch)->module->reg_print(arch, reg, f)
482 #define yasm_arch_segreg_print(arch, segreg, f) \
483  ((yasm_arch_base *)arch)->module->segreg_print(arch, segreg, f)
484 #define yasm_arch_ea_create(arch, e) \
485  ((yasm_arch_base *)arch)->module->ea_create(arch, e)
486 #define yasm_arch_ea_destroy(arch, ea) \
487  ((yasm_arch_base *)arch)->module->ea_destroy(ea)
488 #define yasm_arch_ea_print(arch, ea, f, i) \
489  ((yasm_arch_base *)arch)->module->ea_print(ea, f, i)
490 #define yasm_arch_create_empty_insn(arch, line) \
491  ((yasm_arch_base *)arch)->module->create_empty_insn(arch, line)
492 
493 #endif
494 
495 #endif