From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4NdXE/YuB2dGzgAAqHPOHw:P1 (envelope-from ) for ; Thu, 10 Oct 2024 03:33:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 4NdXE/YuB2dGzgAAqHPOHw (envelope-from ) for ; Thu, 10 Oct 2024 03:33:42 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=TFBuzCmD; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=opYF2x0f; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728524021; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Hn2iNye5mN3G0GsE4wjG3/7UCtJwE8pAJ0AbkQMXBAM=; b=iwIfFb0wDvw0QuuoWrTN3s0DhoetKgDo60Rqh6g8myLhkLMJnrhaGP8w6vQvJELiTfP95Y 45ZypU7XTdFQRGTFgRIWfknFYNM1KsQaE18gymMLIwJZFyRHwYyyLF+5678eGQc71Tf+wq Q7k13QF46+1w7z0YAi6L+pr6Y+gMk/xC3xk2Pmm5JXqqdHKcJtaMebDOid+Ak4X2pqQ5v6 w8Y52h1yZPMkjFyfMCI4Eaa+Yqg5bLFrZ9iwwIaE3vl4TyEsSL5ZbA8vPQzMl0SBcFcI65 fE+sZPjREqNICBGrnVT19N3VTOVi8e7+khUwW5p+7BGkKNZDykscErJecSQjGw== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728524021; a=rsa-sha256; cv=pass; b=BEfMo1zGsLF587nF+iHqRthNzVh6x576WyzA6hbVBvb1ZkpK0mUEqoT/INU6/fZ7KZ9BGp TEWyRMsgYLZQ8OEeNLpqerTZqR15XXKqZCg3ZUa5NAD1srwHGsn/D8EFepSPjdOoqeyQTX zCMQsYLRt9Fht2FS6gALdhYrV6ZA1saHgHS5jTirGtBL4IZTo6FQTr8oZGIvMAv8wYl5wq tNMpjqYO0N4taViPt2ECvIUR63b4gaJuzuc8VJ+PI9x4eoIV5KNiY4MgfciSqU1cRJZ/gs 5yFQaDdqUSigpDyUQ3Vj5T+mJ+wHeEkmXIwxddzw/Jtt8ke+3PtAARvY/Ef0kA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=TFBuzCmD; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=opYF2x0f; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 403B05C5AA for ; Thu, 10 Oct 2024 03:33:41 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=3Oe85eWr4Fdeg2ZfeZcDUgBq9DRypvne+5Ot7Stsx6Y=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:In-Reply-To:References:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1728524021; v=1; b=TFBuzCmDdkdK83l89BQQJ5alQ9FR8aWKtF8cgdqdEFZhcHFZCSvu6BqxywH4c6sKTYo1V3UH TdQ6yUrd4nCaxnvMKpabt5WmVzCbS2PSLgnhx8HBnCMhDirFe4OJ6pUWMbQKAlfUqjKu8xO9E1e bHnWEVxKzDnuY6dTz9kwvARpxt3z/n+NwBDA6BZEnTv0bgYwwxZHZSIy/Bnqg2FIPy3ZGjBsiQo +cwNrZJL/YGMp/Dp0ZGRyxxaJEBgDzQwVqVDrNYdUjt2AdWaVYONJ3icrrQ3YSn4w+5n2UJF9vk 2d8JkBXAOv/PJXsjO7Apd+d7bwPXYrXOb8SGf2ElCq4IQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 2360420209 for ; Thu, 10 Oct 2024 01:33:41 +0000 (UTC) Received: from shrimp.cherry.relay.mailchannels.net (shrimp.cherry.relay.mailchannels.net [23.83.223.164]) by mail-a.sr.ht (Postfix) with ESMTPS id D4175201E1 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:35 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id ACC5C8C3149 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:32 +0000 (UTC) Received: from fr-int-smtpout5.hostinger.io (100-98-255-245.trex-nlb.outbound.svc.cluster.local [100.98.255.245]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id EB1F48C215D for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:31 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728524012; a=rsa-sha256; cv=none; b=7eVnkLRIiSnsIzxaXV84V4TbxMIVEzGfXUUk/t29cumWcy1pp/Jq8EoapCqhb6vd4gBMti to9na2bJJlqMCh02APOkcXy2WghfwSQU1NH0bjWErIu+I+Hf5xQzrVrbjDkqPGGviPDiPW P/gCb5FQP0/NbtsmjY4YkZByj0lvDdE4fgNKDq5bLV9VCFQfmi4AlZEMWFdZUDEWvbxfoH MIx6VvtVXUW2oV0czJuykmzEJwfOsPdgBJEmAjTv7gsSVg7DWnuj3Onr5KnEsc1B6fyLCH 0UnQ+yqTO+GIuxP2UobFXF3A34TFmff6qNqLGjQXAITf1LIkPLvAD9FhkY69gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728524012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Hn2iNye5mN3G0GsE4wjG3/7UCtJwE8pAJ0AbkQMXBAM=; b=pjjf8Vr98Zfzl+1yvHrKVwthJte75khuQPTxRXDWKp2QLsCwZg+sA17vOhtlDqElwgavZj oZFxaPSJ4bhTsDaw79gsKRJc3AILOhdu8Br7Cys0rFVD5PpVgKoWWDQ0ftFvtC915HZF5l MBAgqWkcCM7nN33pg/k0qXIDwifC8VeAwSVI8b7T4bofUAPoZ9lGeY95GkFgOPd7w8zZ1X mSqVp+0DivlVO6Bm0u4phVUj5lb8VBPdLXdmqb3AEFXR9YliomTM35sFk1iUfeKx1omsZi 9htaeBk8yXRn8OuqA4TMiywToY1L3wv/Rl4nvnYzJc8thhjpsNxkxlJZHzoG3w== ARC-Authentication-Results: i=1; rspamd-5fcd6bf96c-bc64j; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Battle-Wiry: 0c3c24690bad49cc_1728524012617_1748296239 X-MC-Loop-Signature: 1728524012617:184933209 X-MC-Ingress-Time: 1728524012617 Received: from fr-int-smtpout5.hostinger.io (fr-int-smtpout5.hostinger.io [89.116.146.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.98.255.245 (trex/7.0.2); Thu, 10 Oct 2024 01:33:32 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728524010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hn2iNye5mN3G0GsE4wjG3/7UCtJwE8pAJ0AbkQMXBAM=; b=opYF2x0fGnGE4VEtWwCxPDhAIgtnwJ5Wj3iTYnaUKt9LnOE6dNSIJ3qiyhjuBgQVQMnjsC ZPJ6btbT2wxz+3IWK4ghuDoGiHzwRnbpstux/wikp3vWzZhJryqh5hP4vI82laNRkhgEcc ZzGVJwGxdgZ6fmGFW/74aO1sZK5ULhLgKPtpNui4M6y7tL9uRi31qLZ22XyRzpV6G3Vj5k NzGTFD1y1Y/o9bRtA6oPXYV/iqlRO0lD+/vnqty7Gj7u0HFJAd2fKo7Kgv5Ql1HVoErdZJ 2hDbcH5SPU2F6v1KxCSbqgMtyFarznGr5v5sZIy0oiA/2j+6uoO3rc9YjH6oAg== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 1/6] codestyle: change AlignAfterOpenBracket to BlockIndent Message-ID: <20241010013318.222905-2-carlos@maniero.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241010013318.222905-1-carlos@maniero.me> References: <20241010013318.222905-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Thu, 10 Oct 2024 01:33:29 +0000 (UTC) X-CM-Analysis: v=2.4 cv=Z6G+H2RA c=1 sm=1 tr=0 ts=67072eea a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=jX7fAF86wrFgjrYiGqoA:9 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfHiIbgnCh4pccX7oEcntSVcvrmRQ3HcxDJcPDEhctBZwqwEzXccb0zIvycqSpKpCqWyI5GG0xDxp+GfwJQsWljtfHwKVU0GQirq78SsvB35Rg5WG5DD8 HJmXnl5LJVvA69mXCQEFGl3F2lX5IfY2n122uUS4LG9LvChk+L0LXeqdV+ouQVJQiwVfHCw8CtkGWhPiyvhmijdlsARMYzaf/6ttHPIeVeuwwSEobSNBeqed X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: UNKNOWN List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.89 X-Spam-Score: -4.89 X-Migadu-Queue-Id: 403B05C5AA X-Migadu-Scanner: mx13.migadu.com X-TUID: 9nlwDFbGDvC3 before: my_call(ar1, arg2); now: my_call( ar1, arg2 ); Signed-off-by: Carlos Maniero --- .clang-format | 2 +- src/ast.c | 14 ++-- src/ast.h | 14 ++-- src/cli.c | 29 ++++--- src/codegen_linux_x86_64.c | 151 ++++++++++++++++++++++--------------- src/main.c | 24 +++--- src/parser.c | 16 ++-- src/pretty_print_ast.c | 11 +-- src/scope.c | 1 - 9 files changed, 155 insertions(+), 107 deletions(-) diff --git a/.clang-format b/.clang-format index b76afee..5d4dd36 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ Language: Cpp # BasedOnStyle: Mozilla AccessModifierOffset: -2 -AlignAfterOpenBracket: Align +AlignAfterOpenBracket: BlockIndent AlignArrayOfStructures: None AlignConsecutiveAssignments: Enabled: false diff --git a/src/ast.c b/src/ast.c index 5a36ccb..797f5fd 100644 --- a/src/ast.c +++ b/src/ast.c @@ -40,12 +40,14 @@ ast_new_translation_unit(arena_t *arena) } ast_node_t * -ast_new_node_fn_def(arena_t *arena, - token_loc_t loc, - string_view_t id, - list_t *params, - type_t *return_type, - ast_node_t *block) +ast_new_node_fn_def( + arena_t *arena, + token_loc_t loc, + string_view_t id, + list_t *params, + type_t *return_type, + ast_node_t *block +) { assert(arena); assert(params); diff --git a/src/ast.h b/src/ast.h index ee94f57..44caf68 100644 --- a/src/ast.h +++ b/src/ast.h @@ -221,12 +221,14 @@ ast_node_t * ast_new_translation_unit(arena_t *arena); ast_node_t * -ast_new_node_fn_def(arena_t *arena, - token_loc_t loc, - string_view_t id, - list_t *params, - type_t *return_type, - ast_node_t *block); +ast_new_node_fn_def( + arena_t *arena, + token_loc_t loc, + string_view_t id, + list_t *params, + type_t *return_type, + ast_node_t *block +); ast_node_t * ast_new_node_fn_call(arena_t *arena, token_loc_t loc, string_view_t id, list_t *args); diff --git a/src/cli.c b/src/cli.c index 9d0f875..2faf6ce 100644 --- a/src/cli.c +++ b/src/cli.c @@ -107,7 +107,11 @@ cli_opts_parse_arch(cli_opts_t *opts, cli_args_t *args) char *arch = cli_args_shift(args); if (arch == NULL) { - fprintf(stderr, "error: missing architecture for arg '--arch': available options (x86_64 | aarch64)\n"); + fprintf( + stderr, + "error: missing architecture for arg '--arch': " + "available options (x86_64 | aarch64)\n" + ); cli_print_usage(stderr, opts->compiler_path); exit(EXIT_FAILURE); } @@ -137,14 +141,17 @@ cli_opts_parse_sysroot(cli_opts_t *opts, cli_args_t *args) void cli_print_usage(FILE *stream, char *compiler_path) { - fprintf(stream, - "Usage: %s [options] file...\n" - "Options:\n" - " --dump-tokens Display lexer token stream\n" - " --dump-ast Display ast tree to stdout\n" - " --arch Binary arch: default to x86_64 (x86_64 | aarch64)\n" - " --sysroot System root dir where the GNU Assembler and GNU Linker are located: default to '/'\n" - " -o Compile program into a binary file\n" - " --save-temps Keep temp files used to compile program\n", - compiler_path); + fprintf( + stream, + "Usage: %s [options] file...\n" + "Options:\n" + " --dump-tokens Display lexer token stream\n" + " --dump-ast Display ast tree to stdout\n" + " --arch Binary arch: default to x86_64 (x86_64 | aarch64)\n" + " --sysroot System root dir where the GNU Assembler and GNU " + "Linker are located: default to '/'\n" + " -o Compile program into a binary file\n" + " --save-temps Keep temp files used to compile program\n", + compiler_path + ); } diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c index ae28aa5..9a8d76e 100644 --- a/src/codegen_linux_x86_64.c +++ b/src/codegen_linux_x86_64.c @@ -211,10 +211,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " add %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " add %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -262,10 +264,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr fprintf(codegen->out, " pop %%rcx\n"); fprintf(codegen->out, " xor %%rdx, %%rdx\n"); fprintf(codegen->out, " div %s\n", get_reg_for(REG_COUNTER, expr_bytes)); - fprintf(codegen->out, - " mov %s, %s\n", - get_reg_for(REG_DATA, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " mov %s, %s\n", + get_reg_for(REG_DATA, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -280,10 +284,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " sub %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " sub %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -298,10 +304,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " sete %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -318,10 +326,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " setl %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -338,10 +348,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " setg %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -358,10 +370,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " setne %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -378,10 +392,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " setle %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -398,10 +414,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " cmp %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " cmp %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); fprintf(codegen->out, " setge %%al\n"); fprintf(codegen->out, " movzb %%al, %s\n", get_reg_for(REG_ACCUMULATOR, expr_bytes)); @@ -444,10 +462,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " xor %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " xor %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -462,10 +482,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " and %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " and %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -480,10 +502,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr size_in_bytes_t expr_bytes = bytes_max(rhs_bytes, lhs_bytes); fprintf(codegen->out, " pop %%rcx\n"); - fprintf(codegen->out, - " or %s, %s\n", - get_reg_for(REG_COUNTER, expr_bytes), - get_reg_for(REG_ACCUMULATOR, expr_bytes)); + fprintf( + codegen->out, + " or %s, %s\n", + get_reg_for(REG_COUNTER, expr_bytes), + get_reg_for(REG_ACCUMULATOR, expr_bytes) + ); return expr_bytes; } @@ -590,10 +614,12 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) size_t type_size = type_to_bytes(symbol->type); - fprintf(codegen->out, - " mov %s, -%ld(%%rbp)\n", - get_reg_for(REG_ACCUMULATOR, type_size), - codegen->base_offset); + fprintf( + codegen->out, + " mov %s, -%ld(%%rbp)\n", + get_reg_for(REG_ACCUMULATOR, type_size), + codegen->base_offset + ); codegen->base_offset += type_size; break; @@ -647,7 +673,8 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block) break; } default: { - // FIXME: improve error: replace the node->kind to a string representation + // FIXME: improve error: replace the node->kind to a string + // representation fprintf(stderr, "node kind %d not supported\n", node->kind); assert(0 && "unsupported block statement"); break; @@ -704,7 +731,10 @@ type_to_bytes(type_t *type) return 8; } case TYPE_UNKNOWN: { - assert(0 && "cannot calculate size of an unknown type: probably a parser issue."); + assert( + 0 && "cannot calculate size of an unknown type: probably a " + "parser issue." + ); } } @@ -770,11 +800,13 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ codegen_linux_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset); - fprintf(codegen->out, - " mov %s, -%ld(%%rbp)\n", - // FIXME: Type may not be an as_primitive - get_reg_for(x86_call_args[i], symbol->type->as_primitive.size), - offset); + fprintf( + codegen->out, + " mov %s, -%ld(%%rbp)\n", + // FIXME: Type may not be an as_primitive + get_reg_for(x86_call_args[i], symbol->type->as_primitive.size), + offset + ); // FIXME: add offset according to the param size codegen->base_offset += 8; @@ -796,7 +828,6 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ static void codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol, size_t offset) { - size_t *stack_offset = arena_alloc(codegen->arena, sizeof(size_t)); *stack_offset = offset; diff --git a/src/main.c b/src/main.c index d1c76e3..d7738bd 100644 --- a/src/main.c +++ b/src/main.c @@ -179,11 +179,13 @@ handle_codegen_linux(cli_opts_t *opts) exit(exit_code); } - sprintf(command, - "%s/bin/ld " SV_FMT ".o -o " SV_FMT "", - opts->sysroot, - SV_ARG(opts->output_bin), - SV_ARG(opts->output_bin)); + sprintf( + command, + "%s/bin/ld " SV_FMT ".o -o " SV_FMT "", + opts->sysroot, + SV_ARG(opts->output_bin), + SV_ARG(opts->output_bin) + ); exit_code = system(command); @@ -244,9 +246,11 @@ read_entire_file(char *filepath, arena_t *arena) static void print_token(token_t *token) { - printf("%s:%lu:%lu: <%s>\n", - token->loc.src.filepath, - token_loc_to_lineno(token->loc), - token_loc_to_colno(token->loc), - token_kind_to_cstr(token->kind)); + printf( + "%s:%lu:%lu: <%s>\n", + token->loc.src.filepath, + token_loc_to_lineno(token->loc), + token_loc_to_colno(token->loc), + token_kind_to_cstr(token->kind) + ); } diff --git a/src/parser.c b/src/parser.c index f712bfc..9d3d6e0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -750,13 +750,15 @@ static bool expected_token(token_t *token, token_kind_t expected_kind) { if (token->kind != expected_kind) { - fprintf(stderr, - "%s:%lu:%lu: syntax error: got '" SV_FMT "' token but expect '%s'\n", - token->loc.src.filepath, - token_loc_to_lineno(token->loc), - token_loc_to_colno(token->loc), - SV_ARG(token->value), - token_kind_to_cstr(expected_kind)); + fprintf( + stderr, + "%s:%lu:%lu: syntax error: got '" SV_FMT "' token but expect '%s'\n", + token->loc.src.filepath, + token_loc_to_lineno(token->loc), + token_loc_to_colno(token->loc), + SV_ARG(token->value), + token_kind_to_cstr(expected_kind) + ); fprintf(stderr, SV_FMT "\n", SV_ARG(token_loc_to_line(token->loc))); fprintf(stderr, "%*s\n", (int)token_loc_to_colno(token->loc), "^"); diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index 3a42412..f5cd571 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -57,7 +57,6 @@ pretty_print_print_ident(uint64_t *prefix, size_t level, bool lst_children) } for (size_t i = 0; i < level; ++i) { - if (!PP_IS_BIT_SET(*prefix, i)) { printf(" "); continue; @@ -145,10 +144,12 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) ast_fn_definition_t fn_def = ast->as_fn_def; char name[256]; - sprintf(name, - "Function_Definition ", - SV_ARG(fn_def.id), - SV_ARG(fn_def.return_type->id)); + sprintf( + name, + "Function_Definition ", + SV_ARG(fn_def.id), + SV_ARG(fn_def.return_type->id) + ); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); diff --git a/src/scope.c b/src/scope.c index e483fbe..ff9067c 100644 --- a/src/scope.c +++ b/src/scope.c @@ -67,7 +67,6 @@ scope_lookup(scope_t *scope, string_view_t id) { assert(scope); while (scope != NULL) { - char cstr_id[id.size + 1]; cstr_id[id.size] = 0; memcpy(cstr_id, id.chars, id.size); -- 2.46.0