public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sim: ppc: constify strings in igen tooling
@ 2021-11-01  2:38 Mike Frysinger
  2021-11-01  2:38 ` [PATCH 2/2] sim: ppc: handle \r in igen inputs [PR sim/28476] Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2021-11-01  2:38 UTC (permalink / raw)
  To: gdb-patches

---
 sim/ppc/filter.c     |  8 ++++----
 sim/ppc/gen-icache.c |  4 ++--
 sim/ppc/gen-itable.c | 12 ++++++------
 sim/ppc/gen-model.c  |  8 ++++----
 sim/ppc/ld-cache.c   |  9 +++++----
 sim/ppc/ld-cache.h   | 20 ++++++++++----------
 sim/ppc/ld-decode.c  |  2 +-
 sim/ppc/ld-decode.h  |  2 +-
 sim/ppc/ld-insn.c    | 16 ++++++++--------
 sim/ppc/lf.c         |  4 ++--
 sim/ppc/lf.h         |  4 ++--
 sim/ppc/misc.c       |  8 ++++----
 sim/ppc/misc.h       |  4 ++--
 13 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/sim/ppc/filter.c b/sim/ppc/filter.c
index a2024275290a..f1da310b1c24 100644
--- a/sim/ppc/filter.c
+++ b/sim/ppc/filter.c
@@ -40,8 +40,8 @@ new_filter(const char *filt,
   while (strlen(filt) > 0) {
     filter *new_filter;
     /* break up the filt list */
-    char *end = strchr(filt, ',');
-    char *next;
+    const char *end = strchr(filt, ',');
+    const char *next;
     int len;
     if (end == NULL) {
       end = strchr(filt, '\0');
@@ -71,8 +71,8 @@ is_filtered_out(const char *flags,
     int present;
     filter *filt = filters;
     /* break the string up */
-    char *end = strchr(flags, ',');
-    char *next;
+    const char *end = strchr(flags, ',');
+    const char *next;
     int len;
     if (end == NULL) {
       end = strchr(flags, '\0');
diff --git a/sim/ppc/gen-icache.c b/sim/ppc/gen-icache.c
index aa7ea6c9d316..4efc7392705a 100644
--- a/sim/ppc/gen-icache.c
+++ b/sim/ppc/gen-icache.c
@@ -366,14 +366,14 @@ print_icache_body(lf *file,
 
 typedef struct _icache_tree icache_tree;
 struct _icache_tree {
-  char *name;
+  const char *name;
   icache_tree *next;
   icache_tree *children;
 };
 
 static icache_tree *
 icache_tree_insert(icache_tree *tree,
-		   char *name)
+		   const char *name)
 {
   icache_tree *new_tree;
   /* find it */
diff --git a/sim/ppc/gen-itable.c b/sim/ppc/gen-itable.c
index a0d1560027c1..97ff91a888d1 100644
--- a/sim/ppc/gen-itable.c
+++ b/sim/ppc/gen-itable.c
@@ -64,12 +64,12 @@ gen_itable_h(insn_table *table, lf *file)
   /* output the table that contains the actual instruction info */
   lf_printf(file, "typedef struct _itable_instruction_info {\n");
   lf_printf(file, "  itable_index nr;\n");
-  lf_printf(file, "  char *format;\n");
-  lf_printf(file, "  char *form;\n");
-  lf_printf(file, "  char *flags;\n");
-  lf_printf(file, "  char *mnemonic;\n");
-  lf_printf(file, "  char *name;\n");
-  lf_printf(file, "  char *file;\n");
+  lf_printf(file, "  const char *format;\n");
+  lf_printf(file, "  const char *form;\n");
+  lf_printf(file, "  const char *flags;\n");
+  lf_printf(file, "  const char *mnemonic;\n");
+  lf_printf(file, "  const char *name;\n");
+  lf_printf(file, "  const char *file;\n");
   lf_printf(file, "  int line_nr;\n");
   lf_printf(file, "} itable_info;\n");
   lf_printf(file, "\n");
diff --git a/sim/ppc/gen-model.c b/sim/ppc/gen-model.c
index 1322391b25ae..a8bcc66e9f14 100644
--- a/sim/ppc/gen-model.c
+++ b/sim/ppc/gen-model.c
@@ -48,7 +48,7 @@ static void
 model_c_or_h_function(insn_table *entry,
 		      lf *file,
 		      table_entry *function,
-		      char *prefix)
+		      const char *prefix)
 {
   if (function->fields[function_type] == NULL
       || function->fields[function_type][0] == '\0') {
@@ -68,7 +68,7 @@ gen_model_h(insn_table *table, lf *file)
   insn *insn_ptr;
   model *model_ptr;
   insn *macro;
-  char *name;
+  const char *name;
   int model_create_p = 0;
   int model_init_p = 0;
   int model_halt_p = 0;
@@ -174,7 +174,7 @@ model_c_insn(insn_table *entry,
 {
   model_c_passed_data *data_ptr = (model_c_passed_data *)data;
   lf *file = data_ptr->file;
-  char *current_name = data_ptr->model_ptr->printable_name;
+  const char *current_name = data_ptr->model_ptr->printable_name;
   table_model_entry *model_ptr = instruction->file_entry->model_first;
 
   while (model_ptr) {
@@ -229,7 +229,7 @@ gen_model_c(insn_table *table, lf *file)
 {
   insn *insn_ptr;
   model *model_ptr;
-  char *name;
+  const char *name;
   int model_create_p = 0;
   int model_init_p = 0;
   int model_halt_p = 0;
diff --git a/sim/ppc/ld-cache.c b/sim/ppc/ld-cache.c
index 611ac7a08754..f57f7db650a0 100644
--- a/sim/ppc/ld-cache.c
+++ b/sim/ppc/ld-cache.c
@@ -42,9 +42,10 @@ static const name_map cache_type_map[] = {
 
 
 void
-append_cache_rule (cache_table **table, char *type, char *field_name,
-		   char *derived_name, char *type_def,
-		   char *expression, table_entry *file_entry)
+append_cache_rule (cache_table **table, const char *type,
+		   const char *field_name, const char *derived_name,
+		   const char *type_def, const char *expression,
+		   table_entry *file_entry)
 {
   while ((*table) != NULL)
     table = &(*table)->next;
@@ -60,7 +61,7 @@ append_cache_rule (cache_table **table, char *type, char *field_name,
 
 
 cache_table *
-load_cache_table(char *file_name,
+load_cache_table(const char *file_name,
 		 int hi_bit_nr)
 {
   table *file = table_open(file_name, nr_cache_rule_fields, 0);
diff --git a/sim/ppc/ld-cache.h b/sim/ppc/ld-cache.h
index 9662bd1795ff..ca4f6f6f91ec 100644
--- a/sim/ppc/ld-cache.h
+++ b/sim/ppc/ld-cache.h
@@ -66,25 +66,25 @@ typedef enum {
 typedef struct _cache_table cache_table;
 struct _cache_table {
   cache_rule_type type;
-  char *field_name;
-  char *derived_name;
-  char *type_def;
-  char *expression;
+  const char *field_name;
+  const char *derived_name;
+  const char *type_def;
+  const char *expression;
   table_entry *file_entry;
   cache_table *next;
 };
 
 
 extern cache_table *load_cache_table
-(char *file_name,
+(const char *file_name,
  int hi_bit_nr);
 
 extern void append_cache_rule
 (cache_table **table,
- char *type,
- char *field_name,
- char *derived_name,
- char *type_def,
- char *expression,
+ const char *type,
+ const char *field_name,
+ const char *derived_name,
+ const char *type_def,
+ const char *expression,
  table_entry *file_entry);
 
diff --git a/sim/ppc/ld-decode.c b/sim/ppc/ld-decode.c
index cee006fe6f10..68d9f5f4f52d 100644
--- a/sim/ppc/ld-decode.c
+++ b/sim/ppc/ld-decode.c
@@ -70,7 +70,7 @@ force_decode_gen_type(const char *type)
 
 
 decode_table *
-load_decode_table(char *file_name,
+load_decode_table(const char *file_name,
 		  int hi_bit_nr)
 {
   table *file = table_open(file_name, nr_decode_fields, 0);
diff --git a/sim/ppc/ld-decode.h b/sim/ppc/ld-decode.h
index 3e6447720875..4332dccb3aca 100644
--- a/sim/ppc/ld-decode.h
+++ b/sim/ppc/ld-decode.h
@@ -134,7 +134,7 @@ extern void force_decode_gen_type
 (const char *type);
 
 extern decode_table *load_decode_table
-(char *file_name,
+(const char *file_name,
  int hi_bit_nr);
 
 extern void dump_decode_rule
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index 126fc78037b7..3910af3fdf67 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -77,9 +77,9 @@ insn_table_depth(insn_table *table)
 
 static insn_fields *
 parse_insn_format(table_entry *entry,
-		  char *format)
+		  const char *format)
 {
-  char *chp;
+  const char *chp;
   insn_fields *fields = ZALLOC(insn_fields);
 
   /* create a leading sentinal */
@@ -102,8 +102,8 @@ parse_insn_format(table_entry *entry,
   chp = format;
 
   while (*chp != '\0') {
-    char *start_pos;
-    char *start_val;
+    const char *start_pos;
+    const char *start_val;
     int strlen_val;
     int strlen_pos;
     insn_field *new_field;
@@ -208,7 +208,7 @@ parse_insn_format(table_entry *entry,
 }
 
 
-void
+static void
 parse_include_entry (table *file,
                      table_entry *file_entry,
 		     filter *filters,
@@ -304,7 +304,7 @@ insn_table_insert_insn(insn_table *table,
   /* Check out any model information returned to make sure the model
      is correct.  */
   for(insn_model_ptr = file_entry->model_first; insn_model_ptr; insn_model_ptr = insn_model_ptr->next) {
-    char *name = insn_model_ptr->fields[insn_model_name];
+    const char *name = insn_model_ptr->fields[insn_model_name];
     int len = strlen (insn_model_ptr->fields[insn_model_fields]);
 
     while (len > 0 && isspace(*insn_model_ptr->fields[insn_model_fields])) {
@@ -544,10 +544,10 @@ insn_field_is_constant(insn_field *field,
     return field_constant_slash;
   /* field, though variable is on the list */
   if (field->is_string && rule->force_expansion != NULL) {
-    char *forced_fields = rule->force_expansion;
+    const char *forced_fields = rule->force_expansion;
     while (*forced_fields != '\0') {
       int field_len;
-      char *end = strchr(forced_fields, ',');
+      const char *end = strchr(forced_fields, ',');
       if (end == NULL)
 	field_len = strlen(forced_fields);
       else
diff --git a/sim/ppc/lf.c b/sim/ppc/lf.c
index a3815a8788ed..c40de5b5c5db 100644
--- a/sim/ppc/lf.c
+++ b/sim/ppc/lf.c
@@ -42,8 +42,8 @@ struct _lf {
 
 
 lf *
-lf_open(char *name,
-	char *real_name,
+lf_open(const char *name,
+	const char *real_name,
 	lf_file_references references,
 	lf_file_type type,
 	const char *program)
diff --git a/sim/ppc/lf.h b/sim/ppc/lf.h
index fabf8fbc58a8..f1c41a93c442 100644
--- a/sim/ppc/lf.h
+++ b/sim/ppc/lf.h
@@ -42,8 +42,8 @@ typedef enum {
    suppressed with LINE_NUMBERS */
 
 extern lf *lf_open
-(char *name,
- char *real_name,
+(const char *name,
+ const char *real_name,
  lf_file_references file_references,
  lf_file_type type,
  const char *program);
diff --git a/sim/ppc/misc.c b/sim/ppc/misc.c
index 6de3cf9a95b9..8f2581e3ef32 100644
--- a/sim/ppc/misc.c
+++ b/sim/ppc/misc.c
@@ -29,7 +29,7 @@
 #include <string.h>
 
 void
-error (char *msg, ...)
+error (const char *msg, ...)
 {
   va_list ap;
   va_start(ap, msg);
@@ -49,7 +49,7 @@ zalloc(long size)
 }
 
 void
-dumpf (int indent, char *msg, ...)
+dumpf (int indent, const char *msg, ...)
 {
   va_list ap;
   for (; indent > 0; indent--)
@@ -159,8 +159,8 @@ name2i(const char *names,
   const char *name = names;
   while (*name != '\0') {
     /* find our name */
-    char *end = strchr(name, ',');
-    char *next;
+    const char *end = strchr(name, ',');
+    const char *next;
     int len;
     if (end == NULL) {
       end = strchr(name, '\0');
diff --git a/sim/ppc/misc.h b/sim/ppc/misc.h
index 95b07390a0f4..784ccfdd37b9 100644
--- a/sim/ppc/misc.h
+++ b/sim/ppc/misc.h
@@ -31,7 +31,7 @@
 #include "filter_filename.h"
 
 extern void error
-(char *msg, ...);
+(const char *msg, ...);
 
 #define ASSERT(EXPRESSION) \
 do { \
@@ -48,7 +48,7 @@ extern void *zalloc
 (long size);
 
 extern void dumpf
-(int indent, char *msg, ...);
+(int indent, const char *msg, ...);
 
 extern unsigned target_a2i
 (int ms_bit_nr,
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] sim: ppc: handle \r in igen inputs [PR sim/28476]
  2021-11-01  2:38 [PATCH 1/2] sim: ppc: constify strings in igen tooling Mike Frysinger
@ 2021-11-01  2:38 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2021-11-01  2:38 UTC (permalink / raw)
  To: gdb-patches

Make sure we consume & ignore \r bytes in inputs in case the file
encodings are from a non-LF systems (e.g. Windows).
---
 sim/ppc/table.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/sim/ppc/table.c b/sim/ppc/table.c
index 3c7e4464beb5..6399bdaddcb1 100644
--- a/sim/ppc/table.c
+++ b/sim/ppc/table.c
@@ -208,7 +208,7 @@ table_entry_read(table *root)
   /* break the line into its colon delimitered fields */
   for (field = 0; field < file->nr_fields-1; field++) {
     entry->fields[field] = file->pos;
-    while(*file->pos && *file->pos != ':' && *file->pos != '\n')
+    while(*file->pos && *file->pos != ':' && *file->pos != '\n' && *file->pos != '\r')
       file->pos++;
     if (*file->pos == ':') {
       *file->pos = '\0';
@@ -219,7 +219,11 @@ table_entry_read(table *root)
   /* any trailing stuff not the last field */
   ASSERT(field == file->nr_fields-1);
   entry->fields[field] = file->pos;
-  while (*file->pos && *file->pos != '\n') {
+  while (*file->pos && *file->pos != '\n' && *file->pos != '\r') {
+    file->pos++;
+  }
+  if (*file->pos == '\r') {
+    *file->pos = '\0';
     file->pos++;
   }
   if (*file->pos == '\n') {
@@ -243,7 +247,7 @@ table_entry_read(table *root)
     file->pos++;
     for (field = 0; field < file->nr_model_fields-1; field++) {
       model->fields[field] = file->pos;
-      while(*file->pos && *file->pos != ':' && *file->pos != '\n')
+      while(*file->pos && *file->pos != ':' && *file->pos != '\n' && *file->pos != '\r')
 	file->pos++;
       if (*file->pos == ':') {
 	*file->pos = '\0';
@@ -254,7 +258,11 @@ table_entry_read(table *root)
     /* any trailing stuff not the last field */
     ASSERT(field == file->nr_model_fields-1);
     model->fields[field] = file->pos;
-    while (*file->pos && *file->pos != '\n') {
+    while (*file->pos && *file->pos != '\n' && *file->pos != '\r') {
+      file->pos++;
+    }
+    if (*file->pos == '\r') {
+      *file->pos = '\0';
       file->pos++;
     }
     if (*file->pos == '\n') {
@@ -274,13 +282,13 @@ table_entry_read(table *root)
     do {
       do {
 	file->pos++;
-      } while (*file->pos != '\0' && *file->pos != '\n');
-      if (*file->pos == '\n') {
+      } while (*file->pos != '\0' && *file->pos != '\n' && *file->pos != '\r');
+      if (*file->pos == '\n' || *file->pos == '\r') {
 	char *save_pos = ++file->pos;
 	int extra_lines = 0;
 	file->line_nr++;
 	/* Allow tab indented to have blank lines */
-	while (*save_pos == '\n') {
+	while (*save_pos == '\n' || *save_pos == '\r') {
 	  save_pos++;
 	  extra_lines++;
 	}
@@ -290,7 +298,7 @@ table_entry_read(table *root)
 	}
       }
     } while (*file->pos != '\0' && *file->pos == '\t');
-    if (file->pos[-1] == '\n')
+    if (file->pos[-1] == '\n' || file->pos[-1] == '\r')
       file->pos[-1] = '\0';
   }
   else
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-01  2:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01  2:38 [PATCH 1/2] sim: ppc: constify strings in igen tooling Mike Frysinger
2021-11-01  2:38 ` [PATCH 2/2] sim: ppc: handle \r in igen inputs [PR sim/28476] Mike Frysinger

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).