From 97b0a3dcdf750ae36eb40cdc57b30b1ee021d3d3 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 23 Dec 2021 13:59:20 +0100 Subject: Fix warnings on macos --- Makefile | 2 +- src/ir.h | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 4e31a67..31e98e3 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ BIN := $(BUILD_DIR)/$(TARGET) # Compiler and linker configuration. CC := cc -CFLAGS := -Wall -Wextra -pedantic -DBIN_NAME=\"$(TARGET)\" +CFLAGS := -Wall -Wextra -pedantic -DBIN_NAME=\"$(TARGET)\" -Wno-missing-braces CFLAGS += $(INC_FLAGS) NASM_FLAGS ?= -felf64 LDFLAGS := diff --git a/src/ir.h b/src/ir.h index c87babe..8518adb 100644 --- a/src/ir.h +++ b/src/ir.h @@ -132,7 +132,13 @@ typedef struct ProgramIr { #define INST_ARG(PROC, OP, ARG, LINE, COL) \ do { \ - Instruction inst = (Instruction){(OP), (ARG), (LINE), (COL)}; \ + Instruction inst = (Instruction){(OP), .argument = (ARG), (LINE), (COL)}; \ + array_push((PROC)->instructions, inst); \ + } while(false); + +#define INST_LABEL(PROC, OP, ARG, LINE, COL) \ + do { \ + Instruction inst = (Instruction){(OP), .label_id = (ARG), (LINE), (COL)}; \ array_push((PROC)->instructions, inst); \ } while(false); @@ -208,15 +214,15 @@ compile_numeric_cmp(ProgramIr *program, Procedure *proc, Op op, args = args->tail; INST_SIMPLE(proc, OP_DUP, line, col); INST_SIMPLE(proc, OP_ROT_RIGHT, line, col); - INST_ARG(proc, op, label_false, line, col); + INST_LABEL(proc, op, label_false, line, col); } INST_SIMPLE(proc, OP_DROP, line, col); INST_ARG(proc, OP_PUSH, &obj_true, line, col); - INST_ARG(proc, OP_JUMP, label_exit, line, col); - INST_ARG(proc, OP_LABEL, label_false, line, col); + INST_LABEL(proc, OP_JUMP, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_false, line, col); INST_SIMPLE(proc, OP_DROP, line, col); INST_ARG(proc, OP_PUSH, &obj_false, line, col); - INST_ARG(proc, OP_LABEL, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_exit, line, col); } void @@ -244,13 +250,13 @@ compile_and(ProgramIr *program, Procedure *proc, while (args != NULL) { compile_object(program, proc, args->head); args = args->tail; - INST_ARG(proc, OP_JUMP_IF_FALSE, label_false, line, col); + INST_LABEL(proc, OP_JUMP_IF_FALSE, label_false, line, col); } INST_ARG(proc, OP_PUSH, &obj_true, line, col); - INST_ARG(proc, OP_JUMP, label_exit, line, col); - INST_ARG(proc, OP_LABEL, label_false, line, col); + INST_LABEL(proc, OP_JUMP, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_false, line, col); INST_ARG(proc, OP_PUSH, &obj_false, line, col); - INST_ARG(proc, OP_LABEL, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_exit, line, col); } void @@ -261,13 +267,13 @@ compile_or(ProgramIr *program, Procedure *proc, while (args != NULL) { compile_object(program, proc, args->head); args = args->tail; - INST_ARG(proc, OP_JUMP_IF_TRUE, label_true, line, col); + INST_LABEL(proc, OP_JUMP_IF_TRUE, label_true, line, col); } INST_ARG(proc, OP_PUSH, &obj_false, line, col); - INST_ARG(proc, OP_JUMP, label_exit, line, col); - INST_ARG(proc, OP_LABEL, label_true, line, col); + INST_LABEL(proc, OP_JUMP, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_true, line, col); INST_ARG(proc, OP_PUSH, &obj_true, line, col); - INST_ARG(proc, OP_LABEL, label_exit, line, col); + INST_LABEL(proc, OP_LABEL, label_exit, line, col); } void @@ -332,16 +338,16 @@ void compile_if(ProgramIr *program, Procedure *proc, Object *obj) { size_t label_false = program->labels++; compile_object(program, proc, obj->condition); - INST_ARG(proc, OP_JUMP_IF_FALSE, label_false, obj->line, obj->col); + INST_LABEL(proc, OP_JUMP_IF_FALSE, label_false, obj->line, obj->col); compile_object(program, proc, obj->expr_true); if (obj->expr_false != NULL) { size_t label_exit = program->labels++; - INST_ARG(proc, OP_JUMP, label_exit, obj->line, obj->col); - INST_ARG(proc, OP_LABEL, label_false, obj->line, obj->col); + INST_LABEL(proc, OP_JUMP, label_exit, obj->line, obj->col); + INST_LABEL(proc, OP_LABEL, label_false, obj->line, obj->col); compile_object(program, proc, obj->expr_false); - INST_ARG(proc, OP_LABEL, label_exit, obj->line, obj->col); + INST_LABEL(proc, OP_LABEL, label_exit, obj->line, obj->col); } else { - INST_ARG(proc, OP_LABEL, label_false, obj->line, obj->col); + INST_LABEL(proc, OP_LABEL, label_false, obj->line, obj->col); } } -- cgit v1.2.1