ast *optimizeRRCRLC (ast *);
ast *optimizeGetHbit (ast *);
ast *backPatchLabels (ast *, symbol *, symbol *);
+void PA(ast *t);
int inInitMode = 0;
memmap *GcurMemmap=NULL; /* points to the memmap that's currently active */
FILE *codeOutFile;
dest->level = src->level;
dest->funcName = src->funcName;
+ if (src->ftype)
+ dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype));
+
/* if this is a leaf */
/* if value */
if (src->type == EX_VALUE)
/* if this is a node that has special values */
copyAstValues (dest, src);
- if (src->ftype)
- dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype));
-
dest->trueLabel = copySymbol (src->trueLabel);
dest->falseLabel = copySymbol (src->falseLabel);
dest->left = copyAst (src->left);
return 1;
}
+ if (IS_VOID(actParm->ftype)) {
+ werror (E_VOID_VALUE_USED);
+ return 1;
+ }
+
/* If this is a varargs function... */
if (!defParm && actParm && IFFUNC_HASVARARGS(func->ftype))
{
if (IS_AGGREGATE (ftype))
{
- // jwk: don't we need aggregateToPointer here?
newType = newAst_LINK (copyLinkChain (ftype));
DCL_TYPE (newType->opval.lnk) = GPOINTER;
}
}
/* if defined parameters ended but actual has not & */
- /* stackAuto */
+ /* reentrant */
if (!defParm && actParm &&
(options.stackAuto || IFFUNC_ISREENT (func->ftype)))
return 0;
* Therefore, if there are more defined parameters, the caller didn't
* supply enough.
*/
- if (0 && rightmost && defParm->next)
+ if (rightmost && defParm->next)
{
werror (E_TOO_FEW_PARMS);
return 1;
/* the parameter type must be at least castable */
if (compareType (defParm->type, actParm->ftype) == 0) {
werror (E_INCOMPAT_TYPES);
- fprintf (stderr, "type --> '");
- printTypeChain (actParm->ftype, stderr);
- fprintf (stderr, "' ");
- fprintf (stderr, "assigned to type --> '");
- printTypeChain (defParm->type, stderr);
- fprintf (stderr, "'\n");
+ printFromToType (actParm->ftype, defParm->type);
return 1;
}
createIvalStruct (ast * sym, sym_link * type, initList * ilist)
{
ast *rast = NULL;
+ ast *lAst;
symbol *sflds;
initList *iloop;
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL))
{
- ast *lAst;
-
/* if we have come to end */
if (!iloop)
break;
if (!TARGET_IS_MCS51 || !(options.model==MODEL_LARGE)) {
fprintf (stderr, "Can't \"TRY_THE_NEW_INITIALIZER\" unless "
- "with -mmcs51 and --model-large");
+ "with -mmcs51 and --model-large\n");
exit(404);
}
#endif
-/*-----------------------------------------------------------------*/
-/* Given an assignment operation in a tree, determine if the LHS */
-/* (the result) has a different (integer) type than the RHS. */
-/* If so, walk the RHS and add a typecast to the type of the LHS */
-/* to all leaf nodes. */
-/*-----------------------------------------------------------------*/
-void
-propAsgType (ast * tree)
-{
-#ifdef DEMAND_INTEGER_PROMOTION
- if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
- {
- /* Nothing to do here... */
- return;
- }
-
- if (getSize (LTYPE (tree)) > getSize (RTYPE (tree)))
- {
- pushTypeCastToLeaves (LTYPE (tree), tree->right, &(tree->right));
- }
-#else
- (void) tree;
-#endif
-}
-
/*-----------------------------------------------------------------*/
/* decorateType - compute type for this tree also does type cheking */
/* this is done bottom up, since type have to flow upwards */
/* if bit field then error */
if (IS_BITVAR (tree->left->etype))
{
- werror (E_ILLEGAL_ADDR, "addrress of bit variable");
+ werror (E_ILLEGAL_ADDR, "address of bit variable");
goto errorTreeReturn;
}
goto errorTreeReturn;
}
- if (LRVAL (tree))
+ if (IS_LITERAL(LTYPE(tree)))
+ {
+ werror (E_ILLEGAL_ADDR, "address of literal");
+ goto errorTreeReturn;
+ }
+
+ if (LRVAL (tree))
{
werror (E_LVALUE_REQUIRED, "address of");
goto errorTreeReturn;
}
LLVAL (tree) = 1;
- propAsgType (tree);
-
return tree;
case AND_ASSIGN:
}
LLVAL (tree) = 1;
- propAsgType (tree);
-
return tree;
/*------------------------------------------------------------------*/
}
LLVAL (tree) = 1;
- propAsgType (tree);
-
return tree;
/*------------------------------------------------------------------*/
tree->right = decorateType (newNode ('+', copyAst (tree->left), tree->right));
tree->opval.op = '=';
- propAsgType (tree);
-
return tree;
/*------------------------------------------------------------------*/
if (IS_VOID (LTYPE (tree)))
{
werror (E_CAST_ZERO);
- fprintf (stderr, "type --> '");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "' ");
- fprintf (stderr, "assigned to type --> '");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, "'\n");
+ printFromToType(RTYPE(tree), LTYPE(tree));
}
TETYPE (tree) = getSpec (TTYPE (tree) =
goto errorTreeReturn;
}
- propAsgType (tree);
-
return tree;
/*------------------------------------------------------------------*/
if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
{
werror (W_RETURN_MISMATCH);
- fprintf (stderr, "from type '");
- printTypeChain (RTYPE(tree), stderr);
- fprintf (stderr, "' to type '");
- printTypeChain (currFunc->type->next, stderr);
- fprintf (stderr, "'\n");
+ printFromToType (RTYPE(tree), currFunc->type->next);
goto errorTreeReturn;
}
/* if there is going to be a casing required then add it */
if (compareType (currFunc->type->next, RTYPE (tree)) < 0)
{
-#if 0 && defined DEMAND_INTEGER_PROMOTION
- if (IS_INTEGRAL (currFunc->type->next))
- {
- pushTypeCastToLeaves (currFunc->type->next, tree->right, &(tree->right));
- }
- else
-#endif
- {
- tree->right =
- decorateType (newNode (CAST,
- newAst_LINK (copyLinkChain (currFunc->type->next)),
- tree->right));
- }
+ tree->right =
+ decorateType (newNode (CAST,
+ newAst_LINK (copyLinkChain (currFunc->type->next)),
+ tree->right));
}
RRVAL (tree) = 1;
ex = newAst_VALUE (symbolVal (name)); /* create name */
ex = newNode (FUNCTION, ex, body);
ex->values.args = FUNC_ARGS(name->type);
-
+ ex->decorated=1;
+ if (options.dump_tree) PA(ex);
if (fatalError)
{
werror (E_FUNC_NO_CODE, name->name);
}
if (tree->opval.op == FUNCTION) {
- fprintf(outfile,"FUNCTION (%p) type (",tree);
+ int arg=0;
+ value *args=FUNC_ARGS(tree->left->opval.val->type);
+ fprintf(outfile,"FUNCTION (%s=%p) type (",
+ tree->left->opval.val->name, tree);
printTypeChain (tree->ftype,outfile);
+ fprintf(outfile,") args (");
+ do {
+ if (arg) {
+ fprintf (outfile, ", ");
+ }
+ printTypeChain (args->type, outfile);
+ arg++;
+ args=args->next;
+ } while (args);
fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+4);
- ast_print(tree->right,outfile,indent+4);
+ ast_print(tree->left,outfile,indent);
+ ast_print(tree->right,outfile,indent);
return ;
}
if (tree->opval.op == BLOCK) {
symbol *decls = tree->values.sym;
+ INDENT(indent,outfile);
fprintf(outfile,"{\n");
while (decls) {
INDENT(indent+4,outfile);
- fprintf(outfile,"DECLARE SYMBOL %s, type(",decls->name);
+ fprintf(outfile,"DECLARE SYMBOL (%s=%p) type (",
+ decls->name, decls);
printTypeChain(decls->type,outfile);
fprintf(outfile,")\n");
decls = decls->next;
}
ast_print(tree->right,outfile,indent+4);
+ INDENT(indent,outfile);
fprintf(outfile,"}\n");
return;
}
} else {
fprintf(outfile,"SYMBOL ");
}
- fprintf(outfile,"(%p) name= %s ",tree,tree->opval.val->sym->name);
+ fprintf(outfile,"(%s=%p)",
+ tree->opval.val->sym->name,tree);
}
if (tree->ftype) {
fprintf(outfile," type (");
/* casting */
/*----------------------------*/
case CAST: /* change the type */
- fprintf(outfile,"CAST (%p) type (",tree);
+ fprintf(outfile,"CAST (%p) from type (",tree);
+ printTypeChain(tree->right->ftype,outfile);
+ fprintf(outfile,") to type (");
printTypeChain(tree->ftype,outfile);
fprintf(outfile,")\n");
ast_print(tree->right,outfile,indent+4);
/* ifx Statement */
/*----------------------------*/
case IFX:
- ast_print(tree->left,outfile,indent);
- INDENT(indent,outfile);
fprintf(outfile,"IF (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+4);
if (tree->trueLabel) {
INDENT(indent,outfile);
- fprintf(outfile,"NE(==) 0 goto %s\n",tree->trueLabel->name);
+ fprintf(outfile,"NE(!=) 0 goto %s\n",tree->trueLabel->name);
}
if (tree->falseLabel) {
INDENT(indent,outfile);
fprintf(outfile,"EQ(==) 0 goto %s\n",tree->falseLabel->name);
}
- ast_print(tree->right,outfile,indent);
+ ast_print(tree->right,outfile,indent+4);
return ;
/*------------------------------------------------------------------*/
/*----------------------------*/
void PA(ast *t)
{
- ast_print(t,stdout,1);
+ ast_print(t,stdout,0);
}