Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/lintAndFormat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ jobs:
with:
python-version: '3.10'

- name: Check Liquid Syntax
run: python3 utils/check_liquid_syntax.py

- name: Install black
run: |
pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion include/aie/Dialect/AIE/IR/AIEOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ def AIE_ObjectFifoAllocateOp: AIE_Op<"objectfifo.allocate", [HasParent<"DeviceOp

In the following example the objects of @of4 will be allocated on %tile14:
```
aie.objectfifo @of4 (%tile13, {%tile14}, 2 : i32) : !aie.objectfifo<memref<256xi32>>
aie.objectfifo @of4 (%tile13, { %tile14 }, 2 : i32) : !aie.objectfifo<memref<256xi32>>
aie.objectfifo.allocate @of4 (%tile14)
```
}];
Expand Down
80 changes: 80 additions & 0 deletions utils/check_liquid_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
import os
import re
import sys


def check_file(filepath):
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()

# Remove {% raw %}...{% endraw %} blocks
content_no_raw = re.sub(
r"\{%\s*raw\s*%\}.*?\{%\s*endraw\s*%\}", "", content, flags=re.DOTALL
)

# Check for remaining {%
# In .td files, we assume ANY {% that is not in a raw block is suspicious
# because .td files are for MLIR definitions, not Liquid templates.
# If it's MLIR syntax, it MUST be escaped (e.g. inside raw block) to pass Jekyll.

match = re.search(r"\{%", content_no_raw)
if match:
# Iterate through all {% occurrences in original content.
# Check if each occurrence is inside a raw block.

raw_blocks = []
for m in re.finditer(
r"\{%\s*raw\s*%\}.*?\{%\s*endraw\s*%\}", content, flags=re.DOTALL
):
raw_blocks.append(m.span())

for m in re.finditer(r"\{%", content):
start, end = m.span()

# Check if this {% is part of a raw block definition itself
if re.match(r"\{%\s*(raw|endraw)\s*%\}", content[start:]):
continue

# Check if it is inside a raw block
is_inside = False
for rb_start, rb_end in raw_blocks:
if start >= rb_start and end <= rb_end:
is_inside = True
break

if not is_inside:
# Found an unescaped {%
line_num = content.count("\n", 0, start) + 1
print(f"Error: Unescaped '{{%' found in {filepath} at line {line_num}")
print(f"Context: {content[start:start+20]}...")
return False

return True


def main():
root_dir = "include"
extensions = [".td"]
has_error = False

for root, dirs, files in os.walk(root_dir):
for file in files:
if any(file.endswith(ext) for ext in extensions):
filepath = os.path.join(root, file)
if not check_file(filepath):
has_error = True

if has_error:
print("\nFound potential Liquid syntax errors in .td files.")
print(
"Please escape '{%' using '{% raw %}{%{% endraw %}' or add a space '{ %' if it represents MLIR syntax."
)
sys.exit(1)
else:
print("No Liquid syntax errors found in .td files.")
sys.exit(0)


if __name__ == "__main__":
main()
Loading