diff --git a/unoptimized_lr/simple_lr_table.py b/unoptimized_lr/simple_lr_table.py new file mode 100644 index 0000000000000000000000000000000000000000..a14a227469da91144532c3229a62f9a56b672c6d --- /dev/null +++ b/unoptimized_lr/simple_lr_table.py @@ -0,0 +1,82 @@ +from nmigen import * +from nmigen.cli import main + + +from functools import reduce + + +# We know this is not really likely to synthesize well, but we implement here so +# we can get a gold-standard/reference implementation, against which we can test +# our further optimizations, including compression and non-standard representations. + + + +class LRTable(Elaboratable): + def __init__(self, number_of_states, number_of_terminals, number_of_reduce_rules): + # Parameters + + # So the LR table is a two-dimensional array, where one of the dimensions (rows) + # is indexed by state number, and the other dimension (columns) is indexed by + # terminal. + + # Each element of the array can be one of four values: + # 1) Shift terminal + # 2) Accept parse + # 3) Error + # 4) Reduce with rule number k + + # This means that the length of each element has to be: + # TIW = (2 bits + number of bits to index the reduce rules) + + # Because this is not initially meant for synthesis efficiency, we + # initially just choose the width of the memory to be: + + # width = number_of_terminals * TIW + + # and the depth to be: + # depth = number_of_states + + # We calculate these now: + + reduce_rule_signal = Signal(range(number_of_reduce_rules)) + reduce_rule_bits = len(reduce_rule_signal) + + table_entry_width = (reduce_rule_bits + 2) + + table_width = number_of_terminals * table_entry_width + + table_depth = number_of_states + + + + + self.mem = Memory(width=table_width, depth=table_depth) + + + def elaborate(self, platform): + m = Module() + + + + return m + + +class DummyPlug(Elaboratable): + + #def __init__(self): + + + + def elaborate(self, platform): + m = Module() + + m.submodules.table = LRTable(7,20,33) + + return m + + + +if __name__ == '__main__': + baka =DummyPlug() + main(baka) + #platform.build(DummyPlug())