public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gas: all: new macro directive ifquoted for determine the string
@ 2020-01-21  7:17 Dmitrij V
  0 siblings, 0 replies; only message in thread
From: Dmitrij V @ 2020-01-21  7:17 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

Hi ! The patch is small, about 100 strings of code.

[USAGE]

.section .text

.macro INVOKE arg1
  .ifquoted "\arg1\()"
    .warning "arg1 is string: \"\arg1\()\""
    .section .rodata
    tmp_string\@: .string "\arg1\()"
    # here we need to recall invoke with new arg1 point to tmp_string\@
    .section .text
  .endif;
.endm;

INVOKE "hello world !"

INVOKE 45646

INVOKE $32

[/USAGE]

[-- Attachment #2: quoted.diff --]
[-- Type: text/plain, Size: 2115 bytes --]

diff --git a/gas/cond.c b/gas/cond.c
index 9753369e18..1e926e99ab 100644
--- a/gas/cond.c
+++ b/gas/cond.c
@@ -580,3 +580,67 @@ cond_exit_macro (int nest)
       obstack_free (&cond_obstack, hold);
     }
 }
+
+/* Checks if current value is quoted by \". */
+
+void
+s_ifquoted (int arg)
+{
+  (void)arg;
+
+  struct conditional_frame cframe;
+
+  initialize_cframe (&cframe);
+
+  if (cframe.dead_tree)
+    cframe.ignoring = 1;
+  else
+  {
+    int do_ignore;
+    char *label;
+    char delim;
+
+    do_ignore = 1;
+
+    SKIP_WHITESPACE ();
+
+    delim = get_symbol_name(&label);
+    // printf("label: %s; delim: %c\n",(label),(delim));
+
+    if (delim == '"' && !symbol_find (label))
+    {
+      char *p, *e, dots;
+
+      p = label;
+      e = p+strlen(label);
+      dots = 0;
+
+      if (*p == '$' || *p == '-') // for digit
+        ++p;
+
+      while (*p)
+      {
+        if (*p == '.') // for float
+        {
+          if (dots)
+            break;
+          ++dots;
+          continue;
+        }
+        if (!(*p >= '0' && *p <= '9'))
+          break;
+        ++p;
+      }
+
+      do_ignore = (p == e);
+    }
+
+    cframe.ignoring = do_ignore;
+  }
+
+  current_cframe =
+  (struct conditional_frame *) obstack_alloc (&cond_obstack, sizeof cframe);
+  memcpy (current_cframe, &cframe, sizeof cframe);
+
+  ignore_rest_of_line ();
+}
diff --git a/gas/read.c b/gas/read.c
index bf594f12a2..a0af048f73 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -393,6 +394,7 @@ static const pseudo_typeS potable[] = {
   {"ifne", s_if, (int) O_ne},
   {"ifnes", s_ifeqs, 1},
   {"ifnotdef", s_ifdef, 1},
+  {"ifquoted", s_ifquoted, 0},
   {"incbin", s_incbin, 0},
   {"include", s_include, 0},
   {"int", cons, 4},
diff --git a/gas/read.h b/gas/read.h
index 502f3b6f2d..2ba62c5355 100644
--- a/gas/read.h
+++ b/gas/read.h
@@ -188,6 +188,7 @@ extern void s_ifb (int arg);
 extern void s_ifc (int arg);
 extern void s_ifdef (int arg);
 extern void s_ifeqs (int arg);
+extern void s_ifquoted (int arg);
 extern void s_ignore (int arg);
 extern void s_include (int arg);
 extern void s_irp (int arg);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-21  7:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21  7:17 [PATCH] gas: all: new macro directive ifquoted for determine the string Dmitrij V

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).