1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # helpers for dealing with atomics.tbl 3 # helpers for dealing with atomics.tbl 4 4 5 #meta_in(meta, match) 5 #meta_in(meta, match) 6 meta_in() 6 meta_in() 7 { 7 { 8 case "$1" in 8 case "$1" in 9 [$2]) return 0;; 9 [$2]) return 0;; 10 esac 10 esac 11 11 12 return 1 12 return 1 13 } 13 } 14 14 15 #meta_has_ret(meta) 15 #meta_has_ret(meta) 16 meta_has_ret() 16 meta_has_ret() 17 { 17 { 18 meta_in "$1" "bBiIfFlR" 18 meta_in "$1" "bBiIfFlR" 19 } 19 } 20 20 21 #meta_has_acquire(meta) 21 #meta_has_acquire(meta) 22 meta_has_acquire() 22 meta_has_acquire() 23 { 23 { 24 meta_in "$1" "BFIlR" 24 meta_in "$1" "BFIlR" 25 } 25 } 26 26 27 #meta_has_release(meta) 27 #meta_has_release(meta) 28 meta_has_release() 28 meta_has_release() 29 { 29 { 30 meta_in "$1" "BFIRs" 30 meta_in "$1" "BFIRs" 31 } 31 } 32 32 33 #meta_has_relaxed(meta) 33 #meta_has_relaxed(meta) 34 meta_has_relaxed() 34 meta_has_relaxed() 35 { 35 { 36 meta_in "$1" "BFIR" 36 meta_in "$1" "BFIR" 37 } 37 } 38 38 39 #meta_is_implicitly_relaxed(meta) !! 39 #find_fallback_template(pfx, name, sfx, order) 40 meta_is_implicitly_relaxed() !! 40 find_fallback_template() 41 { << 42 meta_in "$1" "vls" << 43 } << 44 << 45 #find_template(tmpltype, pfx, name, sfx, order << 46 find_template() << 47 { 41 { 48 local tmpltype="$1"; shift << 49 local pfx="$1"; shift 42 local pfx="$1"; shift 50 local name="$1"; shift 43 local name="$1"; shift 51 local sfx="$1"; shift 44 local sfx="$1"; shift 52 local order="$1"; shift 45 local order="$1"; shift 53 46 54 local base="" 47 local base="" 55 local file="" 48 local file="" 56 49 57 # We may have fallbacks for a specific 50 # We may have fallbacks for a specific case (e.g. read_acquire()), or 58 # an entire class, e.g. *inc*(). 51 # an entire class, e.g. *inc*(). 59 # 52 # 60 # Start at the most specific, and fall 53 # Start at the most specific, and fall back to the most general. Once 61 # we find a specific fallback, don't b 54 # we find a specific fallback, don't bother looking for more. 62 for base in "${pfx}${name}${sfx}${orde !! 55 for base in "${pfx}${name}${sfx}${order}" "${name}"; do 63 file="${ATOMICDIR}/${tmpltype} !! 56 file="${ATOMICDIR}/fallbacks/${base}" 64 57 65 if [ -f "${file}" ]; then 58 if [ -f "${file}" ]; then 66 printf "${file}" 59 printf "${file}" 67 break 60 break 68 fi 61 fi 69 done 62 done 70 } 63 } 71 64 72 #find_fallback_template(pfx, name, sfx, order) << 73 find_fallback_template() << 74 { << 75 find_template "fallbacks" "$@" << 76 } << 77 << 78 #find_kerneldoc_template(pfx, name, sfx, order << 79 find_kerneldoc_template() << 80 { << 81 find_template "kerneldoc" "$@" << 82 } << 83 << 84 #gen_ret_type(meta, int) 65 #gen_ret_type(meta, int) 85 gen_ret_type() { 66 gen_ret_type() { 86 local meta="$1"; shift 67 local meta="$1"; shift 87 local int="$1"; shift 68 local int="$1"; shift 88 69 89 case "${meta}" in 70 case "${meta}" in 90 [sv]) printf "void";; 71 [sv]) printf "void";; 91 [bB]) printf "bool";; 72 [bB]) printf "bool";; 92 [aiIfFlR]) printf "${int}";; 73 [aiIfFlR]) printf "${int}";; 93 esac 74 esac 94 } 75 } 95 76 96 #gen_ret_stmt(meta) 77 #gen_ret_stmt(meta) 97 gen_ret_stmt() 78 gen_ret_stmt() 98 { 79 { 99 if meta_has_ret "${meta}"; then 80 if meta_has_ret "${meta}"; then 100 printf "return "; 81 printf "return "; 101 fi 82 fi 102 } 83 } 103 84 104 # gen_param_name(arg) 85 # gen_param_name(arg) 105 gen_param_name() 86 gen_param_name() 106 { 87 { 107 # strip off the leading 'c' for 'cv' 88 # strip off the leading 'c' for 'cv' 108 local name="${1#c}" 89 local name="${1#c}" 109 printf "${name#*:}" 90 printf "${name#*:}" 110 } 91 } 111 92 112 # gen_param_type(arg, int, atomic) 93 # gen_param_type(arg, int, atomic) 113 gen_param_type() 94 gen_param_type() 114 { 95 { 115 local type="${1%%:*}"; shift 96 local type="${1%%:*}"; shift 116 local int="$1"; shift 97 local int="$1"; shift 117 local atomic="$1"; shift 98 local atomic="$1"; shift 118 99 119 case "${type}" in 100 case "${type}" in 120 i) type="${int} ";; 101 i) type="${int} ";; 121 p) type="${int} *";; 102 p) type="${int} *";; 122 v) type="${atomic}_t *";; 103 v) type="${atomic}_t *";; 123 cv) type="const ${atomic}_t *";; 104 cv) type="const ${atomic}_t *";; 124 esac 105 esac 125 106 126 printf "${type}" 107 printf "${type}" 127 } 108 } 128 109 129 #gen_param(arg, int, atomic) 110 #gen_param(arg, int, atomic) 130 gen_param() 111 gen_param() 131 { 112 { 132 local arg="$1"; shift 113 local arg="$1"; shift 133 local int="$1"; shift 114 local int="$1"; shift 134 local atomic="$1"; shift 115 local atomic="$1"; shift 135 local name="$(gen_param_name "${arg}") 116 local name="$(gen_param_name "${arg}")" 136 local type="$(gen_param_type "${arg}" 117 local type="$(gen_param_type "${arg}" "${int}" "${atomic}")" 137 118 138 printf "${type}${name}" 119 printf "${type}${name}" 139 } 120 } 140 121 141 #gen_params(int, atomic, arg...) 122 #gen_params(int, atomic, arg...) 142 gen_params() 123 gen_params() 143 { 124 { 144 local int="$1"; shift 125 local int="$1"; shift 145 local atomic="$1"; shift 126 local atomic="$1"; shift 146 127 147 while [ "$#" -gt 0 ]; do 128 while [ "$#" -gt 0 ]; do 148 gen_param "$1" "${int}" "${ato 129 gen_param "$1" "${int}" "${atomic}" 149 [ "$#" -gt 1 ] && printf ", " 130 [ "$#" -gt 1 ] && printf ", " 150 shift; 131 shift; 151 done 132 done 152 } 133 } 153 134 154 #gen_args(arg...) 135 #gen_args(arg...) 155 gen_args() 136 gen_args() 156 { 137 { 157 while [ "$#" -gt 0 ]; do 138 while [ "$#" -gt 0 ]; do 158 printf "$(gen_param_name "$1") 139 printf "$(gen_param_name "$1")" 159 [ "$#" -gt 1 ] && printf ", " 140 [ "$#" -gt 1 ] && printf ", " 160 shift; 141 shift; 161 done 142 done 162 } << 163 << 164 #gen_desc_return(meta) << 165 gen_desc_return() << 166 { << 167 local meta="$1"; shift << 168 << 169 case "${meta}" in << 170 [v]) << 171 printf "Return: Nothing." << 172 ;; << 173 [Ff]) << 174 printf "Return: The original v << 175 ;; << 176 [R]) << 177 printf "Return: The updated va << 178 ;; << 179 [l]) << 180 printf "Return: The value of @ << 181 ;; << 182 esac << 183 } << 184 << 185 #gen_template_kerneldoc(template, class, meta, << 186 gen_template_kerneldoc() << 187 { << 188 local template="$1"; shift << 189 local class="$1"; shift << 190 local meta="$1"; shift << 191 local pfx="$1"; shift << 192 local name="$1"; shift << 193 local sfx="$1"; shift << 194 local order="$1"; shift << 195 local atomic="$1"; shift << 196 local int="$1"; shift << 197 << 198 local atomicname="${atomic}_${pfx}${na << 199 << 200 local ret="$(gen_ret_type "${meta}" "$ << 201 local retstmt="$(gen_ret_stmt "${meta} << 202 local params="$(gen_params "${int}" "$ << 203 local args="$(gen_args "$@")" << 204 local desc_order="" << 205 local desc_instrumentation="" << 206 local desc_return="" << 207 << 208 if [ ! -z "${order}" ]; then << 209 desc_order="${order##_}" << 210 elif meta_is_implicitly_relaxed "${met << 211 desc_order="relaxed" << 212 else << 213 desc_order="full" << 214 fi << 215 << 216 if [ -z "${class}" ]; then << 217 desc_noinstr="Unsafe to use in << 218 else << 219 desc_noinstr="Safe to use in n << 220 fi << 221 << 222 desc_return="$(gen_desc_return "${meta << 223 << 224 . ${template} << 225 } << 226 << 227 #gen_kerneldoc(class, meta, pfx, name, sfx, or << 228 gen_kerneldoc() << 229 { << 230 local class="$1"; shift << 231 local meta="$1"; shift << 232 local pfx="$1"; shift << 233 local name="$1"; shift << 234 local sfx="$1"; shift << 235 local order="$1"; shift << 236 << 237 local atomicname="${atomic}_${pfx}${na << 238 << 239 local tmpl="$(find_kerneldoc_template << 240 if [ -z "${tmpl}" ]; then << 241 printf "/*\n" << 242 printf " * No kerneldoc availa << 243 printf " */\n" << 244 else << 245 gen_template_kerneldoc "${tmpl}" "${cl << 246 fi << 247 } 143 } 248 144 249 #gen_proto_order_variants(meta, pfx, name, sfx 145 #gen_proto_order_variants(meta, pfx, name, sfx, ...) 250 gen_proto_order_variants() 146 gen_proto_order_variants() 251 { 147 { 252 local meta="$1"; shift 148 local meta="$1"; shift 253 local pfx="$1"; shift 149 local pfx="$1"; shift 254 local name="$1"; shift 150 local name="$1"; shift 255 local sfx="$1"; shift 151 local sfx="$1"; shift 256 152 257 gen_proto_order_variant "${meta}" "${p 153 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@" 258 154 259 if meta_has_acquire "${meta}"; then 155 if meta_has_acquire "${meta}"; then 260 gen_proto_order_variant "${met 156 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@" 261 fi 157 fi 262 if meta_has_release "${meta}"; then 158 if meta_has_release "${meta}"; then 263 gen_proto_order_variant "${met 159 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@" 264 fi 160 fi 265 if meta_has_relaxed "${meta}"; then 161 if meta_has_relaxed "${meta}"; then 266 gen_proto_order_variant "${met 162 gen_proto_order_variant "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@" 267 fi 163 fi 268 } 164 } 269 165 270 #gen_proto_variants(meta, name, ...) 166 #gen_proto_variants(meta, name, ...) 271 gen_proto_variants() 167 gen_proto_variants() 272 { 168 { 273 local meta="$1"; shift 169 local meta="$1"; shift 274 local name="$1"; shift 170 local name="$1"; shift 275 local pfx="" 171 local pfx="" 276 local sfx="" 172 local sfx="" 277 173 278 meta_in "${meta}" "fF" && pfx="fetch_" 174 meta_in "${meta}" "fF" && pfx="fetch_" 279 meta_in "${meta}" "R" && sfx="_return" 175 meta_in "${meta}" "R" && sfx="_return" 280 176 281 gen_proto_order_variants "${meta}" "${ 177 gen_proto_order_variants "${meta}" "${pfx}" "${name}" "${sfx}" "$@" 282 } 178 } 283 179 284 #gen_proto(meta, ...) 180 #gen_proto(meta, ...) 285 gen_proto() { 181 gen_proto() { 286 local meta="$1"; shift 182 local meta="$1"; shift 287 for m in $(echo "${meta}" | grep -o .) 183 for m in $(echo "${meta}" | grep -o .); do 288 gen_proto_variants "${m}" "$@" 184 gen_proto_variants "${m}" "$@" 289 done 185 done 290 } 186 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.