Difference: CS255Spring08Discussions (56 vs. 57)

Revision 572008-03-13 - ChenDing

Line: 1 to 1
 
META TOPICPARENT name="CS255Spring08"

CS255/455 Spring 2008 Questions and Answers

Line: 6 to 6
 
Q: How can we identify definitions and uses of global variables like "int array[32]" in fibonacci.c?
Changed:
<
<
A:
>
>
A: Depending on the purpose, usually a compiler traverses the code, examines each node, and stores information as needed. Can you iterate the nodes and record all the pointers to the defs and uses of a variable of your interest? Then you can traverse your special data structure for these defs and uses. Please elaborate if this does not answer the question.
 
Q: Is there a standard way to handle function calls like printf, scanf or in general var-arg functions ? TREE_CHAIN can lead to variable declarations instead of a chain of arguments, and unless explicit care of those functions is taken (through string matching == printf/scanf), I think we have to resolve to SSA graph to find relevant information (name of operands of functions, especially var-arg functions). What do we do : handle them explicitly, or is there a way to do it I cannot track down (except for SSA)?
Line: 161 to 164
 Another problem that the original example shows is what to do when we use complex expressions as arguments to scanf/printf. We can certainly do something more elaborate to make the compiler not only weird but also insistently weird but we don't have to. You don't need to go beyond the requirement. When demonstrating your compiler, do not use complex expressions and instead perhaps explain that yours is a weird compiler, not a weird and wicked compiler. (ChenDing)


Added:
>
>
 Q: How to dump c-like code for a gimple node?

A: Suppose node is the node, use debug_tree(node); to do the dump. I think another useful dump function is dump_node(node, TDF_SLIM, stderr), which prints detailed information about a node.

Added:
>
>
If you want to print out the string representation of the node type, you can use the following trick due to TongxinBai. As an example cute code trick in Gcc, while the tree types are defined in enum tree_code in tree.h, the actual definition is not in tree.h but in tree.def, which includes a list of all node types and their (string) symbols. Looking at the code you'll quickly see how the trick works, and borrowing it you can easily construct an array of type strings (in your program file) as follows:

#define DEFTREECODE(SYM, STRING, TYPE, NARGS)   STRING,
char *type_names[] = {
#include "tree.def"
};

During debugging, you can use the node type as the index into the type_names array and pull up the string name that you so often crave for under the circumstance.

 

Q: How to get the number of parameters of a function call?

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback