Re: how to read linux kernel source with pycparser

2016-10-13 Thread Michael Torrie
On 10/13/2016 02:19 AM, meInvent bbird wrote:
> is it possible to git pull a part of directory such as sched
> and compile this subdirectory and pycparser it?

I'm sure you could but it wouldn't help you.  The parts of the kernel
are modular but you can't compile them without configuring the whole
source tree.  Configuration is stored in header files farther up the
tree, generated by the configuration process.  Once the kernel source
tree is configured (make menuconfig), you can, of course, just build a
particular directory, such as sched.  But as you can see from your trial
run, there are a lot of header file dependencies.

Why are you trying to use the linux kernel? That's one of the largest
and most complicated projects in the world.  Why not start with a
simple, one-file C program?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read linux kernel source with pycparser

2016-10-13 Thread meInvent bbird
is it possible to git pull a part of directory such as sched
and compile this subdirectory and pycparser it?

i got error when run gcc -E

git submodule add he...@github.com:hello/repo.git kernel/sched
cd kernel/sched
git pull

martin@ubuntu:~/Downloads/kernel/sched$ gcc -E -std=c99 *.c
# 1 "auto_group.c"
# 1 ""
# 1 ""
# 1 "auto_group.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from auto_group.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "clock.c"
# 1 ""
# 1 ""
# 1 "clock.c"
clock.c:55:28: fatal error: linux/spinlock.h: No such file or directory
compilation terminated.
# 1 "completion.c"
# 1 ""
# 1 ""
# 1 "completion.c"
# 14 "completion.c"
# 1 "/usr/include/linux/sched.h" 1 3 4
# 15 "completion.c" 2
completion.c:15:30: fatal error: linux/completion.h: No such file or directory
compilation terminated.
# 1 "core.c"
# 1 ""
# 1 ""
# 1 "core.c"
core.c:29:25: fatal error: linux/kasan.h: No such file or directory
compilation terminated.
# 1 "cpuacct.c"
# 1 ""
# 1 ""
# 1 "cpuacct.c"
cpuacct.c:1:26: fatal error: linux/cgroup.h: No such file or directory
compilation terminated.
# 1 "cpudeadline.c"
# 1 ""
# 1 ""
# 1 "cpudeadline.c"
cpudeadline.c:14:23: fatal error: linux/gfp.h: No such file or directory
compilation terminated.
# 1 "cpufreq.c"
# 1 ""
# 1 ""
# 1 "cpufreq.c"
# 12 "cpufreq.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from cpufreq.c:12:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "cpufreq_schedutil.c"
# 1 ""
# 1 ""
# 1 "cpufreq_schedutil.c"
cpufreq_schedutil.c:14:27: fatal error: linux/cpufreq.h: No such file or 
directory
compilation terminated.
# 1 "cpupri.c"
# 1 ""
# 1 ""
# 1 "cpupri.c"
cpupri.c:30:23: fatal error: linux/gfp.h: No such file or directory
compilation terminated.
# 1 "cputime.c"
# 1 ""
# 1 ""
# 1 "cputime.c"
cputime.c:1:26: fatal error: linux/export.h: No such file or directory
compilation terminated.
# 1 "deadline.c"
# 1 ""
# 1 ""
# 1 "deadline.c"
# 17 "deadline.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from deadline.c:17:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "debug.c"
# 1 ""
# 1 ""
# 1 "debug.c"
debug.c:13:27: fatal error: linux/proc_fs.h: No such file or directory
compilation terminated.
# 1 "fair.c"
# 1 ""
# 1 ""
# 1 "fair.c"
# 23 "fair.c"
# 1 "/usr/include/linux/sched.h" 1 3 4
# 24 "fair.c" 2
fair.c:24:30: fatal error: linux/latencytop.h: No such file or directory
compilation terminated.
# 1 "idle.c"
# 1 ""
# 1 ""
# 1 "idle.c"



# 1 "/usr/include/linux/sched.h" 1 3 4
# 5 "idle.c" 2
idle.c:5:23: fatal error: linux/cpu.h: No such file or directory
compilation terminated.
# 1 "idle_task.c"
# 1 ""
# 1 ""
# 1 "idle_task.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from idle_task.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "loadavg.c"
# 1 ""
# 1 ""
# 1 "loadavg.c"
loadavg.c:9:26: fatal error: linux/export.h: No such file or directory
compilation terminated.
# 1 "rt.c"
# 1 ""
# 1 ""
# 1 "rt.c"





# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from rt.c:6:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "stats.c"
# 1 ""
# 1 ""
# 1 "stats.c"
stats.c:1:24: fatal error: linux/slab.h: No such file or directory
compilation terminated.
# 1 "stop_task.c"
# 1 ""
# 1 ""
# 1 "stop_task.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from stop_task.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "swait.c"
# 1 ""
# 1 &q

Re: how to read linux kernel source with pycparser (Reposting On Python-List Prohibited)

2016-10-04 Thread meInvent bbird
yes, i searched in google between 2011 and 2012

descending for loop is faster than ascending for loop

On Wednesday, October 5, 2016 at 9:48:41 AM UTC+8, Chris Angelico wrote:
> On Wed, Oct 5, 2016 at 12:41 PM, meInvent bbird  wrote:
> > so far i do not know which bug i search for
> >
> > i would like to change style of for loop
> >
> > form ascending to descending style
> >
> > for(int i=0; i<3; ++i)
> >
> > to
> >
> > for(int i=3; i>=0; --i)
> >
> > or
> >
> > most crazy to change if else if else into mealy machine
> 
> Are you aware that those loops are significantly different?
> 
> ChrisA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read linux kernel source with pycparser (Reposting On Python-List Prohibited)

2016-10-04 Thread Chris Angelico
On Wed, Oct 5, 2016 at 12:41 PM, meInvent bbird  wrote:
> so far i do not know which bug i search for
>
> i would like to change style of for loop
>
> form ascending to descending style
>
> for(int i=0; i<3; ++i)
>
> to
>
> for(int i=3; i>=0; --i)
>
> or
>
> most crazy to change if else if else into mealy machine

Are you aware that those loops are significantly different?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read linux kernel source with pycparser (Reposting On Python-List Prohibited)

2016-10-04 Thread meInvent bbird
On Wednesday, October 5, 2016 at 2:34:49 AM UTC+8, Lawrence D’Oliveiro wrote:
> On Tuesday, October 4, 2016 at 10:38:14 PM UTC+13, meInvent bbird wrote:
> > how to customize pycparser to search what we want such as bug 
> 
> What kind of bug do you want to search for?

so far i do not know which bug i search for

i would like to change style of for loop

form ascending to descending style

for(int i=0; i<3; ++i)

to

for(int i=3; i>=0; --i)

or 

most crazy to change if else if else into mealy machine
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read linux kernel source with pycparser

2016-10-04 Thread Michael Torrie
On 10/04/2016 03:36 AM, meInvent bbird wrote:
> i expect to use pycparser to read linux kernel source
> and get a AST tree, 
> 
> but there are so many directory, 
> 
> how to read linux kernel source with pycparser?
> 
> how to customize pycparser to search what we want such as bug or fix 
> to make a linux patch for linux kernel source with python?

C projects with many .c files aren't meant to be compiled into one unit
(AST) usually.  The kernel is designed to be compiled into many
discrete, compiled object files which are then linked together after
compilation.  Each compilation unit would come from its own AST tree.
Furthermore, most C files can't be parsed by a compiler or parser at all
until the preprocessor has run over it first to handle the many
#define's, #if's, etc.  Fortunately you can run the preprocessor by
itself and output the bare C code.  On gcc I think if you pass -E it
will output the processed code.  Or use the cpp binary, which is
normally invoked by the compiler.

Another thing that will make this very difficult (and is related to the
preprocessor stuff) is that the Linux kernel's compilation can take many
different paths depending on how you configure the kernel. Some parts
may be skipped over entirely, other parts depend on which platform you
are configuring it for.

You could probably do this, and get lots of ASTs you can look at, but
you'll have to do some heavy-duty scripting and modification of
Makefiles to get it to happen in any sort of automatic way.  You make be
able to modify the Makefiles to have GCC itself dump the parse trees as
it creates them. I know GCC can do this. This is really the only
practical way I can see.
-- 
https://mail.python.org/mailman/listinfo/python-list


how to read linux kernel source with pycparser

2016-10-04 Thread meInvent bbird
i expect to use pycparser to read linux kernel source
and get a AST tree, 

but there are so many directory, 

how to read linux kernel source with pycparser?

how to customize pycparser to search what we want such as bug or fix 
to make a linux patch for linux kernel source with python?

-- 
https://mail.python.org/mailman/listinfo/python-list