From: Avi Kivity <a...@redhat.com>

Signed-off-by: Avi Kivity <a...@redhat.com>

diff --git a/ia64/hack-module.awk b/ia64/hack-module.awk
deleted file mode 100644
index e768343..0000000
--- a/ia64/hack-module.awk
+++ /dev/null
@@ -1,29 +0,0 @@
-BEGIN { split("INIT_WORK on_each_cpu smp_call_function smp_send_reschedule " \
-             "hrtimer_add_expires_ns hrtimer_get_expires " \
-             "hrtimer_get_expires_ns hrtimer_start_expires " \
-             "hrtimer_expires_remaining " \
-             "request_irq free_irq", compat_apis); }
-
-/MODULE_AUTHOR/ {
-    printf("MODULE_INFO(version, \"%s\");\n", version)
-}
-
-{ sub(/..\/..\/..\/lib\/vsprintf\.c/, "vsprintf.c") }
-{ sub(/..\/..\/..\/lib\/ctype\.c/, "ctype.c") }
-/#undef CONFIG_MODULES/ { $0 = "" }
-
-{
-    for (i in compat_apis) {
-       ident = compat_apis[i]
-       sub("\\<" ident "\\>", "kvm_" ident)
-    }
-}
-
-/#include <linux\/compiler.h>/ { $0 = "" }
-/#include <linux\/types.h>/ { $0 = "#include <asm/types.h>" }
-
-{ sub(/linux\/mm_types\.h/, "linux/mm.h") }
-
-{ sub(/\<__user\>/, " ") }
-
-{ print }
diff --git a/powerpc/hack-module.awk b/powerpc/hack-module.awk
deleted file mode 100644
index 570b034..0000000
--- a/powerpc/hack-module.awk
+++ /dev/null
@@ -1,5 +0,0 @@
-/MODULE_AUTHOR/ {
-    printf("MODULE_INFO(version, \"%s\");\n", version)
-}
-
-{ print }
diff --git a/sync b/sync
index 07dae44..cb4a9db 100755
--- a/sync
+++ b/sync
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import sys, os, glob, os.path, shutil
+import sys, os, glob, os.path, shutil, re
 
 glob = glob.glob
 
@@ -14,13 +14,92 @@ if len(sys.argv) >= 2:
 
 linux = 'linux-2.6'
 
