Add local HLS dev setup: clangd, pragma highlighting + linting, local C-sim

This commit is contained in:
2026-10-24 17:13:18 +01:00
parent e036c194ed
commit 04b7425598
180 changed files with 745644 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
" ===========================================================================
" HLS pragma highlighting for Vitis HLS (EMBS)
" ---------------------------------------------------------------------------
" Vim's stock C/C++ syntax files treat the whole "#pragma HLS ..." line as one
" anonymous preprocessor directive, so the pragma name and its options are
" invisible. These rules give them their own highlight groups.
"
" Loaded automatically when this directory is on 'runtimepath' (see the
" hlsdev README). Safe to source twice.
" ===========================================================================
if !exists('b:current_syntax')
finish
endif
if b:current_syntax !=# 'cpp' && b:current_syntax !=# 'c'
finish
endif
" The pragma line as a whole, so options inside it can be picked out.
syntax region hlsPragma
\ start=/#\s*pragma\s\+HLS\>/
\ end="$"
\ keepend
\ contains=hlsPragmaName,hlsPragmaOption,hlsPragmaValue,hlsPragmaMode
" The pragma name: PIPELINE, UNROLL, ARRAY_PARTITION, INTERFACE, ...
syntax match hlsPragmaName /\<HLS\>\s\+\zs[A-Z][A-Z_]*/ contained
" Option keys: variable=, II=, type=, port=, bundle=
syntax match hlsPragmaOption /\<\w\+\ze\s*=/ contained
" Option values: complete, 2, in_words, AXILiteS
syntax match hlsPragmaValue /=\s*\zs[^ ]\+/ contained
" INTERFACE modes are positional, so they have no "mode=" in front of them:
" #pragma HLS INTERFACE s_axilite port=return bundle=ctrl
syntax match hlsPragmaMode /\<\%(ap_none\|ap_vld\|ap_ack\|ap_hs\|ap_ovld\|ap_fifo\|ap_memory\|ap_bram\|bram\|ap_ctrl_none\|ap_ctrl_hs\|ap_ctrl_chain\|m_axi\|s_axilite\|axis\|s_axis\|m_axis\|ap_stable\|ap_bus\)\>/ contained
highlight default link hlsPragma PreProc
highlight default link hlsPragmaName Statement
highlight default link hlsPragmaOption Identifier
highlight default link hlsPragmaValue Constant
highlight default link hlsPragmaMode Constant

View File

@@ -0,0 +1,92 @@
-- ===========================================================================
-- HLS pragma diagnostics for Neovim (EMBS)
-- ---------------------------------------------------------------------------
-- Runs hls_pragma_lint.py over C/C++ buffers and reports the results through
-- vim.diagnostic, so they show up exactly like clangd's errors.
--
-- No plugin manager involved: this file lives in the hlsdev nvim runtimepath
-- entry, and Neovim sources plugin/*.lua automatically.
--
-- Commands:
-- :HlsPragmaLint re-run on the current buffer
-- :lua vim.diagnostic.reset(...) (see :h vim.diagnostic)
-- ===========================================================================
if vim.g.loaded_hls_pragma_lint then
return
end
vim.g.loaded_hls_pragma_lint = true
local ns = vim.api.nvim_create_namespace('hls_pragma_lint')
-- Locate hls_pragma_lint.py next to this runtimepath entry.
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h')
local linter = vim.fn.fnamemodify(plugin_dir, ':h:h') .. '/hls_pragma_lint.py'
local function python()
if vim.fn.executable('python3') == 1 then
return 'python3'
end
return nil
end
local SEVERITY = {
error = vim.diagnostic.severity.ERROR,
warning = vim.diagnostic.severity.WARN,
info = vim.diagnostic.severity.INFO,
}
local function parse(output, bufnr)
local diags = {}
for line in vim.gsplit(output, '\n', { plain = true }) do
local _, l, c, sev, msg = line:match('^(.-):(%d+):(%d+): (%a+): (.*)$')
if l then
table.insert(diags, {
bufnr = bufnr,
lnum = tonumber(l) - 1,
col = tonumber(c) - 1,
severity = SEVERITY[sev] or vim.diagnostic.severity.INFO,
message = msg,
source = 'hls-pragma',
})
end
end
return diags
end
local function lint(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
local ft = vim.bo[bufnr].filetype
if ft ~= 'c' and ft ~= 'cpp' then
return
end
if vim.fn.filereadable(linter) ~= 1 then
return
end
local py = python()
if not py then
return
end
local path = vim.api.nvim_buf_get_name(bufnr)
if path == '' then
return
end
local out = vim.fn.system({ py, linter, path })
vim.diagnostic.set(ns, bufnr, parse(out, bufnr))
end
vim.api.nvim_create_autocmd({ 'BufWritePost', 'BufReadPost' }, {
group = vim.api.nvim_create_augroup('HlsPragmaLint', { clear = true }),
pattern = { '*.c', '*.cpp', '*.cc', '*.h', '*.hpp' },
callback = function(ev)
lint(ev.buf)
end,
})
vim.api.nvim_create_user_command('HlsPragmaLint', function()
lint(0)
end, { desc = 'Check #pragma HLS lines in this buffer' })