icode: add a way to output icodes without line numbers and/or locations
authorJean-Sebastien Gelinas <calestar@gmail.com>
Fri, 4 Dec 2009 01:39:20 +0000 (20:39 -0500)
committerJean Privat <jean@pryen.org>
Mon, 11 Jan 2010 21:52:34 +0000 (16:52 -0500)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/analysis/icode_dump.nit
src/nitc.nit

index 26f5c0c..7c60d59 100644 (file)
@@ -65,9 +65,16 @@ redef class IClosureDecl
 end
 
 class ICodeDumper
+       readable var _dump_locations: Bool
+       readable var _dump_line_numbers: Bool
        var _ids: HashMap[Object, String] = new HashMap[Object, String]
        var _last_value: Int = 0
 
+       init(dump_locations: Bool, dump_line_numbers: Bool) do
+               _dump_locations = dump_locations
+               _dump_line_numbers = dump_line_numbers
+       end
+
        # Return the name of e
        # If e is unknown, a new name is gived
        fun register(e: IRegister): String
@@ -168,7 +175,7 @@ class ICodeDumper
                print s
        end
 
-       var _indent_level: Int = 0
+       readable var _indent_level: Int = 0
 
        # Indent the next writes
        fun indent do _indent_level += 1
@@ -182,15 +189,19 @@ redef class ICode
        fun dump(icd: ICodeDumper)
        do
                var result = result
-               var s = ""
-               var l = location
-               if l != null then
-                       s = "        ... {l}"
+               var s_loc = ""
+               var s_line = ""
+               var loc = location
+               if loc != null and icd.dump_locations then
+                       s_loc = "        ... {loc}"
+               end
+               if icd.dump_line_numbers then
+                       s_line = "{icd.line(self)}: "
                end
                if result == null then
-                       icd.write "{icd.line(self)}: {dump_intern(icd)}{s}"
+                       icd.write "{s_line}{dump_intern(icd)}{s_loc}"
                else
-                       icd.write "{icd.line(self)}: {icd.register(result)} := {dump_intern(icd)}{s}"
+                       icd.write "{s_line}{icd.register(result)} := {dump_intern(icd)}{s_loc}"
                end
        end
 
index 232c404..6f2bd3e 100644 (file)
@@ -121,11 +121,11 @@ special AbstractCompiler
                                        end
                                        if routine == null then continue
                                        print "**** Property {p.full_name} ****"
-                                       var icd = new ICodeDumper
+                                       var icd = new ICodeDumper(true, true)
                                        routine.dump(icd)
                                        print "**** OPTIMIZE {p.full_name} ****"
                                        routine.optimize(mod)
-                                       icd = new ICodeDumper
+                                       icd = new ICodeDumper(true, true)
                                        routine.dump(icd)
                                end
                        end