From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6BVaL9kb72a1CgAA62LTzQ:P1 (envelope-from ) for ; Sat, 21 Sep 2024 21:17:45 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 6BVaL9kb72a1CgAA62LTzQ (envelope-from ) for ; Sat, 21 Sep 2024 21:17:45 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=qi5aQ5ux; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=n9VLN4Lp; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726946265; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-unsubscribe:list-subscribe: list-post:dkim-signature; bh=gqeAz4rCa19NUPEhn7MWIa0rrkUoqAAeh59IKxHrKGo=; b=jp2WSxFGV08RmQ/P6XbNRsrPFU1kfTOzFyqjZ9wjpyd1YGQ5V+2jbCk+oEPO+lq1JHE+11 p/L3hvTRoGcBu47TpZC9XEHJFe5gGMF2izqb2FTrhv5B0CEbBNVx3CNCv2KQ4zcSjxEZux IAEbE3pasxyBUmLDwC78kWAgyVcOWVsPHDY5IGOwCcMEOZdHdNTPNnUwVFF+7Ost6sSwqL 1X04w7lFRRXNyw7/2N6p3k+WIKROkjdLDNklf0/8DjbQYKteMABwrW3h20UmaXUN2hsUCY 7AvaHYfjwzP1Jxt8AcObKscpK8SK5JnxYLO/ukiQHWVNa8/7suaDVZ2EYH/qIA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=qi5aQ5ux; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=n9VLN4Lp; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1726946265; a=rsa-sha256; cv=none; b=dTWx7ZhFTLThtAmnzoa3WIxf8KCxvJf3bxIqK7La54LhDeqNvHp2+spnzWId+BCSdqYSzK YVDtEDCWFXI44KQW5AjMDMVcxsTJuYnO/SA8iT5QoWl4IrV8tI1VtX67CE99GTYX7fNWT8 X1bl/bLX+X4L3mscAVPHBUQhIAsm7+dCKsguCEpzv4S0EjTIXlNQKJY6zjrLS3FzCaZziE L9hmPWHMEe0rWJkCsFAj8D1qBPT+nGK0zwiUpbzDeV43jI/frd27XkdKEoo0Q2KI9C5tNI Cssdi4r3F88H4qcEdGs77KSkZp+pR9Gs+LB9c2dlWksQxr+7qxJmS2o+gy7Gxg== 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 9FBAB675E for ; Sat, 21 Sep 2024 21:17:45 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=P8AuYrJXGLq+rfEinfoBn7d2psWW7TLjB5Oikk7/6f4=; c=simple/simple; d=lists.sr.ht; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1726946265; v=1; b=qi5aQ5uxwMF771X5lCiHA4UMv5EqSPEuRy2rdJxqyb/IvfAcAhHq3MRlPiIl6l8QBtO9ysTK k3q9v3XSYOCqw9eGfDr7e86o6sErp3YRWrStptdfFTJMMhh+oDu+zVRuHnPnquXwV8u6AkH8LPb uYMt4/O2gua7kiXvML/MTzRvBlD/VrrJ2U/BandOedWyfZIeu7mVMvJT+db/ywQx0gwXe6MhFH8 +avB574tTwjHFC2BCf/uGCGsh7WOOn0YIwSuQIQhLB1OEXmoBa6DwHg6xjuKn/qrCQ3APctk2x4 JDr0zWbTwO3QsVG0TT5PdYQOk+UxsI2N268OLmk1SoBjw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 6C45C20326 for ; Sat, 21 Sep 2024 19:17:45 +0000 (UTC) Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by mail-a.sr.ht (Postfix) with ESMTPS id B43BE202C4 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 19:17:44 +0000 (UTC) Date: Sat, 21 Sep 2024 21:17:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726946263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gqeAz4rCa19NUPEhn7MWIa0rrkUoqAAeh59IKxHrKGo=; b=n9VLN4LpFZUW3I454NrT6JiN2i/PordP27rBT/WOQgxO2VwMbMwj4CLlxjRuGsgS2CADB0 BfED/6NA5bxxFuqrDzx3m1VSpnn3iENdA92dobzQAwm6M8EKu4++Kn3y7qk5FqiKSh+xDj 9eG1q3dr1RN0wpgM6wY8BmH9lqirr0DXET812uqMe/B1c5BASiFKGwpl2QKsX+FAaRUw0a Hle+nKiXiMEKiYyCkSieewn0cbImjvc1lQQbx7KiZFGAqHZ9s7V61zDLZwj15Dy2m4SxRa 56VZajxjMiD5FMGhiPh4GioqgwhIwZHQ6rndlpDBlRjNsZKH9HOJraSCX0MRqA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Johnny Richard To: Carlos Maniero Cc: ~johnnyrichard/olang-devel@lists.sr.ht Subject: Re: [PATCH olang 5/5] codegen: perform mov instructions based on variable type Message-ID: References: <20240921082437.396691-1-carlos@maniero.me> <20240921082437.396691-6-carlos@maniero.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240921082437.396691-6-carlos@maniero.me> 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: -1.16 X-Spam-Score: -1.16 X-Migadu-Queue-Id: 9FBAB675E X-Migadu-Scanner: mx10.migadu.com X-TUID: bIrWCkBN4VOs On Sat, Sep 21, 2024 at 08:25:03AM GMT, Carlos Maniero wrote: > There are two function that was introduced to performe the translations > bellow: > > type | type_to_bytes | bytes_to_rax > ----------------------------------- > u8 | 1 | ah > u16 | 2 | ax > u32 | 4 | eax > u64 | 8 | rax > > I opted to create *bytes_to_rax* instead of *type_to_rax* mainly because > we may use the same function to mov literals once we extend the literals > as well (We say that all literals are u32 but we actually handle them as > u64 on codegen). Yeah, you are very right here. I always mess with bytes sizes LOL. > diff --git a/src/checker.c b/src/checker.c > index f5068e0..3a78a59 100644 > --- a/src/checker.c > +++ b/src/checker.c > @@ -133,11 +133,26 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) > static void > evaluate_type(type_t *type) > { > + if (string_view_eq_to_cstr(type->id, "u8")) { > + type->kind = TYPE_PRIMITIVE; > + type->as_primitive = TYPE_U8; > + return; > + } > + if (string_view_eq_to_cstr(type->id, "u16")) { > + type->kind = TYPE_PRIMITIVE; > + type->as_primitive = TYPE_U16; > + return; > + } > if (string_view_eq_to_cstr(type->id, "u32")) { > type->kind = TYPE_PRIMITIVE; > type->as_primitive = TYPE_U32; > return; > } > + if (string_view_eq_to_cstr(type->id, "u64")) { > + type->kind = TYPE_PRIMITIVE; > + type->as_primitive = TYPE_U64; > + return; > + } > > type->kind = TYPE_USER_DEFINED; > } Is "as_primitive" property used only for calculate the size in bytes or you see any other need in the future? > diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c > index 415c81b..fa2a082 100644 > --- a/src/codegen_linux_x86_64.c > +++ b/src/codegen_linux_x86_64.c > @@ -38,6 +38,12 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_ > static size_t > type_to_bytes(type_t *type); > > +static char * > +bytes_to_mov(size_t bytes); Is this necessary? I mean, isn't GAS smart enough to pick the right mov instruction based on register size? If we have to pick the right size mov explicitly, what do you think about renaming it to **get_mov_inst_for(size_t)** or something alike to express better the intention? > +static char * > +bytes_to_rax(size_t bytes); This is similar to MOV instruction above, I was thinking about naming it to **get_accumulator_reg_for(size_t)** or something else like it. What do you think? The current name uses the 64bit version of the accumulator register. > + > void > codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out) > { > @@ -474,7 +502,7 @@ calculate_fn_local_size(scope_t *scope) > static void > codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_t *fn) > { > - codegen->base_offset = 0; > + codegen->base_offset = 8; Nicely spotted! > ast_node_t *block_node = fn->block; > fprintf(codegen->out, "" SV_FMT ":\n", SV_ARG(fn->identifier)); >