|
|
|
@ -7,6 +7,40 @@
|
|
|
|
|
typedef uint32_t var;
|
|
|
|
|
typedef uint32_t label;
|
|
|
|
|
|
|
|
|
|
struct jump_target {
|
|
|
|
|
label label;
|
|
|
|
|
var* args;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Declare a new label in the current scope with the provided number
|
|
|
|
|
/// of arguments.
|
|
|
|
|
///
|
|
|
|
|
/// Local variables (not part of a stack frame generated by `define` or `enter`)
|
|
|
|
|
/// will not be in scope of the definition of the label.
|
|
|
|
|
label declare(uint32_t argc);
|
|
|
|
|
|
|
|
|
|
/// Define a label and create a new scope for local variables.
|
|
|
|
|
///
|
|
|
|
|
/// The new scope will have access to all of the variables
|
|
|
|
|
/// of the parent scope of the label and the label's arguments,
|
|
|
|
|
/// but not any local variables from previous definitions.
|
|
|
|
|
void define(label label, var* args);
|
|
|
|
|
|
|
|
|
|
/// Create a new scope which encompasses all local variables defined up to this point.
|
|
|
|
|
///
|
|
|
|
|
/// This allows nested definitions to have access to local variables.
|
|
|
|
|
void enter(void);
|
|
|
|
|
|
|
|
|
|
/// Jump to label, unconditionally. Ends the continuation.
|
|
|
|
|
void jump(struct jump_target dest);
|
|
|
|
|
|
|
|
|
|
/// Jump to `then` if `cond` is not zero; jump to `else` otherwise.
|
|
|
|
|
/// Ends the continuation.
|
|
|
|
|
void jump_if(struct jump_target then, struct jump_target else_, var cond);
|
|
|
|
|
|
|
|
|
|
/// Jump to the `index`th destination. Ends the continuation.
|
|
|
|
|
void jump_table(uint32_t destc, struct jump_target* destinations, var index);
|
|
|
|
|
|
|
|
|
|
/// Call this at the beginning of execution.
|
|
|
|
|
/// It performs initialization and stuff.
|
|
|
|
|
void init_ir(var* argc, var* argv, var* env);
|
|
|
|
@ -61,11 +95,8 @@ void jump(label label, var* args);
|
|
|
|
|
/// `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.
|
|
|
|
|
void jump_if(label label, var cond, var* args);
|
|
|
|
|
|
|
|
|
|
/// Jump to label if `cond` is zero.
|
|
|
|
|
void jump_unless(label label, var cond, var* args);
|
|
|
|
|
/// Jump to `then` if cond is not zero, `else` if cond is zero.
|
|
|
|
|
void jump_if(label then, label else_, var cond, var* args);
|
|
|
|
|
|
|
|
|
|
/// Integer literal.
|
|
|
|
|
var lit(uint64_t lit);
|
|
|
|
|