public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: "Carlos Maniero" <carlos@maniero.me>
To: "Johnny Richard" <johnny@johnnyrichard.com>,
	<~johnnyrichard/olang-devel@lists.sr.ht>
Subject: Re: [PATCH olang v1 3/3] cli: add compilation -o option with --save-temps
Date: Mon, 04 Mar 2024 23:02:14 -0300	[thread overview]
Message-ID: <CZLG3530TMZL.2F7UL2NLVP17H@maniero.me> (raw)
In-Reply-To: <20240304193313.961286-4-johnny@johnnyrichard.com>


> +typedef enum
> +{
> +    CLI_OPT_DUMP_TOKENS = 1 << 1,
> +    CLI_OPT_OUTPUT = 1 << 2,
> +    CLI_OPT_SAVE_TEMPS = 1 << 3
> +} cli_opt;

nitpick: Any particular reason to avoid using the first bit?

  typedef enum
  {
      CLI_OPT_DUMP_TOKENS = 1 << 0,
      CLI_OPT_OUTPUT = 1 << 1,
      CLI_OPT_SAVE_TEMPS = 1 << 2
  } cli_opt;

> +    string_view_t file_path;

What is the point of making *file_path* a SV? Ever single place it is
used you are accessing it's char pointer directly - *file_path.chars*.
It looks unsafe to just ignore the SV's size, example:
*print_token(opts->file_path.chars, &token)*

> -    char *prog = cli_args_shift(&args);
> +    opts.prog = string_view_from_cstr(cli_args_shift(&args));

nitpick: Is that a standard calling arg0 as prog? I know it was already
there, but taking a fresh look at this name, I find it hard to
understand. WDYT about *opts.compiler_path*, *opts.the_0c_path* or
*opts.this_path*? The point is that, program can be ambiguos here as it
could be both the compiler's program or the program to be compiled.

> +    assert(opts && "args is required");

s/opts/args

> +    string_view_t asm_ext = string_view_from_cstr(".s");
> +    char asm_file[opts->output_bin.size + asm_ext.size + 1];
> +    memcpy(asm_file, opts->output_bin.chars, opts->output_bin.size);
> +    memcpy(asm_file + opts->output_bin.size, asm_ext.chars, asm_ext.size);
> +    asm_file[opts->output_bin.size + asm_ext.size] = 0;

nitpick: you have achieved the same later at this same file using
*sprintf* which I think reads better.

+    char asm_file[opts->output_bin.size + 3];
+    sprintf(asm_file, "" SV_FMT ".s", SV_ARG(opts->output_bin));



  parent reply	other threads:[~2024-03-05  2:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 19:23 [PATCH olang v1 0/3] implement assembly linux x86_64 compiler Johnny Richard
2024-03-04 19:23 ` [PATCH olang v1 1/3] be: create linux-x86_64 gas asm codegen Johnny Richard
2024-03-04 19:23 ` [PATCH olang v1 2/3] string_view: add function to create from cstr Johnny Richard
2024-03-04 19:23 ` [PATCH olang v1 3/3] cli: add compilation -o option with --save-temps Johnny Richard
2024-03-04 18:33   ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-03-04 19:39     ` Johnny Richard
2024-03-05  2:05       ` Carlos Maniero
2024-03-05  2:02   ` Carlos Maniero [this message]
2024-03-05  8:27     ` [PATCH olang v1 3/3] cli: add compilation -o option with --save-temps Johnny Richard
2024-03-05  8:53 ` [PATCH olang v1 0/3] implement assembly linux x86_64 compiler Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CZLG3530TMZL.2F7UL2NLVP17H@maniero.me \
    --to=carlos@maniero.me \
    --cc=johnny@johnnyrichard.com \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox