@nirguna/plugin-fasm 1.1.1 → 1.3.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.
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isMemberExpression,
|
|
5
|
+
isAwaitExpression,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
4
8
|
const PREFIX = '__nirguna_';
|
|
5
9
|
|
|
6
10
|
export const report = ({name, newName}) => `Add prefix to label: '${name}' -> '${newName}'`;
|
|
@@ -41,8 +45,16 @@ function getIds(path, name) {
|
|
|
41
45
|
if (isMemberExpression(path.parentPath))
|
|
42
46
|
return;
|
|
43
47
|
|
|
44
|
-
if (name
|
|
45
|
-
|
|
48
|
+
if (name !== path.node.name)
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
const calleePath = path.parentPath.get('callee');
|
|
52
|
+
const parentAwait = isAwaitExpression(path.parentPath.parentPath);
|
|
53
|
+
|
|
54
|
+
if (!parentAwait && calleePath === path)
|
|
55
|
+
return;
|
|
56
|
+
|
|
57
|
+
ids.push(path);
|
|
46
58
|
},
|
|
47
59
|
});
|
|
48
60
|
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
types,
|
|
4
4
|
operator,
|
|
5
5
|
} from 'putout';
|
|
6
|
+
import {TARGETS} from '#targets';
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
replaceWithMultiple,
|
|
@@ -104,7 +105,19 @@ const BYTES = {
|
|
|
104
105
|
i64: 8,
|
|
105
106
|
};
|
|
106
107
|
|
|
108
|
+
function getTarget({scope}) {
|
|
109
|
+
const programPath = scope.getProgramParent().path;
|
|
110
|
+
const {target} = programPath.node.extra;
|
|
111
|
+
|
|
112
|
+
return target;
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
function getBytes(path) {
|
|
116
|
+
const target = getTarget(path);
|
|
117
|
+
|
|
118
|
+
if (target)
|
|
119
|
+
return TARGETS[target].size;
|
|
120
|
+
|
|
108
121
|
const {returnType} = path.node;
|
|
109
122
|
|
|
110
123
|
if (!returnType)
|
|
@@ -116,6 +129,14 @@ function getBytes(path) {
|
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
function getRegister(path, reg) {
|
|
132
|
+
const target = getTarget(path);
|
|
133
|
+
|
|
134
|
+
if (target) {
|
|
135
|
+
const {bits} = TARGETS[target];
|
|
136
|
+
|
|
137
|
+
return REG[bits][reg];
|
|
138
|
+
}
|
|
139
|
+
|
|
119
140
|
const {returnType} = path.node;
|
|
120
141
|
|
|
121
142
|
if (!returnType)
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import {template} from 'putout';
|
|
2
|
+
import {TARGETS} from '#targets';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}`;
|
|
7
|
-
|
|
8
|
-
const TARGET = {
|
|
9
|
-
boot: createBinary('0x7c00'),
|
|
10
|
-
kernel: createBinary('0x7e00'),
|
|
11
|
-
nemesis: createBinary('0x500'),
|
|
12
|
-
linux: `{
|
|
13
|
-
format.ELF64.executable;
|
|
14
|
-
entry.$;
|
|
15
|
-
}`,
|
|
4
|
+
export const report = (path, {options}) => {
|
|
5
|
+
const {target} = options;
|
|
6
|
+
return `Insert target: '${target}'`;
|
|
16
7
|
};
|
|
17
8
|
|
|
18
|
-
export const report = (path, {target}) => `Insert target: '${target}'`;
|
|
19
|
-
|
|
20
9
|
export const fix = (path, {options}) => {
|
|
21
10
|
const {target} = options;
|
|
11
|
+
|
|
22
12
|
path.node.extra.target = target;
|
|
23
|
-
|
|
13
|
+
const {code} = TARGETS[target];
|
|
14
|
+
|
|
15
|
+
path.node.body.unshift(template.ast(code));
|
|
24
16
|
};
|
|
25
17
|
|
|
26
18
|
export const include = () => ['Program'];
|
|
@@ -34,5 +26,5 @@ export const filter = (path, {options}) => {
|
|
|
34
26
|
if (path.node.extra.target)
|
|
35
27
|
return;
|
|
36
28
|
|
|
37
|
-
return
|
|
29
|
+
return TARGETS[target];
|
|
38
30
|
};
|
package/lib/targets.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const createBinary = (address) => `{
|
|
2
|
+
org(${address});
|
|
3
|
+
use16();
|
|
4
|
+
}`;
|
|
5
|
+
|
|
6
|
+
export const TARGETS = {
|
|
7
|
+
linux: {
|
|
8
|
+
size: 8,
|
|
9
|
+
bits: 'i64',
|
|
10
|
+
code: `{
|
|
11
|
+
format.ELF64.executable;
|
|
12
|
+
entry.$;
|
|
13
|
+
}`,
|
|
14
|
+
},
|
|
15
|
+
kernel: {
|
|
16
|
+
size: 2,
|
|
17
|
+
bits: 'i16',
|
|
18
|
+
code: createBinary('0x7e00'),
|
|
19
|
+
},
|
|
20
|
+
boot: {
|
|
21
|
+
size: 2,
|
|
22
|
+
bits: 'i16',
|
|
23
|
+
code: createBinary('0x7c00'),
|
|
24
|
+
},
|
|
25
|
+
nemesis: {
|
|
26
|
+
size: 2,
|
|
27
|
+
bits: 'i16',
|
|
28
|
+
code: createBinary('0x500'),
|
|
29
|
+
},
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirguna/plugin-fasm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊nirguna plugin adds ability to optimize fasm",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/coderaiser/putout.git"
|
|
15
15
|
},
|
|
16
|
+
"imports": {
|
|
17
|
+
"#targets": "./lib/targets.js"
|
|
18
|
+
},
|
|
16
19
|
"scripts": {
|
|
17
20
|
"test": "madrun test",
|
|
18
21
|
"watch:test": "madrun watch:test",
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
"devDependencies": {
|
|
36
39
|
"@putout/plugin-remove-nested-blocks": "^9.1.0",
|
|
37
40
|
"@putout/test": "^15.1.1",
|
|
38
|
-
"c8": "^
|
|
41
|
+
"c8": "^11.0.0",
|
|
39
42
|
"eslint": "^10.0.1",
|
|
40
43
|
"eslint-plugin-n": "^17.0.0",
|
|
41
44
|
"eslint-plugin-putout": "^31.0.1",
|