-def _hack(file, arch):
-    cmd('mv "%(file)s" "%(file)s.orig"'
-        ' && gawk -v version="%(version)s" '
-        '    -f "%(arch)s/hack-module.awk" "%(file)s.orig"'
-        ' | sed "/\#include/! s/\blapic\b/l_apic/g"'
-        ' > "%(file)s" && rm "%(file)s.orig"'
-        % { 'file': file, 'arch': arch, 'version': version })
+def __hack(data):
+    compat_apis = str.split(
+        'INIT_WORK desc_struct ldttss_desc64 desc_ptr '
+        'hrtimer_add_expires_ns hrtimer_get_expires '
+        'hrtimer_get_expires_ns hrtimer_start_expires '
+        'hrtimer_expires_remaining smp_send_reschedule '
+        'on_each_cpu relay_open request_irq free_irq')
+    anon_inodes = anon_inodes_exit = False
+    result = []
+    def sub(regexp, repl, str):
+        return re.sub(regexp, repl, str)
+    for line in data.splitlines():
+        orig = line
+        def match(regexp):
+            return re.search(regexp, line)
+        def w(line, result = result):
+            result.append(line)
+        f = line.split()
+        if match(r'^int kvm_init\('): anon_inodes = 1
+        if match(r'return 0;') and anon_inodes:
+            w('\tr = kvm_init_anon_inodes();')
+            w('\tif (r) {')
+            w('\t\t__free_page(bad_page);')
+            w('\t\tgoto out;')
+            w('\t}')
+            w('\tpreempt_notifier_sys_init();')
+            w('\tprintk("loaded kvm module (%s)\\n");\n' % (version,))
+            anon_inodes = False
+        if match(r'^void kvm_exit'): anon_inodes_exit = True
+        if match(r'\}') and anon_inodes_exit:
+            w('\tkvm_exit_anon_inodes();')
+            w('\tpreempt_notifier_sys_exit();')
+            anon_inodes_exit = False
+        if match(r'^int kvm_arch_init'): kvm_arch_init = True
+        if match(r'\btsc_khz\b') and kvm_arch_init:
+            line = sub(r'\btsc_khz\b', 'kvm_tsc_khz', line)
+        if match(r'^}'): kvm_arch_init = False
+        if match(r'MODULE_AUTHOR'):
+            w('MODULE_INFO(version, "%s");' % (version,))
+        line = sub(r'match->dev->msi_enabled',
+                      'kvm_pcidev_msi_enabled(match->dev)', line)
+        if match(r'atomic_inc\(&kvm->mm->mm_count\);'):
+            line = 'mmget(&kvm->mm->mm_count);'
+        if match(r'^\t\.fault = '):
+            fcn = sub(r',', '', f[2])
+            line = '\t.VMA_OPS_FAULT(fault) = VMA_OPS_FAULT_FUNC(' + fcn + '),'
+        if match(r'^static int (.*_stat_get|lost_records_get)'):
+            line = line[0:11] + '__' + line[11:]
+        if match(r'DEFINE_SIMPLE_ATTRIBUTE.*(_stat_get|lost_records_get)'):
+            name = sub(r',', '', f[1])
+            w('MAKE_SIMPLE_ATTRIBUTE_GETTER(' + name + ')')
+        line = sub(r'linux/mm_types\.h', 'linux/mm.h', line)
+        line = sub(r'\b__user\b', ' ', line)
+        if match(r'^\t\.name = "kvm"'):
+            line = '\tset_kset_name("kvm"),'
+        if match(r'#include <linux/compiler.h>'):
+            line = ''
+        if match(r'#include <linux/clocksource.h>'):
+            line = ''
+        if match(r'#include <linux\/types.h>'):
+            line = '#include <asm/types.h>'
+        line = sub(r'\bhrtimer_init\b', 'hrtimer_init_p', line)
+        line = sub(r'\bhrtimer_start\b', 'hrtimer_start_p', line)
+        line = sub(r'\bhrtimer_cancel\b', 'hrtimer_cancel_p', line)
+        if match(r'case KVM_CAP_SYNC_MMU'):
+            line = '#ifdef CONFIG_MMU_NOTIFIER\n' + line + '\n#endif'
+        for ident in compat_apis:
+            line = sub(r'\b' + ident + r'\b', 'kvm_' + ident, line)
+        if match(r'kvm_.*_fops\.owner = module;'):
+            line = 'IF_ANON_INODES_DOES_REFCOUNTS(' + line + ')'
+        if not match(r'#include'):
+            line = sub(r'\blapic\n', 'l_apic', line)
+        w(line)
+        if match(r'\tkvm_init_debug'):
+            w('\thrtimer_kallsyms_resolve();')
+        if match(r'apic->timer.dev.function ='):
+            w('\thrtimer_data_pointer(&apic->timer.dev);')
+        if match(r'pt->timer.function ='):
+            w('\thrtimer_data_pointer(&pt->timer);')
+    data = str.join('', [line + '\n' for line in result])
+    return data
+
+def _hack(fname, arch):
+    data = file(fname).read()
+    data = __hack(data)
+    file(fname, 'w').write(data)
 
 def unifdef(fname):
     data = file('unifdef.h').read() + file(fname).read()
diff --git a/x86/hack-module.awk b/x86/hack-module.awk
deleted file mode 100644
index 5bb1c31..0000000
--- a/x86/hack-module.awk
+++ /dev/null
@@ -1,89 +0,0 @@
-BEGIN { split("INIT_WORK desc_struct ldttss_desc64 desc_ptr " \
-             "hrtimer_add_expires_ns hrtimer_get_expires " \
-             "hrtimer_get_expires_ns hrtimer_start_expires " \
-             "hrtimer_expires_remaining smp_send_reschedule " \
-             "on_each_cpu relay_open request_irq free_irq" , compat_apis); }
-
-/^int kvm_init\(/ { anon_inodes = 1 }
-
-/return 0;/ && anon_inodes {
-    print "\tr = kvm_init_anon_inodes();";
-    print "\tif (r) {";
-    print "\t\t__free_page(bad_page);";
-    print "\t\tgoto out;";
-    print "\t}";
-    print "\tpreempt_notifier_sys_init();";
-    printf("\tprintk(\"loaded kvm module (%s)\\n\");\n", version);
-    anon_inodes = 0
-}
-
-/^void kvm_exit/ { anon_inodes_exit = 1 }
-
-/\}/ && anon_inodes_exit {
-    print "\tkvm_exit_anon_inodes();";
-    print "\tpreempt_notifier_sys_exit();";
-    anon_inodes_exit = 0
-}
-
-/^int kvm_arch_init/ { kvm_arch_init = 1 }
-/\<tsc_khz\>/ && kvm_arch_init { sub("\\<tsc_khz\\>", "kvm_tsc_khz") }
-/^}/ { kvm_arch_init = 0 }
-
-/MODULE_AUTHOR/ {
-    printf("MODULE_INFO(version, \"%s\");\n", version)
-}
-
-{ sub(/match->dev->msi_enabled/, "kvm_pcidev_msi_enabled(match->dev)") }
-
-/atomic_inc\(&kvm->mm->mm_count\);/ { $0 = "mmget(&kvm->mm->mm_count);" }
-
-/^\t\.fault = / {
-    fcn = gensub(/,/, "", "g", $3)
-    $0 = "\t.VMA_OPS_FAULT(fault) = VMA_OPS_FAULT_FUNC(" fcn "),"
-}
-
-/^static int (.*_stat_get|lost_records_get)/ {
-    $3 = "__" $3
-}
-
-/DEFINE_SIMPLE_ATTRIBUTE.*(_stat_get|lost_records_get)/ {
-    name = gensub(/,/, "", "g", $2);
-    print "MAKE_SIMPLE_ATTRIBUTE_GETTER(" name ")"
-}
-
-{ sub(/linux\/mm_types\.h/, "linux/mm.h") }
-
-{ sub(/\<__user\>/, " ") }
-
-/^\t\.name = "kvm"/ { $0 = "\tset_kset_name(\"kvm\")," }
-
-/#include <linux\/compiler.h>/ { $0 = "" }
-/#include <linux\/clocksource.h>/ { $0 = "" }
-/#include <linux\/types.h>/ { $0 = "#include <asm/types.h>" }
-
-{ sub(/\<hrtimer_init\>/, "hrtimer_init_p") }
-{ sub(/\<hrtimer_start\>/, "hrtimer_start_p") }
-{ sub(/\<hrtimer_cancel\>/, "hrtimer_cancel_p") }
-
-/case KVM_CAP_SYNC_MMU/ { $0 = "#ifdef CONFIG_MMU_NOTIFIER\n" $0 "\n#endif" }
-
-{
-    for (i in compat_apis) {
-       ident = compat_apis[i]
-       sub("\\<" ident "\\>", "kvm_" ident)
-    }
-}
-
-/\kvm_.*_fops\.owner = module;/ { $0 = "IF_ANON_INODES_DOES_REFCOUNTS(" $0 ")" 
}
-
-{ print }
-
-/\tkvm_init_debug/ {
-    print "\thrtimer_kallsyms_resolve();"
-}
-/apic->timer.dev.function =/ {
-    print "\thrtimer_data_pointer(&apic->timer.dev);"
-}
-/pt->timer.function =/ {
-    print "\thrtimer_data_pointer(&pt->timer);"
-}
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to