From: Luke Kenneth Casson Leighton Date: Mon, 20 Dec 2021 15:47:50 +0000 (+0000) Subject: create header/footer for crtl code-generation X-Git-Tag: sv_maxu_works-initial~616 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4d98a95ada958a9f683bc2c013f7c8037762eb17;p=openpower-isa.git create header/footer for crtl code-generation code += code += ... is a bit naff --- diff --git a/src/openpower/decoder/test/_pyrtl.py b/src/openpower/decoder/test/_pyrtl.py index 4ce02f1b..a384c3ac 100644 --- a/src/openpower/decoder/test/_pyrtl.py +++ b/src/openpower/decoder/test/_pyrtl.py @@ -412,6 +412,29 @@ class _StatementCompiler(StatementVisitor, _Compiler): emitter.append(f"slots[{signal_index}].set(next_{signal_index})") return emitter.flush() +# TODO: for use in the linux kernel stdint.h will not be available. ok for now +code_hdr = """\ +#include +typedef struct slot_t +{ + uint64_t curr; + uint64_t next; +} slot_t; +slot_t slots[%d] = +{ +""" + +code_ftr = """\ +}; + +static void set(slot_t *slot, uint64_t value) +{ + if (slot->next == value) + return; + slot->next = value; +} +""" + class _FragmentCompiler: def __init__(self, state): @@ -456,29 +479,11 @@ class _FragmentCompiler: signal_index = self.state.get_signal(signal) emitter.append(f"set(&slots[{signal_index}], next_{signal_index});") - code = "" - code += "#include \n" - code += "typedef struct slot_t\n" - code += "{\n" - code += " uint64_t curr;\n" - code += " uint64_t next;\n" - code += "} slot_t;\n" - - code += f"slot_t slots[{len(self.state.slots)}] =\n" - code += "{\n" - + # create code header, slots, footer, followed by emit actual code + code = code_hdr % len(self.state.slots) for slot in self.state.slots: - code += " {" + str(slot.curr) + ", " + str(slot.next) + "},\n" - - code += "};\n" - - code += "void set(slot_t *slot, uint64_t value)\n" - code += "{\n" - code += " if (slot->next == value)\n" - code += " return;\n" - code += " slot->next = value;\n" - code += "}\n" - + code += " {%s, %s},\n" % (str(slot.curr), str(slot.next)) + code += code_ftr code += emitter.flush() try: