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

[NFC] Make Generator class becomes ABC #336

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
45 changes: 24 additions & 21 deletions rvv-intrinsic-generator/rvv_intrinsic_gen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

Generator classes that controls structures of the output.
"""
from abc import ABC, abstractmethod
import os
import collections
import re
Expand All @@ -25,7 +26,7 @@
from enums import ToolChainType


class Generator():
class Generator(ABC):
"""
Base class for all generators.
"""
Expand All @@ -36,29 +37,23 @@ def __init__(self):
pass

def write(self, text):
pass
return NotImplemented

def write_title(self, text, link):
pass
return NotImplemented

def gen_prologue(self):
pass
return NotImplemented

def inst_group_prologue(self):
return ""
return NotImplemented

def inst_group_epilogue(self):
return ""
return NotImplemented

@abstractmethod
def func(self, inst_info, name, return_type, **kwargs):
# pylint: disable=unused-argument
# FIXME: inst_info is currently only used by RIFGenerator.
self.generated_functions_set.add(name)
args = ", ".join(map(lambda a: f"{a[1]} {a[0]}", kwargs.items()))
# "T * name" to "T *name"
args = args.replace("* ", "*")
s = f"{return_type} {name} ({args});\n"
return s
return NotImplemented

def function_group(self, template, title, link, op_list, type_list, sew_list,
lmul_list, decorator_list):
Expand All @@ -74,7 +69,7 @@ def function_group(self, template, title, link, op_list, type_list, sew_list,
decorator_list=decorator_list)

def start_group(self, group_name):
pass
return NotImplemented

@staticmethod
def func_name(name):
Expand Down Expand Up @@ -296,7 +291,7 @@ def report_summary(self):
\x1b[0mfunctions")

def post_gen(self):
pass
return NotImplemented


class DocGenerator(Generator):
Expand Down Expand Up @@ -358,7 +353,13 @@ def function_group(self, template, title, link, op_list, type_list, sew_list,

def func(self, inst_info, name, return_type, **kwargs):
name = Generator.func_name(name)
s = super().func(inst_info, name, return_type, **kwargs)
# pylint: disable=unused-argument
# FIXME: inst_info is currently only used by RIFGenerator.
self.generated_functions_set.add(name)
args = ", ".join(map(lambda a: f"{a[1]} {a[0]}", kwargs.items()))
# "T * name" to "T *name"
args = args.replace("* ", "*")
s = f"{return_type} {name} ({args});\n"
self.write(s)

def start_group(self, group_name):
Expand Down Expand Up @@ -517,10 +518,12 @@ def func(self, inst_info, name, return_type, **kwargs):
os.path.join(self.folder, test_file_name), mode, encoding="utf-8")

stripped_prefix_non_overloaded_func_name = non_overloaded_func_name[8:]
func_decl = super().func(inst_info,
"test_" + stripped_prefix_non_overloaded_func_name,
return_type, **kwargs)
func_decl = func_decl.replace(" (", "(")
non_overloaded_func_name = "test_" + stripped_prefix_non_overloaded_func_name
self.generated_functions_set.add(non_overloaded_func_name)
args = ", ".join(map(lambda a: f"{a[1]} {a[0]}", kwargs.items()))
# "T * name" to "T *name"
args = args.replace("* ", "*")
func_decl = f"{return_type} {non_overloaded_func_name}({args});\n"

# Strip redundant parameters in function declaration because the intrinsic
# requires an immediate to be provided to the parameter.
Expand Down
Loading