]> granicus.if.org Git - esp-idf/commitdiff
console, ulp: don’t use nested functions
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 6 Dec 2018 07:08:05 +0000 (15:08 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 6 Dec 2018 08:12:47 +0000 (16:12 +0800)
These are not supported by clang

Ref LLVM-12

components/console/split_argv.c
components/ulp/ulp_macro.c

index 79ae918fcb943a89a9c7f6eac9d7d4fd733d2612..66b5d0f80347cd016abe32f1beed6615c70d5fa7 100644 (file)
@@ -31,6 +31,13 @@ typedef enum {
     SS_QUOTED_ARG_ESCAPED = SS_QUOTED_ARG | SS_FLAG_ESCAPE,
 } split_state_t;
 
+/* helper macro, called when done with an argument */
+#define END_ARG() do { \
+    char_out = 0; \
+    argv[argc++] = next_arg_start; \
+    state = SS_SPACE; \
+} while(0)
+
 size_t esp_console_split_argv(char *line, char **argv, size_t argv_size)
 {
     const int QUOTE = '"';
@@ -47,13 +54,6 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size)
         }
         int char_out = -1;
 
-        /* helper function, called when done with an argument */
-        void end_arg() {
-            char_out = 0;
-            argv[argc++] = next_arg_start;
-            state = SS_SPACE;
-        }
-
         switch (state) {
         case SS_SPACE:
             if (char_in == SPACE) {
@@ -73,7 +73,7 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size)
 
         case SS_QUOTED_ARG:
             if (char_in == QUOTE) {
-                end_arg();
+                END_ARG();
             } else if (char_in == ESCAPE) {
                 state = SS_QUOTED_ARG_ESCAPED;
             } else {
@@ -93,7 +93,7 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size)
 
         case SS_ARG:
             if (char_in == SPACE) {
-                end_arg();
+                END_ARG();
             } else if (char_in == ESCAPE) {
                 state = SS_ARG_ESCAPED;
             } else {
index eae72ffe028e1631ca3e84323faa885b2f50db28..bf4039df117bd1a81e94c08839431d5b206f6079 100644 (file)
@@ -58,6 +58,27 @@ typedef struct {
     .unused = 0, \
     .type = RELOC_TYPE_BRANCH }
 
+/* Comparison function used to sort the relocations array */
+static int reloc_sort_func(const void* p_lhs, const void* p_rhs)
+{
+    const reloc_info_t lhs = *(const reloc_info_t*) p_lhs;
+    const reloc_info_t rhs = *(const reloc_info_t*) p_rhs;
+    if (lhs.label < rhs.label) {
+        return -1;
+    } else if (lhs.label > rhs.label) {
+        return 1;
+    }
+    // label numbers are equal
+    if (lhs.type < rhs.type) {
+        return -1;
+    } else if (lhs.type > rhs.type) {
+        return 1;
+    }
+
+    // both label number and type are equal
+    return 0;
+}
+
 
 /* Processing branch and label macros involves four steps:
  *
@@ -203,24 +224,6 @@ esp_err_t ulp_process_macros_and_load(uint32_t load_addr, const ulp_insn_t* prog
     }
 
     // step 3: sort relocations array
-    int reloc_sort_func(const void* p_lhs, const void* p_rhs) {
-        const reloc_info_t lhs = *(const reloc_info_t*) p_lhs;
-        const reloc_info_t rhs = *(const reloc_info_t*) p_rhs;
-        if (lhs.label < rhs.label) {
-            return -1;
-        } else if (lhs.label > rhs.label) {
-            return 1;
-        }
-        // label numbers are equal
-        if (lhs.type < rhs.type) {
-            return -1;
-        } else if (lhs.type > rhs.type) {
-            return 1;
-        }
-
-        // both label number and type are equal
-        return 0;
-    }
     qsort(reloc_info, macro_count, sizeof(reloc_info_t),
             reloc_sort_func);