exp_def.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* exp_def.h: Definitions for file exports
  2. Copyright (C) 2002-2003 Sebastian Reichelt
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later 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; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #ifndef EXP_DEF_H
  15. #define EXP_DEF_H
  16. #include "../generic.h"
  17. #include "../integers.h"
  18. #include "../intrface.h"
  19. #include "../data.h"
  20. #ifdef TARGET_EMBEDDED
  21. #include <string.h>
  22. // This is the complete export file, created locally by ExportFile.
  23. typedef struct {
  24. INT_EXP_FILE File; // Internal part of the export file.
  25. OFFSET CurPos; // Current writing position inside the file
  26. } EXP_FILE;
  27. #define ExportWrite(F,P,L,C) (memcpy ((F)->File.Data + (F)->CurPos, P, (L) * (C)), (F)->CurPos += (L) * (C))
  28. #define ExportSeek(F,P) ((F)->CurPos = (P))
  29. #define ExportTell(F) ((F)->CurPos)
  30. #define ExportWriteTI1(F,D) ({ WriteTI1 (*((TI1 *) ((F)->File.Data + (F)->CurPos)), D); (F)->CurPos += 1; })
  31. #define ExportWriteTI2(F,D) ({ WriteTI2 (*((TI2 *) ((F)->File.Data + (F)->CurPos)), D); (F)->CurPos += 2; })
  32. #define ExportWriteTI4(F,D) ({ WriteTI4 (*((TI4 *) ((F)->File.Data + (F)->CurPos)), D); (F)->CurPos += 4; })
  33. #define ExportWriteTI(F,D,L,AllowSigned,AllowUnsigned) ({ WriteTI (((F)->File.Data + (F)->CurPos), L, D, AllowSigned, AllowUnsigned); (F)->CurPos += (L); })
  34. #else /* !TARGET_EMBEDDED */
  35. #include <stdio.h>
  36. // This is the complete export file, created locally by ExportFile.
  37. typedef struct {
  38. INT_EXP_FILE File; // Internal part of the export file.
  39. } EXP_FILE;
  40. #define ExportWrite(F,P,L,C) ({ I1 *__P = (I1 *) (P); OFFSET __CP; fwrite (__P, L, C, (F)->File.File); for (__CP = 0; __CP < (OFFSET) ((L) * (C)); __CP++) (F)->File.CheckSum += *(__P++); })
  41. #define ExportSeek(F,P) (fseek ((F)->File.File, P, SEEK_SET))
  42. #define ExportTell(F) (ftell ((F)->File.File))
  43. #endif /* !TARGET_EMBEDDED */
  44. #ifndef ExportWriteTI1
  45. #define ExportWriteTI1(F,D) ({ TI1 __D; WriteTI1 (__D, D); ExportWrite (F, &__D, 1, 1); })
  46. #endif
  47. #ifndef ExportWriteTI2
  48. #define ExportWriteTI2(F,D) ({ TI2 __D; WriteTI2 (__D, D); ExportWrite (F, &__D, 2, 1); })
  49. #endif
  50. #ifndef ExportWriteTI4
  51. #define ExportWriteTI4(F,D) ({ TI4 __D; WriteTI4 (__D, D); ExportWrite (F, &__D, 4, 1); })
  52. #endif
  53. #ifndef ExportWriteTI
  54. #define ExportWriteTI(F,D,L,AllowSigned,AllowUnsigned) ({ I1 __D[(L)]; WriteTI (__D, L, D, AllowSigned, AllowUnsigned); ExportWrite (F, __D, L, 1); })
  55. #endif
  56. // This is the format of a "Get...FileSize" function.
  57. typedef SIZE (*GET_FILE_SIZE_FUNCTION) (const PROGRAM *Program);
  58. // This is the format of a "Export...File" function.
  59. typedef BOOLEAN (*EXPORT_FILE_FUNCTION) (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize, ProgramCalcs DestCalc);
  60. // If the reloc can be resolved to a calculator-dependent builtin value,
  61. // write the value into the data segment in the file which starts at
  62. // DataStart.
  63. BOOLEAN EmitCalcBuiltinValue (const RELOC *Reloc, ProgramCalcs DestCalc, EXP_FILE *File, SIZE FileSize, OFFSET DataStart);
  64. #ifdef PUCRUNCH_SUPPORT
  65. // If the reloc can be resolved to a calculator-dependent builtin value,
  66. // write the value into the data segment in the buffer which starts at
  67. // DataStart. This function is only needed with pucrunch compression.
  68. BOOLEAN EmitCalcBuiltinValueBuf (const RELOC *Reloc, ProgramCalcs DestCalc, I1 *Buffer, SIZE BufferSize, OFFSET DataStart);
  69. #endif /* PUCRUNCH_SUPPORT */
  70. #endif