Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping #210

Merged
merged 25 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d18bf6
build: yarn add --dev prettier
xen0n Oct 11, 2024
cb84962
build: configure prettier
xen0n Oct 23, 2024
97413f9
style: format with prettier
xen0n Oct 26, 2024
129327f
refactor: fix TS error in prism-asmloong.ts
xen0n Oct 26, 2024
8965f81
build: add type declaration for mdast
xen0n Oct 26, 2024
dfd557b
refactor: fix ESM import in awly-remark-natlang-usage
xen0n Oct 26, 2024
8ed63db
refactor: fix TS error in HomepageFeatures/index.tsx
xen0n Oct 26, 2024
66b4cf7
build: bump Yarn to 4.5.1
xen0n Oct 26, 2024
c066b22
build: add typescript-eslint
xen0n Oct 26, 2024
c7f37e7
build: configure eslint
xen0n Oct 26, 2024
7ad9c82
build: migrate babel config to TS
xen0n Oct 26, 2024
493389b
refactor(asmdb): make augmentedDecodeTree plain TS
xen0n Oct 26, 2024
4fd18c3
refactor: un-nest plugin directories
xen0n Oct 26, 2024
347d7c9
refactor: fix eslint for ejected prism-include-languages
xen0n Oct 26, 2024
a40202c
refactor: fix prefer-const
xen0n Oct 26, 2024
dc15d03
build: update tsconfig to align with latest docusaurus preset
xen0n Oct 26, 2024
fec7c29
refactor: fix no-prototype-builtins
xen0n Oct 26, 2024
2b8270c
refactor: fix typescript-eslint/no-explicit-any
xen0n Oct 26, 2024
c0731ad
refactor: fix no-useless-escape
xen0n Oct 26, 2024
d01e350
refactor: fix no-case-declarations
xen0n Oct 26, 2024
febcd25
refactor: fix typescript-eslint/no-unused-vars
xen0n Oct 26, 2024
b61f2ce
build: yarn dedupe
xen0n Oct 26, 2024
32ed489
ci: add linting action for PRs
xen0n Oct 26, 2024
5edbb59
ci: configure dependabot
xen0n Oct 26, 2024
eb8403f
build: update editorconfig with more extensions
xen0n Oct 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.css,*.js,*.json,*.ts,*.tsx,*.yaml,*.yml}]
[{*.css,*.cjs,*.cts,*.js,*.json,*.mjs,*.mts,*.ts,*.tsx,*.yaml,*.yml}]
indent_size = 2

[*.md]
[{*.md,*.mdx}]
indent_size = 4

[*.go]
Expand Down
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: yarn
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /scripts/asmdb
schedule:
interval: weekly
29 changes: 29 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR checks

on:
pull_request:

jobs:
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Check out the source code
uses: actions/checkout@v4
with:
submodules: true
- name: Enable Corepack for Yarn Modern
run: corepack enable
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install --immutable
- name: Check code style with Prettier
run: yarn prettier --check .
- name: Lint with ESLint
run: yarn eslint
- name: Type-check with tsc
run: yarn tsc
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.github
/.vscode
/.yarn
/3rdparty
/build
/node_modules
/scripts
/static
/yarn.lock
*.md
*.mdx
7 changes: 7 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tabWidth = 2
semi = false
singleQuote = true

[[overrides]]
files = ["*.md", "*.mdx"]
options = { tabWidth = 4 }
5 changes: 5 additions & 0 deletions babel.config.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import docusaurusPreset from '@docusaurus/core/lib/babel/preset'

export default {
presets: [docusaurusPreset],
}
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

18 changes: 9 additions & 9 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ const config: Config = {
routeBasePath: 'newsletter',
path: './newsletter',
blogTitle: '每周一龙',
blogDescription: '龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
editUrl: 'https://github.com/loongson-community/areweloongyet/edit/main',
blogDescription:
'龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
editUrl:
'https://github.com/loongson-community/areweloongyet/edit/main',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
onUntruncatedBlogPosts: 'throw',
onUntruncatedBlogPosts: 'throw',
} satisfies BlogOptions,
],
],
Expand All @@ -171,8 +173,7 @@ const config: Config = {
sidebarPath: require.resolve('./sidebars.js'),
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/loongson-community/areweloongyet',
editUrl: 'https://github.com/loongson-community/areweloongyet',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
},
Expand All @@ -182,11 +183,10 @@ const config: Config = {
showReadingTime: true,
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/loongson-community/areweloongyet',
editUrl: 'https://github.com/loongson-community/areweloongyet',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
onUntruncatedBlogPosts: 'throw',
onUntruncatedBlogPosts: 'throw',
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
Expand All @@ -199,7 +199,7 @@ const config: Config = {
[
'@easyops-cn/docusaurus-search-local',
{
hashed: "filename",
hashed: 'filename',
language: ['en', 'zh'],
blogDir: ['blog', 'newsletter'],
blogRouteBasePath: ['/blog', '/newsletter'],
Expand Down
28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check

import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['.docusaurus/', '.yarn/', '.pnp.*', 'build/'],
},
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},
)
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "3.5.2",
"@docusaurus/tsconfig": "3.5.2",
"@eslint/js": "^9.13.0",
"@types/eslint__js": "^8.42.3",
"@types/glob": "^8.1.0",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.10",
"@types/mdast": "^4.0.4",
"@types/node": "^22.7.5",
"@types/prismjs": "^1.26.4",
"@types/react": "^18.3.11",
"@types/react-router-dom": "^5.3.3",
"eslint": "^9.13.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0",
"update-browserslist-db": "^1.1.1"
},
"resolutions": {
Expand All @@ -77,5 +83,5 @@
"engines": {
"node": ">=20"
},
"packageManager": "[email protected].0"
"packageManager": "[email protected].1"
}
6 changes: 3 additions & 3 deletions sidebars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs'
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs'

const sidebars: SidebarsConfig = {
main: [{type: 'autogenerated', dirName: '.'}],
};
main: [{ type: 'autogenerated', dirName: '.' }],
}

export default sidebars
119 changes: 86 additions & 33 deletions src/components/AsmDB/antdDecodeTreeAdapter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Tag, type TreeDataNode } from "antd"
import { Tag, type TreeDataNode } from 'antd'
import { CheckOutlined, EyeOutlined } from '@ant-design/icons'
import _ from 'lodash'

import styles from './index.module.css'
import { type AugmentedDecodeTreeMatch, type AugmentedDecodeTreeNode } from "./augmentedDecodeTree"
import { bitfieldWidth, representBitfields } from "./bitfield"
import type { Bitfield } from "./types"
import {
type AugmentedDecodeTreeMatch,
type AugmentedDecodeTreeNode,
} from './augmentedDecodeTree'
import { bitfieldWidth, representBitfields } from './bitfield'
import type { Bitfield } from './types'

function representMatchValue(val: number, bfs: Bitfield[]): string {
const sortedBFs = _.sortBy(_.clone(bfs), 'lsb')
Expand All @@ -24,10 +27,8 @@ type NodeTitleProps = {
node?: AugmentedDecodeTreeNode
}


function NodeTitle({ match, node }: NodeTitleProps): JSX.Element {
if (!match)
match = node.parentMatch
if (!match) match = node.parentMatch

const matchNumber = match ? match.match : 0
const matchPattern = node ? node.key : match.key
Expand All @@ -40,57 +41,109 @@ function NodeTitle({ match, node }: NodeTitleProps): JSX.Element {
const postAttribs: JSX.Element[] = []
if (match?.fmt)
if (node)
postAttribs.push(<span className={styles.contentAttrib} key={`${matchPattern}-fmt`}>并确定格式为 {match.fmt}</span>)
postAttribs.push(
<span className={styles.contentAttrib} key={`${matchPattern}-fmt`}>
并确定格式为 {match.fmt}
</span>,
)
else
postAttribs.push(<Tag className={styles.insnFmtTagAttrib} key={`${matchPattern}-fmt`}>{match.fmt}</Tag>)
postAttribs.push(
<Tag className={styles.insnFmtTagAttrib} key={`${matchPattern}-fmt`}>
{match.fmt}
</Tag>,
)
if (alias)
preAttribs.push(<Tag className={styles.aliasTagAttrib} key={`${matchPattern}-alias`}>{alias}</Tag>)
preAttribs.push(
<Tag className={styles.aliasTagAttrib} key={`${matchPattern}-alias`}>
{alias}
</Tag>,
)

if (insn) {
return <>
<span>{representMatchValue(matchNumber, lookAt)}: {preAttribs}{insn}</span>
{postAttribs}
</>
return (
<>
<span>
{representMatchValue(matchNumber, lookAt)}: {preAttribs}
{insn}
</span>
{postAttribs}
</>
)
}

const root = matchPattern == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
if (root)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-major`}>主操作码</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-major`}>
主操作码
</span>,
)
if (node) {
const numAllocatedPrefixes = node.matches.length
const numTotalPrefixes = 1 << bitfieldWidth(node.look_at)
if (numAllocatedPrefixes == numTotalPrefixes && node.numUsedInsnWords == node.numTotalInsnWords) {
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子空间已满</span>)
if (
numAllocatedPrefixes == numTotalPrefixes &&
node.numUsedInsnWords == node.numTotalInsnWords
) {
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子空间已满
</span>,
)
} else {
if (numAllocatedPrefixes == numTotalPrefixes)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-fanout`}>子前缀空间已满</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-fanout`}>
子前缀空间已满
</span>,
)
else
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-fanout`}>子前缀空间 {numAllocatedPrefixes}/{numTotalPrefixes}</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-fanout`}>
子前缀空间 {numAllocatedPrefixes}/{numTotalPrefixes}
</span>,
)

if (node.numUsedInsnWords == node.numTotalInsnWords)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子编码空间已满</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子编码空间已满
</span>,
)
else
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子编码空间已用 {(node.numUsedInsnWords / node.numTotalInsnWords * 100).toFixed(2)}%</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子编码空间已用{' '}
{((node.numUsedInsnWords / node.numTotalInsnWords) * 100).toFixed(
2,
)}
%
</span>,
)
}
}

if (root)
return <>
<span>检查 [{representBitfields(lookAt)}] 位</span>
return (
<>
<span>检查 [{representBitfields(lookAt)}] 位</span>
{postAttribs}
</>
)

return (
<>
<span>
{representMatchValue(matchNumber, parentLookAt)}: {preAttribs}检查 [
{representBitfields(lookAt)}] 位
</span>
{postAttribs}
</>

return <>
<span>{representMatchValue(matchNumber, parentLookAt)}: {preAttribs}检查 [{representBitfields(lookAt)}] 位</span>
{postAttribs}
</>
)
}

function makeMatchNode(
m: AugmentedDecodeTreeMatch,
): TreeDataNode {
if (m.next)
return transformDecodeTreeForAntd(m.next)
function makeMatchNode(m: AugmentedDecodeTreeMatch): TreeDataNode {
if (m.next) return transformDecodeTreeForAntd(m.next)

return {
title: <NodeTitle match={m} />,
Expand Down
Loading