From: Gergely K. <ger...@ma...> - 2009-12-16 15:19:23
|
Hi, Actually XMLVM already makes a distinction in the code between the different types, because you generate the following code: _st[_sp++].i - for integers _st[_sp++].d - for double ... etc. The only problem is that in C, you cannot inspect at runtime what is stored in a union. One idea would be to make a small change in XMLVMElem to also allow the storage of the type that was stored in it, and change the generated code to something like this: _st[_sp++].type = 'i'; _st[_sp].i = ...; Then the pop2 implementation (and other opcodes that work similarly) can examine the contents of the stack, and act accordingly. Do you have more information regarding the register machine conversion that you are doing? Do you have a timeframe? Will it change the interface between the hand-written objc code and the generated code? Do you use the DEX model which I mentioned earlier, or are you inventing something else? Best Regards, Gergely 2009/12/16 Arno Puder <ar...@pu...> > > Sometimes the compiler will generate a pop2 byte code instruction. The > documentation says that it will remove either one long or double > element, or two integers (the spec refers to these as computational > types 1 and 2). In XMLVM, we have a union called XMLVMElem that > represents the union of all data types that can be pushed onto the > stack. The sizeof(XMLVMElem) therefore corresponds to a computational > type 2. This makes it difficult to implement pop2 since we need to know > if the top of the stack is of computational type 1 or 2. We don't do a > data flow analysis and therefore we don't know. As a consequence, we > cannot implement pop2. > > Here are two situations where the compiler can generate the pop2 > instruction: > > // Example 1 > long foo() { return 42; } > > void bar() { foo(); } > > Since bar() does not make use of the long return value, the compiler > will generate the pop2 instruction to clean up the stack. > > // Example 2 > int foo() { return 42; } > > void bar() { foo(); foo(); } > > Here a good-optimizing compiler will do one pop2 instruction after the > second call to foo(). > > We are currently working on a conversion from stack- to register-based > instructions which will also take care of this problem. What can you do > in the meantime to avoid the pop2-problem? Luckily the answer is simple: > assign the return value to a local variable: > > void bar() { long ret = foo(); } > > For good optimizing compilers it might notice the unused local variable > and might still generate the pop2 instruction. In this case make 'ret' > an instance variable. > > Arno > > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and > easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > -- Kis Gergely MattaKis Consulting Email: ger...@ma... Web: http://www.mattakis.com Phone: +36 70 408 1723 |