blob: 51783acc1b23f98afcb6eb23188ab4c428658623 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# Copyright (C) 2006 Holger Hans Peter Freyther
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006
7from bb.utils import better_compile, better_exec
8
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05009def insert_method(modulename, code, fn, lineno):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010 """
11 Add code of a module should be added. The methods
12 will be simply added, no checking will be done
13 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014 comp = better_compile(code, modulename, fn, lineno=lineno)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015 better_exec(comp, None, code, fn)
16
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050017compilecache = {}
18
19def compile_cache(code):
20 h = hash(code)
21 if h in compilecache:
22 return compilecache[h]
23 return None
24
25def compile_cache_add(code, compileobj):
26 h = hash(code)
27 compilecache[h] = compileobj