MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / parse_json_data

Function parse_json_data

Scripts/InstructionCountParser.py:96–223  ·  view source on GitHub ↗
(json_filepath, json_filename, json_data, output_binary_path)

Source from the content-addressed store, hash-verified

94 return HostFeaturesData
95
96def parse_json_data(json_filepath, json_filename, json_data, output_binary_path):
97 Bitness = 64
98 EnabledHostFeatures = HostFeatures.FEATURE_ANY
99 DisabledHostFeatures = HostFeatures.FEATURE_ANY
100 OptionEnvironmentVariables = {}
101
102 if "Features" in json_data:
103 items = json_data["Features"]
104 if ("Bitness" in items):
105 Bitness = int(items["Bitness"])
106
107 if ("EnabledHostFeatures" in items):
108 EnabledHostFeatures = GetHostFeatures(items["EnabledHostFeatures"])
109
110 if ("DisabledHostFeatures" in items):
111 DisabledHostFeatures = GetHostFeatures(items["DisabledHostFeatures"])
112
113 if ("Env" in items):
114 data = items["Env"]
115 if not (type(data) is dict):
116 sys.exit("Environment variables value must be list of key:value pairs")
117
118 for data_key, data_val in data.items():
119 OptionEnvironmentVariables[data_key] = data_val
120
121 for key, items in json_data["Instructions"].items():
122 ExpectedInstructionCount = 0
123 Instructions = []
124 if ("ExpectedInstructionCount" in items):
125 ExpectedInstructionCount = int(items["ExpectedInstructionCount"])
126
127 if ("Skip" in items):
128 if items["Skip"].upper() == "YES":
129 continue
130
131 if "x86Insts" in items:
132 Instructions = items["x86Insts"]
133 else:
134 # No list of instructions, only one which is the key.
135 Instructions.append(key)
136 TestName = base64.b64encode("{}.{}.{}".format(str(hash(json_filepath)), json_filename, key).encode("ascii")).decode("ascii")
137 tmp_asm = "/tmp/{}.asm".format(TestName)
138 tmp_asm_out = "/tmp/{}.asm.o".format(TestName)
139 logging.info("'{}' -> '{}' -> '{}'".format(key, tmp_asm, tmp_asm_out))
140
141 if TestName in TestDataMap:
142 sys.exit("Duplicate test name {} in tests".format(TestName))
143
144 with open(tmp_asm, "w") as tmp_asm_file:
145 tmp_asm_file.write("BITS {};\n".format(Bitness))
146 for Inst in Instructions:
147 tmp_asm_file.write("{}\n".format(Inst))
148
149 Process = subprocess.Popen(["nasm", tmp_asm, "-o", tmp_asm_out])
150 Process.wait()
151 ResultCode = Process.returncode
152
153 if ResultCode != 0:

Callers 1

mainFunction · 0.85

Calls 5

GetHostFeaturesFunction · 0.85
strFunction · 0.85
TestDataClass · 0.85
appendMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected