diff options
| author | azidar | 2015-06-02 10:41:27 -0700 |
|---|---|---|
| committer | azidar | 2015-06-02 10:41:27 -0700 |
| commit | f8f9de58dbba5e53193246a5fd2145dfe6537e10 (patch) | |
| tree | dedcbc9b1dc7709d6efbc2dce3c5f36303f2a990 /src/main/stanza/ir-utils.stanza | |
| parent | 8fc826a2770f46d63d8d7b1bccf14d2bf6e6b7cd (diff) | |
Added sequential/combinational memories. Started debugging verilog backend. Added Long support so UInt(LARGENUMBER) works
Diffstat (limited to 'src/main/stanza/ir-utils.stanza')
| -rw-r--r-- | src/main/stanza/ir-utils.stanza | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza index c39a1ad1..1d209622 100644 --- a/src/main/stanza/ir-utils.stanza +++ b/src/main/stanza/ir-utils.stanza @@ -69,7 +69,26 @@ public defmulti name (p:Pass) -> String public defmulti short-name (p:Pass) -> String public defmethod print (o:OutputStream, p:Pass) : print(o,name(p)) + +;============== Various Useful Functions ============== + +public defn ceil-log2 (i:Long) -> Long : + defn* loop (n:Long, l:Long) : + if n < i : + if l == 30 : to-long(31) + else : loop(n * to-long(2), l + to-long(1)) + else : l + error("Log of negative number!") when i < to-long(0) + loop(to-long $ 1, to-long $ 0) + +public defn abs (x:Long) -> Long : + if x < to-long(0) : to-long(0) - x + else : x + +;public defn to-int (x:Long) -> Int : + ;if x > to-long(2147483647) or x < to-long(–2147483648) : error("Long too big to convert to Int") + ;else : x + 0 ;============== PRINTERS =================================== |
