tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

split-swizzles.js (1502B)


      1 /*
      2 
      3 run with
      4   node split-swizzles.js
      5 
      6 notes:
      7 
      8 swizzles.test is generated from the C++ based dEQP tests
      9 https://github.com/KhronosGroup/VK-GL-CTS/blob/main/modules/gles2/scripts/gen-swizzles.py
     10 
     11 You need to manually add these tests to the 00_test_list.txt
     12 
     13 */
     14 
     15 const fs = require('fs');
     16 
     17 process.chdir(__dirname);
     18 
     19 const testWarning = `\
     20 # WARNING: This file is auto-generated. Do NOT modify it manually, but rather
     21 # modify the generating script file. Otherwise changes will be lost!
     22 # See split-swizzles.js
     23 
     24 `;
     25 
     26 const swizzlesHTML = fs.readFileSync('swizzles.template', {encoding: 'utf8'});
     27 const swizzles = fs.readFileSync('swizzles.test', {encoding: 'utf8'});
     28 const caseMatches = swizzles.matchAll(/\scase (\w+)_(\w+)_(\w+)\n[\s\S]+?end\n/g);
     29 
     30 // quick sanity check
     31 const numCases = swizzles.matchAll('\bcase\b').length;
     32 if (caseMatches.length !== numCases) {
     33  throw Error(`numCases(${numCases}) does not match caseMatches.length(${caseMatches.length})`);
     34 }
     35 
     36 const byType = {}
     37 for (const [str, precision, type, swizzle] of caseMatches) {
     38  byType[type] = byType[type] || [];
     39  byType[type].push(str);
     40 }
     41 
     42 for (const [type, cases] of Object.entries(byType)) {
     43  const baseName = `swizzles_${type}`;
     44  const str = `group ${type}_swizzles "${type} swizzles"\n\n${cases.join('\n\n')}\n\nend # ${type}_swizzles`;
     45  fs.writeFileSync(`${baseName}.test`, `${testWarning}${str}`);
     46  fs.writeFileSync(`${baseName}.html`, `<!--\n${testWarning}-->\n${swizzlesHTML.replace("'swizzles'", `'${baseName}'`)}`);
     47 }