Mercurial > hg > graal-compiler
annotate mx/outputparser.py @ 4389:6ffa3413096e
Improved layout algorithm to put an emphasis on CFG edges.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 28 Jan 2012 15:48:40 +0100 |
parents | 063ea022532c |
children | 3aab15f42934 |
rev | line source |
---|---|
4225
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
1 # ---------------------------------------------------------------------------------------------------- |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
2 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
3 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
5 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
6 # This code is free software; you can redistribute it and/or modify it |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
7 # under the terms of the GNU General Public License version 2 only, as |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
8 # published by the Free Software Foundation. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
9 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
10 # This code is distributed in the hope that it will be useful, but WITHOUT |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
13 # version 2 for more details (a copy is included in the LICENSE file that |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
14 # accompanied this code). |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
15 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
16 # You should have received a copy of the GNU General Public License version |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
17 # 2 along with this work; if not, write to the Free Software Foundation, |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
19 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
21 # or visit www.oracle.com if you need additional information or have any |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
22 # questions. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
23 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
24 # ---------------------------------------------------------------------------------------------------- |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
25 |
4151 | 26 import mx |
27 import commands | |
4225
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
28 import subprocess |
4151 | 29 |
30 class OutputParser: | |
31 | |
32 def __init__(self, nonZeroIsFatal=True): | |
33 self.matchers = [] | |
34 self.nonZeroIsFatal = nonZeroIsFatal | |
35 | |
36 def addMatcher(self, matcher): | |
37 self.matchers.append(matcher) | |
38 | |
4219
47f7d91d34cf
Fix javac build issues with classpath
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4215
diff
changeset
|
39 def parse(self, vm, cmd, cwd=None, vmbuild=None): |
4282
063ea022532c
mx commands : improve bench command, fix in the outparser so that no empty 'line' is retruned if there was no match, fix bootstrap's regex
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4225
diff
changeset
|
40 ret = [] |
4151 | 41 |
42 def parseLine(line): | |
43 anyMatch = False | |
44 for matcher in self.matchers: | |
4215
a2caa019ba3a
Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4151
diff
changeset
|
45 parsed = matcher.parse(line.strip()) |
4151 | 46 if parsed: |
47 anyMatch = True | |
4282
063ea022532c
mx commands : improve bench command, fix in the outparser so that no empty 'line' is retruned if there was no match, fix bootstrap's regex
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4225
diff
changeset
|
48 if len(ret) is 0 or (matcher.startNewLine and len(ret[len(ret)-1]) > 0): |
4151 | 49 ret.append({}) |
50 ret[len(ret)-1].update(parsed) | |
51 if anyMatch : | |
4215
a2caa019ba3a
Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4151
diff
changeset
|
52 mx.log('>' + line.rstrip()) |
4151 | 53 else : |
4215
a2caa019ba3a
Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4151
diff
changeset
|
54 mx.log( line.rstrip()) |
4151 | 55 |
4225
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
56 retcode = commands.vm(cmd, vm, nonZeroIsFatal=self.nonZeroIsFatal, out=parseLine, err=subprocess.STDOUT, cwd=cwd, vmbuild=vmbuild) |
4215
a2caa019ba3a
Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
4151
diff
changeset
|
57 return {'parsed' : ret, 'retcode' : retcode} |
4151 | 58 |
59 class Matcher: | |
60 | |
61 def __init__(self, regex, valuesToParse, startNewLine=False): | |
62 assert isinstance(valuesToParse, dict) | |
63 self.regex = regex | |
64 self.valuesToParse = valuesToParse | |
65 self.startNewLine = startNewLine | |
66 | |
67 def parse(self, line): | |
68 match = self.regex.search(line) | |
69 if not match: | |
70 return False | |
71 ret = {} | |
72 for key, value in self.valuesToParse.items(): | |
73 ret[self.parsestr(match, key)] = self.parsestr(match, value) | |
74 return ret | |
75 | |
76 def parsestr(self, match, key): | |
77 if isinstance(key, tuple): | |
78 if len(key) != 2: | |
4225
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
79 raise Exception('Tuple arguments must have a length of 2') |
4151 | 80 tup1, tup2 = key |
81 # check if key is a function | |
82 if hasattr(tup1, '__call__'): | |
83 return tup1(self.parsestr(match, tup2)) | |
84 elif hasattr(tup2, '__call__'): | |
85 return tup2(self.parsestr(match, tup1)) | |
86 else: | |
87 raise Exception('Tuple must contain a function pointer') | |
88 elif key.startswith('const:'): | |
89 return key.split(':')[1] | |
90 else: | |
91 return match.group(key) |