Changeset 220753 in webkit for trunk/Source/JavaScriptCore/generate-bytecode-files
- Timestamp:
- Aug 15, 2017, 1:13:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/generate-bytecode-files
r217526 r220753 105 105 return sha1.hexdigest() 106 106 107 108 def toCpp(name): 109 camelCase = re.sub(r'([^a-z0-9].)', lambda c: c.group(0)[1].upper(), name) 110 CamelCase = camelCase[:1].upper() + camelCase[1:] 111 return CamelCase 112 113 114 def writeInstructionAccessor(bytecodeHFile, typeName, name): 115 bytecodeHFile.write(" {0}& {1}() {{ return *reinterpret_cast<{0}*>(&m_{1}); }}\n".format(typeName, name)) 116 bytecodeHFile.write(" const {0}& {1}() const {{ return *reinterpret_cast<const {0}*>(&m_{1}); }}\n".format(typeName, name)) 117 118 119 def writeInstructionMember(bytecodeHFile, typeName, name): 120 bytecodeHFile.write(" std::aligned_storage<sizeof({0}), sizeof(Instruction)>::type m_{1};\n".format(typeName, name)) 121 122 123 def writeStruct(bytecodeHFile, bytecode): 124 bytecodeHFile.write("struct {0} {{\n".format(toCpp(bytecode["name"]))) 125 bytecodeHFile.write("public:\n") 126 127 writeInstructionAccessor(bytecodeHFile, "Opcode", "opcode") 128 for offset in bytecode["offsets"]: 129 for name, typeName in offset.iteritems(): 130 writeInstructionAccessor(bytecodeHFile, typeName, name) 131 132 bytecodeHFile.write("\nprivate:\n") 133 bytecodeHFile.write(" friend class LLIntOffsetsExtractor;\n\n") 134 135 writeInstructionMember(bytecodeHFile, "Opcode", "opcode") 136 for offset in bytecode["offsets"]: 137 for name, typeName in offset.iteritems(): 138 writeInstructionMember(bytecodeHFile, typeName, name) 139 bytecodeHFile.write("};\n\n") 140 141 107 142 if __name__ == "__main__": 108 143 parser = optparse.OptionParser(usage = "usage: %prog [--bytecodes_h <FILE>] [--init_bytecodes_asm <FILE>] <bytecode-json-file>") 109 144 parser.add_option("-b", "--bytecodes_h", dest = "bytecodesHFileName", help = "generate bytecodes macro .h FILE", metavar = "FILE") 145 parser.add_option("-s", "--bytecode_structs_h", dest = "bytecodeStructsHFileName", help = "generate bytecodes macro .h FILE", metavar = "FILE") 110 146 parser.add_option("-a", "--init_bytecodes_asm", dest = "initASMFileName", help="generate ASM bytecodes init FILE", metavar = "FILE") 111 147 (options, args) = parser.parse_args() … … 122 158 123 159 bytecodeHFilename = options.bytecodesHFileName 160 bytecodeStructsHFilename = options.bytecodeStructsHFileName 124 161 initASMFileName = options.initASMFileName 125 162 126 if not bytecodeHFilename and not initASMFileName :163 if not bytecodeHFilename and not initASMFileName and not bytecodeStructsHFilename: 127 164 parser.print_help() 128 165 exit(0) … … 133 170 try: 134 171 bytecodeHReadFile = open(bytecodeHFilename, "rb") 135 172 136 173 hashLine = bytecodeHReadFile.readline() 137 174 if hashLine != hFileHashString: … … 141 178 else: 142 179 bytecodeHReadFile.close() 180 181 if bytecodeStructsHFilename: 182 try: 183 bytecodeStructsHReadFile = open(bytecodeStructsHFilename, "rb") 184 185 hashLine = bytecodeStructsHReadFile.readline() 186 if hashLine != hFileHashString: 187 needToGenerate = True 188 except: 189 needToGenerate = True 190 else: 191 bytecodeStructsHReadFile.close() 143 192 144 193 if initASMFileName: … … 160 209 bytecodeHFile = openOrExit(bytecodeHFilename, "wb") 161 210 211 if bytecodeStructsHFilename: 212 bytecodeStructsHFile = openOrExit(bytecodeStructsHFilename, "wb") 213 162 214 if initASMFileName: 163 215 initBytecodesFile = openOrExit(initASMFileName, "wb") … … 172 224 bytecodeHFile.write(cCopyrightMsg % bytecodeJSONFile) 173 225 bytecodeHFile.write("#pragma once\n\n") 226 227 if bytecodeStructsHFilename: 228 bytecodeStructsHFile.write(hFileHashString) 229 bytecodeStructsHFile.write(cCopyrightMsg % bytecodeJSONFile) 230 bytecodeStructsHFile.write("#pragma once\n\n") 231 bytecodeStructsHFile.write("#include \"Instruction.h\"\n") 232 bytecodeStructsHFile.write("\n") 174 233 175 234 if initASMFileName: … … 194 253 if "length" in bytecode: 195 254 length = bytecode["length"] 255 elif "offsets" in bytecode: 256 # Add one for the opcode 257 length = len(bytecode["offsets"]) + 1 196 258 197 259 bytecodeHFile.write(" macro({0}, {1})".format(bytecode["name"], length)) … … 201 263 bytecodeHFile.write("\n\n") 202 264 bytecodeHFile.write("#define NUMBER_OF_{0}_IDS {1}\n\n".format(section["macroNameComponent"], bytecodeNum)) 265 266 267 if bytecodeStructsHFilename and section['emitInStructsFile']: 268 bytecodeStructsHFile.write("namespace JSC {\n\n") 269 270 for bytecode in section["bytecodes"]: 271 if not "offsets" in bytecode: 272 continue 273 writeStruct(bytecodeStructsHFile, bytecode) 274 275 bytecodeStructsHFile.write("} // namespace JSC \n") 203 276 204 277 if bytecodeHFilename and section['emitOpcodeIDStringValuesInHFile']:
Note:
See TracChangeset
for help on using the changeset viewer.