#!/bin/sh # # Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h # global IN := $1 global OUT := $2 proc dump_array { global ARRAY := $1 global SIZE := $2 global PFX := $3 global POSTFIX := $4 global PFX_SZ := $[echo $PFX | wc -c] global TABS := $[printf '\t\t\t\t\t] echo "const char * const $ARRAY[$SIZE] = {" # Iterate through any input lines starting with #define $PFX sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN | while read i { # Name is everything up to the first whitespace global NAME := $[echo $i | sed 's/ .*//] # If the /* comment */ starts with a quote string, grab that. global VALUE := $[echo $i | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p] test -z $VALUE && global VALUE := ""\"$NAME"\"" test $VALUE = '""' && continue # Name is uppercase, VALUE is all lowercase global VALUE := $[echo $VALUE | tr A-Z a-z] if test -n $POSTFIX { global T := $( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ) global TABS := $[printf '\t\t\t\t\t\t] global TABCOUNT := $( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ) printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" $POSTFIX $TABCOUNT $TABS $VALUE } else { global TABCOUNT := $( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ) printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" $TABCOUNT $TABS $VALUE } } echo "};" } trap 'rm "$OUT"' EXIT shell { echo "#ifndef _ASM_X86_CPUFEATURES_H" echo "#include " echo "#endif" echo "" dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" echo "" dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" } > $OUT trap - EXIT (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:IN) op:Equal rhs:{($ VSub_Number "$1")} spids:[13])] spids: [13] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:OUT) op:Equal rhs:{($ VSub_Number "$2")} spids:[16])] spids: [16] ) (FuncDef name: dump_array body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ARRAY) op: Equal rhs: {($ VSub_Number "$1")} spids: [27] ) ] spids: [27] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SIZE) op: Equal rhs: {($ VSub_Number "$2")} spids: [31] ) ] spids: [31] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PFX) op: Equal rhs: {($ VSub_Number "$3")} spids: [35] ) ] spids: [35] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:POSTFIX) op: Equal rhs: {($ VSub_Number "$4")} spids: [39] ) ] spids: [39] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PFX_SZ) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(echo)} {($ VSub_Name "$PFX")}) (C {(wc)} {(-c)})] negated: False ) ] ) left_token: spids: [45 55] ) } spids: [44] ) ] spids: [44] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TABS) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(printf)} {(SQ <"\\t\\t\\t\\t\\t">)})] ) left_token: spids: [60 66] ) ) } spids: [58] ) ] spids: [58] ) (C {(echo)} { (DQ ("const char * const ") ($ VSub_Name "$ARRAY") ("[") ($ VSub_Name "$SIZE") ("] = {")) } ) (Pipeline children: [ (C {(sed)} {(-n)} {(-e)} {(SQ <"s/\\t/ /g">)} {(-e)} {(DQ ("s/^ *# *define *") ($ VSub_Name "$PFX") (//p))} {($ VSub_Name "$IN")} ) (While cond: [(C {(read)} {(i)})] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NAME) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$i"))}) (C {(sed)} {(SQ <"s/ .*//">)}) ] negated: False ) ] ) left_token: spids: [126 140] ) ) } spids: [124] ) ] spids: [124] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:VALUE) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$i"))}) (C {(sed)} {(-n)} {(SQ <"s@.*/\\* *\\(\"[^\"]*\"\\).*\\*/@\\1@p">)} ) ] negated: False ) ] ) left_token: spids: [151 167] ) ) } spids: [149] ) ] spids: [149] ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$VALUE"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:VALUE) op: Equal rhs: { (DQ (EscapedLiteralPart token:) ($ VSub_Name "$NAME") (EscapedLiteralPart token:) ) } spids: [183] ) ] spids: [183] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VALUE"))} {(Lit_Other "=")} {(SQ <"\"\"">)} {(Lit_Other "]")} ) (ControlFlow token: ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:VALUE) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$VALUE"))}) (C {(tr)} {(A-Z)} {(a-z)}) ] negated: False ) ] ) left_token: spids: [217 231] ) ) } spids: [215] ) ] spids: [215] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$POSTFIX"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:T) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$PFX_SZ")}) right: (ArithWord w: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$POSTFIX")} ) (C {(wc)} {(-c)}) ] negated: False ) ] ) left_token: spids: [259 269] ) } ) ) right: (ArithWord w:{(Lit_Digits 2)}) ) spids: [253 276] ) } spids: [252] ) ] spids: [252] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TABS) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(printf)} {(SQ <"\\t\\t\\t\\t\\t\\t">)}) ] ) left_token: spids: [281 287] ) ) } spids: [279] ) ] spids: [279] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TABCOUNT) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Minus left: (ArithBinary op_id: Arith_Minus left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{(Lit_Digits 6)}) right: (ArithWord w:{(Lit_Digits 8)}) ) right: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$T")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) right: (ArithWord w: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} { (DQ ($ VSub_Name "$NAME")) } ) (C {(wc)} {(-c)}) ] negated: False ) ] ) left_token: spids: [312 324] ) } ) ) right: (ArithWord w:{(Lit_Digits 8)}) ) spids: [292 333] ) } spids: [291] ) ] spids: [291] ) (C {(printf)} { (DQ (EscapedLiteralPart token:) ("[%s - %s]%.*s = %s,") (EscapedLiteralPart token:) ) } {(DQ ($ VSub_Name "$PFX") ($ VSub_Name "$NAME"))} {(DQ ($ VSub_Name "$POSTFIX"))} {(DQ ($ VSub_Name "$TABCOUNT"))} {(DQ ($ VSub_Name "$TABS"))} {(DQ ($ VSub_Name "$VALUE"))} ) ] spids: [-1 249] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TABCOUNT) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Slash left: (ArithBinary op_id: Arith_Minus left: (ArithBinary op_id: Arith_Minus left: (ArithBinary op_id: Arith_Star left: (ArithWord w:{(Lit_Digits 5)}) right: (ArithWord w:{(Lit_Digits 8)}) ) right: (ArithBinary op_id: Arith_Plus left: (ArithWord w:{($ VSub_Name "$PFX_SZ")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) right: (ArithWord w: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$NAME"))} ) (C {(wc)} {(-c)}) ] negated: False ) ] ) left_token: spids: [390 402] ) } ) ) right: (ArithWord w:{(Lit_Digits 8)}) ) spids: [370 411] ) } spids: [369] ) ] spids: [369] ) (C {(printf)} { (DQ (EscapedLiteralPart token:) ("[%s]%.*s = %s,") (EscapedLiteralPart token:) ) } {(DQ ($ VSub_Name "$PFX") ($ VSub_Name "$NAME"))} {(DQ ($ VSub_Name "$TABCOUNT"))} {(DQ ($ VSub_Name "$TABS"))} {(DQ ($ VSub_Name "$VALUE"))} ) ] spids: [366 440] ) ] spids: [117 443] ) ) ] negated: False ) (C {(echo)} {(DQ ("};"))}) ] spids: [24] ) spids: [20 23] ) (C {(trap)} {(SQ <"rm \"$OUT\"">)} {(EXIT)}) (Subshell child: (CommandList children: [ (C {(echo)} {(DQ ("#ifndef _ASM_X86_CPUFEATURES_H"))}) (C {(echo)} {(DQ ("#include "))}) (C {(echo)} {(DQ ("#endif"))}) (C {(echo)} {(DQ )}) (C {(dump_array)} {(DQ (x86_cap_flags))} {(DQ ("NCAPINTS*32"))} {(DQ (X86_FEATURE_))} {(DQ )}) (C {(echo)} {(DQ )}) (C {(dump_array)} {(DQ (x86_bug_flags))} {(DQ ("NBUGINTS*32"))} {(DQ (X86_BUG_))} {(DQ ("NCAPINTS*32"))} ) ] ) redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Name "$OUT")} spids:[541])] spids: [464 539] ) (C {(trap)} {(-)} {(EXIT)}) ] )