@nirguna/plugin-fasm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +48 -0
  2. package/lib/add-label-prefix/index.js +50 -0
  3. package/lib/apply-equality/index.js +8 -0
  4. package/lib/apply-inc/index.js +8 -0
  5. package/lib/apply-include/index.js +17 -0
  6. package/lib/apply-registers/index.js +44 -0
  7. package/lib/apply-types/index.js +79 -0
  8. package/lib/convert-args-to-regs/index.js +170 -0
  9. package/lib/convert-assign-to-add/index.js +5 -0
  10. package/lib/convert-assign-to-and/index.js +5 -0
  11. package/lib/convert-assign-to-member/index.js +5 -0
  12. package/lib/convert-assign-to-mov/index.js +53 -0
  13. package/lib/convert-assign-to-or/index.js +5 -0
  14. package/lib/convert-assign-to-shl/index.js +5 -0
  15. package/lib/convert-assign-to-sub/index.js +5 -0
  16. package/lib/convert-assign-to-xor/index.js +5 -0
  17. package/lib/convert-await-to-call/index.js +53 -0
  18. package/lib/convert-bios-clear-screen-to-int-10/index.js +8 -0
  19. package/lib/convert-bios-print-line-to-int-10/index.js +52 -0
  20. package/lib/convert-bios-read-char-to-int-16/index.js +18 -0
  21. package/lib/convert-bios-read-sector-to-int-13/index.js +80 -0
  22. package/lib/convert-bios-reboot-to-jmp-far/index.js +5 -0
  23. package/lib/convert-bios-scroll-to-int-10/index.js +16 -0
  24. package/lib/convert-const-to-equ/index.js +15 -0
  25. package/lib/convert-dec-to-hex/index.js +19 -0
  26. package/lib/convert-declaration-to-mov/index.js +23 -0
  27. package/lib/convert-do-while-to-jnz/index.js +155 -0
  28. package/lib/convert-equ-call-to-member/index.js +30 -0
  29. package/lib/convert-function-to-label/index.js +114 -0
  30. package/lib/convert-if-to-jmp/index.js +166 -0
  31. package/lib/convert-if-to-jmp/operator.js +27 -0
  32. package/lib/convert-linux-exit-to-syscall/index.js +15 -0
  33. package/lib/convert-linux-write-to-syscall/index.js +48 -0
  34. package/lib/convert-mov-to-add/index.js +5 -0
  35. package/lib/convert-return-to-eax/index.js +76 -0
  36. package/lib/convert-strncmp-to-repe-cmpsb/index.js +23 -0
  37. package/lib/convert-ternary-to-if/index.js +5 -0
  38. package/lib/convert-ureg-to-reg/index.js +108 -0
  39. package/lib/convert-while-to-jz/index.js +158 -0
  40. package/lib/extract-labeled-block/index.js +68 -0
  41. package/lib/index.js +93 -0
  42. package/lib/remove-useless-braces/index.js +5 -0
  43. package/lib/remove-useless-declarations/index.js +7 -0
  44. package/lib/remove-useless-promise/index.js +5 -0
  45. package/lib/split-assign-await-with-assign-eax/index.js +41 -0
  46. package/lib/split-binary-expression/index.js +31 -0
  47. package/lib/split-stack-operations/index.js +50 -0
  48. package/lib/switch-cmp-operands/index.js +19 -0
  49. package/package.json +56 -0
@@ -0,0 +1,50 @@
1
+ import {types, operator} from 'putout';
2
+
3
+ const {
4
+ expressionStatement,
5
+ labeledStatement,
6
+ blockStatement,
7
+ isLabeledStatement,
8
+ callExpression,
9
+ } = types;
10
+
11
+ const {
12
+ replaceWith,
13
+ replaceWithMultiple,
14
+ } = operator;
15
+
16
+ export const report = ({node}) => {
17
+ const {callee} = node;
18
+ const {name} = callee;
19
+
20
+ return `Split '${name}(__array)' to couple calls`;
21
+ };
22
+
23
+ export const fix = (path) => {
24
+ const {callee} = path.node;
25
+ const [first] = path.get('arguments');
26
+ const {elements} = first.node;
27
+ const nodes = [];
28
+
29
+ for (const element of elements) {
30
+ nodes.push(callExpression(callee, [element]));
31
+ }
32
+
33
+ const {parentPath} = path.parentPath;
34
+
35
+ if (isLabeledStatement(parentPath)) {
36
+ const {label} = parentPath.node;
37
+ const expressions = nodes.map(expressionStatement);
38
+
39
+ replaceWith(parentPath, labeledStatement(label, blockStatement(expressions)));
40
+
41
+ return;
42
+ }
43
+
44
+ replaceWithMultiple(path, nodes);
45
+ };
46
+
47
+ export const include = () => [
48
+ 'push(__array)',
49
+ 'pop(__array)',
50
+ ];
@@ -0,0 +1,19 @@
1
+ import {types} from 'putout';
2
+ import {isRegister} from '@nirguna/operator-fasm/regs';
3
+
4
+ const {isArrayExpression} = types;
5
+
6
+ export const report = () => `Switch 'cmp' operands`;
7
+
8
+ export const match = () => ({
9
+ 'cmp(__a, __b)': ({__a}) => {
10
+ if (isArrayExpression(__a))
11
+ return false;
12
+
13
+ return !isRegister(__a.name);
14
+ },
15
+ });
16
+
17
+ export const replace = () => ({
18
+ 'cmp(__a, __b)': 'cmp(__b, __a)',
19
+ });
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@nirguna/plugin-fasm",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
+ "description": "🐊nirguna plugin adds ability to optimize fasm",
7
+ "homepage": "https://github.com/putoutjs/nirguna/tree/master/packages/plugin-fasm#readme",
8
+ "main": "lib/index.js",
9
+ "release": false,
10
+ "tag": false,
11
+ "changelog": false,
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/coderaiser/putout.git"
15
+ },
16
+ "scripts": {
17
+ "test": "madrun test",
18
+ "watch:test": "madrun watch:test",
19
+ "lint": "madrun lint",
20
+ "fresh:lint": "madrun fresh:lint",
21
+ "lint:fresh": "madrun lint:fresh",
22
+ "fix:lint": "madrun fix:lint",
23
+ "coverage": "madrun coverage",
24
+ "report": "madrun report"
25
+ },
26
+ "keywords": [
27
+ "putout",
28
+ "putout-plugin",
29
+ "plugin",
30
+ "madrun"
31
+ ],
32
+ "dependencies": {
33
+ "@nirguna/operator-fasm": "^1.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@putout/plugin-remove-nested-blocks": "^9.1.0",
37
+ "@putout/test": "^15.1.1",
38
+ "c8": "^10.0.0",
39
+ "eslint": "^10.0.0",
40
+ "eslint-plugin-n": "^17.0.0",
41
+ "eslint-plugin-putout": "^30.0.2",
42
+ "madrun": "^12.1.3",
43
+ "montag": "^1.2.1",
44
+ "nodemon": "^3.0.1"
45
+ },
46
+ "peerDependencies": {
47
+ "putout": ">=41"
48
+ },
49
+ "license": "MIT",
50
+ "engines": {
51
+ "node": ">=22"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }