hpmods.c
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:3k
源码类别:

编译器/解释器

开发平台:

C/C++

  1. /* "p2c", a Pascal to C translator.
  2.    Copyright (C) 1989 David Gillespie.
  3.    Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation (any version).
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING.  If not, write to
  13. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. #define PROTO_HPMODS_C
  15. #include "trans.h"
  16. /* FS functions */
  17. Static Stmt *proc_freadbytes()
  18. {
  19.     Expr *ex, *ex2, *vex, *fex;
  20.     Type *type;
  21.     if (!skipopenparen())
  22. return NULL;
  23.     fex = p_expr(tp_text);
  24.     if (!skipcomma())
  25. return NULL;
  26.     vex = p_expr(NULL);
  27.     if (!skipcomma())
  28. return NULL;
  29.     ex2 = p_expr(tp_integer);
  30.     skipcloseparen();
  31.     type = vex->val.type;
  32.     ex = makeexpr_bicall_4("fread", tp_integer,
  33.                            makeexpr_addr(vex),
  34.                            convert_size(type, ex2, "FREADBYTES"),
  35.                            makeexpr_long(1),
  36.                            copyexpr(fex));
  37.     if (checkeof(fex)) {
  38.         ex = makeexpr_bicall_2(name_SETIO, tp_void,
  39.                                makeexpr_rel(EK_EQ, ex, makeexpr_long(1)),
  40.                                makeexpr_long(30));
  41.     }
  42.     return wrapopencheck(makestmt_call(ex), fex);
  43. }
  44. Static Stmt *proc_fwritebytes()
  45. {
  46.     Expr *ex, *ex2, *vex, *fex;
  47.     Type *type;
  48.     if (!skipopenparen())
  49. return NULL;
  50.     fex = p_expr(tp_text);
  51.     if (!skipcomma())
  52. return NULL;
  53.     vex = p_expr(NULL);
  54.     if (!skipcomma())
  55. return NULL;
  56.     ex2 = p_expr(tp_integer);
  57.     skipcloseparen();
  58.     type = vex->val.type;
  59.     ex = makeexpr_bicall_4("fwrite", tp_integer,
  60.                            makeexpr_addr(vex),
  61.                            convert_size(type, ex2, "FWRITEBYTES"),
  62.                            makeexpr_long(1),
  63.                            copyexpr(fex));
  64.     if (checkfilewrite) {
  65.         ex = makeexpr_bicall_2(name_SETIO, tp_void,
  66.                                makeexpr_rel(EK_EQ, ex, makeexpr_long(1)),
  67.                                makeexpr_long(3));
  68.     }
  69.     return wrapopencheck(makestmt_call(ex), fex);
  70. }
  71. /* SYSGLOBALS */
  72. Static void setup_sysglobals()
  73. {
  74.     Symbol *sym;
  75.     sym = findsymbol("SYSESCAPECODE");
  76.     if (sym->mbase)
  77.         strchange(&sym->mbase->name, name_ESCAPECODE);
  78.     sym = findsymbol("SYSIORESULT");
  79.     if (sym->mbase)
  80.         strchange(&sym->mbase->name, name_IORESULT);
  81. }
  82. void hpmods(name, defn)
  83. char *name;
  84. int defn;
  85. {
  86.     if (!strcmp(name, "FS")) {
  87.         makespecialproc("freadbytes", proc_freadbytes);
  88.         makespecialproc("fwritebytes", proc_fwritebytes);
  89.     } else if (!strcmp(name, "SYSGLOBALS")) {
  90.         setup_sysglobals();
  91.     }
  92. }
  93. /* End. */