Commit b70a935b authored by Ruslan Izhitsky's avatar Ruslan Izhitsky Committed by a-chmil
Browse files

check stealable

parent df5b915e
......@@ -23,7 +23,7 @@ DESCRIPTION
OPTIONS
--help
Show this help and exit
'''
BLOCKH='// %s\nBlockRetStatus block_%d(CF &self)\n{\n'
......@@ -78,7 +78,7 @@ def get_sub_block(sub_name):
pos=sub['begin']
sub_blocks[sub_name]=gen_id(pos, 'sub %s' % sub_name)
return sub_blocks[sub_name]
def create_scope(j, parent):
scope={
......@@ -125,17 +125,17 @@ def resolve_id(name, scope):
raise UnresolvedName(name)
if name in scope['names']:
return scope['names'][name]
if name in scope['dfs'] or name in scope['cfs']:
id='_id_%d' % len(scope['create_ids'])
scope['names'][name]=id
scope['create_ids'].append((id, name))
return resolve_id(name, scope)
if is_base_sub_param(name, scope['j']):
raise UnresolvedName('Attempting to access basic type as name',
name)
res=resolve_id(name, scope['parent'])
arg=len(scope['ids'])
if type(res)!=str:
......@@ -150,7 +150,7 @@ def resolve_value(name, scope):
raise UnresolvedName(name)
if name in scope['values']:
return scope['values'][name]
try:
res=resolve_id(name, scope)
scope['values'][name]={
......@@ -160,7 +160,7 @@ def resolve_value(name, scope):
return resolve_value(name, scope)
except UnresolvedName:
pass
res=resolve_value(name, scope['parent'])
arg=len(scope['args'])
scope['args'].append(res['snip'])
......@@ -270,7 +270,7 @@ def gen_formula(x, scope, dest_value_type):
% (ops[0], x['type'], ops[1])
else:
R(x)
for op in x['operands']:
xt=expr_type(op, scope)
......@@ -371,7 +371,7 @@ def value_real(x, scope):
% ref1(x['ref'], scope)
else:
R(x, x['type'])
raise Exception("this is unreachable?")
t=expr_type(x, scope)
if t=='int':
......@@ -468,9 +468,18 @@ def gen_migrate(scope, ja):
res+='\t\treturn MIGRATE;\n\t}\n\n'
else:
raise Exception('Cannot migrate', ja.get('id'), ja['type'])
return res
def gen_stealable(scope, ja):
'''Generate check_steal'''
the_code = ''
for rule in ja.get('rules', []):
if rule['ruletype'] == 'flags':
subflags = rule.get('flags', [])
if len(subflags) == 1 and subflags[0] == "stealable":
the_code += '\t' + 'if (self.check_steal()) {' + '\n\t\t' + 'return STEAL;' + '\n\t' + '}' + '\n\n'
return the_code
def parse_args(scope, ja):
# bind names to sub arguments
......@@ -526,7 +535,7 @@ def gen_exec_extern(scope, ja):
cpp_head+='\t{\n'
args=[]
outs=[]
assert len(ja['args'])==len(sub['args'])
for i in range(len(ja['args'])):
arg=ja['args'][i]
......@@ -575,7 +584,7 @@ def gen_exec_extern(scope, ja):
cpp_afterstores+='\t\t\tself.store(%s, stored);\n' % r
cpp_afterstores+='\t\t}\n'
cpp_tail+='\t}\n\n'
return cpp_head+cpp_alloc_outs+cpp_body+cpp_afterstores+cpp_tail
def gen_exec_struct(scope, ja):
......@@ -588,7 +597,7 @@ def gen_exec_struct(scope, ja):
if ADD_DEBUG_INFO:
res+='\t\tchild->DBG_INFO="%s";\n' % quote(repr_exec(ja))
assert len(ja['args'])==len(sub['args'])
argc, idc=0, 0
for i in range(len(ja['args'])):
......@@ -766,7 +775,7 @@ def gen_requests_preliminary(scope, ja, next_block_info):
assert not rw_rules
return requests
def gen_requests(scope, ja, next_block_info):
'''Can breake the block. Starts and ends in open blocks'''
requests=''
......@@ -778,7 +787,7 @@ def gen_requests(scope, ja, next_block_info):
for r in ja.get('rules', []):
if r['ruletype']=='enum' and r['property']=='wait':
rw_rules.append(r)
# Requests
for r in ja.get('rules', []):
......@@ -858,11 +867,11 @@ def gen_requests(scope, ja, next_block_info):
expect=''
if has_waits:
expect+='\tself.expect_pushes(%s);\n\n' % ref1(ja['id'], scope)
assert not rw_rules
return expect+requests+waits
def gen_bi_exec(ja, parent_scope):
# { migrate} {xp/req}{wait} {exec; afterstuff}
scope=create_scope(ja, parent_scope)
......@@ -875,18 +884,19 @@ def gen_bi_exec(ja, parent_scope):
'comment': 'migrate'
})
cpp+=gen_migrate(scope, ja)
cpp+=gen_stealable(scope, ja)
cpp+=gen_requests(scope, ja, {
'pos': ja['begin'],
'comment': 'execute %s' % repr_ja(ja)
})
if gja[ja['code']]['type']=='struct':
cpp+=gen_exec_struct(scope, ja)
elif gja[ja['code']]['type']=='extern':
cpp+=gen_exec_extern(scope, ja)
else:
R()
cpp+=gen_afterstuff(scope, ja)
cpp+='\treturn EXIT;\n'
......@@ -933,7 +943,7 @@ def gen_bi_for(ja, parent_scope):
scope['values']=json.loads(old_values)
cpp+=gen_afterstuff(scope, ja)
cpp+='\treturn EXIT;\n'
cpp+='}\n\n'
cpp+=cpp_bodyitems
......@@ -1019,7 +1029,7 @@ def gen_bi_if(ja, parent_scope):
cpp+='\t} // if\n'
cpp+=gen_afterstuff(scope, ja)
cpp+='\treturn EXIT;\n'
cpp+='}\n\n'
cpp+=cpp_bodyitems
......@@ -1108,7 +1118,7 @@ if __name__=='__main__':
sys.stderr.write('%s: invalid arguments count, see --help\n' \
% _prog)
sys.exit(1)
try:
for arg in sys.argv[4:]:
if arg=='--add-debug-info':
......@@ -1117,7 +1127,7 @@ if __name__=='__main__':
sys.stderr.write("%s: key not recognized: '%s', see --help\n"\
% (_prog, arg))
sys.exit(1)
gja=json.loads(open(sys.argv[1]).read())
gja['main']['name']='main'
main_id=gen_id(gja['main']['begin'],
......@@ -1146,7 +1156,7 @@ if __name__=='__main__':
mid+=', '.join(args)
mid+=');\n\n'
mid+='\treturn EXIT;\n'
continue
bid, cpp=gen_struct(sub)
......@@ -1164,7 +1174,7 @@ if __name__=='__main__':
mid+='}\n\n'
if gid<200:
tail='extern "C" void init_blocks(BlocksAppender add)\n{\n'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment