pass-lang/src/ir.h

48 lines
1.4 KiB
C

#ifndef _ASSEMBLER_H
#define _ASSEMBLER_H
#include <stddef.h>
#include <stdint.h>
typedef size_t var;
typedef struct label_info* label;
/// Declare a new label.
///
/// A label is the destination of a jump,
/// located with a fixed stack context and fixed argument types.
label declare_label(size_t args);
/// Define a previously-declared label.
///
/// The label must be defined in the same stack context
/// which it was declared in.
///
/// The definition of the label is... here, which is to say
/// whatever code you proceed to generate after this.
///
/// A label is implicitly terminated by an unconditional jump or exit.
/// However, it may exit at multiple locations via unconditional jumps.
void define_label(label label, var* args);
/// Jump to label, unconditionally. Terminates a block.
///
/// It is only possible to jump to a label in a parent or adjacent stack frame
/// (you can't jump *deeper* into the stack).
void jump(label label, var* args);
/// Jump to label in table; never returns. Terminates a block.
///
/// All labels must be at the same depth and accept the same arguments.
/// `index` must not be out of bounds.
void jump_table(size_t branches, label* labels, var index, var* args);
/// Jump to label if `cond` is not zero. Does not terminate a block.
void jump_if(label label, var cond, var* args);
var lit(uint64_t x);
void syscall(size_t argc, var* args);
#endif