diff options
author | Teddy <[email protected]> | 2014-05-18 14:59:36 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-05-18 14:59:36 +0800 |
commit | 8f734c1befb10321577ba715edb0f17deec5f9db (patch) | |
tree | 4a76c28fa2a0ceaac69c64cd4d747e2997bf75ac | |
parent | 1cf0c5b7c23987a05790c50a8c7cb8ebe5eba363 (diff) |
...
-rw-r--r-- | cibic.tex | 65 | ||||
-rw-r--r-- | mips.c | 4 | ||||
-rw-r--r-- | ssa.c | 2 |
3 files changed, 50 insertions, 21 deletions
@@ -361,6 +361,12 @@ struct A { struct A *next; }; +/* a function that returns a pointer to function */ +int (*func(int flag, int (*f)(), int (*g)()))() { + if (flag) return f; + else return g; +} + int main() { struct A a; /* the follow types are distinctly different */ @@ -369,40 +375,63 @@ int main() { int *a2[20]; /* an array of pointers */ int **a3; /* pointer to pointer */ /* pointer to a function */ - int (*f)(); + int (*f)(), (*h)(); /* function declaration, not a variable */ int (*g(int ***e[10]))(); /* complex type casting is also supported */ f = (int (*)())(0x12345678); + f = func(1, f, main); /* f */ + h = func(0, f, main); /* main */ + /* 0 1 */ + printf("%d %d\n", f == main, h == main); } \end{minted} \caption {Source Code Being Proceeded} \end{listing} -\begin{listing} +\begin{listing}[H] \centering \begin{BVerbatim} +[func:{name:func}{size:-1} + {params: + [var@735fd60:flag :: [int]], + [var@735ff00:f :: [ptr]-> + [func:{name:}{size:-1} + {params:} + {local:}]->[int]], + [var@7360080:g :: [ptr]-> + [func:{name:}{size:-1} + {params:} + {local:}]->[int]]} + {local:}]->[ptr]-> + [func:{name:}{size:-1} + {params:} + {local:}]->[int] + [func:{name:main}{size:-1} {params:} {local: - [var@83de610:f :: [ptr]-> + [var@7360d70:h :: [ptr]-> [func:{name:}{size:-1} {params:} {local:}]->[int]], - - [var@83de410:a3 :: [ptr]->[ptr]->[int]], - [var@83de230:a2 :: [arr:{len:20}{size:80}]->[ptr]->[int]], - [var@83de050:a1 :: [ptr]->[arr:{len:20}{size:-1}]->[int]], - [var@83dde70:a0 :: [arr:{len:10}{size:800}]->[arr:{len:20}{size:80}]->[int]], - [var@83ddb60:a :: - [struct@83dd950:{name:A}{size:20}{fields: - [var@83dd8c0:b :: - [struct@83db640:{name:B}{size:8}{fields: - [var@83dd6e0:i :: [int]], - [var@83dd7c0:j :: [int]]}]], - [var@83db4d0:x :: [int]], - [var@83db5b0:y :: [int]], - [var@83dda60:next :: [ptr]->[struct@83dd950:{name:A}] -]}]]}]->[int] + [var@7360c00:f :: [ptr]-> + [func:{name:}{size:-1} + {params:} + {local:}]->[int]], + [var@7360a00:a3 :: [ptr]->[ptr]->[int]], + [var@7360820:a2 :: [arr:{len:20}{size:80}]->[ptr]->[int]], + [var@7360640:a1 :: [ptr]->[arr:{len:20}{size:-1}]->[int]], + [var@7360460:a0 :: [arr:{len:10}{size:800}]->[arr:{len:20}{size:80}]->[int]], + [var@7360110:a :: + [struct@735da40:{name:A}{size:20}{fields: + [var@735d9b0:b :: + [struct@735b730:{name:B}{size:8}{fields: + [var@735d7d0:i :: [int]], + [var@735d8b0:j :: [int]]}]], + [var@735b5c0:x :: [int]], + [var@735b6a0:y :: [int]], + [var@735db50:next :: [ptr]-> + [struct@735da40:{name:A}]]}]]}]->[int] \end{BVerbatim} \caption {Dump Info from CIBIC: Scope Stack} @@ -156,7 +156,9 @@ int mips_to_reg(COpr_t opr, int reg0) { } else if (opr->kind == IMMF) { - printf("\tla $%d, _func_%s\n", reg0, opr->info.str); + printf("\tla $%d, %s%s\n", reg0, + strcmp(opr->info.str, "main") ? "_func_" : "", + opr->info.str); return reg0; } if (opr->reg != -1) @@ -339,8 +339,6 @@ void ssa_generate(int quiet) { cf->defs = defs; cf->entry = entry; cf->next = func_ir; - memmove(cf->blks, blks); - memmove(cf->ord, ord); func_ir = cf; gbbase += bcnt; bcnt = 0; |