From 0e7751f51ec37d322304fc769d7e26829aaaaa4d Mon Sep 17 00:00:00 2001
From: Kia <kia@special-circumstanc.es>
Date: Fri, 15 Jan 2021 17:52:10 -0700
Subject: [PATCH] wrong but keeping this for further reference

---
 unoptimized_lr/simple_lr_table.py | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/unoptimized_lr/simple_lr_table.py b/unoptimized_lr/simple_lr_table.py
index 67a537b..42fe552 100644
--- a/unoptimized_lr/simple_lr_table.py
+++ b/unoptimized_lr/simple_lr_table.py
@@ -15,7 +15,7 @@ from functools import reduce
 # 3) make it optimized
 
 class LRTable(Elaboratable):
-    def __init__(self, number_of_states, number_of_terminals, number_of_reduce_rules):
+    def __init__(self, number_of_states, number_of_terminals, number_of_reduce_rules, input_array):
         # Parameters
 
         # So the LR table is a two-dimensional array, where one of the dimensions (rows)
@@ -66,8 +66,16 @@ class LRTable(Elaboratable):
         self.table_entry_out_valid = Signal(1)
 
 
+        # Prepare the table for consumption
+        assert(len(input_array) == number_of_states)
+
+        rasterized = []
+        for row in input_array:
+            assert(len(row) == number_of_terminals)
+            rasterized.extend(row)
+
         # Memory
-        self.mem = Memory(width=self.table_width, depth=self.table_depth, init= [0x1a,0x2b,0x3c,0x4d])
+        self.mem = Memory(width=self.table_width, depth=self.table_depth, init=rasterized)
 
 
     def elaborate(self, platform):
@@ -105,7 +113,7 @@ class LRTable(Elaboratable):
 
 
 class GOTOtable(Elaboratable):
-    def __init__(self, number_of_states, number_of_nonterminals):
+    def __init__(self, number_of_states, number_of_nonterminals, input_array):
         # Parameters
 
         # So the GOTO table is a two-dimensional array, where one of the dimensions (rows)
@@ -158,8 +166,17 @@ class GOTOtable(Elaboratable):
         self.table_entry_out_valid = Signal(1)
 
 
+        # Prepare the table for consumption
+        assert(len(input_array) == number_of_states)
+
+        rasterized = []
+        for row in input_array:
+            assert(len(row) == number_of_nonterminals)
+            rasterized.extend(row)
+
         # Memory
-        self.mem = Memory(width=self.table_width, depth=self.table_depth, init= [0x4a,0x3b,0x2c,0x1d])
+
+        self.mem = Memory(width=self.table_width, depth=self.table_depth, init=rasterized)
 
 
     def elaborate(self, platform):
@@ -199,7 +216,7 @@ class DummyPlug(Elaboratable):
     def elaborate(self, platform):
         m = Module()
 
-        m.submodules.table = table = GOTOtable(4,8)
+        m.submodules.table = table = GOTOtable(3,2,[[1,2],[3,4],[5,6]])
         counter = Signal(8)
         m.d.sync += counter.eq(counter+1)
 
-- 
GitLab