Mercurial > hg > CbC > old > device
changeset 526:9ff5cd7afe2f
*** empty log message ***
author | kono |
---|---|
date | Wed, 28 Dec 2005 15:45:39 +0900 |
parents | d84cea14dbdc |
children | 6b0fd56848e6 |
files | mc-code-powerpc.c mc-inline.c mc-parse.c mc.h stdio.h test/code-gen.pl |
diffstat | 6 files changed, 73 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-powerpc.c Wed Dec 28 11:32:22 2005 +0900 +++ b/mc-code-powerpc.c Wed Dec 28 15:45:39 2005 +0900 @@ -20,6 +20,8 @@ #define __BIG_ENDIAN__ 1\n\ #define __STDC__ 1\n\ #define __GNUC__ 1\n\ +#define __inline inline\n\ +#define __inline__ inline\n\ #define __builtin_va_list int\n\ #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\ #define __builtin_va_arg(ap,type) (*((type *)ap)++)\n\
--- a/mc-inline.c Wed Dec 28 11:32:22 2005 +0900 +++ b/mc-inline.c Wed Dec 28 15:45:39 2005 +0900 @@ -303,7 +303,7 @@ error(TYERR); /* should check compatible */ } } else { - g_expr(correct_type(e,cadr(fnptr->ty))); + g_expr(e); t = type_value(cadr(fnptr->ty)); if (ret_reg_mode==0) { // return value register is not fixed @@ -482,6 +482,18 @@ } static int +plor(int op,int e1,int e2) +{ + return list3(op,pexpr(e1),pexpr(e2)); +} + +static int +pland(int op,int e1,int e2) +{ + return list3(op,pexpr(e1),pexpr(e2)); +} + +static int psassign(int e) { return list4(car(e),pexpr(cadr(e)),pexpr(caddr(e)),cadddr(e)); @@ -940,11 +952,18 @@ // relational operator case GT: case UGT: case GE: case UGE: case LT: case ULT: case LE: case ULE: + case LOP+GT: case LOP+UGT: case LOP+GE: case LOP+UGE: case LOP+LT: + case LOP+ULT: case LOP+LE: case LOP+ULE: case DOP+GT: case DOP+GE: case DOP+LT: case DOP+LE: case FOP+GT: case FOP+GE: case FOP+LT: case FOP+LE: case FOP+EQ: case FOP+NEQ: case EQ: case NEQ: case DOP+EQ: case DOP+NEQ: + case LOP+EQ: case LOP+NEQ: return prexpr(car(e1),cadr(e1),caddr(e1)); + case LAND: + return pland(car(e1),cadr(e1),caddr(e1)); + case LOR: + return plor(car(e1),cadr(e1),caddr(e1)); #if BIT_FIELD_CODE case RBIT_FIELD: return prbit_field(e1); @@ -1005,6 +1024,8 @@ int arg_disp = cadr(e1); // number of arguments int e2,e3,t,e4,dots; int ret_type = function_type(cadddr(e),&dots); + int fargtype; + NMTBL *anptr; // checkret(); @@ -1021,10 +1042,14 @@ fnptr = n; // st_return see this pvartable = p_vartable(e,arg_disp,caddr(e1)); + + /* function arguments type */ + fargtype = n->dsp; // we cannot do destruct reverse here + /* inline function arguments */ narg = 0; for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) { - // for (e3 = e1 = caddr(e); e3; e3 = cadr(e3)) { + anptr = (NMTBL*)caddr(fargtype); t=caddr(e3); // type e4 = car(e3); if (0 && is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) { @@ -1032,9 +1057,14 @@ } else { arg = heap[pdisp+narg]=list3(LVAR,new_lvar(size(t)),0); // should contain correct argument variable name + if (anptr) + printf("## var %s\n",anptr->nm); + else + printf("## var 0\n"); g_expr_u(assign_expr0(arg,e4,t,t)); } narg ++; + fargtype = cadr(fargtype); } caddr(e) = reverse0(e1); // make it normal e2 = pexpr(parse);
--- a/mc-parse.c Wed Dec 28 11:32:22 2005 +0900 +++ b/mc-parse.c Wed Dec 28 15:45:39 2005 +0900 @@ -851,6 +851,10 @@ getsym(0); attributes(); continue; + case INLINE: + inmode = INLINE; + getsym(0); + continue; default: return; } @@ -1798,6 +1802,7 @@ int args,nargs,cargs; NMTBL *a,*n1; + stmode = (n->sc==EXTRN||n->sc==EXTRN1)?EXTRN:STATIC; if(!chk) gen_enter(n->nm); extrn_use(n); local_static_list = &null_nptr; @@ -1810,8 +1815,8 @@ fnptr->attr=n->attr; fnptr->next=0; + // make copied called function argment for(args=n->dsp,nargs=0;args;args=cadr(args)) { - // make copied called function argment n1 = get_nptr(); a = (NMTBL*)caddr(args); n1->ty = a->ty; @@ -1831,6 +1836,7 @@ disp=0; arg_register(fnptr); // should fix n1->dsp + // make calling argments for(args=fnptr->dsp,cargs=0;args;args=cadr(args)) { a = (NMTBL*)caddr(args); // make call function argment for gen_inline @@ -2474,7 +2480,7 @@ } set_lfree(slfree); } else { - parse = list3(ST_RETURN,parse,expr(0)); + parse = list3(ST_RETURN,parse,correct_type(expr(0),cadr(fnptr->ty))); } conv->return_end_(); checksym(SM); @@ -2982,6 +2988,12 @@ case LVAR: e=list2(ADDRESS,e); break; + case IVAR: + if ((nptr1=(NMTBL*)caddr(e))) { + set_attr(nptr1,HAS_ADDRESS,1); + } + e=list2(ADDRESS,e); + break; case FNAME: break; default:error(LVERR);
--- a/mc.h Wed Dec 28 11:32:22 2005 +0900 +++ b/mc.h Wed Dec 28 15:45:39 2005 +0900 @@ -427,6 +427,8 @@ #define IS_STATEMENT(i) (i==INLINE||(ST_DECL<=i&&i<=ST_COMMENT)) +#define HAS_ADDRESS 131 + /* statement end */ /* error number start */ @@ -464,6 +466,8 @@ /* error number end */ +/* ctmode bit */ + #define KONST_BIT 1 #define VOLATILE_BIT 2 #define RESTRICT_BIT 4
--- a/stdio.h Wed Dec 28 11:32:22 2005 +0900 +++ b/stdio.h Wed Dec 28 15:45:39 2005 +0900 @@ -1,4 +1,4 @@ -#ifndef __micro_c__ +#ifndef __micro_c___ #include "/usr/include/stdio.h" long long strtoll(const char *, char **, int); char *malloc(int);
--- a/test/code-gen.pl Wed Dec 28 11:32:22 2005 +0900 +++ b/test/code-gen.pl Wed Dec 28 15:45:39 2005 +0900 @@ -1,14 +1,29 @@ #!/usr/bin/perl +my $call; + +open(INLINE,">test/code-gen-inline.c"); + print "#include \"code-gen.c\"\n"; -print "int main() {\n"; + +$call .= "int main() {\n"; while(<>) { - if (/^\w+\(/) { - print "\t$&",");\n"; + if (/^(\w+)(\(.*)/) { + $call .= "\t$1(".");\n"; + print INLINE "inline $1$2"; } elsif (/^#/) { - print; + $call .= $_; + print INLINE; + } else { + print INLINE; } } -print "return 0; }\n"; +$call .= "return 0; }\n"; + +print $call; + +print INLINE $call; + +# end