aboutsummaryrefslogtreecommitdiff
path: root/src/ir_print.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-10-18 03:00:48 -0400
committerAndrew Kelley <superjoe30@gmail.com>2016-10-18 03:00:48 -0400
commit682511d1b22d50a77ff967d1d6415a68560cd49a (patch)
tree03bfa3971672e40aedd5bc113a41f868bf0401e2 /src/ir_print.cpp
parentac6d1674e3384bacd6893191feaf814a23d24b08 (diff)
downloadzig-682511d1b22d50a77ff967d1d6415a68560cd49a.tar.gz
zig-682511d1b22d50a77ff967d1d6415a68560cd49a.zip
add variable declaration IR
Diffstat (limited to 'src/ir_print.cpp')
-rw-r--r--src/ir_print.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index fb6f4d16bb..aae0f109e1 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -198,6 +198,19 @@ static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction
ir_print_other_instruction(irp, bin_op_instruction->op2);
}
+static void ir_print_decl_var(IrPrint *irp, IrInstructionDeclVar *decl_var_instruction) {
+ const char *var_or_const = decl_var_instruction->var->is_const ? "const" : "var";
+ const char *name = buf_ptr(&decl_var_instruction->var->name);
+ if (decl_var_instruction->var_type) {
+ fprintf(irp->f, "%s %s: ", var_or_const, name);
+ ir_print_other_instruction(irp, decl_var_instruction->var_type);
+ fprintf(irp->f, " = ");
+ } else {
+ fprintf(irp->f, "%s %s = ", var_or_const, name);
+ }
+ ir_print_other_instruction(irp, decl_var_instruction->init_value);
+}
+
static void ir_print_load_var(IrPrint *irp, IrInstructionLoadVar *load_var_instruction) {
fprintf(irp->f, "%s", buf_ptr(&load_var_instruction->var->name));
}
@@ -288,6 +301,11 @@ static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruc
fprintf(irp->f, "unreachable");
}
+static void ir_print_store(IrPrint *irp, IrInstructionStoreVar *store_instruction) {
+ fprintf(irp->f, "%s = ", buf_ptr(&store_instruction->var->name));
+ ir_print_other_instruction(irp, store_instruction->value);
+}
+
static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
ir_print_prefix(irp, instruction);
switch (instruction->id) {
@@ -302,6 +320,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdBinOp:
ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
break;
+ case IrInstructionIdDeclVar:
+ ir_print_decl_var(irp, (IrInstructionDeclVar *)instruction);
+ break;
case IrInstructionIdLoadVar:
ir_print_load_var(irp, (IrInstructionLoadVar *)instruction);
break;
@@ -335,8 +356,10 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdUnreachable:
ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
break;
- case IrInstructionIdSwitchBr:
case IrInstructionIdStoreVar:
+ ir_print_store(irp, (IrInstructionStoreVar *)instruction);
+ break;
+ case IrInstructionIdSwitchBr:
zig_panic("TODO print more IR instructions");
}
fprintf(irp->f, "\n");