if statement for options
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@904 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
51305ee6cc
commit
2366020f23
|
@ -4,6 +4,8 @@ import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
debug = 0
|
debug = 0
|
||||||
|
warnings = 0
|
||||||
|
errors = 0
|
||||||
|
|
||||||
arch = ''
|
arch = ''
|
||||||
ldscriptbase = ''
|
ldscriptbase = ''
|
||||||
|
@ -135,14 +137,12 @@ class option:
|
||||||
return self.value
|
return self.value
|
||||||
if (self.value == '' or self.value[0] != '{'):
|
if (self.value == '' or self.value[0] != '{'):
|
||||||
return self.value
|
return self.value
|
||||||
# evaluate expression
|
|
||||||
a = re.sub("^{", "", self.value)
|
|
||||||
a = re.sub("}$", "", a)
|
|
||||||
# save curpart so we can evaluate expression
|
# save curpart so we can evaluate expression
|
||||||
# in context of part
|
# in context of part
|
||||||
s = curpart
|
s = curpart
|
||||||
curpart = part
|
curpart = part
|
||||||
v = parse('value', a)
|
v = parse('delexpr', self.value)
|
||||||
|
# TODO: need to check for parse errors!
|
||||||
curpart = s
|
curpart = s
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -298,18 +298,27 @@ class partsstack:
|
||||||
return self.stack[-1]
|
return self.stack[-1]
|
||||||
pstack = partsstack()
|
pstack = partsstack()
|
||||||
|
|
||||||
def fatal(string):
|
def error(string):
|
||||||
global loc
|
global errors, loc
|
||||||
|
errors = errors + 1
|
||||||
size = len(loc.stack)
|
size = len(loc.stack)
|
||||||
i = 0
|
i = 0
|
||||||
while(i < size -1):
|
while(i < size -1):
|
||||||
print loc.stack[i].at()
|
print loc.stack[i].at()
|
||||||
i = i + 1
|
i = i + 1
|
||||||
print "%s: %s"% (loc.at(), string)
|
print "%s: %s"% (loc.at(), string)
|
||||||
|
|
||||||
|
def exitiferrors():
|
||||||
|
if (errors != 0):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def fatal(string):
|
||||||
|
error(string)
|
||||||
|
exitiferrors()
|
||||||
|
|
||||||
def warning(string):
|
def warning(string):
|
||||||
global loc
|
global warnings, loc
|
||||||
|
warnings = warnings + 1
|
||||||
print "===> Warning:"
|
print "===> Warning:"
|
||||||
size = len(loc.stack)
|
size = len(loc.stack)
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -369,7 +378,8 @@ def getoption(name, part):
|
||||||
else:
|
else:
|
||||||
o = getvalue(options, name)
|
o = getvalue(options, name)
|
||||||
if (o == 0 or not o.defined):
|
if (o == 0 or not o.defined):
|
||||||
fatal( "Error: Option %s Undefined (Missing use command?)." % name)
|
error("Error: Option %s undefined (missing use command?)." % name)
|
||||||
|
return
|
||||||
v = o.getvalue(part)
|
v = o.getvalue(part)
|
||||||
if (debug > 2):
|
if (debug > 2):
|
||||||
print "getoption returns %s" % v
|
print "getoption returns %s" % v
|
||||||
|
@ -447,7 +457,7 @@ def getformated(name, part):
|
||||||
else:
|
else:
|
||||||
o = getvalue(options, name)
|
o = getvalue(options, name)
|
||||||
if (o == 0 or not o.defined):
|
if (o == 0 or not o.defined):
|
||||||
fatal( "Error: Option %s Undefined (Missing use command?)." % name)
|
fatal( "Error: Option %s undefined (missing use command?)." % name)
|
||||||
v = o.getvalue(part)
|
v = o.getvalue(part)
|
||||||
f = o.getformat()
|
f = o.getformat()
|
||||||
return (f % v)
|
return (f % v)
|
||||||
|
@ -626,13 +636,18 @@ def dodir(path, file):
|
||||||
doconfigfile(fullpath, file)
|
doconfigfile(fullpath, file)
|
||||||
curdir = dirstack.pop()
|
curdir = dirstack.pop()
|
||||||
|
|
||||||
def ternary(expr, yes, no):
|
def lookup(name):
|
||||||
|
global curpart
|
||||||
|
v = getoption(name, curpart)
|
||||||
|
exitiferrors()
|
||||||
|
return v
|
||||||
|
|
||||||
|
def ternary(val, yes, no):
|
||||||
if (debug):
|
if (debug):
|
||||||
print "ternary %s" % expr
|
print "ternary %s" % expr
|
||||||
a = tohex(expr) # expr # eval(expr)
|
|
||||||
if (debug):
|
if (debug):
|
||||||
print "expr %s a %d yes %d no %d"% (expr, a, yes, no)
|
print "expr %s a %d yes %d no %d"% (expr, a, yes, no)
|
||||||
if (a == 0):
|
if (val == 0):
|
||||||
if (debug):
|
if (debug):
|
||||||
print "Ternary returns %d" % yes
|
print "Ternary returns %d" % yes
|
||||||
return yes
|
return yes
|
||||||
|
@ -957,31 +972,31 @@ parser Config:
|
||||||
token STR: r'"([^\\"]+|\\.)*"'
|
token STR: r'"([^\\"]+|\\.)*"'
|
||||||
token RAWTEXT: r'.*'
|
token RAWTEXT: r'.*'
|
||||||
|
|
||||||
rule expr<<V>>: logical<<V>> {{ l = logical }}
|
rule expr: logical {{ l = logical }}
|
||||||
( "&&" logical<<V>> {{ l = l and logical }}
|
( "&&" logical {{ l = l and logical }}
|
||||||
| "||" logical<<V>> {{ l = l or logical }}
|
| "||" logical {{ l = l or logical }}
|
||||||
)* {{ return l }}
|
)* {{ return l }}
|
||||||
|
|
||||||
rule logical<<V>>: factor<<V>> {{ n = factor }}
|
rule logical: factor {{ n = factor }}
|
||||||
( "[+]" factor<<V>> {{ n = n+factor }}
|
( "[+]" factor {{ n = n+factor }}
|
||||||
| "-" factor<<V>> {{ n = n-factor }}
|
| "-" factor {{ n = n-factor }}
|
||||||
)* {{ return n }}
|
)* {{ return n }}
|
||||||
|
|
||||||
rule factor<<V>>: term<<V>> {{ v = term }}
|
rule factor: term {{ v = term }}
|
||||||
( "[*]" term<<V>> {{ v = v*term }}
|
( "[*]" term {{ v = v*term }}
|
||||||
| "/" term<<V>> {{ v = v/term }}
|
| "/" term {{ v = v/term }}
|
||||||
| "<<" term<<V>> {{ v = v << term }}
|
| "<<" term {{ v = v << term }}
|
||||||
| ">=" term<<V>> {{ v = (v < term)}}
|
| ">=" term {{ v = (v < term)}}
|
||||||
)* {{ return v }}
|
)* {{ return v }}
|
||||||
|
|
||||||
rule unop<<V>>: "!" ID {{ return ternary(getoption(ID, curpart), 1, 0)}}
|
|
||||||
|
|
||||||
# A term is a number, variable, or an expression surrounded by parentheses
|
# A term is a number, variable, or an expression surrounded by parentheses
|
||||||
rule term<<V>>: NUM {{ return atoi(NUM) }}
|
rule term: NUM {{ return atoi(NUM) }}
|
||||||
| XNUM {{ return tohex(XNUM) }}
|
| XNUM {{ return tohex(XNUM) }}
|
||||||
| ID {{ return tohex(getoption(ID, curpart)) }}
|
| ID {{ return lookup(ID) }}
|
||||||
| unop<<V>> {{ return unop }}
|
| unop {{ return unop }}
|
||||||
| "\\(" expr<<V>> "\\)" {{ return expr }}
|
| "\\(" expr "\\)" {{ return expr }}
|
||||||
|
|
||||||
|
rule unop: "!" expr {{ return not(expr) }}
|
||||||
|
|
||||||
rule partend<<C>>: (stmt<<C>>)* END {{ partpop()}}
|
rule partend<<C>>: (stmt<<C>>)* END {{ partpop()}}
|
||||||
|
|
||||||
|
@ -1024,7 +1039,7 @@ parser Config:
|
||||||
# if is a bad id ....
|
# if is a bad id ....
|
||||||
# needs to be C and ID, but nested if's are, we hope, not going to
|
# needs to be C and ID, but nested if's are, we hope, not going to
|
||||||
# happen. IF so, possibly ID && C could be used.
|
# happen. IF so, possibly ID && C could be used.
|
||||||
rule iif<<C>>: IF ID {{ c = tohex(getoption(ID, curpart)) }}
|
rule iif<<C>>: IF ID {{ c = lookup(ID) }}
|
||||||
(stmt<<c>>)* END
|
(stmt<<c>>)* END
|
||||||
|
|
||||||
rule depsacts<<ID, C>>:
|
rule depsacts<<ID, C>>:
|
||||||
|
@ -1076,18 +1091,26 @@ parser Config:
|
||||||
|
|
||||||
rule uses<<C>>: USES (usesid<<C>>)+
|
rule uses<<C>>: USES (usesid<<C>>)+
|
||||||
|
|
||||||
# ENTRY for parsing a value
|
|
||||||
rule value: STR {{ return dequote(STR) }}
|
rule value: STR {{ return dequote(STR) }}
|
||||||
| term<<[]>> {{ return term }}
|
| expr {{ return expr }}
|
||||||
| DELEXPR {{ return DELEXPR }}
|
| DELEXPR {{ return DELEXPR }}
|
||||||
|
|
||||||
rule option: OPTION ID EQ value {{ setoptionstmt(ID, value) }}
|
rule option<<C>>: OPTION ID EQ value {{ if (C): setoptionstmt(ID, value) }}
|
||||||
|
|
||||||
|
rule opif: IF ID {{ c = lookup(ID) }}
|
||||||
|
(option<<c>>)* END
|
||||||
|
|
||||||
|
rule opstmt: option<<1>>
|
||||||
|
| opif
|
||||||
|
|
||||||
|
# ENTRY for parsing a delayed value
|
||||||
|
rule delexpr: "{" expr "}" {{ return expr }}
|
||||||
|
|
||||||
# ENTRY for parsing root part
|
# ENTRY for parsing root part
|
||||||
rule board: LOADOPTIONS {{ loadoptions() }}
|
rule board: LOADOPTIONS {{ loadoptions() }}
|
||||||
TARGET DIRPATH {{ target(DIRPATH) }}
|
TARGET DIRPATH {{ target(DIRPATH) }}
|
||||||
(uses<<1>>)*
|
(uses<<1>>)*
|
||||||
(option)*
|
(opstmt)*
|
||||||
mainboard {{ return 1 }}
|
mainboard {{ return 1 }}
|
||||||
|
|
||||||
rule defstmts<<ID>>: {{ d = 0 }}
|
rule defstmts<<ID>>: {{ d = 0 }}
|
||||||
|
@ -1144,6 +1167,7 @@ def doconfigfile(path, file):
|
||||||
loc.push_file(filename)
|
loc.push_file(filename)
|
||||||
if (not parse('cfgfile', open(filename, 'r').read())):
|
if (not parse('cfgfile', open(filename, 'r').read())):
|
||||||
fatal("Error: Could not parse file")
|
fatal("Error: Could not parse file")
|
||||||
|
exitiferrors()
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
Loading…
Reference in New Issue