Best JavaScript code snippet using wpt
test.js
Source:test.js
...104});105test("Hex Parsing", function() {106 equal (tinycolor("rgb 255 0 0").toHexString(), "#ff0000");107 equal (tinycolor("rgb 255 0 0").toHexString(true), "#f00");108 equal (tinycolor("rgb 255 0 0").toHex(), "ff0000");109 equal (tinycolor("rgb 255 0 0").toHex(true), "f00");110});111test("HSV Parsing", function() {112 equal( tinycolor("hsv 251.1 0.887 .918").toHsvString(), "hsv(251, 89%, 92%)");113 equal( tinycolor("hsv 251.1 0.887 0.918").toHsvString(), "hsv(251, 89%, 92%)");114});115test("Invalid Parsing", function() {116 equal( tinycolor("this is not a color").toHexString(), "#000000");117});118test("Named colors", function() {119 equal (tinycolor("aliceblue").toHex(), "f0f8ff");120 equal (tinycolor("antiquewhite").toHex(), "faebd7");121 equal (tinycolor("aqua").toHex(), "00ffff");122 equal (tinycolor("aquamarine").toHex(), "7fffd4");123 equal (tinycolor("azure").toHex(), "f0ffff");124 equal (tinycolor("beige").toHex(), "f5f5dc");125 equal (tinycolor("bisque").toHex(), "ffe4c4");126 equal (tinycolor("black").toHex(), "000000");127 equal (tinycolor("blanchedalmond").toHex(), "ffebcd");128 equal (tinycolor("blue").toHex(), "0000ff");129 equal (tinycolor("blueviolet").toHex(), "8a2be2");130 equal (tinycolor("brown").toHex(), "a52a2a");131 equal (tinycolor("burlywood").toHex(), "deb887");132 equal (tinycolor("cadetblue").toHex(), "5f9ea0");133 equal (tinycolor("chartreuse").toHex(), "7fff00");134 equal (tinycolor("chocolate").toHex(), "d2691e");135 equal (tinycolor("coral").toHex(), "ff7f50");136 equal (tinycolor("cornflowerblue").toHex(), "6495ed");137 equal (tinycolor("cornsilk").toHex(), "fff8dc");138 equal (tinycolor("crimson").toHex(), "dc143c");139 equal (tinycolor("cyan").toHex(), "00ffff");140 equal (tinycolor("darkblue").toHex(), "00008b");141 equal (tinycolor("darkcyan").toHex(), "008b8b");142 equal (tinycolor("darkgoldenrod").toHex(), "b8860b");143 equal (tinycolor("darkgray").toHex(), "a9a9a9");144 equal (tinycolor("darkgreen").toHex(), "006400");145 equal (tinycolor("darkkhaki").toHex(), "bdb76b");146 equal (tinycolor("darkmagenta").toHex(), "8b008b");147 equal (tinycolor("darkolivegreen").toHex(), "556b2f");148 equal (tinycolor("darkorange").toHex(), "ff8c00");149 equal (tinycolor("darkorchid").toHex(), "9932cc");150 equal (tinycolor("darkred").toHex(), "8b0000");151 equal (tinycolor("darksalmon").toHex(), "e9967a");152 equal (tinycolor("darkseagreen").toHex(), "8fbc8f");153 equal (tinycolor("darkslateblue").toHex(), "483d8b");154 equal (tinycolor("darkslategray").toHex(), "2f4f4f");155 equal (tinycolor("darkturquoise").toHex(), "00ced1");156 equal (tinycolor("darkviolet").toHex(), "9400d3");157 equal (tinycolor("deeppink").toHex(), "ff1493");158 equal (tinycolor("deepskyblue").toHex(), "00bfff");159 equal (tinycolor("dimgray").toHex(), "696969");160 equal (tinycolor("dodgerblue").toHex(), "1e90ff");161 equal (tinycolor("firebrick").toHex(), "b22222");162 equal (tinycolor("floralwhite").toHex(), "fffaf0");163 equal (tinycolor("forestgreen").toHex(), "228b22");164 equal (tinycolor("fuchsia").toHex(), "ff00ff");165 equal (tinycolor("gainsboro").toHex(), "dcdcdc");166 equal (tinycolor("ghostwhite").toHex(), "f8f8ff");167 equal (tinycolor("gold").toHex(), "ffd700");168 equal (tinycolor("goldenrod").toHex(), "daa520");169 equal (tinycolor("gray").toHex(), "808080");170 equal (tinycolor("grey").toHex(), "808080");171 equal (tinycolor("green").toHex(), "008000");172 equal (tinycolor("greenyellow").toHex(), "adff2f");173 equal (tinycolor("honeydew").toHex(), "f0fff0");174 equal (tinycolor("hotpink").toHex(), "ff69b4");175 equal (tinycolor("indianred ").toHex(), "cd5c5c");176 equal (tinycolor("indigo ").toHex(), "4b0082");177 equal (tinycolor("ivory").toHex(), "fffff0");178 equal (tinycolor("khaki").toHex(), "f0e68c");179 equal (tinycolor("lavender").toHex(), "e6e6fa");180 equal (tinycolor("lavenderblush").toHex(), "fff0f5");181 equal (tinycolor("lawngreen").toHex(), "7cfc00");182 equal (tinycolor("lemonchiffon").toHex(), "fffacd");183 equal (tinycolor("lightblue").toHex(), "add8e6");184 equal (tinycolor("lightcoral").toHex(), "f08080");185 equal (tinycolor("lightcyan").toHex(), "e0ffff");186 equal (tinycolor("lightgoldenrodyellow").toHex(), "fafad2");187 equal (tinycolor("lightgrey").toHex(), "d3d3d3");188 equal (tinycolor("lightgreen").toHex(), "90ee90");189 equal (tinycolor("lightpink").toHex(), "ffb6c1");190 equal (tinycolor("lightsalmon").toHex(), "ffa07a");191 equal (tinycolor("lightseagreen").toHex(), "20b2aa");192 equal (tinycolor("lightskyblue").toHex(), "87cefa");193 equal (tinycolor("lightslategray").toHex(), "778899");194 equal (tinycolor("lightsteelblue").toHex(), "b0c4de");195 equal (tinycolor("lightyellow").toHex(), "ffffe0");196 equal (tinycolor("lime").toHex(), "00ff00");197 equal (tinycolor("limegreen").toHex(), "32cd32");198 equal (tinycolor("linen").toHex(), "faf0e6");199 equal (tinycolor("magenta").toHex(), "ff00ff");200 equal (tinycolor("maroon").toHex(), "800000");201 equal (tinycolor("mediumaquamarine").toHex(), "66cdaa");202 equal (tinycolor("mediumblue").toHex(), "0000cd");203 equal (tinycolor("mediumorchid").toHex(), "ba55d3");204 equal (tinycolor("mediumpurple").toHex(), "9370db");205 equal (tinycolor("mediumseagreen").toHex(), "3cb371");206 equal (tinycolor("mediumslateblue").toHex(), "7b68ee");207 equal (tinycolor("mediumspringgreen").toHex(), "00fa9a");208 equal (tinycolor("mediumturquoise").toHex(), "48d1cc");209 equal (tinycolor("mediumvioletred").toHex(), "c71585");210 equal (tinycolor("midnightblue").toHex(), "191970");211 equal (tinycolor("mintcream").toHex(), "f5fffa");212 equal (tinycolor("mistyrose").toHex(), "ffe4e1");213 equal (tinycolor("moccasin").toHex(), "ffe4b5");214 equal (tinycolor("navajowhite").toHex(), "ffdead");215 equal (tinycolor("navy").toHex(), "000080");216 equal (tinycolor("oldlace").toHex(), "fdf5e6");217 equal (tinycolor("olive").toHex(), "808000");218 equal (tinycolor("olivedrab").toHex(), "6b8e23");219 equal (tinycolor("orange").toHex(), "ffa500");220 equal (tinycolor("orangered").toHex(), "ff4500");221 equal (tinycolor("orchid").toHex(), "da70d6");222 equal (tinycolor("palegoldenrod").toHex(), "eee8aa");223 equal (tinycolor("palegreen").toHex(), "98fb98");224 equal (tinycolor("paleturquoise").toHex(), "afeeee");225 equal (tinycolor("palevioletred").toHex(), "db7093");226 equal (tinycolor("papayawhip").toHex(), "ffefd5");227 equal (tinycolor("peachpuff").toHex(), "ffdab9");228 equal (tinycolor("peru").toHex(), "cd853f");229 equal (tinycolor("pink").toHex(), "ffc0cb");230 equal (tinycolor("plum").toHex(), "dda0dd");231 equal (tinycolor("powderblue").toHex(), "b0e0e6");232 equal (tinycolor("purple").toHex(), "800080");233 equal (tinycolor("red").toHex(), "ff0000");234 equal (tinycolor("rosybrown").toHex(), "bc8f8f");235 equal (tinycolor("royalblue").toHex(), "4169e1");236 equal (tinycolor("saddlebrown").toHex(), "8b4513");237 equal (tinycolor("salmon").toHex(), "fa8072");238 equal (tinycolor("sandybrown").toHex(), "f4a460");239 equal (tinycolor("seagreen").toHex(), "2e8b57");240 equal (tinycolor("seashell").toHex(), "fff5ee");241 equal (tinycolor("sienna").toHex(), "a0522d");242 equal (tinycolor("silver").toHex(), "c0c0c0");243 equal (tinycolor("skyblue").toHex(), "87ceeb");244 equal (tinycolor("slateblue").toHex(), "6a5acd");245 equal (tinycolor("slategray").toHex(), "708090");246 equal (tinycolor("snow").toHex(), "fffafa");247 equal (tinycolor("springgreen").toHex(), "00ff7f");248 equal (tinycolor("steelblue").toHex(), "4682b4");249 equal (tinycolor("tan").toHex(), "d2b48c");250 equal (tinycolor("teal").toHex(), "008080");251 equal (tinycolor("thistle").toHex(), "d8bfd8");252 equal (tinycolor("tomato").toHex(), "ff6347");253 equal (tinycolor("turquoise").toHex(), "40e0d0");254 equal (tinycolor("violet").toHex(), "ee82ee");255 equal (tinycolor("wheat").toHex(), "f5deb3");256 equal (tinycolor("white").toHex(), "ffffff");257 equal (tinycolor("whitesmoke").toHex(), "f5f5f5");258 equal (tinycolor("yellow").toHex(), "ffff00");259 equal (tinycolor("yellowgreen").toHex(), "9acd32");260 equal (tinycolor("#f00").toName(), "red");261 equal (tinycolor("#fa0a0a").toName(), false);262});263module("Alpha handling");264test("Invalid alpha should normalize to 1", function() {265 equal(tinycolor({r:255,g:20,b:10,a: -1}).toRgbString(), "rgb(255, 20, 10)", "Negative value");266 equal(tinycolor({r:255,g:20,b:10,a: -0}).toRgbString(), "rgba(255, 20, 10, 0)", "Negative 0");267 equal(tinycolor({r:255,g:20,b:10,a: 0}).toRgbString(), "rgba(255, 20, 10, 0)", "0");268 equal(tinycolor({r:255,g:20,b:10,a: .5}).toRgbString(), "rgba(255, 20, 10, 0.5)", ".5");269 equal(tinycolor({r:255,g:20,b:10,a: 1}).toRgbString(), "rgb(255, 20, 10)", "1");270 equal(tinycolor({r:255,g:20,b:10,a: 100}).toRgbString(), "rgb(255, 20, 10)", "Greater than 1");271 equal(tinycolor({r:255,g:20,b:10,a: "asdfasd"}).toRgbString(), "rgb(255, 20, 10)", "Non Numeric");272 equal(tinycolor("#fff").toRgbString(), "rgb(255, 255, 255)", "Hex should be 1");273 equal(tinycolor("rgba 255 0 0 100").toRgbString(), "rgb(255, 0, 0)", "Greater than 1 in string parsing");274 var redNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "name"});275 var transparentNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: 0 }, {format: "name"});276 var redHex = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "hex"});277 equal(redNamed.toString(), "rgba(255, 0, 0, 0.5)", "Names should default to rgba if alpha is < 1");278 equal(redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");279 equal(redNamed.toString("hex"), "#ff0000", "Names should not be returned as rgba if format is specified");280 equal(redNamed.toString("hex6"), "#ff0000", "Names should not be returned as rgba if format is specified");281 equal(redNamed.toString("hex3"), "#f00", "Names should not be returned as rgba if format is specified");282 equal(redNamed.toString("name"), "red", "Names should not be returned as rgba if format is specified");283 equal(redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");284 equal(transparentNamed.toString(), "transparent", "Named color should equal transparent if alpha == 0");285});286test("Alpha = 0 should act differently on toName()", function() {287 equal(tinycolor({r:255,g:20,b:10,a: 0}).toName(), "transparent", "0");288 equal(tinycolor("transparent").toString(), "transparent", "toString when passed");289 equal(tinycolor("transparent").toHex(), "000000", "toHex");290});291module("Initialization from tinycolor output");292test("HSL Object", function() {293 var random = tinycolor.random();294 equal (random.toHexString(), tinycolor(random.toHsl()).toHexString(), "HSL Object");295});296/*297test("HSL String", function() {298 var random = tinycolor.random();299 equal (random.toHexString(), tinycolor(random.toHslString()).toHexString(), random.toHexString());300});301test("HSV String", function() {302 var random = tinycolor.random();303 equal (random.toHexString(), tinycolor(random.toHsvString()).toHexString(), random.toHsvString());304});305*/306test("HSV Object", function() {307 var random = tinycolor.random();308 equal (random.toHexString(), tinycolor(random.toHsv()).toHexString(), "HSV Object");309});310test("RGB Object", function() {311 var random = tinycolor.random();312 equal (random.toHexString(), tinycolor(random.toRgb()).toHexString(), "RGB Object");313});314test("RGB String", function() {315 var random = tinycolor.random();316 equal (random.toHexString(), tinycolor(random.toRgbString()).toHexString(), "RGB String");317});318test("PRGB Object", function() {319 var random = tinycolor.random();320 var input = random.toRgb();321 var output = tinycolor(random.toPercentageRgb()).toRgb();322 var maxDiff = 2;323 equal(Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);324 equal(Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);325 equal(Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);326});327test("PRGB String", function() {328 var random = tinycolor.random();329 var input = random.toRgb();330 var output = tinycolor(random.toPercentageRgbString()).toRgb();331 var maxDiff = 2;332 equal(Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);333 equal(Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);334 equal(Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);335});336test("Object", function() {337 var random = tinycolor.random();338 equal (random.toHexString(), tinycolor(random).toHexString(), "Object");339});340module("Utilities");341test("Color equality", function() {342 ok (tinycolor.equals("#ff0000", "#ff0000"), "Same hex");343 ok (tinycolor.equals("#ff0000", "rgb(255, 0, 0)"), "Same alphas");344 ok (!tinycolor.equals("#ff0000", "rgba(255, 0, 0, .1)"), "Different alphas");345 ok (tinycolor.equals("ff0000", "#ff0000"), "Same hex");346 ok (tinycolor.equals("#f00", "#ff0000"), "Same hex");347 ok (tinycolor.equals("f00", "#ff0000"), "Same hex");348 equal (tinycolor("010101").toHexString(), "#010101");349 ok (!tinycolor.equals("#ff0000", "#00ff00"), "Different hex");350 ok (tinycolor.equals("#ff8000", "rgb(100%, 50%, 0%)"), "Percentage bounds checking");351});352test("Readability", function () {353 ok (tinycolor.readable("#000000", "#ffffff"), "white/black is readable");354 ok (!tinycolor.readable("#FF0088", "#8822AA"), "pink on pink is not readable");355 equal (tinycolor.mostReadable("#000", ["#111", "#222"]).toHexString(), "#222222", "pick most readable color");356 equal (tinycolor.mostReadable("#f00", ["#d00", "#0d0"]).toHexString(), "#00dd00", "pick most readable color");357});358test("Filters", function () {359 equal (tinycolor("red").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ffff0000)");360 equal (tinycolor("red").toFilter("blue"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ff0000ff)");361 equal(tinycolor("transparent").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#00000000)");362 equal(tinycolor("transparent").toFilter("red"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#ffff0000)");363});364/* Originally generated with:365var results = [];366for (var i = 0; i <= 100; i++) results.push( tinycolor.saturate("red", i).toHex() )367console.log(JSON.stringify(results))368*/369var DESATURATIONS = ["ff0000","fe0101","fc0303","fb0404","fa0505","f90606","f70808","f60909","f50a0a","f40b0b","f20d0d","f10e0e","f00f0f","ee1111","ed1212","ec1313","eb1414","e91616","e81717","e71818","e61919","e41b1b","e31c1c","e21d1d","e01f1f","df2020","de2121","dd2222","db2424","da2525","d92626","d72828","d62929","d52a2a","d42b2b","d22d2d","d12e2e","d02f2f","cf3030","cd3232","cc3333","cb3434","c93636","c83737","c73838","c63939","c43b3b","c33c3c","c23d3d","c13e3e","bf4040","be4141","bd4242","bb4444","ba4545","b94646","b84747","b64949","b54a4a","b44b4b","b34d4d","b14e4e","b04f4f","af5050","ad5252","ac5353","ab5454","aa5555","a85757","a75858","a65959","a45b5b","a35c5c","a25d5d","a15e5e","9f6060","9e6161","9d6262","9c6363","9a6565","996666","986767","966969","956a6a","946b6b","936c6c","916e6e","906f6f","8f7070","8e7171","8c7373","8b7474","8a7575","887777","877878","867979","857a7a","837c7c","827d7d","817e7e","808080"];370var SATURATIONS = ["ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000","ff0000"];371var LIGHTENS = ["ff0000","ff0505","ff0a0a","ff0f0f","ff1414","ff1a1a","ff1f1f","ff2424","ff2929","ff2e2e","ff3333","ff3838","ff3d3d","ff4242","ff4747","ff4d4d","ff5252","ff5757","ff5c5c","ff6161","ff6666","ff6b6b","ff7070","ff7575","ff7a7a","ff8080","ff8585","ff8a8a","ff8f8f","ff9494","ff9999","ff9e9e","ffa3a3","ffa8a8","ffadad","ffb3b3","ffb8b8","ffbdbd","ffc2c2","ffc7c7","ffcccc","ffd1d1","ffd6d6","ffdbdb","ffe0e0","ffe5e5","ffebeb","fff0f0","fff5f5","fffafa","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff","ffffff"];372var DARKENS = ["ff0000","fa0000","f50000","f00000","eb0000","e60000","e00000","db0000","d60000","d10000","cc0000","c70000","c20000","bd0000","b80000","b30000","ad0000","a80000","a30000","9e0000","990000","940000","8f0000","8a0000","850000","800000","7a0000","750000","700000","6b0000","660000","610000","5c0000","570000","520000","4d0000","470000","420000","3d0000","380000","330000","2e0000","290000","240000","1f0000","190000","140000","0f0000","0a0000","050000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000","000000"];373test("Combinations", function () {374 for (var i = 0; i <= 100; i++) {375 equal(tinycolor.desaturate("red", i).toHex(), DESATURATIONS[i], "Desaturation " + i + " works");376 }377 for (var i = 0; i <= 100; i++) {378 equal(tinycolor.saturate("red", i).toHex(), SATURATIONS[i], "Saturation " + i + " works");379 }380 for (var i = 0; i <= 100; i++) {381 equal(tinycolor.lighten("red", i).toHex(), LIGHTENS[i], "Lighten " + i + " works");382 }383 for (var i = 0; i <= 100; i++) {384 equal(tinycolor.darken("red", i).toHex(), DARKENS[i], "Darken " + i + " works");385 }386 equal(tinycolor.greyscale("red").toHex(), "808080", "Greyscale works")387 equal(tinycolor.complement("red").toHex(), "00ffff", "Complement works");388});389/* Too slow: 1677731 possibilities390asyncTest("Ajax load", function() {391 $.get("allhex.txt", function(d) {392 var hex = d.split('\n');393 for (var i = 0, l = hex.length; i < l; i++) {394 ok(tinycolor(hex[i]).toHex(), hex[i]);395 }396 console.log(hex.length);397 start();398 });399});...
disassemble.js
Source:disassemble.js
1"use strict";2var message = require('../messagehandler');3var utils = require('../utils');4var PRV_U = 0x00;5var PRV_S = 0x01;6var PRV_H = 0x02;7var PRV_M = 0x03;8var CSR_MSTATUS = 0x300;9function Disassemble(ins,r,csr,pc) {10 switch(ins&0x7F) {11 case 0x03:12 //lb,lh,lw,lbu,lhu13 switch((ins >> 12)&0x7) {14 15 case 0x00:16 //lb17 message.Debug("lb - "+ utils.ToHex(ins));18 break;19 case 0x01:20 //lh21 message.Debug("lh - "+ utils.ToHex(ins));22 break;23 case 0x02:24 //lw25 message.Debug("lw - "+ utils.ToHex(ins));26 break;27 case 0x04:28 //lbu29 message.Debug("lbu - "+ utils.ToHex(ins));30 break;31 case 0x05:32 //lhu33 message.Debug("lhu - "+ utils.ToHex(ins));34 break;35 default:36 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");37 break;38 }39 break;40 case 0x23:41 //sb,sh,sw42 switch((ins >> 12)&0x7) {43 44 case 0x00:45 //sb46 message.Debug("sb - "+ utils.ToHex(ins));47 break;48 case 0x01:49 //sh50 message.Debug("sh - "+ utils.ToHex(ins));51 break;52 case 0x02:53 //sw54 message.Debug("sw - "+ utils.ToHex(ins));55 break;56 default:57 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");58 break;59 }60 break;61 case 0x13:62 //addi,slti,sltiu,xori,ori,andi,slli,srli,srai63 switch((ins >> 12)&0x7) {64 65 case 0x00:66 //addi67 message.Debug("addi - "+ utils.ToHex(ins));68 break;69 case 0x02:70 //slti71 message.Debug("slti - "+ utils.ToHex(ins));72 break;73 case 0x03:74 //sltiu75 message.Debug("sltiu - "+ utils.ToHex(ins));76 break;77 case 0x04:78 //xori79 message.Debug("xori - "+ utils.ToHex(ins));80 break;81 case 0x06:82 //ori83 message.Debug("ori - "+ utils.ToHex(ins));84 break;85 case 0x07:86 //andi87 message.Debug("andi - "+ utils.ToHex(ins));88 break;89 case 0x01:90 //slli91 message.Debug("slli - "+ utils.ToHex(ins));92 break;93 case 0x05:94 if(((ins >> 25) & 0x7F) == 0x00){95 //srli96 message.Debug("srli - "+ utils.ToHex(ins));97 }98 else if(((ins >> 25) & 0x7F) == 0x20){99 //srai100 message.Debug("srai - "+ utils.ToHex(ins)); 101 }102 break;103 default:104 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");105 break;106 }107 break;108 case 0x33:109 //add,sub,sll,slt,sltu,xor,srl,sra,or,and110 switch((ins >> 25)&0x7F) {111 112 case 0x00:113 //add,slt,sltu,add,or,xor,sll,srl114 switch((ins >> 12)&0x7) {115 case 0x00:116 //add117 message.Debug("add - "+ utils.ToHex(ins));118 break;119 case 0x02:120 //slt121 message.Debug("slt - "+ utils.ToHex(ins));122 break;123 case 0x03:124 //sltu125 message.Debug("sltu - "+ utils.ToHex(ins));126 break;127 case 0x07:128 //and129 message.Debug("and - "+ utils.ToHex(ins));130 break;131 case 0x06:132 //or133 message.Debug("or - "+ utils.ToHex(ins));134 break;135 case 0x04:136 //xor137 message.Debug("xor - "+ utils.ToHex(ins));138 break;139 case 0x01:140 //sll141 message.Debug("sll - "+ utils.ToHex(ins));142 break;143 case 0x05:144 //srl145 message.Debug("srl - "+ utils.ToHex(ins));146 break;147 }148 break;149 case 0x20:150 //sub151 switch((ins >> 12)&0x7) {152 case 0x00:153 //sub154 message.Debug("sub - "+ utils.ToHex(ins));155 break;156 case 0x05:157 //sra158 message.Debug("sra - "+ utils.ToHex(ins));159 break;160 }161 break;162 case 0x01:163 //mul,mulh,mulhsu,mulhu,div,divu,rem,remu164 switch((ins >> 12)&0x7) {165 case 0x00:166 //mul167 message.Debug("mul - "+ utils.ToHex(ins));168 break;169 case 0x01:170 //mulh171 message.Debug("mulh - "+ utils.ToHex(ins));172 break;173 case 0x02:174 //mulhsu175 message.Debug("mulhsu - "+ utils.ToHex(ins));176 break;177 case 0x03:178 //mulhu179 message.Debug("mulhu - "+ utils.ToHex(ins));180 break;181 case 0x04:182 //div183 message.Debug("div - "+ utils.ToHex(ins));184 break;185 case 0x05:186 //divu187 message.Debug("divu - "+ utils.ToHex(ins));188 break;189 case 0x06:190 //rem191 message.Debug("rem - "+ utils.ToHex(ins));192 break;193 case 0x07:194 //remu195 message.Debug("remu - "+ utils.ToHex(ins));196 break;197 }198 break;199 200 default:201 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");202 break;203 }204 break;205 case 0x37:206 //lui207 message.Debug("Lui - "+ utils.ToHex(ins));208 break;209 case 0x17:210 //auipc211 message.Debug("auipc - "+ utils.ToHex(ins));212 break;213 case 0x6F:214 //jal215 message.Debug("jal - "+ utils.ToHex(ins));216 break; 217 case 0x67:218 //jalr219 message.Debug("jalr - "+ utils.ToHex(ins));220 break;221 case 0x63:222 //beq,bne,blt,bge,bltu,bgeu223 switch((ins >> 12)&0x7) {224 225 case 0x00:226 //beq227 message.Debug("beq - "+ utils.ToHex(ins));228 break;229 case 0x01:230 //bne231 message.Debug("bne - "+ utils.ToHex(ins));232 break;233 case 0x04:234 //blt235 message.Debug("blt - "+ utils.ToHex(ins));236 break;237 case 0x05:238 //bge239 message.Debug("bge - "+ utils.ToHex(ins));240 break;241 case 0x06:242 //bltu243 message.Debug("bltu - "+ utils.ToHex(ins));244 break;245 case 0x07:246 //bgeu247 message.Debug("bgeu - "+ utils.ToHex(ins));248 break;249 default:250 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");251 break;252 }253 break;254 case 0x73:255 //csrrw,csrrs,csrrc,csrrwi,csrrsi,csrrci,ecall,eret,ebreak,mrts256 switch((ins >> 12)&0x7) {257 258 case 0x01:259 //csrrw260 message.Debug("csrrw - "+ utils.ToHex(ins));261 break;262 case 0x02:263 //csrrs264 message.Debug("csrrs - "+ utils.ToHex(ins));265 break;266 case 0x03:267 //csrrc268 message.Debug("csrrc - "+ utils.ToHex(ins));269 break;270 case 0x05:271 //csrrwi272 message.Debug("csrrwi - "+ utils.ToHex(ins));273 break;274 275 case 0x06:276 //csrrsi277 message.Debug("csrrsi - "+ utils.ToHex(ins));278 break;279 case 0x07:280 //csrrci281 message.Debug("csrrci - "+ utils.ToHex(ins));282 break;283 284 case 0x00:285 //ecall,eret,ebreak,mrts286 switch((ins >> 20)&0xFFF) {287 case 0x00:288 //ecall289 var current_privilege_level = (csr[CSR_MSTATUS] & 0x06) >> 1;290 switch(current_privilege_level)291 {292 case PRV_U:293 message.Debug("ecall PRV_U -"+ utils.ToHex(ins));294 break;295 case PRV_S:296 message.Debug("ecall PRV_S -"+ utils.ToHex(ins));297 break;298 case PRV_H:299 message.Debug("Not supported ecall PRV_H -"+ utils.ToHex(ins));300 break;301 case PRV_M:302 message.Debug("ecall PRV_M -"+ utils.ToHex(ins));303 break;304 305 default:306 message.Debug("Error in ecall: Don't know how to handle privilege level " + current_privilege_level);307 break;308 }309 break;310 case 0x001:311 //ebreak312 message.Debug("ebreak - "+ utils.ToHex(ins)+" at PC" + utils.ToHex(this.pc));313 break;314 case 0x100:315 //eret316 var current_privilege_level = (csr[CSR_MSTATUS] & 0x06) >> 1;317 if(current_privilege_level < PRV_S) {318 message.Debug("Error in eret: current_privilege_level isn't allowed access");319 break; 320 }321 switch(current_privilege_level)322 {323 324 case PRV_S:325 message.Debug("eret PRV_S -"+ utils.ToHex(ins));326 break;327 case PRV_H:328 message.Debug("Not supported eret PRV_H -"+ utils.ToHex(ins));329 break;330 case PRV_M:331 message.Debug("eret PRV_M -"+ utils.ToHex(ins));332 break;333 334 default:335 message.Debug("Error in eret: Don't know how to handle privilege level " + current_privilege_level);336 break;337 }338 break;339 case 0x305:340 //mrts 341 if(current_privilege_level != PRV_M) {342 message.Debug("Error in mrts: current_privilege_level isn't allowed access");343 break; 344 }345 message.Debug("mrts - "+ utils.ToHex(ins));346 break;347 case 0x101:348 //sfence.vm349 message.Debug("sfence.vm - "+ utils.ToHex(ins));350 break;351 default:352 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");353 break;354 }355 break; 356 default:357 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");358 break;359 }360 break;361 case 0x07:362 //flw,fld363 switch((ins >> 12)&0x7) {364 365 case 0x02:366 //flw367 message.Debug("flw - "+ utils.ToHex(ins));368 break;369 case 0x03:370 //fld371 message.Debug("fld - "+ utils.ToHex(ins));372 break;373 default:374 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");375 break;376 }377 break;378 case 0x27:379 //fsw,fsd380 switch((ins >> 12)&0x7) {381 case 0x02:382 //fsw383 message.Debug("fsw - "+ utils.ToHex(ins));384 break;385 case 0x03:386 //fsd387 message.Debug("fsw - "+ utils.ToHex(ins));388 break;389 default:390 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");391 break;392 }393 break;394 case 0x53:395 //fadd.s,fsub.s396 switch((ins >> 25)&0x7F) {397 398 case 0x00 :399 //fadd.s400 message.Debug("fadd.s - "+ utils.ToHex(ins));401 break;402 case 0x04:403 //fsub.s404 message.Debug("fsub.s - "+ utils.ToHex(ins));405 break;406 case 0x60:407 //fcvt.w.s408 message.Debug("fcvt.w.s - "+ utils.ToHex(ins));409 break;410 case 0x01 :411 //fadd.d412 message.Debug("fadd.d - "+ utils.ToHex(ins));413 break;414 case 0x05:415 //fsub.d416 message.Debug("fsub.d - "+ utils.ToHex(ins));417 break;418 case 0x61:419 //fcvt.w.d420 message.Debug("fcvt.w.s - "+ utils.ToHex(ins));421 break;422 case 0x78:423 //fmv.s.x424 message.Debug("fmv.s.x - "+ utils.ToHex(ins));425 break;426 default:427 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + "not found");428 break;429 }430 break;431 case 0x2F:432 //amoswap,amoadd,amoxor,amoand,amoor,amomin,amomax,amominu,amomaxu433 switch((ins >> 27)&0x1F) {434 435 case 0x01:436 //amoswap437 message.Debug("amoswap - "+ utils.ToHex(ins));438 break;439 case 0x00:440 //amoadd441 message.Debug("amoadd - "+ utils.ToHex(ins));442 break;443 case 0x04:444 //amoxor445 message.Debug("amoxor - "+ utils.ToHex(ins));446 break;447 case 0x0C:448 //amoand449 message.Debug("amoand - "+ utils.ToHex(ins));450 break;451 case 0x08:452 //amoor453 message.Debug("amoor - "+ utils.ToHex(ins));454 break;455 case 0x10:456 //amomin457 message.Debug("amomin - "+ utils.ToHex(ins));458 break;459 case 0x14:460 //amomax461 message.Debug("amomax - "+ utils.ToHex(ins));462 break;463 case 0x18:464 //amominu465 message.Debug("amominu - "+ utils.ToHex(ins));466 break;467 case 0x1C:468 //amomaxu469 message.Debug("amomaxu - "+ utils.ToHex(ins));470 break;471 case 0x02:472 //lr.d473 message.Debug("lr.d - "+ utils.ToHex(ins));474 break;475 case 0x03:476 //sc.d477 message.Debug("sc.d - "+ utils.ToHex(ins));478 break;479 default:480 message.Debug("Error in Atomic Memory Instruction " + utils.ToHex(ins) + "not found");481 break;482 }483 break;484 case 0x0F:485 //fence486 message.Debug("fence - "+ utils.ToHex(ins));487 break;488 default:489 message.Debug("Error in safecpu: Instruction " + utils.ToHex(ins) + " not found at "+utils.ToHex(this.pc));490 break;491 }492 message.Debug(utils.ToHex(pc));493};...
Using AI Code Generation
1var wptools = require('wptools');2var hex = wptools.toHex(123);3console.log(hex);4var wptools = require('wptools');5var hex = wptools.toHex(123);6console.log(hex);7var wptools = require('wptools');8var hex = wptools.toHex(123);9console.log(hex);10var wptools = require('wptools');11var hex = wptools.toHex(123);12console.log(hex);13var wptools = require('wptools');14var hex = wptools.toHex(123);15console.log(hex);16var wptools = require('wptools');17var hex = wptools.toHex(123);18console.log(hex);19var wptools = require('wptools');20var hex = wptools.toHex(123);21console.log(hex);22var wptools = require('wptools');23var hex = wptools.toHex(123);24console.log(hex);25var wptools = require('wptools');26var hex = wptools.toHex(123);27console.log(hex);28var wptools = require('wptools');29var hex = wptools.toHex(123);30console.log(hex);31var wptools = require('wptools');32var hex = wptools.toHex(123);33console.log(hex);34var wptools = require('wptools');
Using AI Code Generation
1var hex = wpt.toHex(1,2,3);2console.log(hex);3var hex = wpt.toHex(1,2,3);4console.log(hex);5var wpt = require('wpt.js');6var hex = wpt.toHex(1,2,3);7console.log(hex);8var hex = wpt.toHex(1,2,3);9console.log(hex);10var hex = wpt.toHex(1,2,3);11console.log(hex);12var wpt = require('wpt.js');13var hex = wpt.toHex(1,2,3);14console.log(hex);15var hex = wpt.toHex(1,2,3);16console.log(hex);17var hex = wpt.toHex(1,2,3);18console.log(hex);19var wpt = require('wpt.js');20var hex = wpt.toHex(1,2,3);21console.log(hex);22var hex = wpt.toHex(1,2,3);23console.log(hex);24var hex = wpt.toHex(1,2,3);25console.log(hex);26var wpt = require('wpt.js');27var hex = wpt.toHex(1,2,3);28console.log(hex);29var hex = wpt.toHex(1,2,3);30console.log(hex);31var hex = wpt.toHex(1,2,3);32console.log(hex);33var wpt = require('wpt.js');34var hex = wpt.toHex(1,2,3
Using AI Code Generation
1var wptools = require('wptools');2var hex = wptools.toHex('test');3console.log(hex);4exports.toHex = function(str) {5 var hex = '';6 for(var i=0;i<str.length;i++) {7 hex += ''+str.charCodeAt(i).toString(16);8 }9 return hex;10};11var wptools = require('wptools');12var hex = wptools.toHex('test');13console.log(hex);14var toHex = function(str) {15 var hex = '';16 for(var i=0;i<str.length;i++) {17 hex += ''+str.charCodeAt(i).toString(16);18 }19 return hex;20};21exports.toHex = toHex;22var wptools = require('wptools');23var hex = wptools.toHex('test');24console.log(hex);25var toHex = function(str) {26 var hex = '';27 for(var i=0;i<str.length;i++) {28 hex += ''+str.charCodeAt(i).toString(16);29 }30 return hex;31};32exports.toHex = toHex;33var wptools = require('wptools');34var hex = wptools.toHex('test');35console.log(hex);36var toHex = function(str) {37 var hex = '';38 for(var i=0;i<str.length;i++) {39 hex += ''+str.charCodeAt(i).toString(16
Using AI Code Generation
1var wpt = require('wpt.js');2var hex = wpt.toHex(255, 255, 0);3console.log(hex);4var toHex = function(r, g, b) {5 return '#' + r.toString(16) + g.toString(16) + b.toString(16);6}7exports.toHex = toHex;8var toHex = function(r, g, b) {9 return '#' + r.toString(16) + g.toString(16) + b.toString(16);10}11exports.toHex = toHex;12var toHex = function(r, g, b) {13 return '#' + r.toString(16) + g.toString(16) + b.toString(16);14}15exports.toHex = toHex;16var toHex = function(r, g, b) {17 return '#' + r.toString(16) + g.toString(16) + b.toString(16);18}19exports.toHex = toHex;20var toHex = function(r, g, b) {21 return '#' + r.toString(16) + g.toString(16) + b.toString(16);22}23exports.toHex = toHex;24var toHex = function(r, g, b) {25 return '#' + r.toString(16) + g.toString(16) + b.toString(16);26}27exports.toHex = toHex;28var toHex = function(r, g, b) {29 return '#' + r.toString(16) + g.toString(16) + b.toString(16);30}31exports.toHex = toHex;32var toHex = function(r, g, b) {33 return '#' + r.toString(16) + g.toString(16) + b.toString(16);34}35exports.toHex = toHex;
Using AI Code Generation
1var hex = toHex(100);2function toHex(num) {3 var hex = num.toString(16);4 return hex;5}6var data = require('./data.json');7{8}9var cron = require('cron');10var job = new cron.CronJob('00 * * * * *', function() {11 console.log('You will see this message every minute');12}, null, true, 'America/Los_Angeles');13job.start();
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt.Wpt();3wpt.toHex(12345, function(err, hex) {4 if(err) {5 console.log('Error: ', err);6 } else {7 console.log('Hex: ', hex);8 }9});10var util = require('util');11var events = require('events');12var wpt = function() {13 events.EventEmitter.call(this);14};15util.inherits(wpt, events.EventEmitter);16wpt.prototype.toHex = function(num, callback) {17 callback(null, num.toString(16));18};19module.exports = wpt;20 at Object.<anonymous> (/Users/eric/Projects/wpt/wpt.js:7:1)21 at Module._compile (module.js:456:26)22 at Object..js (module.js:474:10)23 at Module.load (module.js:356:32)24 at Function._load (module.js:312:12)25 at Array.0 (module.js:475:10)26 at EventEmitter._tickCallback (node.js:192:40)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!