Skip to content

Commit af8c80c

Browse files
authored
Merge branch 'main' into misa-readonly-zero
2 parents 2f82166 + 292b34f commit af8c80c

File tree

150 files changed

+799
-96743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+799
-96743
lines changed

.github/workflows/deploy.yml

Lines changed: 603 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/merge.yml

Lines changed: 0 additions & 249 deletions
This file was deleted.

.github/workflows/regress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,6 @@ jobs:
224224
- name: Run cpp unit tests
225225
run: ./do gen:ext_pdf EXT=Xqci CFG=qc_iu.yaml VERSION=latest
226226
call-deploy:
227-
uses: ./.github/workflows/merge.yml
227+
uses: ./.github/workflows/deploy.yml
228228
with:
229229
dry-run: true

backends/generators/c_header/generate_encoding.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import argparse
1010
import yaml
11+
import json
1112

1213
# Add parent directory to path to import generator.py
1314
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -29,15 +30,55 @@ def calculate_mask(match_str):
2930
return int("".join("0" if c == "-" else "1" for c in match_str), 2)
3031

3132

32-
def load_exception_codes(ext_dir, enabled_extensions=None, include_all=False):
33-
"""Load exception codes from extension YAML files."""
33+
def load_exception_codes(
34+
ext_dir, enabled_extensions=None, include_all=False, resolved_codes_file=None
35+
):
36+
"""Load exception codes from extension YAML files or pre-resolved JSON file."""
3437
exception_codes = []
3538
found_extensions = 0
3639
found_files = 0
3740

3841
if enabled_extensions is None:
3942
enabled_extensions = []
4043

44+
# If we have a resolved codes file, use it instead of processing YAML files
45+
if resolved_codes_file and os.path.exists(resolved_codes_file):
46+
try:
47+
with open(resolved_codes_file, encoding="utf-8") as f:
48+
resolved_codes = json.load(f)
49+
50+
for code in resolved_codes:
51+
num = code.get("num")
52+
name = code.get("name")
53+
if num is not None and name is not None:
54+
sanitized_name = (
55+
name.lower()
56+
.replace(" ", "_")
57+
.replace("/", "_")
58+
.replace("-", "_")
59+
)
60+
exception_codes.append((num, sanitized_name))
61+
62+
logging.info(
63+
f"Loaded {len(exception_codes)} pre-resolved exception codes from {resolved_codes_file}"
64+
)
65+
66+
# Sort by exception code number and deduplicate
67+
seen_nums = set()
68+
unique_codes = []
69+
for num, name in sorted(exception_codes, key=lambda x: x[0]):
70+
if num not in seen_nums:
71+
seen_nums.add(num)
72+
unique_codes.append((num, name))
73+
74+
return unique_codes
75+
76+
except Exception as e:
77+
logging.error(
78+
f"Error loading resolved codes file {resolved_codes_file}: {e}"
79+
)
80+
# Fall back to processing YAML files
81+
4182
for dirpath, _, filenames in os.walk(ext_dir):
4283
for fname in filenames:
4384
if not fname.endswith(".yaml"):
@@ -298,6 +339,10 @@ def main():
298339
action="store_true",
299340
help="Fallback to hardcoded exception causes if none are loaded from files",
300341
)
342+
parser.add_argument(
343+
"--resolved-codes",
344+
help="JSON file containing pre-resolved exception codes",
345+
)
301346

302347
args = parser.parse_args()
303348

@@ -321,7 +366,10 @@ def main():
321366
# Load exception codes
322367
logging.info(f"Loading exception codes from {args.ext_dir}")
323368
causes = load_exception_codes(
324-
args.ext_dir, args.extensions, include_all=args.include_all
369+
args.ext_dir,
370+
args.extensions,
371+
include_all=args.include_all,
372+
resolved_codes_file=args.resolved_codes,
325373
)
326374

327375
# Process instructions and calculate masks

backends/generators/tasks.rake

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
require "udb/resolver"
4+
require 'json'
5+
require 'tempfile'
46

57
directory "#{$root}/gen/go"
68
directory "#{$root}/gen/c_header"
@@ -53,8 +55,36 @@ namespace :gen do
5355
csr_dir = cfg_arch.path / "csr"
5456
ext_dir = cfg_arch.path / "ext"
5557

56-
# Run the C header generator script using the same Python environment
57-
# The script generates encoding.h for inclusion in C programs
58-
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --output=#{output_dir}encoding.out.h --include-all"
58+
# Process ERB templates in exception codes using Ruby ERB processing
59+
resolved_exception_codes = []
60+
61+
# Collect all exception codes from extensions and resolve ERB templates
62+
cfg_arch.extensions.each do |ext|
63+
ext.exception_codes.each do |ecode|
64+
# Use Ruby's ERB processing to resolve templates in exception names
65+
resolved_name = cfg_arch.render_erb(ecode.name, "exception code name: #{ecode.name}")
66+
67+
resolved_exception_codes << {
68+
'num' => ecode.num,
69+
'name' => resolved_name,
70+
'var' => ecode.var,
71+
'ext' => ext.name
72+
}
73+
end
74+
end
75+
76+
# Write resolved exception codes to a temporary JSON file
77+
resolved_codes_file = Tempfile.new(['resolved_exception_codes', '.json'])
78+
resolved_codes_file.write(JSON.pretty_generate(resolved_exception_codes))
79+
resolved_codes_file.flush
80+
81+
begin
82+
# Run the C header generator script using the same Python environment
83+
# The script generates encoding.h for inclusion in C programs
84+
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --resolved-codes=#{resolved_codes_file.path} --output=#{output_dir}encoding.out.h --include-all"
85+
ensure
86+
resolved_codes_file.close
87+
resolved_codes_file.unlink
88+
end
5989
end
6090
end

0 commit comments

Comments
 (0)