Commit b77d8636 authored by Kunshan Wang's avatar Kunshan Wang

Fixed muapi.h and improved parser.

Fixed a bug where the last param of new_thread_nor should be

Removed MuIRNodeRefValue to make MuIRNode unique.

muapi.h also includes the common instruction names in the comment after
the macro. Improved the API parser for this purpose.
parent e5170430
......@@ -697,7 +697,7 @@ Stack and thread operations
MuStackRefValue (*new_stack )(MuCtx *ctx, MuFuncRefValue func);
MuThreadRefValue (*new_thread_nor)(MuCtx *ctx, MuStackRefValue stack,
MuRefValue threadlocal,
MuValue *vals, MuBool nvals);
MuValue *vals, MuArraySize nvals);
MuThreadRefValue (*new_thread_exc)(MuCtx *ctx, MuStackRefValue stack,
MuRefValue threadlocal,
MuRefValue exc);
This diff is collapsed.
......@@ -19,9 +19,10 @@ text =
for opcode, name in pat.findall(text):
macro_name = "MU_CI_" + name.upper().replace(".", "_")
opcode = opcode.lower()
defs.append((macro_name, opcode))
defs.append((name, macro_name, opcode))
longest = max(longest, len(macro_name))
for macro_name, opcode in defs:
print("#define {} ((MuCommInst){})".format(macro_name.ljust(longest), opcode))
for name, macro_name, opcode in defs:
print("#define {} ((MuCommInst){}) /// MUAPIPARSER muname:@{}".format(
macro_name.ljust(longest), opcode, name))
......@@ -8,12 +8,12 @@ import re
import injecttools
r_commpragma = re.compile(r'///\s*MUAPIPARSER:(.*)$')
rfrag_commpragma = r'(?:///\s*MUAPIPARSER\s+(?P<pragma>.*))?'
r_comment = re.compile(r'//.*$', re.MULTILINE)
r_decl = re.compile(r'(?P<ret>\w+\s*\*?)\s*\(\s*\*\s*(?P<name>\w+)\s*\)\s*\((?P<params>[^)]*)\)\s*;\s*(?:///\s*MUAPIPARSER\s+(?P<pragma>.*)$)?', re.MULTILINE)
r_decl = re.compile(r'(?P<ret>\w+\s*\*?)\s*\(\s*\*\s*(?P<name>\w+)\s*\)\s*\((?P<params>[^)]*)\)\s*;\s*' + rfrag_commpragma, re.MULTILINE)
r_param = re.compile(r'\s*(?P<type>\w+\s*\*?)\s*(?P<name>\w+)')
r_define = re.compile(r'^\s*#define\s+(?P<name>\w+)\s*\(\((?P<type>\w+)\)(?P<value>\w+)\)\s*$', re.MULTILINE)
r_define = re.compile(r'^\s*#define\s+(?P<name>\w+)\s*\(\((?P<type>\w+)\)(?P<value>\w+)\)\s*' + rfrag_commpragma + r'\s*$', re.MULTILINE)
r_typedef = re.compile(r'^\s*typedef\s+(?P<expand_to>\w+\s*\*?)\s*(?P<name>\w+)\s*;', re.MULTILINE)
......@@ -56,11 +56,13 @@ def extract_struct(text, name):
def extract_enums(text, typename, pattern):
defs = []
for m in r_define.finditer(text):
if m is not None:
name, ty, value = m.groups()
if is not None:
defs.append({"name": name, "value": value})
for name, ty, value, pragma in r_define.findall(text):
if is not None:
"name": name,
"value": value,
"pragmas": extract_pragmas(pragma),
return {
"name": typename,
"defs": defs,
......@@ -81,11 +83,14 @@ _enums = [(typename, re.compile(regex)) for typename, regex in [
def extract_typedefs(text):
typedefs = {}
typedefs_order = []
for m in r_typedef.finditer(text):
expand_to, name = m.groups()
typedefs[name] = expand_to.replace(" ","")
expand_to = expand_to.replace(" ","")
typedefs[name] = expand_to
typedefs_order.append((name, expand_to))
return typedefs
return typedefs, typedefs_order
def parse_muapi(text):
structs = []
......@@ -100,12 +105,13 @@ def parse_muapi(text):
for tn,pat in _enums:
enums.append(extract_enums(text, tn, pat))
typedefs = extract_typedefs(text)
typedefs, typedefs_order = extract_typedefs(text)
return {
"structs": structs,
"enums": enums,
"typedefs": typedefs,
"typedefs_order": typedefs_order,
if __name__=='__main__':
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