Closed
Bug 487918
Opened 17 years ago
Closed 13 years ago
porky: tracking
Categories
(Developer Infrastructure :: Source Code Analysis, defect)
Tracking
(Not tracked)
RESOLVED
WONTFIX
People
(Reporter: cjones, Unassigned)
References
Details
Attachments
(2 files, 9 obsolete files)
|
3.06 KB,
patch
|
taras.mozilla
:
review+
|
Details | Diff | Splinter Review |
|
61.73 KB,
patch
|
taras.mozilla
:
review+
|
Details | Diff | Splinter Review |
Coding a pork rewrite tool is a bit time consuming, because one needs to learn (at the very least) the pork "stack" and the elsa AST. Pork aims to make this easier; one should only have to learn the (hopefully) much simpler porky syntax. Porky does this by only supporting a vastly reduced set of possible rewrites that can be done with pork.
Porky is implemented as a simple porky-source to pork-source (C++) compiler. Basically, the state of the art of porky at the moment is implementing the rewrite program
rewrite SwapArgs {
type PRLock* => mozilla::Mutex*
call PR_Lock(g, lock) => lock->Lock(g)
call mozilla::Mutex::Lock(this, g) => PR_Lock(g, this)
}
which means
* create the rewriter |SwapArgs|
* globally change the type |PRLock*| into |mozilla::Mutex*|
* at each callsite matching |PR_Lock(*1, *2)|, rewrite it into |*2->Lock(*1)|
* at each callsite matching |mozilla::Mutex::Lock(*1, *2)|, rewrite it into |PR_Lock(*2, *1)|
Note that the current state of porky allows |Foo(f, b)| to be rewritten to |f->Foo(b)| and vice versa. This is as almost as much as is necessary to solve the problem that motivated the creation of porky.
There are many ways to extend porky, and they should be tracked here. The most immediately important change is making it sanely integrate into the piglet build system. This is blocked on bug 440068.
Ideas on extending porky will probably follow in this bug. Right now, it's sleep time in the Pacific time zone.
| Reporter | ||
Comment 1•17 years ago
|
||
Attached for backup purposes. Not likely to be terribly usable for the general mozilla public.
| Reporter | ||
Updated•17 years ago
|
Assignee: nobody → jones.chris.g
| Reporter | ||
Comment 2•17 years ago
|
||
After a few hours' hacking, I got porky to handle the rewrite that inspired its creation (bug 486606). Ready to spit out a patch.
Still waiting on the pork build system to stabilize before asking for review. There are a few other niceties porky should support, like automatically invoking pork-barrel.py, understanding file filters (--exclude 'nspr/*'), and handling simple rewrite specs passed on the command line (|porky -e 'type Foo => Bar'|). These are easy, though.
Attachment #372210 -
Attachment is obsolete: true
| Reporter | ||
Comment 3•17 years ago
|
||
Seem me on IRC (cjones) if you want a walkthrough.
Attachment #372371 -
Attachment is obsolete: true
Attachment #372823 -
Flags: review?(tglek)
| Reporter | ||
Comment 4•17 years ago
|
||
I should add that porky expects by default to run in this directory structure
/
piglet/
porky/
but all it really needs to know is where |piglet/| is. This can be communicated through the |PIGLET_DIR| environment variable.
| Reporter | ||
Comment 5•17 years ago
|
||
Attachment #372823 -
Attachment is obsolete: true
Attachment #372977 -
Flags: review?(tglek)
Attachment #372823 -
Flags: review?(tglek)
Comment 6•17 years ago
|
||
First I'd like to say this is extremely impressive. I couldn't imagine building something this nice on top of Pork until I saw the code.
Things that I'd like to see cleaned up
* Break up parsing/astgen/cmdline+running into separate modules. set python path to script location to avoid getting annoyed
* No temporary directory business, output directory should be based on rewrite filename and spit out to the cwd. Need minimal error handling for that(maybe a big try statement look for filesystem exceptions)
* Support for multi-stage operation. Either spit out a makefile that can do the individual steps or like setup.py
* I prefer human-readable commandline options. porky isn't something as frequently used as ls, one can take a few seconds to write out the arguments, but it makes porky usage a little more self-documenting
* Past experience has shown that it's convenient to have -j stuff default to the number of cpus
Comment 7•17 years ago
|
||
forgot to add
* Need a configure that takes care of stuff like
if not (os.path.isdir(pigletdir)
and os.path.isfile(config_mk)
and os.path.isfile(build_mk)):
Comment 8•17 years ago
|
||
Some notes on generated code:
varName = (const D_name*) idecl;
* Don't do C/C++ casts, use Elsa's -asFoo(), they do more error checking
* I think it's better to structure the generated code as an #include and just copy over(or even symlink) the handwritten portion
| Reporter | ||
Comment 9•17 years ago
|
||
The core of porky now expects to live under piglet/, although this is still configurable. Run piglet/porky/configure. In the future, once pork/ has been properly reorganized, this configure script can be invoked automatically by pork/configure.
Using porky:
Step 1: invoke 'piglet/porkyc' on the rewrite spec. It now doesn't matter where this command is run from; every successive step has its PYTHONPATH automagically set, if necessary. This spits out code in './[Rewriter].code'.
Step 2: compile the rewriter. |make -C ./[Rewriter].code| will do the trick.
Step 3: run the rewriter. porky generates a convenience script './[Rewriter].code/dorewrite'; this is easiest to invoke. Just |./[Rewriter].code/dorewrite FILE_PATS -x EXCLUDE_PATS| should work most of the time. This spits out a patch to stdout, but you can override this with '-o ...'.
Attachment #372977 -
Attachment is obsolete: true
Attachment #373196 -
Flags: review?(tglek)
Attachment #372977 -
Flags: review?(tglek)
| Reporter | ||
Comment 10•17 years ago
|
||
Whoops, forgot to make porkyc compile by default.
Attachment #373196 -
Attachment is obsolete: true
Attachment #373197 -
Flags: review?(tglek)
Attachment #373196 -
Flags: review?(tglek)
| Reporter | ||
Comment 11•17 years ago
|
||
I should add that Step 2 in comment 9 is not necessary by default.
| Reporter | ||
Comment 12•17 years ago
|
||
Comment on attachment 373197 [details] [diff] [review]
porky v 0.0.1, compiles code by default
I've fixed a few bugs since this was submitted, and managing all its dependencies is getting complicated. Delaying review until the pork reorg.
Attachment #373197 -
Flags: review?(tglek)
| Reporter | ||
Comment 13•17 years ago
|
||
Attachment #383832 -
Flags: review?
| Reporter | ||
Comment 14•17 years ago
|
||
Attachment #373197 -
Attachment is obsolete: true
Attachment #383833 -
Flags: review?(tglek)
| Reporter | ||
Updated•17 years ago
|
Attachment #383832 -
Flags: review? → review?(tglek)
| Reporter | ||
Updated•17 years ago
|
Attachment #383832 -
Attachment description: minor configure changes to event support porky → minor configure changes to eventually support porky
Updated•17 years ago
|
Attachment #383832 -
Flags: review?(tglek) → review-
Comment 15•17 years ago
|
||
Comment on attachment 383832 [details] [diff] [review]
minor configure changes to eventually support porky
>@@ -1,5 +1,3 @@
>-PIGLET_DIR = $(PWD)
>-
> ELSA_INCDIRS := -I$(ELSA_DIR)/smbase -I$(ELSA_DIR)/elkhound -I$(ELSA_DIR)/ast -I$(ELSA_DIR)
> ELSA_INCFLAGS := -D__UNIX__ -DUSE_SERIAL_NUMBERS=1 -DNDEBUG -D__LINUX__ $(ELSA_INCDIRS)
>
>@@ -7,3 +5,8 @@ PIGLET_INCDIRS := -I$(PIGLET_DIR)
> PIGLET_INCFLAGS := -I$(PIGLET_DIR)
>
> CXXFLAGS += $(ELSA_INCFLAGS) $(PIGLET_INCFLAGS)
>+
>+PIGLET_EXPORTS = piglet expr_visitor patcher
>+PIGLET_OBJS = \
>+ $(addprefix $(PIGLET_DIR)/, $(addsuffix .o, $(PIGLET_EXPORTS))) \
>+ $(ELSA_DIR)/libelsa.a
I don't like this piglet_exports stuff. just archive the piglet objects into libpiglet.a. Can stick contents of libelsa.a into there too.
| Reporter | ||
Comment 16•17 years ago
|
||
Attachment #383832 -
Attachment is obsolete: true
Attachment #389832 -
Flags: review?(tglek)
| Reporter | ||
Comment 17•17 years ago
|
||
Attachment #383833 -
Attachment is obsolete: true
Attachment #389853 -
Flags: review?(tglek)
Attachment #383833 -
Flags: review?(tglek)
| Reporter | ||
Comment 18•17 years ago
|
||
Attachment #389853 -
Attachment is obsolete: true
Attachment #389973 -
Flags: review?(tglek)
Attachment #389853 -
Flags: review?(tglek)
Updated•17 years ago
|
Attachment #389973 -
Flags: review?(tglek) → review+
Updated•17 years ago
|
Attachment #389832 -
Flags: review?(tglek) → review+
Comment 19•17 years ago
|
||
Comment on attachment 389832 [details] [diff] [review]
address comments, build libpork.a
>diff --git a/Makefile.in b/Makefile.in
>--- a/Makefile.in
>+++ b/Makefile.in
>@@ -1,22 +1,28 @@
> # Piglet makefile
> # Builds Elsa apps without Oink!
>
> include config.mk
> include build.mk
>
>+PORK_SRCS = expr_visitor piglet patcher
>+PORK_OBJS = $(addsuffix .o, $(PORK_SRCS))
>+
> all: elsa_all stopwatch
>
> $(ELSA_DIR)/Makefile:
> cd $(ELSA_DIR) && ./configure
>
> elsa_all: $(ELSA_DIR)/Makefile
> $(MAKE) -C $(ELSA_DIR)
>
>-stopwatch: stopwatch.o piglet.o expr_visitor.o patcher.o $(ELSA_DIR)/libelsa.a
>+stopwatch: stopwatch.o $(LIBPORK)
> g++ -o $@ $+
>
> piglet.o: piglet.h
>-main.o: piglet.h expr_visitor.h
>+
>+$(LIBPORK): elsa_all $(PORK_OBJS)
>+ cp $(LIBELSA) $@
>+ ar rs $@ $(PORK_OBJS)
>
> clean:
>- rm -f stopwatch *.o *~
>+ rm -f $(LIBPORK) stopwatch *.o *~
>diff --git a/build.mk b/build.mk
>--- a/build.mk
>+++ b/build.mk
>@@ -1,9 +1,10 @@
>-PIGLET_DIR = $(PWD)
>-
> ELSA_INCDIRS := -I$(ELSA_DIR)/smbase -I$(ELSA_DIR)/elkhound -I$(ELSA_DIR)/ast -I$(ELSA_DIR)
> ELSA_INCFLAGS := -D__UNIX__ -DUSE_SERIAL_NUMBERS=1 -DNDEBUG -D__LINUX__ $(ELSA_INCDIRS)
>+LIBELSA := $(ELSA_DIR)/libelsa.a
>
> PIGLET_INCDIRS := -I$(PIGLET_DIR)
> PIGLET_INCFLAGS := -I$(PIGLET_DIR)
>
> CXXFLAGS += $(ELSA_INCFLAGS) $(PIGLET_INCFLAGS)
>+
>+LIBPORK := $(PIGLET_DIR)/libpork.a
>diff --git a/configure b/configure
>--- a/configure
>+++ b/configure
>@@ -52,23 +52,29 @@ if __name__ == "__main__":
> usage()
> exit(0)
> elif o in ('--CXX',):
> cxx = val
> elif o in ('--CXXFLAGS',):
> cxxflags = val
> else:
> error("unhandled option " + o)
>+ usage()
>+ sys.exit(2)
>
> elsa_dir = checkdir(elsa_dir, "elsa")
> if not elsa_dir:
> error("""check out elsa with: hg clone http://hg.mozilla.org/elsa""")
> exit(1)
>+
>+ piglet_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
>+
> config = dict(REWRITING_CXX=rewriting_cxx,
> ELSA_DIR=elsa_dir,
>+ PIGLET_DIR=piglet_dir,
> CXX=cxx,
> CXXFLAGS=cxxflags)
> f = open("config.mk", "w")
> f.write("""# %s
> %s
> """ % (" ".join(["'" + a + "'" for a in sys.argv]),
> "\n".join([k + "=" + v for k, v in config.iteritems()])))
> f.close()
>diff --git a/test/Makefile b/test/Makefile
>--- a/test/Makefile
>+++ b/test/Makefile
>@@ -1,29 +1,21 @@
> # Piglet makefile
> #
> # Builds an Elsa app without Oink!
>
>-PIGLET_DIR := ../
>+topdir = ..
>
>-include $(PIGLET_DIR)/config.mk
>-
>-ELSA_INCDIRS := -I$(PORK_DIR)/smbase -I$(PORK_DIR)/elkhound -I$(PORK_DIR)/ast -I$(PORK_DIR)/elsa -I$(PIGLET_DIR)
>-ELSA_INCFLAGS := -D__UNIX__ -DUSE_SERIAL_NUMBERS=1 -DNDEBUG -D__LINUX__ $(ELSA_INCDIRS)
>-
>-CXXFLAGS := -g -Wall $(ELSA_INCFLAGS)
>-PIGLET_OBJS := $(addprefix $(PIGLET_DIR), $(addsuffix .o,piglet expr_visitor patcher))
>-LIBS = $(PORK_DIR)/elsa/libelsa.a
>-
>-OBJDEPS = $(PIGLET_OBJS) $(LIBS)
>+include $(topdir)/config.mk
>+include $(topdir)/build.mk
>
> .PHONY: check clean
>
> check: checkpatcher
>
> checkpatcher: patchertests
> ./patchertests
>
>-patchertests: patchertests.o $(OBJDEPS)
>+patchertests: patchertests.o $(PIGLET_OBJS)
> g++ -o $@ $+;
>
> clean:
> -rm *.o
| Reporter | ||
Comment 20•17 years ago
|
||
Pushed
6c4e86b1502e Chris Jones - bug 487918: build libpork.a, couple of other tweaks in preparation for porky.py
3c39899f0c9b Chris Jones - bug 487918: porky 0.0.1
Leaving open for tracking.
| Reporter | ||
Updated•13 years ago
|
Assignee: jones.chris.g → nobody
| Reporter | ||
Updated•13 years ago
|
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
Updated•8 years ago
|
Product: Core → Firefox Build System
Updated•4 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•