From db4e719bddcf97dc6f1e13455c88372e3ebe8863 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 15:57:40 +0200 Subject: [PATCH 1/9] Shut up linter --- test/tests.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/tests.py b/test/tests.py index 3d719656a..a06a6d3ab 100644 --- a/test/tests.py +++ b/test/tests.py @@ -4,7 +4,6 @@ import sys, time import os, os.path import re -import functools import itertools import queue import threading @@ -12,10 +11,9 @@ import subprocess import difflib from pathlib import Path -from os.path import join, isdir, isfile, exists +from os.path import join, isdir, exists import glob import json -from fnmatch import fnmatch from simicsutils.host import host_type, is_windows, batch_suffix from simicsutils.internal import package_path, get_simics_major import testparams @@ -205,7 +203,7 @@ def __init__(self, fullname, filename, **info): # Override defaults for k,v in info.items(): setattr(self, k, v) - if self.includepath == None: + if self.includepath is None: assert self.api_version if self.api_version == "4.8": libdir = "dml-old-4.8" @@ -835,7 +833,7 @@ def test(self): self.pr("Found %r" % s) found.add(r) for s,r in rxs: - if not r in found: + if r not in found: self.pr(self.simics_stdout + ":0: Didn't find %r" % s) raise TestFail("grep miss") @@ -863,9 +861,9 @@ def test(self): # Check the validity of profiling data pstats.Stats(stats_file_name) except: - raise TestFail(f'cannot load profile data') + raise TestFail('cannot load profile data') else: - raise TestFail(f'stats file not generated') + raise TestFail('stats file not generated') class SizeStatsTestCase(CTestCase): @@ -1094,8 +1092,8 @@ def test(self): lines = open(join(testparams.sandbox_path(), "scratch", "debuggable-compile", "T_debuggable-compile.c"), "r").readlines() - if not ("static bool _DML_M_mmm(test_t *_dev, int x, int *y)\n" - in lines): + if ("static bool _DML_M_mmm(test_t *_dev, int x, int *y)\n" + not in lines): raise TestFail("didn't find expected code") prereqs = ['debuggable-compile'] @@ -1459,7 +1457,7 @@ class CompareIllegalAttrs(BaseTestCase): __slots__ = () prereqs = ['minimal'] def test(self): - # Extract list of automatic attributes from Simics + # Extract list of automatic attributes from Simics sl = {x[5:].strip() for x in subprocess.run( [join(simics_base_path(), "bin", "simics" + bat_sfx), @@ -1561,11 +1559,11 @@ def validate_file(self, path, regexp): return f'strange copyright year: {start}' return None def test(self): - mpl_lines = f'''\ + mpl_lines = '''\ © (2[0-9]*)(?:-(2[0-9]*))? Intel Corporation SPDX-License-Identifier: MPL-2.0 '''.encode('utf-8').splitlines() - bsd0_copyright_re = re.compile(f'''/[*] + bsd0_copyright_re = re.compile('''/[*] © (2[0-9]*)(?:-(2[0-9]*))? Intel Corporation SPDX-License-Identifier: 0BSD [*]/'''.encode('utf-8')) From 3e11556e24839dac37c10eb6faeea04b13bd6268 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 15:58:02 +0200 Subject: [PATCH 2/9] Remove the --illegal-attrs flag --- py/dml/dmlc.py | 11 ----------- test/tests.py | 20 ++++++++------------ 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/py/dml/dmlc.py b/py/dml/dmlc.py index f2314a41d..37d719bfc 100644 --- a/py/dml/dmlc.py +++ b/py/dml/dmlc.py @@ -440,17 +440,6 @@ def set_debuggable(option, opt, value, parser): help="""Append messages to file with tags for automatic porting to DML 1.4""") - def show_illegal_attributes(option, opt, value, parser): - for n in dml.globals.illegal_attributes: - print(n) - sys.exit(0) - - # Not documented - optpar.add_option( - '--illegal-attributes', dest = 'illegal_attributes', - action = 'callback', - callback = show_illegal_attributes, - help = optparse.SUPPRESS_HELP) optpar.add_option( '--state-change-dml12', action='store_true', help=optparse.SUPPRESS_HELP) diff --git a/test/tests.py b/test/tests.py index a06a6d3ab..cc0fe7d02 100644 --- a/test/tests.py +++ b/test/tests.py @@ -23,6 +23,13 @@ import pstats import tarfile +def project_host_path(): + return join(testparams.project_path(), + testparams.host_platform()) + +sys.path.append(join(project_host_path(), 'bin', 'dml', 'python')) +import dml.globals + class TestFail(Exception): def __init__(self, reason): Exception.__init__(self) @@ -35,10 +42,6 @@ def host_path(): return join(testparams.simics_base_path(), testparams.host_platform()) -def project_host_path(): - return join(testparams.project_path(), - testparams.host_platform()) - # Matches "/// (ANNOTATION) (details)", used for annotating error # expectations etc in test .dml files annotation_re = re.compile(b' */// +([A-Z-]+)(?: +(.*))?') @@ -1470,16 +1473,9 @@ def test(self): capture_output=True, encoding='utf-8').stdout.splitlines() if x.startswith('ATTR ')} - #self.pr("Automatic attributes: %r" % sl) # Extract list of illegal attributes from dmlc - dl = {x.strip() - for x in subprocess.run( - [join(simics_base_path(), "bin", "dmlc" + bat_sfx), - "--illegal-attributes"], - capture_output=True, - encoding='utf-8').stdout.splitlines()} - #self.pr("Illegal attributes: %r" % dl) + dl = dml.globals.illegal_attributes if dl != sl: for n in dl - sl: From 4c66266b52fa7f92b7b320abd8c656a3b2fb5639 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 15:58:02 +0200 Subject: [PATCH 3/9] Remove --illegal-attrs flag From 2011ea09cd9db64ca17b58845a2b81d6cddbb672 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 16:21:38 +0200 Subject: [PATCH 4/9] Remove --version, which was ignored --- py/dml/dmlc.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/py/dml/dmlc.py b/py/dml/dmlc.py index 37d719bfc..3497e7de1 100644 --- a/py/dml/dmlc.py +++ b/py/dml/dmlc.py @@ -403,12 +403,6 @@ def set_debuggable(option, opt, value, parser): '--info', dest = 'output_info', action = 'store_true', help = 'generate XML file describing register layout') - #
--version
- #
Print version information.
- optpar.add_option( - '--version', dest = 'handled_in_c', action = 'store_true', - help = 'print version information') - #
--simics-api=version
#
Use Simics API version version.
optpar.add_option( From 5d2f93435e3dcf4194940e8eaeb7e660194ddb5e Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 15:53:40 +0200 Subject: [PATCH 5/9] Migrate from optparse to argparse --- py/dml/dmlc.py | 210 +++++++++++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 104 deletions(-) diff --git a/py/dml/dmlc.py b/py/dml/dmlc.py index 3497e7de1..737780024 100644 --- a/py/dml/dmlc.py +++ b/py/dml/dmlc.py @@ -2,14 +2,14 @@ # SPDX-License-Identifier: MPL-2.0 import sys, os, traceback, re -import optparse +import argparse import tempfile import shutil import time from pathlib import Path from . import structure, logging, messages, ctree, ast, expr_util, toplevel -from . import codegen, serialize +from . import serialize from . import dmlparse from . import output @@ -265,9 +265,7 @@ def main(argv): # DML files must be utf8, but are generally opened without specifying # the 'encoding' arg. This works only if utf8_mode is enabled. assert sys.flags.utf8_mode - optpar = optparse.OptionParser( - """ - dmlc [flags] [output-base]""") + parser = argparse.ArgumentParser() # # Command Line Options @@ -281,102 +279,96 @@ def main(argv): #
-I path
#
Add path to the search path for imported # modules.
- optpar.add_option( - '-I', dest = 'import_path', action = 'append', - metavar = 'PATH', - default = [], - help = 'add PATH to import search path') + parser.add_argument( + '-I', dest='import_path', action='append', + metavar='PATH', + default=[], + help='add PATH to import search path') #
-D name=definition
#
Define a compile-time parameter. The definition # must be a literal expression, and can be a quoted # string, a boolean, an integer, or a floating point # constant. The parameter will appear in the top-level scope.
- optpar.add_option( - '-D', dest = 'defines', action = 'append', - metavar = 'NAME=VALUE', - default = [], - help = 'set compile time constant NAME to VALUE') + parser.add_argument( + '-D', dest='defines', action='append', + metavar='NAME=VALUE', + default=[], + help='set compile time constant NAME to VALUE') #
--dep
#
Output makefile rules describing dependencies.
- optpar.add_option( - '--dep', dest = "makedep", action = 'store', - help = 'generate makefile dependencies') + parser.add_argument( + '--dep', action='store', + help='generate makefile dependencies') #
--no-dep-phony
#
With --dep, avoid addition of a phony target for each dependency # other than the main file.
- optpar.add_option( - '--no-dep-phony', dest = "no_dep_phony", action = 'store_true', - help = 'With --dep, avoid addition of a phony target for each' + parser.add_argument( + '--no-dep-phony', action='store_true', + help='With --dep, avoid addition of a phony target for each' + ' dependency other than the main file.') #
--dep-target
#
With --dep, change the target of the rule emitted by dependency # generation. Specify multiple times to have multiple targets.
- optpar.add_option( - '--dep-target', dest = "dep_target", action = 'append', - metavar = 'TARGET', - default = [], - help = 'With --dep, change the target of the rule emitted by' + parser.add_argument( + '--dep-target', action='append', metavar='TARGET', default=[], + help='With --dep, change the target of the rule emitted by' + ' dependency generation. Specify multiple times to have multiple' + ' targets.') #
-T
#
Show tags on warning messages. The tags can be used with # the --nowarn and --warn options.
- optpar.add_option( - '-T', dest = 'include_tag', action = 'callback', - callback = lambda *args: set_include_tag(True), - help = 'show tags on warning messages') + parser.add_argument( + '-T', dest='include_tag', action='store_true', + help='show tags on warning messages') # Deprecated with SIMICS_API > 4.8 - optpar.add_option( - '-m', dest = 'full_module', action = 'store_true', - help = optparse.SUPPRESS_HELP) + parser.add_argument( + '-m', dest='full_module', action='store_true', + help=argparse.SUPPRESS) #
-g
#
Generate artifacts that allow for easier source-level debugging. # This generates a DML debug file leveraged by debug-simics, and # causes generated C code to follow the DML code more closely.
- def set_debuggable(option, opt, value, parser): - dml.globals.debuggable = True - optpar.add_option( - '-g', dest = 'debuggable', action = 'callback', - callback = set_debuggable, - help = 'generate artifacts and C code that allow for easier debugging') + parser.add_argument( + '-g', dest='debuggable', action='store_true', + help='generate artifacts and C code that allow for easier debugging') #
--warn=tag
#
Enable selected warnings. The tags can be found using # the -T option.
- optpar.add_option( - '--warn', dest = 'enabled_warnings', action = 'append', - metavar = 'TAG', - default = [], - help = 'enable warning TAG') + parser.add_argument( + '--warn', dest='enabled_warnings', action='append', + metavar='TAG', + default=[], + help='enable warning TAG') #
--nowarn=tag
#
Suppress selected warnings. The tags can be found using # the -T option.
- optpar.add_option( - '--nowarn', dest = 'disabled_warnings', action = 'append', - metavar = 'TAG', - default = [], - help = 'disable warning TAG') + parser.add_argument( + '--nowarn', dest='disabled_warnings', action='append', + metavar='TAG', + default=[], + help='disable warning TAG') #
--werror
#
Turn all warnings into errors.
- optpar.add_option('--werror', dest='werror', action='store_true', + parser.add_argument('--werror', action='store_true', help='Turn all warnings into errors') #
--strict
#
Report errors for some constructs that will be forbidden in # future versions of the DML language
- optpar.add_option('--strict-dml12', dest='strict', action='store_true', + parser.add_argument('--strict-dml12', action='store_true', help='Report errors for some constructs that will be' + ' forbidden in future versions of the DML language') - optpar.add_option('--strict-int', dest='strict_int', action='store_true', + parser.add_argument('--strict-int', action='store_true', help='Use DML 1.4 style integer arithmetic semantics' + ' when compiling DML 1.2 files. Implied by' + ' --strict-dml12.') @@ -385,28 +377,28 @@ def set_debuggable(option, opt, value, parser): #
Adds Synopsys® Coverity® analysis annotations to suppress common # false positives in generated C code created from DML 1.4 device models. #
- optpar.add_option( - '--coverity', dest = 'coverity', action = 'store_true', - help = ('Adds Synopsys® Coverity® analysis annotations to suppress ' + parser.add_argument( + '--coverity', action='store_true', + help=('Adds Synopsys® Coverity® analysis annotations to suppress ' + 'common false positives in generated C code created from ' + 'DML 1.4 device models.')) #
--noline
#
Suppress line directives for the C preprocessor so # that the C code can be debugged.
- optpar.add_option( - '--noline', dest = 'noline', action = 'store_true', - help = 'suppress line directives in generated C code') + parser.add_argument( + '--noline', action='store_true', + help='suppress line directives in generated C code') #
--info
#
Enable the output of an XML file describing register layout.
- optpar.add_option( - '--info', dest = 'output_info', action = 'store_true', - help = 'generate XML file describing register layout') + parser.add_argument( + '--info', action='store_true', + help='generate XML file describing register layout') #
--simics-api=version
#
Use Simics API version version.
- optpar.add_option( - '--simics-api', dest = 'api_version', action = 'store', + parser.add_argument( + '--simics-api', action='store', metavar='VERSION', default=default_api_version(), help=('specify Simics API version (default %s)' @@ -414,47 +406,60 @@ def set_debuggable(option, opt, value, parser): #
--max-errors=N
#
Limit the number of error messages to N.
- optpar.add_option( - '--max-errors', dest = 'max_errors', action = 'store', - metavar = 'N', - default = "0", - help = ('Limit the number of error messages to N')) + parser.add_argument( + '--max-errors', action='store', + metavar='N', + default="0", + help=('Limit the number of error messages to N')) # #
# Legacy: write deps to stdout, and assume it's redirected to .dmldep # Should be removed in 6 - optpar.add_option( - '-M', dest = "makedep_old", action = 'store_true', - help = optparse.SUPPRESS_HELP) + parser.add_argument( + '-M', dest="makedep_old", action='store_true', + help=argparse.SUPPRESS) - optpar.add_option( + parser.add_argument( '-P', dest='porting_filename', action='store', help="""Append messages to file with tags for automatic porting to DML 1.4""") - optpar.add_option( + parser.add_argument( '--state-change-dml12', action='store_true', - help=optparse.SUPPRESS_HELP) + help=argparse.SUPPRESS) # Generate multiple C files, splitting at the specified file size - optpar.add_option( - '--split-c-file', dest = 'split_c_file', - action = 'store', - default = '0', - help = optparse.SUPPRESS_HELP) + parser.add_argument( + '--split-c-file', action='store', default='0', + help=argparse.SUPPRESS) # Enable features for internal testing - optpar.add_option( + parser.add_argument( '--enable-features-for-internal-testing-dont-use-this', - dest = 'enable_testing_features', action = 'store_true', - help = optparse.SUPPRESS_HELP) - - (options, args) = optpar.parse_args(argv[1:]) + dest='enable_testing_features', action='store_true', + help=argparse.SUPPRESS) + + parser.add_argument( + 'input_filename', + help="Main DML file to compile. Must have a `device` statement" + " on top level.") + parser.add_argument( + 'output_base', nargs="?", + help="Prefix for names of generated files. '.c' is appended to the" + " name of the main C file. Defaults to input_filename with the" + " '.dml' suffix stripped.") + options = parser.parse_args(argv[1:]) global outputbase, output_c + if options.include_tag: + set_include_tag(True) + + if options.debuggable: + dml.globals.debuggable = True + defs = {} for d in options.defines: try: @@ -464,12 +469,12 @@ def set_debuggable(option, opt, value, parser): else: defs[name] = value - if options.api_version not in api_versions(): + if options.simics_api not in api_versions(): prerr("dmlc: the version '%s' is not a valid API version" % ( - options.api_version)) + options.simics_api)) sys.exit(1) - if options.full_module and options.api_version not in ['4.8']: + if options.full_module and options.simics_api not in ['4.8']: prerr("dmlc: the -m option is only valid together with --api=4.8" " or older") sys.exit(1) @@ -480,7 +485,7 @@ def set_debuggable(option, opt, value, parser): # to handle the bugs as part of migration, instead of suddenly # overwhelming them with a truly massive amount of warnings in an # intermediate release. - if options.api_version in {'4.8', '5', '6'}: + if options.simics_api in {'4.8', '5', '6'}: ignore_warning('WLOGMIXUP') for w in options.disabled_warnings: @@ -530,16 +535,14 @@ def set_debuggable(option, opt, value, parser): + "The DMLC developers WILL NOT respect their use. " + "NEVER enable this flag for any kind of production code!!!***") - dml.globals.api_version = options.api_version + dml.globals.api_version = options.simics_api - if len(args) not in [1, 2]: - optpar.error('wrong number of arguments') - inputfilename = args[0] + inputfilename = options.input_filename if options.makedep_old: - options.makedep = os.path.basename(inputfilename) + 'dep' - if options.makedep and options.porting_filename: + options.dep = os.path.basename(inputfilename) + 'dep' + if options.dep and options.porting_filename: prerr("dmlc: the -P flag cannot be used together with --dep") sys.exit(1) if options.debuggable and options.porting_filename: @@ -556,15 +559,14 @@ def set_debuggable(option, opt, value, parser): # track additional position information dmlparse.track_lexspan() - if len(args) == 2: - outputbase = args[1] - else: + outputbase = options.output_base + if outputbase is None: outputbase = os.path.basename(inputfilename) if outputbase.endswith('.dml'): outputbase = outputbase[:-4] # Profiling setup - if os.getenv('DMLC_PROFILE') and not options.makedep: + if os.getenv('DMLC_PROFILE') and not options.dep: import cProfile, pstats dmlc_profiler = cProfile.Profile() dmlc_profiler.enable() @@ -577,18 +579,18 @@ def set_debuggable(option, opt, value, parser): dml.globals.serialized_traits = serialize.SerializedTraits() (dml_version, devname, headers, footers, global_defs, top_tpl, imported) = toplevel.parse_main_file( - inputfilename, options.import_path, options.strict) + inputfilename, options.import_path, options.strict_dml12) logtime("parsing") if dml_version != (1, 2): logging.show_porting = False - dml.globals.strict_int_flag = options.strict or options.strict_int + dml.globals.strict_int_flag = options.strict_dml12 or options.strict_int if 'DMLC_DUMP_INPUT_FILES' in os.environ: dump_input_files(outputbase, dict( imported, **{inputfilename: [os.path.basename(inputfilename)]})) - if options.makedep: + if options.dep: print_cdep(outputbase, headers, footers) if logging.failure: sys.exit(2) @@ -612,12 +614,12 @@ def set_debuggable(option, opt, value, parser): if options.dep_target: targetlist = options.dep_target else: - targetlist = [options.makedep, f"{outputbase}.c"] + targetlist = [options.dep, f"{outputbase}.c"] targets = ' '.join(path.replace(" ", "\\ ") for path in targetlist) if options.makedep_old: f = sys.stdout else: - f = open(options.makedep, 'w') + f = open(options.dep, 'w') with f: f.write('%s : %s\n' % (targets, deps)) # By default generate phony targets similar to -MP GCC @@ -630,7 +632,7 @@ def set_debuggable(option, opt, value, parser): dev = process(devname, global_defs, top_tpl, defs) logtime("process") - if options.output_info: + if options.info: dml.info_backend.generate(dev, outputbase + '.xml') logtime("info") From 69b52620030cc4f336055a148c3a2f1c265e894c Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Tue, 12 Sep 2023 14:11:41 +0200 Subject: [PATCH 6/9] Rename function We want to distinguish between proxy attributes and proxy interface ports --- py/dml/c_backend.py | 4 ++-- py/dml/structure.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/py/dml/c_backend.py b/py/dml/c_backend.py index 47a081b8c..d40c0009c 100644 --- a/py/dml/c_backend.py +++ b/py/dml/c_backend.py @@ -15,7 +15,7 @@ from . import objects, logging, crep, output, ctree, serialize, structure from . import traits import dml.globals -from .structure import get_attr_name, port_class_ident, port_should_get_proxies +from .structure import get_attr_name, port_class_ident, need_port_proxy_attrs from .logging import * from .messages import * from .output import * @@ -510,7 +510,7 @@ def check_attribute(node, port, prefix): report(WNDOC(node, node.logname())) attrname = get_attr_name(prefix, node) register_attribute(node.site, port, attrname) - if port and port_should_get_proxies(port): + if port and need_port_proxy_attrs(port): register_attribute(node.site, None, "%s_%s" % (port.name, attrname)) # dimsizes, loopvars, prefix are relative to port. diff --git a/py/dml/structure.py b/py/dml/structure.py index 669690671..81364662d 100644 --- a/py/dml/structure.py +++ b/py/dml/structure.py @@ -2578,7 +2578,7 @@ def mkexpr(self, indices): self.cached = mkLit(self.site, lit, TPtr(TPtr(TNamed('conf_class_t')))) return self.cached -def port_should_get_proxies(port): +def need_port_proxy_attrs(port): assert port.objtype in {'port', 'bank', 'subdevice'} return (port.objtype in {'port', 'bank'} and port.dimensions <= 1 @@ -2602,7 +2602,7 @@ def mkexpr(self, indices): return self.cached object_parent = self.node.object_parent if (object_parent is not dml.globals.device - and port_should_get_proxies(object_parent)): + and need_port_proxy_attrs(object_parent)): is_bank = 'true' if object_parent.objtype == 'bank' else 'false' is_array = 'true' if object_parent.dimensions == 1 else 'false' indices = ((mkLit(self.site, '0', TInt(32, False)),) From 2aeb6e2c12264887675ef5f226759e0648c6bdcf Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Tue, 12 Sep 2023 14:11:41 +0200 Subject: [PATCH 7/9] Refactor: Re-use common function Note that compared to generate_attribute_common, the condition used by need_port_proxy_attr adds a precondition that the bank/port must be on top level. The change is still a pure refactoring since generate_attribute_common is only called in DML 1.2, which requires banks and ports to be on top level. --- py/dml/c_backend.py | 58 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/py/dml/c_backend.py b/py/dml/c_backend.py index d40c0009c..42416697e 100644 --- a/py/dml/c_backend.py +++ b/py/dml/c_backend.py @@ -580,32 +580,37 @@ def generate_attribute_common(initcode, node, port, dimsizes, prefix, register_attribute(node.site, port, attrname) if port: - if port.dimensions == 0 and port.objtype in {'port', 'bank'}: - register_attribute(node.site, None, "%s_%s" % (port.name, attrname)) - initcode.out( - '_register_port_attr(class, %s, offsetof(%s, %s), %s,' - % (port_class_ident(port), - crep.structtype(dml.globals.device), - crep.cref_portobj(port, ()), - 'true' if port.objtype == "bank" else 'false') - + ' "%s", "%s", %s, %s, %s, "%s", %s);\n' - % (port.name, attrname, getter, setter, - attr_flag, attr_type, doc.read())) - elif port.dimensions == 1 and port.objtype in {'port', 'bank'}: - # Generate an accessor attribute for legacy reasons - register_attribute(node.site, None, "%s_%s" % (port.name, attrname)) - member = crep.cref_portobj( - port, (mkLit(port.site, '0', TInt(32, False)),)) - (dimsize,) = port.dimsizes - initcode.out( - '_register_port_array_attr(class, %s, offsetof(%s, %s),' - % (port_class_ident(port), - crep.structtype(dml.globals.device), - member) - + ' %d, %s, "%s", "%s", %s, %s, %s, "%s",' - % (dimsize, 'true' if port.objtype == "bank" else 'false', - port.name, attrname, getter, setter, attr_flag, attr_type) - + ' %s);\n' % (doc.read(),)) + if need_port_proxy_attrs(port): + if port.dimensions == 0: + register_attribute( + node.site, None, "%s_%s" % (port.name, attrname)) + initcode.out( + '_register_port_attr(class, %s, offsetof(%s, %s), %s,' + % (port_class_ident(port), + crep.structtype(dml.globals.device), + crep.cref_portobj(port, ()), + 'true' if port.objtype == "bank" else 'false') + + ' "%s", "%s", %s, %s, %s, "%s", %s);\n' + % (port.name, attrname, getter, setter, + attr_flag, attr_type, doc.read())) + else: + assert port.dimensions == 1 + # Generate an accessor attribute for legacy reasons + register_attribute( + node.site, None, "%s_%s" % (port.name, attrname)) + member = crep.cref_portobj( + port, (mkLit(port.site, '0', TInt(32, False)),)) + (dimsize,) = port.dimsizes + initcode.out( + '_register_port_array_attr(class, %s, offsetof(%s, %s),' + % (port_class_ident(port), + crep.structtype(dml.globals.device), + member) + + ' %d, %s, "%s", "%s", %s, %s, %s, "%s",' + % (dimsize, 'true' if port.objtype == "bank" else 'false', + port.name, attrname, getter, setter, attr_flag, + attr_type) + + ' %s);\n' % (doc.read(),)) else: initcode.out( '_register_port_attr_no_aux(%s,' @@ -613,7 +618,6 @@ def generate_attribute_common(initcode, node, port, dimsizes, prefix, % (port_class_ident(port), attrname, getter, setter, attr_flag, attr_type, doc.read())) - else: initcode.out('SIM_register_typed_attribute(class, "'+attrname+'",'+ '\n '+ From d0fb2fd0f3def79729197215417d2e06be39cfe4 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Tue, 12 Sep 2023 14:29:28 +0200 Subject: [PATCH 8/9] Factor out params for API version ranges --- lib/1.4/dml-builtins.dml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/1.4/dml-builtins.dml b/lib/1.4/dml-builtins.dml index 1382dc9a6..4725dfa23 100644 --- a/lib/1.4/dml-builtins.dml +++ b/lib/1.4/dml-builtins.dml @@ -539,6 +539,9 @@ template device { param _is_simics_object = true; param simics_api_version auto; + param _api_5_or_older = simics_api_version == "5" + || simics_api_version == "4.8"; + param _api_6_or_older = simics_api_version == "6" || _api_5_or_older; // automatic parameters param obj auto; @@ -551,8 +554,7 @@ template device { param be_bitorder default _be_bitorder; param log_group = undefined; - param use_io_memory default simics_api_version == "6" - || simics_api_version == "5" || simics_api_version == "4.8"; + param use_io_memory default _api_6_or_older; // this was available in DML 1.2; defensively reserved in 1.4 param banks = undefined; // this carried semantics in DML 1.2; deprecated in 1.4 @@ -1441,8 +1443,7 @@ template port is object { param _is_simics_object = true; // limitations for ports are not recognized param limitations = undefined; - param obj = (simics_api_version == "5" || simics_api_version == "4.8") - #? dev.obj #: _port_obj(); + param obj = dev._api_5_or_older #? dev.obj #: _port_obj(); session conf_object_t *_cached_port_obj; shared method _port_obj() -> (conf_object_t *) { @@ -1774,8 +1775,7 @@ template bank is (object, shown_desc) { // compatibility: referencing 'obj' in a bank method must evaluate to // dev.obj in code that can compile on both 5 and 6 // TODO: we should probably make obj an immutable session variable - param obj = (simics_api_version == "5" || simics_api_version == "4.8") - #? dev.obj #: _bank_obj(); + param obj = dev._api_5_or_older #? dev.obj #: _bank_obj(); param partial : bool; param overlapping : bool; param _le_byte_order : bool; From cf988afc5157280be49ee2e5f2a450b3d4907ad0 Mon Sep 17 00:00:00 2001 From: Erik Carstensen Date: Wed, 13 Sep 2023 18:53:13 +0200 Subject: [PATCH 9/9] Add option for listing all warning tags --- py/dml/dmlc.py | 23 +++++++++++++++++++++++ py/dml/messages.py | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/py/dml/dmlc.py b/py/dml/dmlc.py index 737780024..cd6b29da4 100644 --- a/py/dml/dmlc.py +++ b/py/dml/dmlc.py @@ -261,6 +261,27 @@ def flush_porting_log(tmpfile, porting_filename): # (so retrying compile will succeed) os.rmdir(lockfile) +class HelpAction(argparse.Action): + def __init__(self, option_strings, dest, **kwargs): + super().__init__(option_strings, dest, nargs=0, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + self.print_help() + parser.exit() + +class WarnHelpAction(HelpAction): + def print_help(self): + print('''Tags accepted by --warn and --nowarn:''') + by_ignored = {True: [], False: []} + for tag in sorted(messages.warnings): + by_ignored[warning_is_ignored(tag)].append(tag) + print(' Enabled by default:') + for tag in by_ignored[False]: + print(f' {tag}') + print(' Disabled by default:') + for tag in by_ignored[True]: + print(f' {tag}') + def main(argv): # DML files must be utf8, but are generally opened without specifying # the 'encoding' arg. This works only if utf8_mode is enabled. @@ -357,6 +378,8 @@ def main(argv): default=[], help='disable warning TAG') + parser.add_argument('--help-warn', action=WarnHelpAction, + help='List warning tags available for --warn/--nowarn') #
--werror
#
Turn all warnings into errors.
parser.add_argument('--werror', action='store_true', diff --git a/py/dml/messages.py b/py/dml/messages.py index 331618713..22ad1c369 100644 --- a/py/dml/messages.py +++ b/py/dml/messages.py @@ -2466,3 +2466,7 @@ class PINT1(PortingMessage): types, then the value of the variable becomes 1, whereas for `int1` in DML 1.4 the value is -1.""" fmt = "Change int1 to uint1" + +warnings = {name: cls for (name, cls) in globals().items() + if isinstance(cls, type) and issubclass(cls, DMLWarning) + and cls is not DMLWarning}