Author: leo
Date: Tue Oct 11 10:21:54 2005
New Revision: 9459
Modified:
trunk/classes/sub.pmc
trunk/src/call_list.txt
trunk/t/pmc/sub.t
Log:
Variable-sized reg frames 3b - tests for reg counts
* add __get_regs_used method for testing mainly
* add method signature to src/call_list.txt
* tests
Modified: trunk/classes/sub.pmc
==============================================================================
--- trunk/classes/sub.pmc (original)
+++ trunk/classes/sub.pmc Tue Oct 11 10:21:54 2005
@@ -575,6 +575,10 @@ Called after the subroutine as been unar
Return the name_space PMC or Undef. The name_space PMC is either a
String PMC or a Key PMC for a nested name_space.
+=item C<METHOD INTVAL __get_regs_used(char *kind)>
+
+Return amount of used registers for register kinds "I", "S", "P", "N".
+
=cut
*/
@@ -586,6 +590,26 @@ String PMC or a Key PMC for a nested nam
pmc_new(INTERP, enum_class_Undef) : sub->name_space;
}
+ METHOD INTVAL __get_regs_used(char *kind) {
+ struct Parrot_sub * sub = PMC_sub(SELF);
+ /* TODO switch to canonical NiSP order
+ * see also imcc/reg_alloc.c
+ */
+ const char *types = "INSP";
+ char *p;
+
+ assert(sub->n_regs_used);
+ if (!*kind || kind[1])
+ real_exception(INTERP, NULL, E_ValueError,
+ "illegal register kind '%s'", kind);
+ p = strchr(types, *kind);
+ if (!p)
+ real_exception(INTERP, NULL, E_ValueError,
+ "illegal register kind '%s'", kind);
+ return sub->n_regs_used[p - types];
+ }
+
+
}
/*
Modified: trunk/src/call_list.txt
==============================================================================
--- trunk/src/call_list.txt (original)
+++ trunk/src/call_list.txt Tue Oct 11 10:21:54 2005
@@ -319,3 +319,6 @@ v JS
# crypt
t tt
+
+# Sub.__get_regs_used
+I JOt
Modified: trunk/t/pmc/sub.t
==============================================================================
--- trunk/t/pmc/sub.t (original)
+++ trunk/t/pmc/sub.t Tue Oct 11 10:21:54 2005
@@ -17,7 +17,7 @@ C<Continuation> PMCs.
=cut
-use Parrot::Test tests => 44;
+use Parrot::Test tests => 46;
use Test::More;
use Parrot::Config;
@@ -1184,3 +1184,52 @@ pir_output_is(<<'CODE', <<'OUTPUT', "imm
CODE
ok 1
OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "__get_regs_used 1");
+.sub main :main
+ .local pmc m
+ .include "interpinfo.pasm"
+ m = interpinfo .INTERPINFO_CURRENT_SUB
+ $I0 = m."__get_regs_used"('N')
+ print $I0
+ $I0 = m."__get_regs_used"('I')
+ print $I0
+ $I0 = m."__get_regs_used"('S')
+ print $I0
+ $I0 = m."__get_regs_used"('P')
+ print $I0
+ print "\n"
+.end
+
+CODE
+0101
+OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "__get_regs_used 2");
+.sub main :main
+ foo()
+.end
+.sub foo
+ .local pmc m
+ .include "interpinfo.pasm"
+ m = interpinfo .INTERPINFO_CURRENT_SUB
+ set N0, 1.0
+ set N7, 1.0
+ add N7, N7, N0
+ set I9, 1
+ add I10, I9, I9
+ $I0 = m."__get_regs_used"('N')
+ print $I0
+ $I0 = m."__get_regs_used"('I')
+ print $I0
+ $I0 = m."__get_regs_used"('S')
+ print $I0
+ $I0 = m."__get_regs_used"('P')
+ print $I0
+ print "\n"
+.end
+
+
+CODE
+81101
+OUTPUT