SystemRDL / PeakRDL-cheader

GNU General Public License v3.0
9 stars 11 forks source link

C header generate file doesn't have suffix #9

Closed zhajio1988 closed 7 months ago

zhajio1988 commented 7 months ago

@amykyta3 I use new C header generator, i find C header generate file doesn't have suffix,i modify below code, text in bold. Could you help make sure it? ` class HeaderGenerator(RDLListener): def init(self, ds: DesignState) -> None: self.ds = ds

    self.defined_namespace: Set[str]
    self.defined_namespace = set()
    self.indent_level = 0

    self.root_node: AddrmapNode
    self.root_node = None

    self.f: TextIO
    self.f = None # type: ignore

def run(self, path: str, top_nodes: List[AddrmapNode]) -> None:
    **header_path = path + ".h"**
    with open(header_path, "w", encoding='utf-8') as f:

`

amykyta3 commented 7 months ago

The expectation is that the path provided by the user to the header generator will already include the file extension since that is the fully defined file path. It would be inappropriate for the tool to implicitly append an additional suffix. None of the other PeakRDL tools do this, so I would not want to create an inconsistency here.

See the example here: https://peakrdl-cheader.readthedocs.io/en/latest/api.html The output path is provided with the extension:

exporter.export(node=top, path='out.h')
zhajio1988 commented 7 months ago

The expectation is that the path provided by the user to the header generator will already include the file extension since that is the fully defined file path. It would be inappropriate for the tool to implicitly append an additional suffix. None of the other PeakRDL tools do this, so I would not want to create an inconsistency here.

See the example here: https://peakrdl-cheader.readthedocs.io/en/latest/api.html The output path is provided with the extension:

exporter.export(node=top, path='out.h')

Hi Thanks for you replay. If path='out.h', the generated test file name is out.h.test.c? Is it correct?

amykyta3 commented 7 months ago

No not at all. if path="out.h" then the resulting file will be out.h.

PeakRDL-cheader will never mangle or change the file path a user provides it.

zhajio1988 commented 7 months ago

@amykyta3 I find blow code snippets, testcase_path = header_path + ".test.c" TestcaseGenerator is called in exporter.py, TestcaseGenerator(ds).run(path, top_nodes) The path argument is from CHeaderExporter path formal argument.

class TestcaseGenerator:
    def __init__(self, ds: DesignState) -> None:
        self.ds = ds

    def run(self, header_path: str, top_nodes: List[AddrmapNode]) -> None:
        testcase_path = header_path + ".test.c"
        with open(testcase_path, "w", encoding='utf-8') as f:
amykyta3 commented 7 months ago

Yes that is because the testcase directly correlates with the user-generated header, and is an optional output. For primary outputs, it would be surprising behavior to append ".c" unconditionally.

See other command line tools like gcc ... -o output_file

zhajio1988 commented 7 months ago

Ok, got it. I think we can close this ticket.