diff options
| author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-25 01:07:21 -0600 | 
|---|---|---|
| committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-25 01:07:21 -0600 | 
| commit | 51c4aaaa21a124abafe3f950e12c3c25ddbe0812 (patch) | |
| tree | 29b35d225f3a77e4faf905d45dfce935c7c4e8f6 | |
| parent | fad36d9324fd13d720bc9366f4de6e968d8b8963 (diff) | |
| download | chill-51c4aaaa21a124abafe3f950e12c3c25ddbe0812.tar.gz chill-51c4aaaa21a124abafe3f950e12c3c25ddbe0812.tar.bz2 chill-51c4aaaa21a124abafe3f950e12c3c25ddbe0812.zip | |
floating literal fix
| -rw-r--r-- | include/chillAST/chillASTs.hh | 16 | ||||
| -rwxr-xr-x | lib/chillcg/src/CG_chillBuilder.cc | 4 | ||||
| -rw-r--r-- | src/chillASTs.cc | 71 | ||||
| -rwxr-xr-x | src/ir_clang.cc | 2 | ||||
| -rw-r--r-- | src/printer/dump.cpp | 3 | 
5 files changed, 11 insertions, 85 deletions
| diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 7e32a3a..a84b820 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -1041,26 +1041,14 @@ class chillAST_FloatingLiteral : public chillAST_Node {  public:    virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_FLOATINGLITERAL;}    // variables that are special for this type of node -  float value; -  double doublevalue; -  int float0double1; +  double value;    char *allthedigits; // if not NULL, use this as printable representation    //! Control the precision, float == 1, double == 2    int precision;    // constructors -  chillAST_FloatingLiteral(float val); - -  chillAST_FloatingLiteral(double val); - -  chillAST_FloatingLiteral(float val, int pre); - -  chillAST_FloatingLiteral(double val, int pre); - -  chillAST_FloatingLiteral(float val, const char *printable); - -  chillAST_FloatingLiteral(float val, int pre, const char *printable); +  chillAST_FloatingLiteral(double val, int pre, const char *printable);    chillAST_FloatingLiteral(chillAST_FloatingLiteral *old); diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 63761c5..9a9a414 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -992,12 +992,12 @@ namespace omega {    }    CG_outputRepr* CG_chillBuilder::CreateFloat(float f) const {      //fprintf(stderr, "CG_chillBuilder::CreateFloat( %f )\n", f);  -    chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f); // parent not available +    chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f, 1, NULL); // parent not available      return new CG_chillRepr(fl);    }    CG_outputRepr* CG_chillBuilder::CreateDouble(double d) const {      //fprintf(stderr, "CG_chillBuilder::CreateInt( %f )\n",d);  -    chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d); // parent not available +    chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d, 1, NULL); // parent not available      return new CG_chillRepr(dl);    } diff --git a/src/chillASTs.cc b/src/chillASTs.cc index be0f5d5..e5e9f74 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -2868,8 +2868,6 @@ void chillAST_VarDecl::splitarraypart() {    char *ptr = arraypart;    for (int i = 0; i < asteriskcount; i++) arraypointerpart[i] = *ptr++;    for (int i = 0; i < fixedcount; i++) arraysetpart[i] = *ptr++; - -  //fprintf(stderr, "%s = %s + %s\n", arraypart, arraypointerpart, arraysetpart);  } @@ -2897,75 +2895,19 @@ class chillAST_Node *chillAST_IntegerLiteral::clone() {  } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, const char *printthis) {    value = val; -  precision = 1; -  float0double1 = 0; // which is live! -  allthedigits = NULL; -  isFromSourceFile = true; // default -  filename = NULL; -} - -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val) { -  doublevalue = val; -  precision = 2; -  float0double1 = 1; // which is live! -  allthedigits = NULL; -  isFromSourceFile = true; // default -  filename = NULL; -} - -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis) { -  value = val; -  float0double1 = 0; // which is live! -  precision = precis; // -  allthedigits = NULL; -  isFromSourceFile = true; // default -  filename = NULL; -} - -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis) { -  doublevalue = val; -  float0double1 = 1; // which is live! -  precision = precis; // +  precision = precis;    allthedigits = NULL; -  isFromSourceFile = true; // default -  filename = NULL; -} - -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis) { -  value = val; -  float0double1 = 0; // which is live! -  precision = 1; -  allthedigits = NULL; -  if (printthis) allthedigits = strdup(printthis); -  //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); -  isFromSourceFile = true; // default -  filename = NULL; -} - -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis) { -  value = val; -  float0double1 = 0; // which is live! -  precision = precis; // but value is a float??  TODO -  allthedigits = NULL; -  if (printthis) { -    //fprintf(stderr, "\nchillAST_FloatingLiteral constructor, printthis "); -    //fprintf(stderr, "%p\n", printthis); +  if (printthis)      allthedigits = strdup(printthis); -  } -  //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); -  isFromSourceFile = true; // default +  isFromSourceFile = true;    filename = NULL;  }  chillAST_FloatingLiteral::chillAST_FloatingLiteral(chillAST_FloatingLiteral *old) { -  //fprintf(stderr, "chillAST_FloatingLiteral::chillAST_FloatingLiteral( old ) allthedigits %p\n", old->allthedigits); -    value = old->value; -  doublevalue = old->doublevalue; -  float0double1 = old->float0double1;    allthedigits = NULL;    if (old->allthedigits) allthedigits = strdup(old->allthedigits);    precision = old->precision; @@ -2984,8 +2926,7 @@ void chillAST_FloatingLiteral::print(int indent, FILE *fp) {      strcpy(output, allthedigits); // if they have specified 100 digits of pi, give 'em 100 digits      //fprintf(stderr, "floatingliteral allthedigits = '%s'\n", allthedigits);    } else { -    if (float0double1 == 0) sprintf(output, "%f", value); -    else sprintf(output, "%f", doublevalue); +    sprintf(output, "%f", value);      // next part to avoid printing 123.4560000000000000000000000000      char *dot = index(output, '.'); @@ -3082,8 +3023,6 @@ chillAST_Node *chillAST_UnaryOperator::constantFold() {          F->parent = FL->parent;          F->value = -F->value; -        F->doublevalue = -F->doublevalue; -          F->print();          fprintf(stderr, "\n"); diff --git a/src/ir_clang.cc b/src/ir_clang.cc index f348099..408148f 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1174,7 +1174,7 @@ chillAST_NodeList* ConvertFloatingLiteral(FloatingLiteral *clangFL) {    buf[len] = '\0';    //fprintf(stderr, "'%s'\n", buf); -  chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf); +  chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val,1, buf);    //chillFL->print(); printf("\n"); fflush(stdout);    NL_RET(chillFL); diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp index 2b2a35c..bf3f6b8 100644 --- a/src/printer/dump.cpp +++ b/src/printer/dump.cpp @@ -119,8 +119,7 @@ void Dump::printS(std::string ident, chillAST_DeclRefExpr *n, std::ostream &o) {  void Dump::printS(std::string ident, chillAST_FloatingLiteral *n, std::ostream &o) {    if (n->precision == 1) o << "float ";    else o << "double "; -  if (n->float0double1) o << n->value; -  else o << n->doublevalue; +  o << n->value;  }  void Dump::printS(std::string ident, chillAST_ForStmt *n, std::ostream &o) { | 
