1 //////////////////////////////////////////////////////////////////////////////
2 //Copyright 2008
3 // Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
4 //////////////////////////////////////////////////////////////////////////////
5 // This file is part of Teyjus. //
6 // //
7 // Teyjus is free software: you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation, either version 3 of the License, or //
10 // (at your option) any later version. //
11 // //
12 // Teyjus is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15 // GNU General Public License for more details. //
16 // //
17 // You should have received a copy of the GNU General Public License //
18 // along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
19 //////////////////////////////////////////////////////////////////////////////
20
21 /***************************************************************************/
22 /* File pervinit.h{c}. */
23 /* Functions for setting up the symbol tables of pervasive constants and */
24 /* kinds are provided. */
25 /***************************************************************************/
26 #include <string.h>
27 #include <stdio.h>
28
29 #include "pervinit.h"
30 #include "pervasives.h"
31 #include "../system/memory.h"
32 #include "../simulator/dataformats.h"
33 #include "../simulator/mcstring.h"
34 #include "../simulator/mctypes.h"
35
PERVINIT_writeName(char * name)36 DF_StrDataPtr PERVINIT_writeName(char* name)
37 {
38 int length = strlen(name);
39 MemPtr rtPtr, mcStr;
40
41 rtPtr = (MemPtr)MEM_memExtend(MCSTR_numWords(length) +
42 DF_STRDATA_HEAD_SIZE);
43 mcStr = rtPtr + DF_STRDATA_HEAD_SIZE;
44
45 //create data head
46 DF_mkStrDataHead((MemPtr)rtPtr);
47 //create the string data
48 MCSTR_toString((MCSTR_Str)mcStr, name, length);
49 return (DF_StrDataPtr)rtPtr;
50 }
51
52 /***************************************************************************/
53 /* PERVASIVE KINDS */
54 /***************************************************************************/
55 MEM_KstEnt PERVINIT_kindDataTab[PERV_KIND_NUM];
56
57 /* Set up pervasive kind symbol table. */
58 /* The kind names are supposed to be written in the current top of system */
59 /* memory. */
PERVINIT_kindTabInit()60 static void PERVINIT_kindTabInit()
61 {
62 int tabInd;
63 for (tabInd = 0; tabInd < PERV_KIND_NUM; tabInd++) {
64 if (PERV_kindDataTab[tabInd].name)
65 PERVINIT_kindDataTab[tabInd].name=
66 PERVINIT_writeName(PERV_kindDataTab[tabInd].name);
67 else PERVINIT_kindDataTab[tabInd].name = NULL;
68
69 PERVINIT_kindDataTab[tabInd].arity=PERV_kindDataTab[tabInd].arity;
70 }
71 }
72
73 /* copy the pervasive kind table into given address */
PERVINIT_copyKindDataTab(MEM_KstPtr dst)74 void PERVINIT_copyKindDataTab(MEM_KstPtr dst)
75 {
76 memcpy((void*)dst, (void*)PERVINIT_kindDataTab,
77 MEM_KST_ENTRY_SIZE * WORD_SIZE * PERV_KIND_NUM);
78 }
79
80 /***************************************************************************/
81 /* PERVASIVE TYPE SKELETONS */
82 /***************************************************************************/
83 MEM_TstPtr PERVINIT_tySkelTab;
84
85 /* Set up pervasive type skeleton table. */
PERVINIT_tySkelTabInit()86 static void PERVINIT_tySkelTabInit()
87 {
88 PERVINIT_tySkelTab = PERV_tySkelTab;
89 PERV_tySkelTabInit();
90 }
91
92 /* copy the pervasive type skeleton table into given address */
PERVINIT_copyTySkelTab(PERV_TySkelData * dst)93 void PERVINIT_copyTySkelTab(PERV_TySkelData* dst)
94 {
95 memcpy((void*)dst, (void*)PERVINIT_tySkelTab,
96 MEM_TST_ENTRY_SIZE * WORD_SIZE * PERV_TY_SKEL_NUM);
97 }
98
99 /***************************************************************************/
100 /* PERVASIVE CONSTANTS */
101 /***************************************************************************/
102 MEM_CstEnt PERVINIT_constDataTab[PERV_CONST_NUM];
103
104 /* Set up pervasive constant symbol table. */
105 /* The constant names are supposed to be written in the current top of */
106 /* system memory. */
PERVINIT_constTabInit()107 static void PERVINIT_constTabInit()
108 {
109 int tabInd;
110
111 for (tabInd = 0; tabInd < PERV_CONST_NUM; tabInd++) {
112 if (PERV_constDataTab[tabInd].name)
113 PERVINIT_constDataTab[tabInd].name =
114 PERVINIT_writeName(PERV_constDataTab[tabInd].name);
115 else PERVINIT_constDataTab[tabInd].name = NULL;
116
117 PERVINIT_constDataTab[tabInd].typeEnvSize =
118 PERV_constDataTab[tabInd].typeEnvSize;
119 PERVINIT_constDataTab[tabInd].tskTabIndex =
120 PERV_constDataTab[tabInd].tskTabIndex;
121 PERVINIT_constDataTab[tabInd].neededness =
122 PERV_constDataTab[tabInd].neededness;
123 PERVINIT_constDataTab[tabInd].univCount =
124 PERV_constDataTab[tabInd].univCount;
125 PERVINIT_constDataTab[tabInd].precedence =
126 PERV_constDataTab[tabInd].precedence;
127 PERVINIT_constDataTab[tabInd].fixity =
128 PERV_constDataTab[tabInd].fixity;
129 }
130 }
131
132 /* copy the pervsive constant table into given address */
PERVINIT_copyConstDataTab(MEM_CstPtr dst)133 void PERVINIT_copyConstDataTab(MEM_CstPtr dst)
134 {
135 memcpy((void*)dst, (void*)PERVINIT_constDataTab,
136 MEM_CST_ENTRY_SIZE * WORD_SIZE * PERV_CONST_NUM);
137
138 }
139
140 /***************************************************************************/
141 /* PERVASIVE TABLES INITIALIZATION */
142 /* Fill in the actual pervasive tables; create string data needed for names*/
143 /* onto the current top of the system memory; create the type skeletons in */
144 /* a malloced space. */
145 /***************************************************************************/
PERVINIT_tableInit()146 void PERVINIT_tableInit()
147 {
148 PERVINIT_kindTabInit();
149 PERVINIT_tySkelTabInit();
150 PERVINIT_constTabInit();
151 }
152
153