summaryrefslogtreecommitdiff
path: root/src/runtime/c/teyjus/tables_gen
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-07-31 15:16:04 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-07-31 15:16:04 +0000
commit83b321d862472f31c0c9f7feca8360ad5bfe8a75 (patch)
tree0f0ef20ad78e25b320013c7bb160211a8612d4e9 /src/runtime/c/teyjus/tables_gen
parent314662dd09d5d1480007faa79258b0e93cc2aa59 (diff)
An initial import of the teyjus source code in the C runtime for GF. The two runtime are still not connected but the source code compiles.
Diffstat (limited to 'src/runtime/c/teyjus/tables_gen')
-rw-r--r--src/runtime/c/teyjus/tables_gen/Makefile28
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrformats.l69
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrformats.y283
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrformats_32.in346
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrformats_64.in346
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.c650
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.h70
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.c841
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.h47
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/lex.yy.c1977
-rw-r--r--src/runtime/c/teyjus/tables_gen/instrformats/y.tab.h104
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/ccode.c1024
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/ccode.h80
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.c1434
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.h152
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/op.c80
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/op.h58
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervasives.in404
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervasives.l96
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervasives.y351
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.c454
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.h95
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.c350
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.h60
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/types.c114
-rw-r--r--src/runtime/c/teyjus/tables_gen/pervasives/types.h92
-rw-r--r--src/runtime/c/teyjus/tables_gen/util/util.c135
-rw-r--r--src/runtime/c/teyjus/tables_gen/util/util.h71
28 files changed, 9811 insertions, 0 deletions
diff --git a/src/runtime/c/teyjus/tables_gen/Makefile b/src/runtime/c/teyjus/tables_gen/Makefile
new file mode 100644
index 000000000..7cf2c532a
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/Makefile
@@ -0,0 +1,28 @@
+all: instrformats/gen pervasives/gen
+
+instrformats/gen: instrformats/y.tab.o instrformats/lex.yy.o \
+ instrformats/instrgen-c.o instrformats/instrgen-ocaml.o \
+ util/util.o
+ gcc -o instrformats/gen $^
+
+pervasives/gen: pervasives/y.tab.o pervasives/lex.yy.o \
+ pervasives/ccode.o pervasives/ocamlcode.o \
+ pervasives/pervgen-c.o pervasives/pervgen-ocaml.o \
+ pervasives/types.o pervasives/op.o \
+ util/util.o
+ gcc -o pervasives/gen $^
+
+.o : .c
+ gcc -c -o $@ $^
+
+instrformats/y.tab.c instrformats/y.tab.h : instrformats/instrformats.y
+ yacc -o instrformats/y.tab.c --defines=instrformats/y.tab.h instrformats/instrformats.y
+
+instrformats/lex.yy.c : instrformats/instrformats.l instrformats/y.tab.h
+ flex -o instrformats/lex.yy.c instrformats/instrformats.l
+
+pervasives/y.tab.c pervasives/y.tab.h : pervasives/pervasives.y
+ yacc -o pervasives/y.tab.c --defines=pervasives/y.tab.h pervasives/pervasives.y
+
+pervasives/lex.yy.c : pervasives/pervasives.l pervasives/y.tab.h
+ flex -o pervasives/lex.yy.c pervasives/pervasives.l
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.l b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.l
new file mode 100644
index 000000000..28e43ab1b
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.l
@@ -0,0 +1,69 @@
+%{
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "y.tab.h"
+#include <string.h>
+#include <stdlib.h>
+
+static int commentLev = 0;
+%}
+
+LETTER [A-Za-z]
+DIGIT [0-9]
+SYMBOL "_"|"+"|"-"|"*"|"/"|"!"|"~"|"@"|"$"|"%"|"^"|"&"|"*"|"<"|">"|"="|"'"|":"|","
+
+ID ({LETTER}|{SYMBOL})({LETTER}|{DIGIT}|{SYMBOL})*
+NUM {DIGIT}+
+WSPACE [ \t]+
+STRING [^*/]+
+STRING2 [^}]+
+
+%x COMMENT COMMENT2 INCLUDE
+
+%%
+<INITIAL,COMMENT>"\n" {continue; }
+<INITIAL>";" {return SEMICOLON; }
+<INITIAL>"[" {return LBRACKET; }
+<INITIAL>"]" {return RBRACKET; }
+<INITIAL>"OPERAND TYPES" {return OPTYPES; }
+<INITIAL>"OPCODE" {return OPCODE; }
+<INITIAL>"INSTR CATEGORY" {return INSTRCAT; }
+<INITIAL>"MAX OPERAND" {return MAXOPERAND; }
+<INITIAL>"CALL_I1_LEN" {return CALL_I1_LEN; }
+<INITIAL>"INSTRUCTIONS" {return INSTRUCTIONS; }
+<INITIAL>{WSPACE} {continue; }
+<INITIAL>"/%" {commentLev = 1; BEGIN(COMMENT); continue; }
+<INITIAL>"/*" {BEGIN(COMMENT2); continue; }
+<INITIAL>"{" {BEGIN(INCLUDE); continue; }
+<INITIAL>{ID} {yylval.name = strdup(yytext); return ID; }
+<INITIAL>{NUM} {yylval.isval.ival = atoi(yytext);
+ yylval.isval.sval = strdup(yytext);
+ return NUM; }
+<COMMENT2>"*/" {BEGIN(INITIAL); continue; }
+<COMMENT2>{STRING} {yylval.text = strdup(yytext); return STRING; }
+
+<COMMENT>[^%/\n]+ {continue; }
+<COMMENT>"/%" {commentLev++; continue; }
+<COMMENT>"%/" {commentLev--;
+ if (!commentLev) BEGIN(INITIAL); continue; }
+<INCLUDE>"}" {BEGIN(INITIAL); continue; }
+<INCLUDE>{STRING2} {yylval.text = strdup(yytext); return STRING2; }
+. {return ERROR; }
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.y b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.y
new file mode 100644
index 000000000..348312732
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats.y
@@ -0,0 +1,283 @@
+%{
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include "instrgen-c.h"
+#include "instrgen-ocaml.h"
+#include "../util/util.h"
+
+extern int yylex();
+
+int yywrap() {return 1;}
+
+void yyerror(const char* str)
+{
+ printf("%s\n", str);
+}
+
+%}
+
+%union{
+ char* name;
+ char* text;
+ struct
+ {
+ int ival;
+ char* sval;
+ } isval;
+}
+
+%token OPTYPES INSTRCAT INSTRUCTIONS OPCODE MAXOPERAND
+ CALL_I1_LEN SEMICOLON ERROR LBRACKET RBRACKET
+%token <name> ID
+%token <isval> NUM
+%token <text> STRING STRING2
+
+%start instr_format
+%type <name> operand_name operand_tname operand_type instr_name instr_cat
+ instr_head instr_length operand_comp_type
+%type <text> comments compiler_include
+%type <isval> max_operand opcode operand_size
+%%
+
+instr_format : compiler_include operands instrcats instructions
+
+compiler_include : STRING2 { ocgenInclude($1);}
+
+
+operands : OPTYPES operand_decs opcode_type
+ { cgenOpsH(); ocgenOps();}
+ ;
+
+operand_decs : operand_dec operand_decs
+ | operand_dec_last
+ ;
+
+operand_dec : operand_name operand_tname operand_type operand_size operand_comp_type comments
+ { cgenOpTypes($1, $2, $3, $6, 0);
+ ocgenOpType($1, $4.ival, $5);
+ }
+ | operand_name comments
+ { cgenOpTypes($1, NULL, NULL, $2, 0); }
+ ;
+
+operand_dec_last : operand_name operand_tname operand_type operand_size operand_comp_type comments
+ { cgenOpTypes($1, $2, $3, $6, 1);
+ ocgenOpType($1, $4.ival, $5);
+ }
+ | operand_name comments
+ { cgenOpTypes($1, NULL, NULL, $2, 1); }
+ ;
+
+
+operand_name : ID { $$ = $1; }
+ ;
+
+operand_tname : ID { $$ = $1; }
+ ;
+
+operand_type : ID { $$ = $1; }
+ ;
+
+operand_comp_type : ID { $$ = $1; }
+ ;
+
+comments : STRING {$$ = $1; }
+ ;
+
+operand_size : NUM { $$ = $1; }
+ ;
+
+opcode_type : OPCODE ID operand_size
+ { cgenOpCodeType($2);
+ ocgenOpCodeType($3.ival);}
+ ;
+
+instrcats : INSTRCAT max_operand instrcat_decs CALL_I1_LEN NUM
+ { cgenInstrCatH($5.sval); cgenInstrCatC($2.sval);
+ ocgenInstrCat();
+ }
+ ;
+
+max_operand : MAXOPERAND NUM { $$ = $2; }
+ ;
+
+instrcat_decs : instrcat_dec instrcat_decs
+ | instrcat_dec_last
+ ;
+
+instrcat_dec : ID LBRACKET instr_format RBRACKET instr_lengths
+ { cgenOneInstrCatH($1, 0); cgenOneInstrCatC($1, 0);
+ ocgenOneInstrCat($1);
+ }
+ ;
+
+instrcat_dec_last : ID LBRACKET instr_format RBRACKET instr_lengths
+ { cgenOneInstrCatH($1, 1); cgenOneInstrCatC($1, 1);
+ ocgenOneInstrCat($1);
+ }
+ ;
+
+instr_format : oneOp instr_format
+ | lastOp
+ ;
+
+oneOp : ID { cgenInstrFormat($1, 0); ocgenInstrFormat($1); }
+ ;
+
+lastOp : ID { cgenInstrFormat($1, 1); ocgenInstrFormat($1); }
+ ;
+
+
+instr_lengths : instr_len_first SEMICOLON instr_lengths_rest
+ | instr_len_first
+ ;
+
+instr_lengths_rest : instr_len SEMICOLON instr_lengths_rest
+ | instr_len
+ ;
+
+instr_len_first : ID NUM
+ {cgenInstrLength($1, $2.sval);
+ ocgenInstrLength($1, $2.sval);}
+ ;
+
+instr_len : ID NUM { cgenInstrLength($1, $2.sval);}
+ ;
+
+
+instructions : instr_head instrs
+ { cgenInstrH($1); cgenInstrC(); cgenSimDispatch();
+ ocgenInstr();
+ }
+ ;
+
+instr_head : INSTRUCTIONS NUM
+ { cinitInstrC($2.ival);
+ cinitSimDispatch($2.ival);
+ $$ = $2.sval;
+ }
+ ;
+
+
+instrs : instr SEMICOLON instrs
+ | last_instr
+ ;
+
+instr : comments opcode instr_name instr_cat instr_length
+ { cgenOneInstrH($1, $2.sval , $3);
+ cgenOneInstrC($2.ival, $3, $4, $5, 0);
+ cgenOneSimDispatch($2.ival, $3, 0);
+ ocgenOneInstr($2.sval, $3, $4, $5, 0);
+ }
+ | opcode instr_name instr_cat instr_length
+ { cgenOneInstrH(NULL, $1.sval , $2);
+ cgenOneInstrC($1.ival, $2, $3, $4, 0);
+ cgenOneSimDispatch($1.ival, $2, 0);
+ ocgenOneInstr($1.sval, $2, $3, $4, 0);
+ }
+ ;
+
+last_instr : comments opcode instr_name instr_cat instr_length
+ { cgenOneInstrH($1, $2.sval , $3);
+ cgenOneInstrC($2.ival, $3, $4, $5, 1);
+ cgenOneSimDispatch($2.ival, $3, 1);
+ ocgenOneInstr($2.sval, $3, $4, $5, 1);
+ }
+ | opcode instr_name instr_cat instr_length
+ { cgenOneInstrH(NULL, $1.sval , $2);
+ cgenOneInstrC($1.ival, $2, $3, $4, 1);
+ cgenOneSimDispatch($1.ival, $2, 1);
+ ocgenOneInstr($1.sval, $2, $3, $4, 1);
+ }
+ ;
+
+opcode : NUM { $$ = $1; }
+ ;
+
+instr_name : ID { $$ = $1; }
+ ;
+
+instr_cat : ID { $$ = $1; }
+ ;
+
+instr_length : ID { $$ = $1; }
+ ;
+
+
+%%
+
+extern FILE* yyin;
+
+int main(argc, argv)
+ int argc;
+ char * argv[];
+{
+ char * root = NULL;
+ int ret = 0;
+
+ if(argc <= 1)
+ {
+ if (sizeof(void*) == 8)
+ {
+ //printf("No input file specified; using 'instrformats_64.in'.\n");
+ yyin = UTIL_fopenR("instrformats_64.in");
+ }
+ else
+ {
+ //printf("No input file specified; using 'instrformats_32.in'.\n");
+ yyin = UTIL_fopenR("instrformats_32.in");
+ }
+ }
+ else
+ {
+ yyin = UTIL_fopenR(argv[1]);
+ }
+
+ if(argc > 2)
+ {
+ root = argv[2];
+ }
+ else
+ {
+ //printf("Teyjus source root directory not specified; using '../../'.\n");
+ root = "../../";
+ }
+
+ //printf("Generating instruction files...\n");
+
+ ret = yyparse();
+ UTIL_fclose(yyin);
+
+ if(ret != 0)
+ {
+ printf("Generation failed.\n");
+ return -1;
+ }
+ cspitCInstructionsH(root);
+ cspitCInstructionsC(root);
+ cspitSimDispatch(root);
+ //ocSpitInstructionMLI(root);
+ //ocSpitInstructionML(root);
+ //printf("Done.\n");
+
+ return 0;
+}
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_32.in b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_32.in
new file mode 100644
index 000000000..1cfddddfb
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_32.in
@@ -0,0 +1,346 @@
+{
+type intref = int ref
+type aconstant = Absyn.aconstant
+type akind = Absyn.akind
+
+}
+
+OPERAND TYPES
+
+ P /* (1 byte) padding */
+ WP /* (1 word) padding */
+ R RegInd Byte 1 int /* argument register number */
+ E EnvInd Byte 1 int /* environment variable number */
+ N NextClauseInd Byte 1 int /* next clause number in impt or impl pt */
+ I1 OneByteInt Byte 1 int /* 1 byte natural number */
+ CE ClEnvInd Byte 1 int /* closure environment variable number */
+ SEG ImpSegInd Byte 1 int /* import segment index */
+ C CstIndex TwoBytes 2 aconstant /* constant symbol table index */
+ K KstIndex TwoBytes 2 akind /* kind symbol table index */
+ L CodeLabel CSpacePtr 4 intref /* code location */
+ I Int int 4 int /* integer immediate value */
+ F Float float 4 float /* floating point immediate value */
+ S Str DF_StrDataPtr 2 int /* string pointer */
+ MT ModTab MemPtr 2 int /* module table address */
+ IT ImplTab MemPtr 2 int /* impl table address */
+ HT HashTab MemPtr 2 int /* hash table address */
+ BVT BranchTab MemPtr 2 int /* branch table for bound var indexing */
+ X /* operand list terminator */
+ OPCODE Byte 1
+
+
+INSTR CATEGORY
+
+ MAX OPERAND 8
+
+ X [P P P X X X X X]
+ X_LEN 4
+
+ RX [R P P X X X X X]
+ RX_LEN 4; RX_R 1
+
+ EX [E P P X X X X X]
+ EX_LEN 4; EX_E 1
+
+ I1X [I1 P P X X X X X]
+ I1X_LEN 4; I1X_I1 1
+
+ CX [P C X X X X X X]
+ CX_LEN 4; CX_C 2
+
+ KX [P K X X X X X X]
+ KX_LEN 4; KX_K 2
+
+ IX [P P P I X X X X]
+ IX_LEN 8; IX_I 4
+
+ FX [P P P F X X X X]
+ FX_LEN 8; FX_F 4
+
+ SX [P P P S X X X X]
+ SX_LEN 8; SX_S 4
+
+ MTX [P P P MT X X X X]
+ MTX_LEN 8; MTX_MT 4
+
+ LX [P P P L X X X X]
+ LX_LEN 8; LX_L 4
+
+ RRX [R R P X X X X X]
+ RRX_LEN 4; RRX_R1 1; RRX_R2 2
+
+ ERX [E R P X X X X X]
+ ERX_LEN 4; ERX_E 1; ERX_R 2
+
+ RCX [R C X X X X X X]
+ RCX_LEN 4; RCX_R 1; RCX_C 2
+
+ RIX [R P P I X X X X]
+ RIX_LEN 8; RIX_R 1; RIX_I 4
+
+ RFX [R P P F X X X X]
+ RFX_LEN 8; RFX_R 1; RFX_F 4
+
+ RSX [R P P S X X X X]
+ RSX_LEN 8; RSX_R 1; RSX_S 4
+
+ RI1X [R I1 P X X X X X]
+ RI1X_LEN 4; RI1X_R 1; RI1X_I1 2
+
+ RCEX [R CE P X X X X X]
+ RCEX_LEN 4; RCEX_R 1; RCEX_CE 2
+
+ ECEX [E CE P X X X X X]
+ ECEX_LEN 4; ECEX_E 1; ECEX_CE 2
+
+ CLX [P C L X X X X X]
+ CLX_LEN 8; CLX_C 2; CLX_L 4
+
+ RKX [R K X X X X X X]
+ RKX_LEN 4; RKX_R 1; RKX_K 2
+
+ ECX [E C X X X X X X]
+ ECX_LEN 4; ECX_E 1; ECX_C 2
+
+ I1ITX [I1 P P IT X X X X]
+ I1ITX_LEN 8; I1ITX_I1 1; I1ITX_IT 4
+
+ I1LX [I1 P P L X X X X]
+ I1LX_LEN 8; I1LX_I1 1; I1LX_L 4
+
+ SEGLX [SEG P P L X X X X]
+ SEGLX_LEN 8; SEGLX_SEG 1; SEGLX_L 4
+
+ I1LWPX [I1 P P L WP X X X]
+ I1LWPX_LEN 12; I1LWPX_I1 1; I1LWPX_L 4
+
+ I1NX [I1 N P X X X X X]
+ I1NX_LEN 4; I1NX_I1 1; I1NX_N 2
+
+ I1HTX [I1 P P HT X X X X]
+ I1HTX_LEN 8; I1HTX_I1 1; I1HTX_HT 4
+
+ I1BVTX [I1 P P BVT X X X X]
+ I1BVTX_LEN 8; I1BVTX_I1 1; I1BVTX_BVT 4
+
+ CWPX [P C WP X X X X X]
+ CWPX_LEN 8; CWPX_C 2
+
+ I1WPX [I1 P P WP X X X X]
+ I1WPX_LEN 8; I1WPX_I1 1
+
+ RRI1X [R R I1 X X X X X]
+ RRI1X_LEN 4; RRI1X_R1 1; RRI1X_R2 2; RRI1X_I1 3
+
+ RCLX [R C L X X X X X]
+ RCLX_LEN 8; RCLX_R 1; RCLX_C 2; RCLX_L 4
+
+ RCI1X [R C I1 P P P X X]
+ RCI1X_LEN 8; RCI1X_R 1; RCI1X_C 2; RCI1X_I1 4
+
+ SEGI1LX [SEG I1 P L X X X X]
+ SEGI1LX_LEN 8; SEGI1LX_SEG 1; SEGI1LX_I1 2; SEGI1LX_L 4
+
+ I1LLX [I1 P P L L X X X]
+ I1LLX_LEN 12; I1LLX_I1 1; I1LLX_L1 4; I1LLX_L2 8
+
+ NLLX [N P P L L X X X]
+ NLLX_LEN 12; NLLX_N 1; NLLX_L1 4; NLLX_L2 8
+
+ LLLLX [P P P L L L L X]
+ LLLLX_LEN 20; LLLLX_L1 4; LLLLX_L2 8; LLLLX_L3 12; LLLLX_L4 16
+
+ I1CWPX [I1 C WP X X X X X]
+ I1CWPX_LEN 8; I1CWPX_I1 1; I1CWPX_C 2
+
+ I1I1WPX [I1 I1 P WP X X X X]
+ I1I1WPX_LEN 8; I1I1WPX_I11 1; I1I1WPX_I12 2
+
+ CALL_I1_LEN 7
+
+
+INSTRUCTIONS 145
+
+ /* Instructions for term unification and creation */
+
+ 0 put_variable_t RRX RRX_LEN;
+ 1 put_variable_p ERX ERX_LEN;
+ 2 put_value_t RRX RRX_LEN;
+ 3 put_value_p ERX ERX_LEN;
+ 4 put_unsafe_value ERX ERX_LEN;
+ 5 copy_value ERX ERX_LEN;
+ 6 put_m_const RCX RCX_LEN;
+ 7 put_p_const RCX RCX_LEN;
+ 8 put_nil RX RX_LEN;
+ 9 put_integer RIX RIX_LEN;
+ 10 put_float RFX RFX_LEN;
+ 11 put_string RSX RSX_LEN;
+ 12 put_index RI1X RI1X_LEN;
+ 13 put_app RRI1X RRI1X_LEN;
+ 14 put_list RX RX_LEN;
+ 15 put_lambda RRI1X RRI1X_LEN;
+
+ 16 set_variable_t RX RX_LEN;
+ 17 set_variable_te RX RX_LEN;
+ 18 set_variable_p EX EX_LEN;
+ 19 set_value_t RX RX_LEN;
+ 20 set_value_p EX EX_LEN;
+ 21 globalize_pt ERX ERX_LEN;
+ 22 globalize_t RX RX_LEN;
+ 23 set_m_const CX CX_LEN;
+ 24 set_p_const CX CX_LEN;
+ 25 set_nil X X_LEN;
+ 26 set_integer IX IX_LEN;
+ 27 set_float FX FX_LEN;
+ 28 set_string SX SX_LEN;
+ 29 set_index I1X I1X_LEN;
+ 30 set_void I1X I1X_LEN;
+ 31 deref RX RX_LEN;
+ 32 set_lambda RI1X RI1X_LEN;
+
+
+ 33 get_variable_t RRX RRX_LEN;
+ 34 get_variable_p ERX ERX_LEN;
+ 35 init_variable_t RCEX RCEX_LEN;
+ 36 init_variable_p ECEX ECEX_LEN;
+ 37 get_m_constant RCX RCX_LEN;
+ 38 get_p_constant RCLX RCLX_LEN;
+ 39 get_integer RIX RIX_LEN;
+ 40 get_float RFX RFX_LEN;
+ 41 get_string RSX RSX_LEN;
+ 42 get_nil RX RX_LEN;
+ 43 get_m_structure RCI1X RCI1X_LEN;
+ 44 get_p_structure RCI1X RCI1X_LEN;
+ 45 get_list RX RX_LEN;
+
+ 46 unify_variable_t RX RX_LEN;
+ 47 unify_variable_p EX EX_LEN;
+ 48 unify_value_t RX RX_LEN;
+ 49 unify_value_p EX EX_LEN;
+ 50 unify_local_value_t RX RX_LEN;
+ 51 unify_local_value_p EX EX_LEN;
+ 52 unify_m_constant CX CX_LEN;
+ 53 unify_p_constant CLX CLX_LEN;
+ 54 unify_integer IX IX_LEN;
+ 55 unify_float FX FX_LEN;
+ 56 unify_string SX SX_LEN;
+ 57 unify_nil X X_LEN;
+ 58 unify_void I1X I1X_LEN;
+
+ /* Instructions for type unification and creation */
+ 59 put_type_variable_t RRX RRX_LEN;
+ 60 put_type_variable_p ERX ERX_LEN;
+ 61 put_type_value_t RRX RRX_LEN;
+ 62 put_type_value_p ERX ERX_LEN;
+ 63 put_type_unsafe_value ERX ERX_LEN;
+ 64 put_type_const RKX RKX_LEN;
+ 65 put_type_structure RKX RKX_LEN;
+ 66 put_type_arrow RX RX_LEN;
+
+ 67 set_type_variable_t RX RX_LEN;
+ 68 set_type_variable_p EX EX_LEN;
+ 69 set_type_value_t RX RX_LEN;
+ 70 set_type_value_p EX EX_LEN;
+ 71 set_type_local_value_t RX RX_LEN;
+ 72 set_type_local_value_p EX EX_LEN;
+ 73 set_type_constant KX KX_LEN;
+
+ 74 get_type_variable_t RRX RRX_LEN;
+ 75 get_type_variable_p ERX ERX_LEN;
+ 76 init_type_variable_t RCEX RCEX_LEN;
+ 77 init_type_variable_p ECEX ECEX_LEN;
+ 78 get_type_value_t RRX RRX_LEN;
+ 79 get_type_value_p ERX ERX_LEN;
+ 80 get_type_constant RKX RKX_LEN;
+ 81 get_type_structure RKX RKX_LEN;
+ 82 get_type_arrow RX RX_LEN;
+
+ 83 unify_type_variable_t RX RX_LEN;
+ 84 unify_type_variable_p EX EX_LEN;
+ 85 unify_type_value_t RX RX_LEN;
+ 86 unify_type_value_p EX EX_LEN;
+ 87 unify_envty_value_t RX RX_LEN;
+ 88 unify_envty_value_p EX EX_LEN;
+ 89 unify_type_local_value_t RX RX_LEN;
+ 90 unify_type_local_value_p EX EX_LEN;
+ 91 unify_envty_local_value_t RX RX_LEN;
+ 92 unify_envty_local_value_p EX EX_LEN;
+ 93 unify_type_constant KX KX_LEN;
+
+ /* Instructions for handling higher-order aspects */
+
+ 94 pattern_unify_t RRX RRX_LEN;
+ 95 pattern_unify_p ERX ERX_LEN;
+ 96 finish_unify X X_LEN;
+ 97 head_normalize_t RX RX_LEN;
+ 98 head_normalize_p EX EX_LEN;
+
+ /* Instructions for handling logical aspects */
+
+ 99 incr_universe X X_LEN;
+ 100 decr_universe X X_LEN;
+ 101 set_univ_tag ECX ECX_LEN;
+ 102 tag_exists_t RX RX_LEN;
+ 103 tag_exists_p EX EX_LEN;
+ 104 tag_variable EX EX_LEN;
+
+ 105 push_impl_point I1ITX I1ITX_LEN;
+ 106 pop_impl_point X X_LEN;
+ 107 add_imports SEGI1LX SEGI1LX_LEN;
+ 108 remove_imports SEGLX SEGLX_LEN;
+ 109 push_import MTX MTX_LEN;
+ 110 pop_imports I1X I1X_LEN;
+
+ /* Control Instructions */
+
+ 111 allocate I1X I1X_LEN;
+ 112 deallocate X X_LEN;
+ 113 call I1LX I1LX_LEN;
+ 114 call_name I1CWPX I1CWPX_LEN;
+ 115 execute LX LX_LEN;
+ 116 execute_name CWPX CWPX_LEN;
+ 117 proceed X X_LEN;
+
+ /* Choice Instructions */
+
+ 118 try_me_else I1LX I1LX_LEN;
+ 119 retry_me_else I1LX I1LX_LEN;
+ 120 trust_me I1WPX I1WPX_LEN;
+ 121 try I1LX I1LX_LEN;
+ 122 retry I1LX I1LX_LEN;
+ 123 trust I1LWPX I1LWPX_LEN;
+ 124 trust_ext I1NX I1NX_LEN;
+ 125 try_else I1LLX I1LLX_LEN;
+ 126 retry_else I1LLX I1LLX_LEN;
+ 127 branch LX LX_LEN;
+
+ /* Indexing Instructions */
+
+ 128 switch_on_term LLLLX LLLLX_LEN;
+ 129 switch_on_constant I1HTX I1HTX_LEN;
+ 130 switch_on_bvar I1BVTX I1BVTX_LEN;
+ 131 switch_on_reg NLLX NLLX_LEN;
+
+ /* Cut Instructions */
+
+ 132 neck_cut X X_LEN;
+ 133 get_level EX EX_LEN;
+ 134 put_level EX EX_LEN;
+ 135 cut EX EX_LEN;
+
+ /* Miscellaneous Instructions */
+
+ 136 call_builtin I1I1WPX I1I1WPX_LEN;
+ 137 builtin I1X I1X_LEN;
+ 138 stop X X_LEN;
+ 139 halt X X_LEN;
+ 140 fail X X_LEN;
+
+ /* new added */
+ 141 create_type_variable EX EX_LEN;
+
+ /* resolved by the linker */
+ 142 execute_link_only CWPX CWPX_LEN;
+ 143 call_link_only I1CWPX I1CWPX_LEN;
+
+ 144 put_variable_te RRX RRX_LEN \ No newline at end of file
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_64.in b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_64.in
new file mode 100644
index 000000000..3aaebdf48
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrformats_64.in
@@ -0,0 +1,346 @@
+{
+type intref = int ref
+type aconstant = Absyn.aconstant
+type akind = Absyn.akind
+
+}
+
+OPERAND TYPES
+
+ P /* (1 byte) padding */
+ WP /* (1 word) padding */
+ R RegInd Byte 1 int /* argument register number */
+ E EnvInd Byte 1 int /* environment variable number */
+ N NextClauseInd Byte 1 int /* next clause number in impt or impl pt */
+ I1 OneByteInt Byte 1 int /* 1 byte natural number */
+ CE ClEnvInd Byte 1 int /* closure environment variable number */
+ SEG ImpSegInd Byte 1 int /* import segment index */
+ C CstIndex TwoBytes 2 aconstant /* constant symbol table index */
+ K KstIndex TwoBytes 2 akind /* kind symbol table index */
+ L CodeLabel CSpacePtr 8 intref /* code location */
+ I Int int 4 int /* integer immediate value */
+ F Float float 4 float /* floating point immediate value */
+ S Str DF_StrDataPtr 2 int /* string pointer */
+ MT ModTab MemPtr 2 int /* module table address */
+ IT ImplTab MemPtr 2 int /* impl table address */
+ HT HashTab MemPtr 2 int /* hash table address */
+ BVT BranchTab MemPtr 2 int /* branch table for bound var indexing */
+ X /* operand list terminator */
+ OPCODE Byte 1
+
+
+INSTR CATEGORY
+
+ MAX OPERAND 12
+
+ X [P P P P P P P X X X X X]
+ X_LEN 8
+
+ RX [R P P P P P P X X X X X]
+ RX_LEN 8; RX_R 1
+
+ EX [E P P P P P P X X X X X]
+ EX_LEN 8; EX_E 1
+
+ I1X [I1 P P P P P P X X X X X]
+ I1X_LEN 8; I1X_I1 1
+
+ CX [P C P P P P X X X X X X]
+ CX_LEN 8; CX_C 2
+
+ KX [P K P P P P X X X X X X]
+ KX_LEN 8; KX_K 2
+
+ IX [P P P P P P P I X X X X]
+ IX_LEN 16; IX_I 8
+
+ FX [P P P P P P P F X X X X]
+ FX_LEN 16; FX_F 8
+
+ SX [P P P P P P P S X X X X]
+ SX_LEN 16; SX_S 8
+
+ MTX [P P P P P P P MT X X X X]
+ MTX_LEN 16; MTX_MT 8
+
+ LX [P P P P P P P L X X X X]
+ LX_LEN 16; LX_L 8
+
+ RRX [R R P P P P P X X X X X]
+ RRX_LEN 8; RRX_R1 1; RRX_R2 2
+
+ ERX [E R P P P P P X X X X X]
+ ERX_LEN 8; ERX_E 1; ERX_R 2
+
+ RCX [R C P P P P X X X X X X]
+ RCX_LEN 8; RCX_R 1; RCX_C 2
+
+ RIX [R P P P P P P I X X X X]
+ RIX_LEN 16; RIX_R 1; RIX_I 8
+
+ RFX [R P P P P P P F X X X X]
+ RFX_LEN 16; RFX_R 1; RFX_F 8
+
+ RSX [R P P P P P P S X X X X]
+ RSX_LEN 16; RSX_R 1; RSX_S 8
+
+ RI1X [R I1 P P P P P X X X X X]
+ RI1X_LEN 8; RI1X_R 1; RI1X_I1 2
+
+ RCEX [R CE P P P P P X X X X X]
+ RCEX_LEN 8; RCEX_R 1; RCEX_CE 2
+
+ ECEX [E CE P P P P P X X X X X]
+ ECEX_LEN 8; ECEX_E 1; ECEX_CE 2
+
+ CLX [P C P P P P L X X X X X]
+ CLX_LEN 16; CLX_C 2; CLX_L 8
+
+ RKX [R K P P P P X X X X X X]
+ RKX_LEN 8; RKX_R 1; RKX_K 2
+
+ ECX [E C P P P P X X X X X X]
+ ECX_LEN 8; ECX_E 1; ECX_C 2
+
+ I1ITX [I1 P P P P P P IT X X X X]
+ I1ITX_LEN 16; I1ITX_I1 1; I1ITX_IT 8
+
+ I1LX [I1 P P P P P P L X X X X]
+ I1LX_LEN 16; I1LX_I1 1; I1LX_L 8
+
+ SEGLX [SEG P P P P P P L X X X X]
+ SEGLX_LEN 16; SEGLX_SEG 1; SEGLX_L 8
+
+ I1LWPX [I1 P P P P P P L WP X X X]
+ I1LWPX_LEN 24; I1LWPX_I1 1; I1LWPX_L 8
+
+ I1NX [I1 N P P P P P X X X X X]
+ I1NX_LEN 8; I1NX_I1 1; I1NX_N 2
+
+ I1HTX [I1 P P P P P P HT X X X X]
+ I1HTX_LEN 16; I1HTX_I1 1; I1HTX_HT 8
+
+ I1BVTX [I1 P P P P P P BVT X X X X]
+ I1BVTX_LEN 16; I1BVTX_I1 1; I1BVTX_BVT 8
+
+ CWPX [P C P P P P WP X X X X X]
+ CWPX_LEN 16; CWPX_C 2
+
+ I1WPX [I1 P P P P P P WP X X X X]
+ I1WPX_LEN 16; I1WPX_I1 1
+
+ RRI1X [R R I1 P P P P X X X X X]
+ RRI1X_LEN 8; RRI1X_R1 1; RRI1X_R2 2; RRI1X_I1 3
+
+ RCLX [R C P P P P L X X X X X]
+ RCLX_LEN 16; RCLX_R 1; RCLX_C 2; RCLX_L 8
+
+ RCI1X [R C I1 P P P X X X X X X]
+ RCI1X_LEN 8; RCI1X_R 1; RCI1X_C 2; RCI1X_I1 4
+
+ SEGI1LX [SEG I1 P P P P P L X X X X]
+ SEGI1LX_LEN 16; SEGI1LX_SEG 1; SEGI1LX_I1 2; SEGI1LX_L 8
+
+ I1LLX [I1 P P P P P P L L X X X]
+ I1LLX_LEN 24; I1LLX_I1 1; I1LLX_L1 8; I1LLX_L2 16
+
+ NLLX [N P P P P P P L L X X X]
+ NLLX_LEN 24; NLLX_N 1; NLLX_L1 8; NLLX_L2 16
+
+ LLLLX [P P P P P P P L L L L X]
+ LLLLX_LEN 40; LLLLX_L1 8; LLLLX_L2 16; LLLLX_L3 24; LLLLX_L4 32
+
+ I1CWPX [I1 C P P P P WP X X X X X]
+ I1CWPX_LEN 16; I1CWPX_I1 1; I1CWPX_C 2
+
+ I1I1WPX [I1 I1 P P P P P WP X X X X]
+ I1I1WPX_LEN 16; I1I1WPX_I11 1; I1I1WPX_I12 2
+
+ CALL_I1_LEN 15
+
+
+INSTRUCTIONS 145
+
+ /* Instructions for term unification and creation */
+
+ 0 put_variable_t RRX RRX_LEN;
+ 1 put_variable_p ERX ERX_LEN;
+ 2 put_value_t RRX RRX_LEN;
+ 3 put_value_p ERX ERX_LEN;
+ 4 put_unsafe_value ERX ERX_LEN;
+ 5 copy_value ERX ERX_LEN;
+ 6 put_m_const RCX RCX_LEN;
+ 7 put_p_const RCX RCX_LEN;
+ 8 put_nil RX RX_LEN;
+ 9 put_integer RIX RIX_LEN;
+ 10 put_float RFX RFX_LEN;
+ 11 put_string RSX RSX_LEN;
+ 12 put_index RI1X RI1X_LEN;
+ 13 put_app RRI1X RRI1X_LEN;
+ 14 put_list RX RX_LEN;
+ 15 put_lambda RRI1X RRI1X_LEN;
+
+ 16 set_variable_t RX RX_LEN;
+ 17 set_variable_te RX RX_LEN;
+ 18 set_variable_p EX EX_LEN;
+ 19 set_value_t RX RX_LEN;
+ 20 set_value_p EX EX_LEN;
+ 21 globalize_pt ERX ERX_LEN;
+ 22 globalize_t RX RX_LEN;
+ 23 set_m_const CX CX_LEN;
+ 24 set_p_const CX CX_LEN;
+ 25 set_nil X X_LEN;
+ 26 set_integer IX IX_LEN;
+ 27 set_float FX FX_LEN;
+ 28 set_string SX SX_LEN;
+ 29 set_index I1X I1X_LEN;
+ 30 set_void I1X I1X_LEN;
+ 31 deref RX RX_LEN;
+ 32 set_lambda RI1X RI1X_LEN;
+
+
+ 33 get_variable_t RRX RRX_LEN;
+ 34 get_variable_p ERX ERX_LEN;
+ 35 init_variable_t RCEX RCEX_LEN;
+ 36 init_variable_p ECEX ECEX_LEN;
+ 37 get_m_constant RCX RCX_LEN;
+ 38 get_p_constant RCLX RCLX_LEN;
+ 39 get_integer RIX RIX_LEN;
+ 40 get_float RFX RFX_LEN;
+ 41 get_string RSX RSX_LEN;
+ 42 get_nil RX RX_LEN;
+ 43 get_m_structure RCI1X RCI1X_LEN;
+ 44 get_p_structure RCI1X RCI1X_LEN;
+ 45 get_list RX RX_LEN;
+
+ 46 unify_variable_t RX RX_LEN;
+ 47 unify_variable_p EX EX_LEN;
+ 48 unify_value_t RX RX_LEN;
+ 49 unify_value_p EX EX_LEN;
+ 50 unify_local_value_t RX RX_LEN;
+ 51 unify_local_value_p EX EX_LEN;
+ 52 unify_m_constant CX CX_LEN;
+ 53 unify_p_constant CLX CLX_LEN;
+ 54 unify_integer IX IX_LEN;
+ 55 unify_float FX FX_LEN;
+ 56 unify_string SX SX_LEN;
+ 57 unify_nil X X_LEN;
+ 58 unify_void I1X I1X_LEN;
+
+ /* Instructions for type unification and creation */
+ 59 put_type_variable_t RRX RRX_LEN;
+ 60 put_type_variable_p ERX ERX_LEN;
+ 61 put_type_value_t RRX RRX_LEN;
+ 62 put_type_value_p ERX ERX_LEN;
+ 63 put_type_unsafe_value ERX ERX_LEN;
+ 64 put_type_const RKX RKX_LEN;
+ 65 put_type_structure RKX RKX_LEN;
+ 66 put_type_arrow RX RX_LEN;
+
+ 67 set_type_variable_t RX RX_LEN;
+ 68 set_type_variable_p EX EX_LEN;
+ 69 set_type_value_t RX RX_LEN;
+ 70 set_type_value_p EX EX_LEN;
+ 71 set_type_local_value_t RX RX_LEN;
+ 72 set_type_local_value_p EX EX_LEN;
+ 73 set_type_constant KX KX_LEN;
+
+ 74 get_type_variable_t RRX RRX_LEN;
+ 75 get_type_variable_p ERX ERX_LEN;
+ 76 init_type_variable_t RCEX RCEX_LEN;
+ 77 init_type_variable_p ECEX ECEX_LEN;
+ 78 get_type_value_t RRX RRX_LEN;
+ 79 get_type_value_p ERX ERX_LEN;
+ 80 get_type_constant RKX RKX_LEN;
+ 81 get_type_structure RKX RKX_LEN;
+ 82 get_type_arrow RX RX_LEN;
+
+ 83 unify_type_variable_t RX RX_LEN;
+ 84 unify_type_variable_p EX EX_LEN;
+ 85 unify_type_value_t RX RX_LEN;
+ 86 unify_type_value_p EX EX_LEN;
+ 87 unify_envty_value_t RX RX_LEN;
+ 88 unify_envty_value_p EX EX_LEN;
+ 89 unify_type_local_value_t RX RX_LEN;
+ 90 unify_type_local_value_p EX EX_LEN;
+ 91 unify_envty_local_value_t RX RX_LEN;
+ 92 unify_envty_local_value_p EX EX_LEN;
+ 93 unify_type_constant KX KX_LEN;
+
+ /* Instructions for handling higher-order aspects */
+
+ 94 pattern_unify_t RRX RRX_LEN;
+ 95 pattern_unify_p ERX ERX_LEN;
+ 96 finish_unify X X_LEN;
+ 97 head_normalize_t RX RX_LEN;
+ 98 head_normalize_p EX EX_LEN;
+
+ /* Instructions for handling logical aspects */
+
+ 99 incr_universe X X_LEN;
+ 100 decr_universe X X_LEN;
+ 101 set_univ_tag ECX ECX_LEN;
+ 102 tag_exists_t RX RX_LEN;
+ 103 tag_exists_p EX EX_LEN;
+ 104 tag_variable EX EX_LEN;
+
+ 105 push_impl_point I1ITX I1ITX_LEN;
+ 106 pop_impl_point X X_LEN;
+ 107 add_imports SEGI1LX SEGI1LX_LEN;
+ 108 remove_imports SEGLX SEGLX_LEN;
+ 109 push_import MTX MTX_LEN;
+ 110 pop_imports I1X I1X_LEN;
+
+ /* Control Instructions */
+
+ 111 allocate I1X I1X_LEN;
+ 112 deallocate X X_LEN;
+ 113 call I1LX I1LX_LEN;
+ 114 call_name I1CWPX I1CWPX_LEN;
+ 115 execute LX LX_LEN;
+ 116 execute_name CWPX CWPX_LEN;
+ 117 proceed X X_LEN;
+
+ /* Choice Instructions */
+
+ 118 try_me_else I1LX I1LX_LEN;
+ 119 retry_me_else I1LX I1LX_LEN;
+ 120 trust_me I1WPX I1WPX_LEN;
+ 121 try I1LX I1LX_LEN;
+ 122 retry I1LX I1LX_LEN;
+ 123 trust I1LWPX I1LWPX_LEN;
+ 124 trust_ext I1NX I1NX_LEN;
+ 125 try_else I1LLX I1LLX_LEN;
+ 126 retry_else I1LLX I1LLX_LEN;
+ 127 branch LX LX_LEN;
+
+ /* Indexing Instructions */
+
+ 128 switch_on_term LLLLX LLLLX_LEN;
+ 129 switch_on_constant I1HTX I1HTX_LEN;
+ 130 switch_on_bvar I1BVTX I1BVTX_LEN;
+ 131 switch_on_reg NLLX NLLX_LEN;
+
+ /* Cut Instructions */
+
+ 132 neck_cut X X_LEN;
+ 133 get_level EX EX_LEN;
+ 134 put_level EX EX_LEN;
+ 135 cut EX EX_LEN;
+
+ /* Miscellaneous Instructions */
+
+ 136 call_builtin I1I1WPX I1I1WPX_LEN;
+ 137 builtin I1X I1X_LEN;
+ 138 stop X X_LEN;
+ 139 halt X X_LEN;
+ 140 fail X X_LEN;
+
+ /* new added */
+ 141 create_type_variable EX EX_LEN;
+
+ /* resolved by the linker */
+ 142 execute_link_only CWPX CWPX_LEN;
+ 143 call_link_only I1CWPX I1CWPX_LEN;
+
+ 144 put_variable_te RRX RRX_LEN \ No newline at end of file
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.c b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.c
new file mode 100644
index 000000000..394f85d9e
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.c
@@ -0,0 +1,650 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/******************************************************************************/
+/* File instrgen-c.h. This files contains function declarations for generating*/
+/* files instructions.h and instructions.c */
+/******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "instrgen-c.h"
+#include "../util/util.h"
+
+#define INDENT1 " "
+#define INDENT1_LEN 4u
+#define PREFIX "INSTR_"
+#define PREFIX_LEN 6u
+#define CATPREFIX "INSTR_CAT_"
+#define CATPREFIX_LEN 10u
+#define DEF "#define "
+#define DEF_LEN 8u
+
+/*************************************************************************/
+/* instructions.h */
+/*************************************************************************/
+#define COMMENTS_BEG_H \
+"/****************************************************************************/\n/* File instructions.h. */ \n/* This file defines instruction operand types, instruction categories and */ \n/* instruction opcode. */ \n/****************************************************************************/ \n"
+
+#define COMPDEF_BEG_H "#ifndef INSTRUCTIONS_H\n#define INSTRUCTIONS_H\n"
+#define COMPDEF_END_H "#endif //INSTRUCTIONS_H\n"
+
+#define INCLUDE_H \
+"#include \"../simulator/mctypes.h\" //to be changed \n#include \"../simulator/dataformats.h\" //to be changed \n"
+
+/* OPERAND TYPES */
+#define OPTYPES_COMMENTS_H \
+"/****************************************************************************/\n/* OPERAND TYPES */ \n/****************************************************************************/ \n\n"
+#define OPTYPES_COMMENTS_H_LEN 300
+
+#define OPERAND_TYPE_BEG \
+"/* possible types of instruction operands */ \ntypedef enum INSTR_OperandType \n{\n"
+#define OPERAND_TYPE_BEG_LEN 200
+
+#define OPERAND_TYPE_END "} INSTR_OperandType;\n\n"
+#define OPERAND_TYPE_END_LEN 30
+
+static char* opTypes = NULL;
+static char* opTypeMaps = NULL ;
+
+void cgenOpTypes(char *name, char* typeName, char* types, char* comments,
+ int last)
+{
+ char* myOpTypes = opTypes;
+ char* myOpTypeMaps = opTypeMaps;
+ size_t length;
+ size_t commentLen = comments ? strlen(comments) : 0u;
+ length = (opTypes ? strlen(opTypes) : 0u) + INDENT1_LEN + PREFIX_LEN +
+ strlen(name) + (comments ? strlen(comments) : 0u) + 30u;
+ opTypes = UTIL_mallocStr(length);
+ if (myOpTypes) { strcpy(opTypes, myOpTypes); strcat(opTypes, INDENT1); }
+ else strcpy(opTypes, INDENT1);
+ if (comments) {
+ strcat(opTypes, "//");
+ strcat(opTypes, comments);
+ strcat(opTypes, "\n");
+ strcat(opTypes, INDENT1);
+ }
+ strcat(opTypes, PREFIX);
+ strcat(opTypes, name);
+ if (last) strcat(opTypes, "\n");
+ else strcat(opTypes, ",\n");
+ if (myOpTypes) free(myOpTypes);
+
+ if (typeName) {
+ length = (opTypeMaps ? strlen(opTypeMaps) : 0u) + PREFIX_LEN +
+ strlen(types) + strlen(typeName) + 30u;
+ opTypeMaps = UTIL_mallocStr(length);
+ if (myOpTypeMaps) {
+ strcpy(opTypeMaps, myOpTypeMaps);
+ strcat(opTypeMaps, "typedef ");
+ } else strcpy(opTypeMaps, "typedef ");
+ strcat(opTypeMaps, types);
+ strcat(opTypeMaps, " ");
+ strcat(opTypeMaps, PREFIX);
+ strcat(opTypeMaps, typeName);
+ strcat(opTypeMaps, ";\n");
+ if (myOpTypeMaps) free(myOpTypeMaps);
+ }
+}
+
+#define OPTYPEMAP_COMMENT \
+"/**************************************************************************/ \n/* Types for instruction operants */ \n/**************************************************************************/ \n\n"
+#define OPTYPEMAP_COMMENT_LEN 300
+
+static char *opcodeType = NULL;
+
+void cgenOpCodeType(char* optype)
+{
+ size_t length = PREFIX_LEN + strlen(optype) + 50;
+ opcodeType = UTIL_mallocStr(length);
+ strcpy(opcodeType, "typedef ");
+ strcat(opcodeType, optype);
+ strcat(opcodeType, " ");
+ strcat(opcodeType, PREFIX);
+ strcat(opcodeType, "OpCode;\n");
+}
+
+
+static char *opsH = NULL;
+
+void cgenOpsH() //assume neither opTypes nor opTypeMaps is empty
+{
+ size_t length = OPTYPES_COMMENTS_H_LEN + OPERAND_TYPE_BEG_LEN +
+ OPTYPEMAP_COMMENT_LEN + OPERAND_TYPE_END_LEN + strlen(opTypes) +
+ strlen(opTypeMaps) + strlen(opcodeType) + 50u;
+ opsH = UTIL_mallocStr(length);
+
+ strcpy(opsH, OPTYPES_COMMENTS_H);
+ strcat(opsH, OPERAND_TYPE_BEG);
+ strcat(opsH, opTypes);
+ strcat(opsH, OPERAND_TYPE_END);
+ strcat(opsH, OPTYPEMAP_COMMENT);
+ strcat(opsH, opcodeType);
+ strcat(opsH, opTypeMaps);
+
+ free(opTypes);
+ free(opcodeType);
+ free(opTypeMaps);
+}
+
+/* INSTRUCTION CATEGORIES */
+#define INSTRCAT_COMMENTS_H \
+"/***************************************************************************/ \n/* INSTRUCTION CATEGORIES */ \n/***************************************************************************/ \n"
+#define INSTRCAT_COMMENTS_H_LEN 300
+
+#define INSTRCAT_TYPE_BEG \
+" /* The names of instruction categories no longer include padding bytes. */\n/* Thus we do not need to maintain two sets of names for different machine */ \n/* architectures. */ \ntypedef enum INSTR_InstrCategory \n{\n"
+#define INSTRCAT_TYPE_BEG_LEN 350
+#define INSTRCAT_TYPE_END "} INSTR_InstrCategory;\n\n"
+#define INSTRCAT_TYPE_END_LEN 50
+
+
+static char *instrcat_type = NULL;
+static char *instrLen = NULL;
+static char *oneInstrLen = NULL;
+static int catNum = 0;
+
+void cgenOneInstrCatH(char* name, int last)
+{
+ char *myInstrCat = instrcat_type, *myInstrLen = instrLen;
+ size_t length = (myInstrCat ? strlen(myInstrCat) : 0u) + strlen(name) +
+ CATPREFIX_LEN + INDENT1_LEN + 10u;
+ instrcat_type = UTIL_mallocStr(length);
+ if (myInstrCat) {
+ strcpy(instrcat_type, myInstrCat);
+ strcat(instrcat_type, INDENT1);
+ } else strcpy(instrcat_type, INDENT1);
+ strcat(instrcat_type, CATPREFIX);
+ strcat(instrcat_type, name);
+ strcat(instrcat_type, " = ");
+ strcat(instrcat_type, UTIL_itoa(catNum));
+ if (last) strcat(instrcat_type, "\n");
+ else strcat(instrcat_type, ",\n");
+ catNum++;
+
+ if (myInstrCat) free(myInstrCat);
+
+ //assume oneInstrLen cannot be empty
+ length = (myInstrLen ? strlen(myInstrLen) : 0u) + strlen(name) +
+ CATPREFIX_LEN + 10u + strlen(oneInstrLen);
+ instrLen = UTIL_mallocStr(length);
+
+ if (myInstrLen) {
+ strcpy(instrLen, myInstrLen);
+ strcat(instrLen, "//");
+ } else strcpy(instrLen, "//");
+ strcat(instrLen, CATPREFIX);
+ strcat(instrLen, name);
+ strcat(instrLen, "\n");
+ strcat(instrLen, oneInstrLen);
+
+ free(oneInstrLen);
+ oneInstrLen = NULL;
+ if (myInstrLen) free(myInstrLen);
+}
+
+#define INSTRLEN_COMMENTS \
+"/**************************************************************************/ \n/* Macros defines instruction lengths and distances between op code and */ \n/* operands. */ \n/* The assumption is that the op code occupies 1 byte. */ \n/**************************************************************************/ \n\n"
+#define INSTRLEN_COMMENTS_LEN 450u
+
+void cgenInstrLength(char* name, char* len)
+{
+ char *myInstrLen = oneInstrLen;
+ size_t length = (myInstrLen ? strlen(myInstrLen) : 0u) + DEF_LEN + PREFIX_LEN
+ + strlen(name) + strlen(len) + 10u;
+ oneInstrLen = UTIL_mallocStr(length);
+ if (myInstrLen) {
+ strcpy(oneInstrLen, myInstrLen);
+ strcat(oneInstrLen, DEF);
+ } else strcpy(oneInstrLen, DEF);
+ strcat(oneInstrLen, PREFIX);
+ strcat(oneInstrLen, name);
+ strcat(oneInstrLen, " ");
+ strcat(oneInstrLen, len);
+ strcat(oneInstrLen, "\n");
+
+ free(myInstrLen);
+}
+
+#define OPTYPE_TAB_H \
+"/****************************************************************************/\n/* OPERAND TYPES TABLE */ \n/****************************************************************************/ \n \n//the operand types array in a given entry \nINSTR_OperandType* INSTR_operandTypes(INSTR_InstrCategory index); \n"
+#define OPTYPE_TAB_H_LEN 500
+
+
+static char *instrCatH = NULL;
+
+void cgenInstrCatH(char* callI1Len)
+{
+ size_t length = strlen(instrcat_type) + strlen(instrLen) +
+ INSTRCAT_TYPE_BEG_LEN + INSTRCAT_TYPE_END_LEN + INSTRCAT_COMMENTS_H_LEN
+ + INSTRLEN_COMMENTS_LEN + OPTYPE_TAB_H_LEN + 160u;
+ instrCatH = UTIL_mallocStr(length);
+
+ strcpy(instrCatH, INSTRCAT_COMMENTS_H);
+ strcat(instrCatH, INSTRCAT_TYPE_BEG);
+ strcat(instrCatH, instrcat_type);
+ strcat(instrCatH, INSTRCAT_TYPE_END);
+ strcat(instrCatH, DEF);
+ strcat(instrCatH, "INSTR_NUM_INSTR_CATS ");
+ strcat(instrCatH, UTIL_itoa(catNum));
+ strcat(instrCatH, "\n\n");
+ strcat(instrCatH, DEF);
+ strcat(instrCatH, "INSTR_CALL_I1_LEN ");
+ strcat(instrCatH, callI1Len);
+ strcat(instrCatH, "\n\n");
+ strcat(instrCatH, INSTRLEN_COMMENTS);
+ strcat(instrCatH, instrLen);
+ strcat(instrCatH, "\n");
+ strcat(instrCatH, OPTYPE_TAB_H);
+
+
+ free(instrcat_type);
+ free(instrLen);
+}
+
+#define INSTR_COMMENTS_H \
+"/***************************************************************************/ \n/* OPCODES OF INSTRUCTIONS */ \n/***************************************************************************/ \n"
+#define INSTR_COMMENTS_H_LEN 250
+
+static char* instrH = NULL;
+
+void cgenOneInstrH(char* comments, char* opCode, char* instrName)
+{
+ char* myInstrH = instrH;
+ size_t length = (myInstrH ? strlen(myInstrH) : 0u) + strlen(instrName) +
+ strlen(opCode) + DEF_LEN + CATPREFIX_LEN +
+ (comments ? strlen(comments) : 0u) + 10u;
+ instrH = UTIL_mallocStr(length);
+ if (myInstrH) {
+ strcpy(instrH, myInstrH);
+ if (comments) {
+ strcat(instrH, "//");
+ strcat(instrH, comments);
+ strcat(instrH, "\n");
+ strcat(instrH, DEF);
+ } else strcat(instrH, DEF);
+ } else {
+ if (comments) {
+ strcpy(instrH, "//");
+ strcat(instrH, comments);
+ strcat(instrH, "\n");
+ strcat(instrH, DEF);
+ } else strcpy(instrH, DEF);
+ }
+ strcat(instrH, instrName);
+ strcat(instrH, " ");
+ strcat(instrH, opCode);
+ strcat(instrH, "\n");
+
+
+ if (myInstrH) free(myInstrH);
+}
+
+#define INSTRTAB_H \
+"/***************************************************************************/ \n/* INSTRUCTION INFORMATION TABLE */ \n/***************************************************************************/ \nINSTR_InstrCategory INSTR_instrType(int index); //instr type in a given entry \nchar* INSTR_instrName(int index); //instr name in a given entry \nint INSTR_instrSize(int index); //instr size in a given entry \n"
+#define INSTRTAB_H_LEN 500
+
+
+
+char* instrOpc = NULL;
+
+void cgenInstrH(char* numInstr)
+{
+ size_t length = INSTR_COMMENTS_H_LEN + strlen(instrH) + DEF_LEN +
+ strlen(numInstr) + INSTRTAB_H_LEN + 20u;
+
+ instrOpc = UTIL_mallocStr(length);
+ strcpy(instrOpc, INSTR_COMMENTS_H);
+ strcat(instrOpc, instrH);
+ strcat(instrOpc, "\n\n");
+ strcat(instrOpc, DEF);
+ strcat(instrOpc, "INSTR_NUM_INSTRS");
+ strcat(instrOpc, " ");
+ strcat(instrOpc, numInstr);
+ strcat(instrOpc, "\n\n");
+ strcat(instrOpc, INSTRTAB_H);
+
+ free(instrH);
+}
+
+
+/* dump instructions.h" */
+void cspitCInstructionsH(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "tables/instructions.h");
+
+ outFile = UTIL_fopenW(filename);
+ fprintf(outFile, "%s\n%s\n%s\n", COMMENTS_BEG_H, COMPDEF_BEG_H, INCLUDE_H);
+ fprintf(outFile, "%s\n", opsH);
+ fprintf(outFile, "%s\n", instrCatH);
+ fprintf(outFile, "%s\n", instrOpc);
+ fprintf(outFile, "%s\n", COMPDEF_END_H);
+ UTIL_fclose(outFile);
+
+ free(opsH);
+ free(instrCatH);
+ free(instrOpc);
+
+ free(filename);
+}
+
+
+/*************************************************************************/
+/* instructions.c */
+/*************************************************************************/
+#define COMMENTS_BEG_C \
+"/****************************************************************************/\n/* */ \n/* File instructions.c. This file defines the operand types table and */ \n/* the instruction information table. */ \n/* */ \n/****************************************************************************/ \n\n"
+#define INCLUDE_C "#include \"instructions.h\"\n"
+
+/*OPERAND TYPE TABLE */
+#define OPTYPE_TAB_COMMENTS \
+"/****************************************************************************/\n/* OPERAND TYPES TABLE */ \n/****************************************************************************/ \n\n"
+#define OPTYPE_TAB_COMMENTS_LEN 250
+
+#define MAX_OP_COMMENTS \
+"/* Max number of operand that could be taken by instructions including the */\n/* padding bytes and one to terminate the list. (machine dependent) */ \n"
+#define MAX_OP_COMMENTS_LEN 200
+
+
+#define OPTYPE_TAB_TYPE \
+"/* this array is indexed by instruction category. For each category, \n INSTR_operandTypeTab contains a string of values indicating the type \n of the operand at that position, terminated by INSTR_X. This \n information is useful when parsing instruction streams. */ \ntypedef INSTR_OperandType \n INSTR_OperandTypeTab[INSTR_NUM_INSTR_CATS][INSTR_MAX_OPERAND]; \n\n"
+
+#define OPTYPE_TAB_TYPE_LEN 500
+
+#define OPTYPE_TAB_BEG "INSTR_OperandTypeTab INSTR_operandTypeTable ={\n"
+#define OPTYPE_TAB_BEG_LEN 80
+#define OPTYPE_TAB_END "};\n\n"
+#define OPTYPE_TAB_END_LEN 10
+
+static char* optypeTabEntry = NULL;
+
+void cgenInstrFormat(char* opType, int last)
+{
+ char* mytabEntry = optypeTabEntry;
+ size_t length = (mytabEntry ? strlen(mytabEntry) : 0u) + PREFIX_LEN +
+ strlen(opType) + 5u;
+ optypeTabEntry = UTIL_mallocStr(length);
+
+ if (mytabEntry) {
+ strcpy(optypeTabEntry, mytabEntry);
+ strcat(optypeTabEntry, PREFIX);
+ } else strcpy(optypeTabEntry, PREFIX);
+ strcat(optypeTabEntry, opType);
+ if (!last) strcat(optypeTabEntry, ", ");
+
+ if (mytabEntry) free(mytabEntry);
+}
+
+static char* optypeTab = NULL;
+
+//assume optypeEntry is not empty
+void cgenOneInstrCatC(char* name, int last)
+{
+ char* myoptypeTab = optypeTab;
+ size_t length = (myoptypeTab ? strlen(myoptypeTab) : 0u) + INDENT1_LEN*2 +
+ strlen(optypeTabEntry) + strlen(name) + 10u + CATPREFIX_LEN;
+
+ optypeTab = UTIL_mallocStr(length);
+
+ if (myoptypeTab) {
+ strcpy(optypeTab, myoptypeTab);
+ strcat(optypeTab, INDENT1);
+ } else strcpy(optypeTab, INDENT1);
+ strcat(optypeTab, "//");
+ strcat(optypeTab, CATPREFIX);
+ strcat(optypeTab, name);
+ strcat(optypeTab, "\n");
+ strcat(optypeTab, INDENT1);
+ strcat(optypeTab, "{");
+ strcat(optypeTab, optypeTabEntry);
+ if (last) strcat(optypeTab, "}\n");
+ else strcat(optypeTab, "},\n");
+
+ free(optypeTabEntry);
+ optypeTabEntry = NULL;
+ if (myoptypeTab) free(myoptypeTab);
+}
+
+#define OPTYPE_FUNC \
+"INSTR_OperandType* INSTR_operandTypes(INSTR_InstrCategory index) \n{ \n return INSTR_operandTypeTable[index]; \n}\n"
+#define OPTYPE_FUNC_LEN 250
+
+static char* opTypeC = NULL;
+
+void cgenInstrCatC(char* max_op){
+ size_t length = OPTYPE_TAB_COMMENTS_LEN + MAX_OP_COMMENTS_LEN +
+ OPTYPE_TAB_TYPE_LEN + OPTYPE_TAB_BEG_LEN + OPTYPE_TAB_END_LEN +
+ strlen(optypeTab) + OPTYPE_FUNC_LEN + strlen(max_op) + 100u;
+ opTypeC = UTIL_mallocStr(length);
+ strcpy(opTypeC, OPTYPE_TAB_COMMENTS);
+ strcat(opTypeC, MAX_OP_COMMENTS);
+ strcat(opTypeC, "#define INSTR_MAX_OPERAND ");
+ strcat(opTypeC, max_op);
+ strcat(opTypeC, "\n\n");
+ strcat(opTypeC, OPTYPE_TAB_TYPE);
+ strcat(opTypeC, OPTYPE_TAB_BEG);
+ strcat(opTypeC, optypeTab);
+ strcat(opTypeC, OPTYPE_TAB_END);
+ strcat(opTypeC, OPTYPE_FUNC);
+}
+
+//dynamic string array type
+typedef struct StringArray
+{
+ char **array;
+ unsigned int length;
+} StringArray;
+
+
+static StringArray instrTab;
+
+void cinitInstrC(int numInstrs)
+{
+ instrTab.length = numInstrs;
+ instrTab.array = (char**)UTIL_malloc(sizeof(char*)*numInstrs);
+}
+
+void cgenOneInstrC(int opcode, char* name, char* cat, char* len, int last)
+{
+ size_t length = strlen(name) + strlen(cat) + strlen(len) + PREFIX_LEN
+ + CATPREFIX_LEN + 20u + INDENT1_LEN ;
+ char* myText = UTIL_mallocStr(length);
+
+ strcpy(myText, INDENT1);
+ strcat(myText, "{\"");
+ strcat(myText, name);
+ strcat(myText, "\", ");
+ strcat(myText, CATPREFIX);
+ strcat(myText, cat);
+ strcat(myText, ", ");
+ strcat(myText, PREFIX);
+ strcat(myText, len);
+ if (last) strcat(myText, "}\n");
+ else strcat(myText, "},\n");
+
+ instrTab.array[opcode] = myText;
+}
+
+#define INSTR_TAB_C_COMMENTS \
+"/****************************************************************************/\n/* INSTRUCTION INFORMATION TABLE */ \n/****************************************************************************/ \n"
+#define INSTR_TAB_C_COMMENTS_LEN 250
+
+#define INSTR_TAB_TYPE \
+"typedef struct //entry of the instruction info table \n{ \n char* name; \n INSTR_InstrCategory type; \n int size; \n} INSTR_InstrInfoTab_; \n\ntypedef INSTR_InstrInfoTab_ INSTR_InstrInfoTab[INSTR_NUM_INSTRS]; \n\n"
+#define INSTR_TAB_TYPE_LEN 600
+
+#define INSTR_TAB_BEG "INSTR_InstrInfoTab INSTR_instrInfoTable ={\n"
+#define INSTR_TAB_BEG_LEN 80
+
+#define INSTR_TAB_END "};\n\n"
+#define INSTR_TAB_END_LEN 10
+
+#define INSTR_TAB_FUNC_C \
+"/* Accessing functions */ \nINSTR_InstrCategory INSTR_instrType(int index) \n{ \n return (INSTR_instrInfoTable[index]).type; \n} \n\nchar* INSTR_instrName(int index) \n{ \n return (INSTR_instrInfoTable[index]).name; \n} \n\nint INSTR_instrSize(int index) \n{ \n return (INSTR_instrInfoTable[index]).size; \n}\n\n"
+#define INSTR_TAB_FUNC_C_LEN 1000
+
+static char* instrC = NULL;
+
+void cgenInstrC()
+{
+ size_t i, length;
+ char *myText = NULL, *myText2;
+ for (i = 0; i < instrTab.length; i++) {
+ if (instrTab.array[i]) {
+ length = (myText ? strlen(myText) : 0u) + strlen(instrTab.array[i]);
+ myText2 = UTIL_mallocStr(length + 100u);
+ if (myText) {
+ strcpy(myText2, myText);
+ strcat(myText2, instrTab.array[i]);
+ } else strcpy(myText2, instrTab.array[i]);
+ free(instrTab.array[i]);
+ free(myText);
+ myText = myText2;
+ }
+ }
+ free(instrTab.array);
+ length = INSTR_TAB_C_COMMENTS_LEN + INSTR_TAB_TYPE_LEN +
+ INSTR_TAB_BEG_LEN + INSTR_TAB_END_LEN + INSTR_TAB_FUNC_C_LEN +
+ strlen(myText);
+ instrC = UTIL_mallocStr(length);
+ strcpy(instrC, INSTR_TAB_C_COMMENTS);
+ strcat(instrC, INSTR_TAB_TYPE);
+ strcat(instrC, INSTR_TAB_BEG);
+ strcat(instrC, myText);
+ strcat(instrC, INSTR_TAB_END);
+ strcat(instrC, INSTR_TAB_FUNC_C);
+ free(myText);
+}
+
+
+/* dump instructions.c" */
+void cspitCInstructionsC(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "tables/instructions.c");
+
+ outFile = UTIL_fopenW(filename);
+ fprintf(outFile, "%s\n%s\n", COMMENTS_BEG_C, INCLUDE_C);
+ fprintf(outFile, "%s\n", opTypeC);
+ fprintf(outFile, "%s\n", instrC);
+ UTIL_fclose(outFile);
+
+ free(opTypeC);
+ free(instrC);
+ free(filename);
+}
+
+/* simdispatch.c */
+#define SIMPREFIX "SINSTR_"
+#define SIMPREFIX_LEN 7
+
+#define SIMDIS_COMMENTS \
+"/***************************************************************************/ \n/* */ \n/* File simdispatch.c. The instruction dispatch table used by the */ \n/* simulator is defined here as an array of function pointers, each of */ \n/* which refers to a function realizing a corresponding instruction. */ \n/* These functions are defined in the file ./siminstr.c. */ \n/***************************************************************************/ \n\n"
+#define SIMDIS_COMMENTS_LEN 600
+
+#define SIMDIS_INCLUDE \
+"#include \"../tables/instructions.h\" //to be modified \n#include \"siminstr.h\" \n#include \"simdispatch.h\"\n\n"
+#define SIMDIS_INCLUDE_LEN 250
+
+#define SIMDIS_TAB_BEG \
+"SDP_InstrFunctionPtr SDP_dispatchTable[INSTR_NUM_INSTRS] = {\n"
+#define SIMDIS_TAB_BEG_LEN 80
+
+#define SIMDIS_TAB_END "};\n"
+#define SIMDIS_TAB_END_LEN 10
+
+static StringArray dispatchTab;
+
+void cinitSimDispatch(int size)
+{
+ dispatchTab.length = size;
+ dispatchTab.array = (char**)UTIL_malloc(sizeof(char*)*size);
+}
+
+void cgenOneSimDispatch(int ind, char* instr, int last)
+{
+ size_t length = strlen(instr) + SIMPREFIX_LEN + INDENT1_LEN + 10u;
+ char* myText = UTIL_mallocStr(length);
+
+ strcpy(myText, INDENT1);
+ strcat(myText, SIMPREFIX);
+ strcat(myText, instr);
+ if (last) strcat(myText, "\n");
+ else strcat(myText, ",\n");
+
+ dispatchTab.array[ind] = myText;
+}
+
+static char* dispatch = NULL;
+
+void cgenSimDispatch()
+{
+ size_t i, length;
+ char *myText = NULL, *myText2;
+
+ for(i = 0; i < dispatchTab.length; i++) {
+ if (dispatchTab.array[i]){
+ length = (myText ? strlen(myText) : 0)+strlen(dispatchTab.array[i]);
+ myText2 = UTIL_mallocStr(length);
+ if (myText){
+ strcpy(myText2, myText);
+ strcat(myText2, dispatchTab.array[i]);
+ } else strcpy(myText2, dispatchTab.array[i]);
+ free(dispatchTab.array[i]);
+ free(myText);
+ myText = myText2;
+ }
+ }
+ free(dispatchTab.array);
+ length = SIMDIS_COMMENTS_LEN + SIMDIS_INCLUDE_LEN + SIMDIS_TAB_BEG_LEN
+ + SIMDIS_TAB_BEG_LEN + SIMDIS_TAB_END_LEN + strlen(myText);
+ dispatch = UTIL_mallocStr(length);
+ strcpy(dispatch, SIMDIS_COMMENTS);
+ strcat(dispatch, SIMDIS_INCLUDE);
+ strcat(dispatch, SIMDIS_TAB_BEG);
+ strcat(dispatch, myText);
+ strcat(dispatch, SIMDIS_TAB_END);
+
+ free(myText);
+}
+
+void cspitSimDispatch(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "simulator/simdispatch.c");
+ outFile = UTIL_fopenW(filename);
+ fprintf(outFile, "%s\n", dispatch);
+
+ free(dispatch);
+ UTIL_fclose(outFile);
+ free(filename);
+}
+
+
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.h b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.h
new file mode 100644
index 000000000..0c1c6b6fd
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-c.h
@@ -0,0 +1,70 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/******************************************************************************/
+/* File instrgen-c.h. This files contains function declarations for generating*/
+/* files instructions.h and instructions.c */
+/******************************************************************************/
+
+/* instructions.h */
+/* generating operand types */
+
+void cgenOpTypes(char *name, char* typeName, char* types, char* comments,
+ int last);
+
+void cgenOpCodeType(char* optype);
+
+void cgenOpsH();
+
+void cgenInstrCatH(char* callI1Len);
+
+void cgenOneInstrCatH(char* name, int last);
+
+void cgenInstrLength(char* name, char* length);
+
+void cgenInstrH(char* numInstr);
+
+void cgenOneInstrH(char* comments, char* opcode, char* name);
+
+
+/* dump instructions.h" */
+void cspitCInstructionsH(char * root);
+
+/* instructions.c */
+
+void cgenInstrFormat(char* opType, int last);
+
+void cgenOneInstrCatC(char* name, int last);
+
+void cgenInstrCatC(char* max_op);
+
+void cinitInstrC(int numInstr);
+void cgenOneInstrC(int opcode, char* name, char* cat, char* len, int last);
+void cgenInstrC();
+
+/* dump instructions.c" */
+void cspitCInstructionsC(char * root);
+
+/* simdispatch.c */
+void cinitSimDispatch(int size);
+void cgenOneSimDispatch(int ind, char* instr, int last);
+void cgenSimDispatch();
+
+void cspitSimDispatch(char * root);
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.c b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.c
new file mode 100644
index 000000000..5309509c8
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.c
@@ -0,0 +1,841 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/*************************************************************************/
+/* functions for generating ocaml instr.mli and instr.ml */
+/*************************************************************************/
+#include "../util/util.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+static char* addLine(char* str, char* addOn)
+{
+ size_t length = (str ? strlen(str) : 0) + strlen(addOn) + 2;
+ char* newStr = UTIL_mallocStr(length);
+
+ if (str) {
+ strcpy(newStr, str);
+ strcat(newStr, addOn);
+ } else strcpy(newStr, addOn);
+ strcat(newStr, "\n\n");
+ return newStr;
+}
+
+static char* addStr(char* str, char* addOn)
+{
+ size_t length = (str ? strlen(str) : 0) + strlen(addOn);
+ char* newStr = UTIL_mallocStr(length);
+
+ if (str) {
+ strcpy(newStr, str);
+ strcat(newStr, addOn);
+ } else strcpy(newStr, addOn);
+ return newStr;
+}
+
+
+/**********************************************************************/
+/* auxiliary functions for making ocaml language constructs */
+/**********************************************************************/
+#define TYPE_SUFFIX "type"
+#define SIZE_SUFFIX "Size"
+#define WRITE_PREFIX "write"
+#define READ_PREFIX "read"
+#define DISPLAY_PREFIX "display"
+#define INDENT " "
+#define INDENT2 " "
+#define WRITE "Bytecode.write"
+#define READ "Bytecode.read"
+#define DISPLAY "Bytecode.display"
+#define INSCAT_PREFIX "inscat"
+#define INS_PREFIX "Ins_"
+
+static char* OC_mkVarDec(char* varName, char* varType)
+{
+ size_t length = strlen(varName) + strlen(varType) + 10;
+ char* vardec = UTIL_mallocStr(length);
+
+ strcpy(vardec, "val ");
+ strcat(vardec, varName);
+ strcat(vardec, " : ");
+ strcat(vardec, varType);
+ strcat(vardec, "\n");
+
+ return vardec;
+}
+
+static char* OC_mkVarDef(char* varName, char* defs)
+{
+ size_t length = strlen(varName) + strlen(defs) + 10;
+ char* vardef = UTIL_mallocStr(length);
+
+ strcpy(vardef, "let ");
+ strcat(vardef, varName);
+ strcat(vardef, " = ");
+ strcat(vardef, defs);
+ strcat(vardef, "\n");
+
+ return vardef;
+}
+
+static char* OC_mkTypeDec(char* typeName, char* defs)
+{
+ size_t length = strlen(typeName) + strlen(defs) + 10;
+ char* typedec = UTIL_mallocStr(length);
+
+ strcpy(typedec, "type ");
+ strcat(typedec, typeName);
+ strcat(typedec, " = ");
+ strcat(typedec, defs);
+ strcat(typedec, "\n");
+
+ return typedec;
+}
+
+static char* OC_mkFunc(char* funcName, char* arg, char* body)
+{
+ size_t length = strlen(funcName) + strlen(arg) + strlen(body) + 20;
+ char* func = UTIL_mallocStr(length);
+
+ strcpy(func, "let ");
+ strcat(func, funcName);
+ strcat(func, " ");
+ strcat(func, arg);
+ strcat(func, " = ");
+ strcat(func, body);
+ strcat(func, "\n");
+
+ return func;
+}
+
+static char* OC_mkCrossType(char *lop, char *rop)
+{
+ size_t length = strlen(lop) + strlen(rop) + 5;
+ char* crossType = UTIL_mallocStr(length);
+
+ strcpy(crossType, lop);
+ strcat(crossType, " * ");
+ strcat(crossType, rop);
+
+ return crossType;
+}
+
+static char* OC_mkValueCtr(char* ctrName, char* types)
+{
+ size_t length = strlen(ctrName) + strlen(types) + 10;
+ char* ctr = UTIL_mallocStr(length);
+
+ strcpy(ctr, ctrName);
+ strcat(ctr, " of ");
+ strcat(ctr, types);
+ return ctr;
+}
+
+static char* OC_mkDisjValueCtrs(char* prev, char* next)
+{
+ size_t length = strlen(prev) + strlen(next) + 10;
+ char* ctr = UTIL_mallocStr(length);
+
+ strcpy(ctr, prev);
+ strcat(ctr, "\n");
+ strcat(ctr, INDENT);
+ strcat(ctr, "| ");
+ strcat(ctr, next);
+
+ return ctr;
+}
+
+static char* OC_mkFuncSeq(char* prev, char* new)
+{
+ size_t length = strlen(prev) + strlen(new) + 20;
+ char* funcSeq = UTIL_mallocStr(length);
+
+ strcpy(funcSeq, prev);
+ strcat(funcSeq, "; ");
+ strcat(funcSeq, new);
+ return funcSeq;
+}
+
+static char* OC_mkArgList(char* prev, char* new)
+{
+ size_t length = strlen(prev) + strlen(new) + 2;
+ char* args = UTIL_mallocStr(length);
+
+ strcpy(args, prev);
+ strcat(args, ", ");
+ strcat(args, new);
+
+ return args;
+}
+
+static char* OC_mkStrConcat(char* prev, char* new)
+{
+ size_t length = strlen(prev) + strlen(new) + 20;
+ char* str = UTIL_mallocStr(length);
+
+ strcpy(str, "(");
+ strcat(str, prev);
+ strcat(str, ") ^ \", \" ^ (");
+ strcat(str, new);
+ strcat(str, ")");
+
+ return str;
+}
+
+
+static char* OC_mkArrow(char* left, char* right)
+{
+ size_t length = strlen(left) + strlen(right) + 20;
+ char* arrow = UTIL_mallocStr(length);
+
+ strcpy(arrow, left);
+ strcat(arrow, " -> ");
+ strcat(arrow, right);
+
+ return arrow;
+}
+
+static char* OC_mkStructure(char* func, char* arg)
+{
+ size_t length = strlen(func) + strlen(arg) + 5;
+ char* app = UTIL_mallocStr(length);
+
+ strcpy(app, func);
+ strcat(app, "(");
+ strcat(app, arg);
+ strcat(app, ")");
+
+ return app;
+}
+
+static char* OC_mkCond(char* cond, char* branch)
+{
+ size_t length = strlen(cond) + strlen(branch) + 20;
+ char* str = UTIL_mallocStr(length);
+
+ strcpy(str, INDENT);
+ strcat(str, "if ");
+ strcat(str, cond);
+ strcat(str, " then ");
+ strcat(str, branch);
+ strcat(str, "\n");
+ strcat(str, INDENT);
+ strcat(str, "else");
+
+ return str;
+}
+
+static char* OC_mkLetIn(char* varName, char* def)
+{
+ size_t length = strlen(varName) + strlen(def) + 20;
+ char* str = UTIL_mallocStr(length);
+
+ strcpy(str, INDENT);
+ strcat(str, "let ");
+ strcat(str, varName);
+ strcat(str, " = ");
+ strcat(str, def);
+ strcat(str, " in\n");
+
+ return str;
+}
+
+/**************************************************************************/
+/* type definitions */
+/**************************************************************************/
+static char* typeDefs;
+
+void ocgenInclude(char* include)
+{
+ typeDefs = include;
+}
+
+/**************************************************************************/
+/* operand types */
+/**************************************************************************/
+static char* opTypes;
+static char* opSizesMLI;
+static char* opSizesML;
+static char* writeFuncs;
+static char* readFuncs;
+
+static char* ocgenWriteOpFunc(char* typeName, char* compType, int numBytes)
+{
+ char* funcName = UTIL_appendStr(WRITE_PREFIX, typeName);
+ char* numBytesText = UTIL_itoa(numBytes);
+ char* arg = "arg";
+ char* funcBody1 = UTIL_mallocStr(strlen(WRITE) + strlen(compType) +
+ strlen(numBytesText));
+ char *funcBody2, *func;
+
+ strcpy(funcBody1, WRITE);
+ strcat(funcBody1, compType);
+ strcat(funcBody1, numBytesText); free(numBytesText);
+
+ funcBody2 = UTIL_appendStr(funcBody1, " arg"); free(funcBody1);
+ func = OC_mkFunc(funcName, arg, funcBody2);
+ free(funcName); free(funcBody2);
+ return func;
+}
+
+static char* ocgenReadOpFunc(char* typeName, char* compType, int numBytes)
+{
+ char* funcName = UTIL_appendStr(READ_PREFIX, typeName);
+ char* numBytesText = UTIL_itoa(numBytes);
+ char* arg = "()";
+ char* funcBody1 = UTIL_mallocStr(strlen(READ) + strlen(compType) +
+ strlen(numBytesText));
+ char* funcBody2, *func;
+
+ strcpy(funcBody1, READ);
+ strcat(funcBody1, compType);
+ strcat(funcBody1, numBytesText); free(numBytesText);
+
+ funcBody2 = UTIL_appendStr(funcBody1, " ()"); free(funcBody1);
+ func = OC_mkFunc(funcName, arg, funcBody2);
+ free(funcName); free(funcBody2);
+ return func;
+}
+
+void ocgenOpType(char* typeName, int numBytes, char* compType)
+{
+ /* generate type declarations*/
+ char* myName = UTIL_lowerCase(typeName);
+ char* myTypeName = UTIL_appendStr(myName, TYPE_SUFFIX);
+ char* myOpType = OC_mkTypeDec(myTypeName, compType);
+ char* myopTypes = addStr(opTypes, myOpType);
+ /* generate write functions */
+ char* func = ocgenWriteOpFunc(typeName, compType, numBytes);
+ char* myWriteFuncs = addStr(writeFuncs, func);
+ /* generate read functions */
+ char* readFunc = ocgenReadOpFunc(typeName, compType, numBytes);
+ char* myReadFuncs = addStr(readFuncs, readFunc);
+
+ /* generate sizes */
+ if (numBytes < 4) {
+ char* mySizeName = UTIL_appendStr(myName, SIZE_SUFFIX);
+ char* myOpSizeMLI = OC_mkVarDec(mySizeName, "int");
+ char* size = UTIL_itoa((int)(0 /*pow(2,(numBytes * 8))-1*/));
+ char* myOpSizeML = OC_mkVarDef(mySizeName, size);
+ char* myopSizesMLI = addStr(opSizesMLI, myOpSizeMLI);
+ char* myopSizesML = addStr(opSizesML, myOpSizeML);
+
+ free(mySizeName); free(size); free(myOpSizeMLI); free(myOpSizeML);
+ free(opSizesMLI); free(opSizesML);
+ opSizesMLI = myopSizesMLI;
+ opSizesML = myopSizesML;
+ }
+ free(myTypeName); free(myName);
+ free(opTypes); free(myOpType);
+ opTypes = myopTypes;
+ free(writeFuncs); free(func);
+ writeFuncs = myWriteFuncs;
+ free(readFuncs); free(readFunc);
+ readFuncs = myReadFuncs;
+}
+
+void ocgenOpCodeType(int numBytes)
+{
+ char* mySizeName = UTIL_appendStr("opcode", SIZE_SUFFIX);
+ char* size = UTIL_itoa((int)(0 /*pow(2,(numBytes * 8))-1*/));
+ char* myOpCodeSizeMLI = OC_mkVarDec(mySizeName, "int");
+ char* myOpCodeSizeML = OC_mkVarDef(mySizeName, size);
+ char* myopSizeMLI = addLine(opSizesMLI, myOpCodeSizeMLI);
+ char* myopSizeML = addLine(opSizesML, myOpCodeSizeML);
+ char* func = ocgenWriteOpFunc("opcode", "int", numBytes);
+ char* myWriteFuncs = addLine(writeFuncs, func);
+ char* readFunc = ocgenReadOpFunc("opcode", "int", numBytes);
+ char* myReadFuncs = addLine(readFuncs, readFunc);
+
+ free(size); free(mySizeName);
+ free(opSizesMLI); free(myOpCodeSizeMLI);
+ free(opSizesML); free(myOpCodeSizeML);
+ free(writeFuncs); free(func);
+ free(readFuncs); free(readFunc);
+ opSizesMLI = myopSizeMLI;
+ opSizesML = myopSizeML;
+ writeFuncs = myWriteFuncs;
+ readFuncs = myReadFuncs;
+}
+
+static char* opMLI;
+static char* opML;
+
+void ocgenOps()
+{
+ char* wordSizeName = "wordSize";
+ char* wordSizeMLI = OC_mkVarDec(wordSizeName, "int");
+ char* wordSize = UTIL_itoa(sizeof(void*));
+ char* wordSizeML = OC_mkVarDef(wordSizeName, wordSize);
+ char* text;
+
+ free(wordSize);
+ opMLI = addLine(opMLI, wordSizeMLI); free(wordSizeMLI);
+ text = addLine(opMLI, opSizesMLI); free(opMLI); free(opSizesMLI);
+ opMLI = addLine(text, opTypes); free(text);
+
+ opML = addLine(opML, wordSizeML); free(wordSizeML);
+ text = addLine(opML, opSizesML); free(opML); free(opSizesML);
+ opML = addLine(text, writeFuncs); free(text); free(writeFuncs);
+ text = addLine(opML, readFuncs); free(opML); free(readFuncs);
+ opML = addLine(text, opTypes); free(text); free(opTypes);
+}
+
+/****************************************************************************/
+/* instruction categories */
+/****************************************************************************/
+static char* instrCatWriteFunc = NULL;
+static char* instrCatReadFunc = NULL;
+static char* instrCatDisplayFunc = NULL;
+static char* instrCatType = NULL;
+static int argInd = 1;
+static char* argList = NULL;
+
+void ocgenInstrFormat(char* opName)
+{
+ char *myop, *myOpName, *myFuncName, *myArgInd, *myFuncCall, *myArg,
+ *myArgList, *myinstrCatType, *myinstrCatWriteFunc, *myReadBody,
+ *myinstrCatReadFunc, * myinstrCatDisplayFunc;
+
+ if (strcmp(opName, "P") == 0 || strcmp(opName, "WP") == 0 ||
+ strcmp(opName, "X") == 0) return;
+
+ //type declaration
+ myop = UTIL_lowerCase(opName);
+ myOpName = UTIL_appendStr(myop, TYPE_SUFFIX); free(myop);
+ if (instrCatType) {
+ myinstrCatType = OC_mkCrossType(instrCatType, myOpName);
+ free(instrCatType); free(myOpName);
+ instrCatType = myinstrCatType;
+ } else instrCatType = myOpName;
+
+ //argument
+ myArgInd = UTIL_itoa(argInd);
+ argInd++;
+ myArg = UTIL_appendStr("arg", myArgInd); free(myArgInd);
+ //argument list
+ if (argList) {
+ myArgList = OC_mkArgList(argList, myArg); free(argList);
+ argList = myArgList;
+ } else argList = myArg;
+
+ //write function
+ myFuncName = UTIL_appendStr(WRITE_PREFIX, opName);
+ myFuncCall = UTIL_mallocStr(strlen(myFuncName) + strlen(myArg) + 5);
+ strcpy(myFuncCall, myFuncName); free(myFuncName);
+ strcat(myFuncCall, " ");
+ strcat(myFuncCall, myArg);
+ if (instrCatWriteFunc) {
+ myinstrCatWriteFunc = OC_mkFuncSeq(instrCatWriteFunc, myFuncCall);
+ free(instrCatWriteFunc);
+ instrCatWriteFunc = myinstrCatWriteFunc;
+ free(myFuncCall);
+ } else instrCatWriteFunc = myFuncCall;
+
+ //read function
+ myFuncName = UTIL_appendStr(READ_PREFIX, opName);
+ myFuncCall = UTIL_mallocStr(strlen(myFuncName) + 5);
+ strcpy(myFuncCall, myFuncName); free(myFuncName);
+ strcat(myFuncCall, " ()");
+ myReadBody = OC_mkLetIn(myArg, myFuncCall); free(myFuncCall);
+ if (instrCatReadFunc) {
+ myinstrCatReadFunc = UTIL_appendStr(instrCatReadFunc, myReadBody);
+ free(instrCatReadFunc);
+ instrCatReadFunc = myinstrCatReadFunc;
+ free(myReadBody);
+ } else instrCatReadFunc = myReadBody;
+
+ //display function
+ myFuncName = UTIL_appendStr(DISPLAY, opName);
+ myFuncCall = UTIL_mallocStr(strlen(myFuncName) + strlen(myArg) + 5);
+ strcpy(myFuncCall, myFuncName); free(myFuncName);
+ strcat(myFuncCall, " ");
+ strcat(myFuncCall, myArg);
+ if (instrCatDisplayFunc) {
+ myinstrCatDisplayFunc = OC_mkStrConcat(instrCatDisplayFunc, myFuncCall);
+ free(instrCatDisplayFunc);
+ instrCatDisplayFunc = myinstrCatDisplayFunc;
+ free(myFuncCall);
+ } else instrCatDisplayFunc = myFuncCall;
+}
+
+static char* instrCatTypes;
+static char* instrCatWriteFuncs;
+static char* instrCatReadFuncs;
+static char* instrCatDisplayFuncs;
+
+
+void ocgenOneInstrCat(char* catName)
+{
+ char *myCatName, *myInstrCatType, *myInstrCatTypes, *myArgs,
+ *myWriteFuncName, *myWriteFunc, *myInstrCatWriteFuncs,
+ *myReadFuncName, *myReadFunc, *myReadFuncBody, *myInstrCatReadFuncs,
+ *myDisplayFuncName, *myDisplayFunc, *myInstrCatDisplayFuncs, *myArgs2, *temp;
+
+ if (instrCatType) {
+ myCatName = UTIL_appendStr(INSCAT_PREFIX, catName);
+ myInstrCatType = OC_mkTypeDec(myCatName, instrCatType);
+ myInstrCatTypes = addStr(instrCatTypes, myInstrCatType);
+
+ myArgs = UTIL_mallocStr(strlen(argList) + 5);
+ strcpy(myArgs, "(");
+ strcat(myArgs, argList);
+ strcat(myArgs, ")");
+
+ /* write function */
+ myWriteFuncName = UTIL_appendStr(WRITE_PREFIX, catName);
+ myWriteFunc = OC_mkFunc(myWriteFuncName, myArgs, instrCatWriteFunc);
+ myInstrCatWriteFuncs = addStr(instrCatWriteFuncs, myWriteFunc);
+
+ /* read function */
+ myReadFuncName = UTIL_appendStr(READ_PREFIX, catName);
+ myArgs2 = UTIL_appendStr(INDENT, myArgs);
+ temp = UTIL_appendStr(instrCatReadFunc, myArgs2); free(myArgs2);
+ myReadFuncBody= UTIL_appendStr("\n", temp); free(temp);
+ myReadFunc = OC_mkFunc(myReadFuncName, "()", myReadFuncBody);
+ myInstrCatReadFuncs = addStr(instrCatReadFuncs, myReadFunc);
+
+ /* display function */
+ myDisplayFuncName = UTIL_appendStr(DISPLAY_PREFIX, catName);
+ myDisplayFunc = OC_mkFunc(myDisplayFuncName, myArgs, instrCatDisplayFunc);
+ myInstrCatDisplayFuncs = addStr(instrCatDisplayFuncs, myDisplayFunc);
+
+
+ free(myCatName); free(myInstrCatType);
+ free(instrCatType); free(instrCatTypes);
+ free(myWriteFuncName); free(myWriteFunc);
+ free(instrCatWriteFunc); free(instrCatWriteFuncs);
+ free(myReadFuncName); free(myReadFunc);
+ free(instrCatReadFunc); free(instrCatReadFuncs);
+ free(myDisplayFuncName); free(myDisplayFunc);
+ free(instrCatDisplayFunc); free(instrCatDisplayFuncs);
+ free(argList);
+
+ argList = NULL; argInd = 1;
+ instrCatType = NULL;
+ instrCatWriteFunc = NULL; instrCatReadFunc = NULL;
+ instrCatDisplayFunc = NULL;
+ instrCatTypes = myInstrCatTypes;
+ instrCatWriteFuncs = myInstrCatWriteFuncs;
+ instrCatReadFuncs = myInstrCatReadFuncs;
+ instrCatDisplayFuncs = myInstrCatDisplayFuncs;
+ }
+}
+
+static char* instrCatLength;
+void ocgenInstrLength(char* varName, char* numBytes)
+{
+ char* myVarName = UTIL_appendStr(INSCAT_PREFIX, varName);
+ char* varDef = OC_mkVarDef(myVarName, numBytes);
+ char* myInstrCatLength = addStr(instrCatLength, varDef);
+
+ free(myVarName); free(varDef); free(instrCatLength);
+ instrCatLength = myInstrCatLength;
+}
+
+static char* instrCatMLI;
+static char* instrCatML;
+
+void ocgenInstrCat()
+{
+ char* text = instrCatTypes;
+ char* text2 = addLine(text, "\n");
+
+ instrCatMLI = text;
+
+ text = addLine(text2, instrCatWriteFuncs);
+ free(instrCatWriteFuncs); free(text2);
+
+ text2 = addLine(text, instrCatReadFuncs);
+ free(instrCatReadFuncs); free(text);
+
+ text = addLine(text2, instrCatDisplayFuncs);
+ free(instrCatDisplayFuncs); free(text2);
+
+ instrCatML = addLine(text, instrCatLength);
+ free(text); free(instrCatLength);
+}
+
+/****************************************************************************/
+/* instructions */
+/****************************************************************************/
+#define GETSIZE_PREFIX "getSize_"
+#define WRITEOPCODE "writeopcode "
+
+static char* instructionTypes;
+static char* insWriteFuncBody;
+static char* insReadFuncBody;
+static char* insDisplayFuncBody;
+static char* insSizesDec;
+static char* insSizesDef;
+
+static void ocgenReadFuncBody(char* opcode, char* myInsName, char* myInsLength, char* insCat,
+ int last)
+{
+ char *ins, *readArgs, *returnValue, *myReadFuncBody, *mycond, *tmp;
+
+ if (strcmp(insCat, "X") == 0) ins = myInsName;
+ else {
+ readArgs = UTIL_appendStr(READ_PREFIX, insCat);
+ ins = UTIL_mallocStr(strlen(readArgs) + strlen(myInsName) + 10);
+ strcpy(ins, myInsName);
+ strcat(ins, " (");
+ strcat(ins, readArgs);
+ strcat(ins, " ())");
+ free(readArgs);
+ }
+ returnValue = UTIL_mallocStr(strlen(ins) + strlen(myInsLength) + 5);
+ strcpy(returnValue, "(");
+ strcat(returnValue, ins);
+ strcat(returnValue, ", ");
+ strcat(returnValue, myInsLength);
+ strcat(returnValue, ")");
+
+ if (last) {
+ tmp = UTIL_appendStr(" ", returnValue); free(returnValue);
+ }else {
+ mycond = UTIL_mallocStr(strlen(opcode) + 10);
+ strcpy(mycond, "opcode = ");
+ strcat(mycond, opcode);
+ tmp = OC_mkCond(mycond, returnValue);
+ free(mycond); free(returnValue);
+ }
+
+ if (insReadFuncBody) {
+ myReadFuncBody = UTIL_appendStr(insReadFuncBody, tmp);
+ free(insReadFuncBody); free(tmp);
+ insReadFuncBody = myReadFuncBody;
+ } else insReadFuncBody = tmp;
+
+}
+
+static char* OC_mkWS(int size)
+{
+ int i;
+ char* text;
+
+ if (size > 0) {
+ text = UTIL_mallocStr(size);
+ for (i = 0; i < size; i++) text[i]= ' ';
+ text[size] = '\0';
+ } else text = strdup(" ");
+
+ return text;
+}
+
+static void ocgenDisplayFuncBody(char* pattern, char* insName, char* insLength,
+ char* insCat)
+{
+ char *displayargs, *funcBody, *myInsName, *ins, *returnValue, *insText,
+ *myDisplayFuncBody;
+
+ myInsName = UTIL_appendStr(insName, OC_mkWS(25u - strlen(insName)));
+ insText = UTIL_mallocStr(strlen(myInsName) + 5);
+ strcpy(insText, "\"");
+ strcat(insText, myInsName); free(myInsName);
+ strcat(insText, "\"");
+
+
+ if (strcmp(insCat, "X") == 0) ins = insText;
+ else {
+ displayargs = UTIL_appendStr(DISPLAY_PREFIX, insCat);
+ ins = UTIL_mallocStr(strlen(displayargs) + strlen(insText) + 10);
+ strcpy(ins, insText);
+ strcat(ins, "^ (");
+ strcat(ins, displayargs);
+ strcat(ins, " arg)");
+ free(displayargs); free(insText);
+ }
+
+ returnValue = UTIL_mallocStr(strlen(ins) + strlen(insLength) + 5);
+ strcpy(returnValue, "(");
+ strcat(returnValue, ins);
+ strcat(returnValue, ", ");
+ strcat(returnValue, insLength);
+ strcat(returnValue, ")");
+
+ funcBody = OC_mkArrow(pattern, returnValue);
+ free(returnValue);
+
+ if (insDisplayFuncBody) {
+ myDisplayFuncBody = OC_mkDisjValueCtrs(insDisplayFuncBody, funcBody);
+ free(insDisplayFuncBody); free(funcBody);
+ insDisplayFuncBody = myDisplayFuncBody;
+ } else {
+ insDisplayFuncBody = UTIL_appendStr(INDENT2, funcBody);
+ free(funcBody);
+ }
+}
+
+
+void ocgenOneInstr(char* opcode, char* insName, char* insCat, char* insLength,
+ int last)
+{
+ char *myCatName, *myInsName, *myValueCtr, *myInstrTypes;
+ char *myInsSizeName, *myInsLength, *mySizeDef, *mySizeDec, *mySizeDefs,
+ *mySizeDecs;
+ char *myPattern, *myWriteOpCodeFunc, *myfuncBody, *myFunc, *myInsWriteFuncBody;
+
+ /* value constructors for type instruction */
+ myInsName = UTIL_appendStr(INS_PREFIX, insName);
+ if (strcmp(insCat, "X") == 0) {
+ myValueCtr = myInsName;
+ } else {
+ myCatName = UTIL_appendStr(INSCAT_PREFIX, insCat);
+ myValueCtr = OC_mkValueCtr(myInsName, myCatName); free(myCatName);
+ }
+ if (instructionTypes) {
+ myInstrTypes = OC_mkDisjValueCtrs(instructionTypes, myValueCtr);
+ free(instructionTypes);
+ instructionTypes = myInstrTypes;
+ } else instructionTypes = myValueCtr;
+
+ /* write function body */
+ myWriteOpCodeFunc = UTIL_appendStr(WRITEOPCODE, opcode);
+ if (strcmp(insCat, "X") == 0) {
+ myPattern = strdup(myInsName);
+ myfuncBody = myWriteOpCodeFunc;
+ } else {
+ char* myWriteArgsName = UTIL_appendStr(WRITE_PREFIX, insCat);
+ char* myWriteArgs = UTIL_mallocStr(strlen(myWriteArgsName) + 5);
+ myPattern = OC_mkStructure(myInsName, "arg");
+ strcpy(myWriteArgs, myWriteArgsName); free(myWriteArgsName);
+ strcat(myWriteArgs, " arg");
+ myfuncBody = OC_mkFuncSeq(myWriteOpCodeFunc, myWriteArgs);
+ free(myWriteArgs);
+ }
+ myFunc = OC_mkArrow(myPattern, myfuncBody);
+ free(myfuncBody);
+ if (insWriteFuncBody) {
+ myInsWriteFuncBody = OC_mkDisjValueCtrs(insWriteFuncBody, myFunc);
+ free(insWriteFuncBody); free(myFunc);
+ insWriteFuncBody = myInsWriteFuncBody;
+ } else {
+ insWriteFuncBody = UTIL_appendStr(INDENT2, myFunc);
+ free(myFunc);
+ }
+ /* instruction sizes */
+ myInsSizeName = UTIL_appendStr(GETSIZE_PREFIX, insName);
+ myInsLength = UTIL_appendStr(INSCAT_PREFIX, insLength);
+ mySizeDef = OC_mkVarDef(myInsSizeName, myInsLength);
+ mySizeDec = OC_mkVarDec(myInsSizeName, "int"); free(myInsSizeName);
+
+ mySizeDefs = addStr(insSizesDef, mySizeDef);
+ free(insSizesDef); free(mySizeDef);
+ mySizeDecs = addStr(insSizesDec, mySizeDec);
+ free(insSizesDec); free(mySizeDec);
+
+ insSizesDef = mySizeDefs;
+ insSizesDec = mySizeDecs;
+
+ ocgenReadFuncBody(opcode, myInsName, myInsLength, insCat, last);
+ ocgenDisplayFuncBody(myPattern, insName, myInsLength, insCat);
+
+ free(myInsName); free(myInsLength); free(myPattern);
+}
+
+#define INSTRTYPE_HEAD "type instruction = "
+
+#define INSTWRITEFUNC_DEF_HEAD "let writeInstruction inst =\n match inst with\n"
+#define INSTWRITEFUNC_DEC "val writeInstruction : instruction -> unit\n"
+
+#define INSTREADFUNC_DEF_HEAD \
+"let readInstruction getKindFunc getConstantFunc = \n Bytecode.setGetKindFn getKindFunc; \n Bytecode.setGetConstantFn getConstantFunc; \n let opcode = readopcode () in\n"
+
+#define INSTREADFUNC_DEC \
+"val readInstruction : \n(int -> int -> Absyn.akind option) -> (int -> int -> Absyn.aconstant option) ->\n(instruction * int)\n"
+
+#define INSTDISPLAYFUNC_DEF_HEAD \
+"let displayInstruction inst =\n match inst with\n"
+#define INSTDISPLAYFUNC_DEC \
+"val displayInstruction : instruction -> (string * int)\n"
+
+static char* instrMLI;
+static char* instrML;
+
+void ocgenInstr()
+{
+ char* text = UTIL_appendStr(INSTRTYPE_HEAD, instructionTypes);
+ char* text2 = UTIL_appendStr(text, "\n\n");
+
+ free(instructionTypes); free(text);
+
+ text = addLine(text2, insSizesDec); free(insSizesDec);
+ instrMLI = addStr(text, INSTWRITEFUNC_DEC); free(text);
+ text = addStr(instrMLI, INSTREADFUNC_DEC); free(instrMLI);
+ instrMLI = addStr(text, INSTDISPLAYFUNC_DEC); free(text);
+
+ text = addLine(text2, insSizesDef); free(text2); free(insSizesDef);
+ text2 = addStr(text, INSTWRITEFUNC_DEF_HEAD); free(text);
+ instrML = addStr(text2, insWriteFuncBody);
+ free(text2); free(insWriteFuncBody);
+ text = addStr(instrML, "\n\n"); free(instrML);
+ text2 = addStr(text, INSTREADFUNC_DEF_HEAD); free(text);
+ instrML = addStr(text2, insReadFuncBody);
+ free(text2); free(insReadFuncBody);
+ text = addStr(instrML, "\n\n"); free(instrML);
+ text2 = addStr(text, INSTDISPLAYFUNC_DEF_HEAD); free(text);
+ instrML = addStr(text2, insDisplayFuncBody);
+ free(text2); free(insDisplayFuncBody);
+}
+
+/****************************************************************************/
+/* dump files */
+/****************************************************************************/
+/* dump files */
+void ocSpitInstructionMLI(char * root)
+{
+ FILE* outFile;
+
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "compiler/instr.mli");
+
+ outFile = UTIL_fopenW(filename);
+ fprintf(outFile, typeDefs);
+ fprintf(outFile, opMLI); free(opMLI);
+ fprintf(outFile, instrCatMLI); free(instrCatMLI);
+ fprintf(outFile, "\n\n");
+ fprintf(outFile, instrMLI); free(instrMLI);
+ UTIL_fclose(outFile);
+ free(filename);
+}
+
+/* dump files */
+void ocSpitInstructionML(char * root)
+{
+ FILE* outFile;
+
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "compiler/instr.ml");
+
+ outFile = UTIL_fopenW(filename);
+ fprintf(outFile, typeDefs); free(typeDefs);
+ fprintf(outFile, opML); free(opML);
+ fprintf(outFile, instrCatML); free(instrCatML);
+ fprintf(outFile, instrML); free(instrML);
+ UTIL_fclose(outFile);
+
+ free(filename);
+}
+
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.h b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.h
new file mode 100644
index 000000000..58cdd02b7
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/instrgen-ocaml.h
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/*************************************************************************/
+/* functions for generating ocaml instr.mli and instr.ml */
+/*************************************************************************/
+/* include */
+void ocgenInclude(char* include);
+
+/* operand types */
+void ocgenOpType(char* typeName, int numBytes, char* compType);
+void ocgenOpCodeType(int numBytes);
+void ocgenOps();
+
+/* instruction category */
+void ocgenInstrFormat(char* opName);
+void ocgenOneInstrCat(char* catName);
+void ocgenInstrLength(char* varName, char* numBytes);
+void ocgenInstrCat();
+
+/* instructions */
+void ocgenOneInstr(char* opcode, char* insName, char* insCat, char* insLength,
+ int last);
+void ocgenInstr();
+
+
+/* dump files */
+void ocSpitInstructionMLI(char * root);
+void ocSpitInstructionML(char * root);
+
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/lex.yy.c b/src/runtime/c/teyjus/tables_gen/instrformats/lex.yy.c
new file mode 100644
index 000000000..d8be9c390
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/lex.yy.c
@@ -0,0 +1,1977 @@
+#line 2 "instrformats/lex.yy.c"
+
+#line 4 "instrformats/lex.yy.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart(yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+extern int yyleng;
+
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart (FILE *input_file );
+void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE yy_create_buffer (FILE *file,int size );
+void yy_delete_buffer (YY_BUFFER_STATE b );
+void yy_flush_buffer (YY_BUFFER_STATE b );
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer );
+void yypop_buffer_state (void );
+
+static void yyensure_buffer_stack (void );
+static void yy_load_buffer_state (void );
+static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len );
+
+void *yyalloc (yy_size_t );
+void *yyrealloc (void *,yy_size_t );
+void yyfree (void * );
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer(yyin,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer(yyin,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int yylineno;
+
+int yylineno = 1;
+
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+
+#define YY_NUM_RULES 25
+#define YY_END_OF_BUFFER 26
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[103] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 26, 24,
+ 11, 1, 15, 15, 15, 16, 2, 15, 15, 15,
+ 15, 3, 4, 14, 19, 25, 25, 18, 25, 25,
+ 23, 22, 11, 15, 15, 15, 12, 13, 16, 15,
+ 15, 15, 15, 19, 21, 20, 18, 17, 23, 15,
+ 15, 15, 15, 15, 15, 15, 0, 15, 15, 15,
+ 15, 0, 15, 15, 15, 0, 15, 0, 6, 15,
+ 15, 0, 15, 0, 15, 15, 0, 15, 0, 0,
+ 15, 0, 15, 0, 0, 15, 0, 15, 0, 0,
+ 9, 0, 15, 8, 0, 0, 10, 0, 0, 5,
+
+ 7, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 4, 5, 1, 1, 6, 7, 8, 9, 1,
+ 1, 10, 11, 12, 13, 1, 14, 15, 16, 15,
+ 15, 15, 15, 15, 15, 15, 15, 17, 18, 19,
+ 20, 21, 1, 22, 23, 24, 25, 26, 27, 24,
+ 28, 24, 29, 24, 24, 30, 31, 32, 33, 34,
+ 24, 35, 36, 37, 38, 24, 24, 39, 40, 24,
+ 41, 1, 42, 43, 44, 1, 24, 24, 24, 24,
+
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+ 24, 24, 45, 1, 46, 47, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[48] =
+ { 0,
+ 1, 1, 2, 1, 1, 1, 2, 1, 1, 3,
+ 1, 1, 1, 4, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 5, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[109] =
+ { 0,
+ 0, 0, 45, 46, 40, 41, 146, 145, 190, 193,
+ 54, 193, 56, 0, 91, 89, 193, 166, 156, 164,
+ 152, 193, 193, 193, 0, 171, 177, 0, 169, 193,
+ 0, 193, 104, 0, 0, 0, 0, 0, 94, 152,
+ 145, 141, 86, 0, 193, 193, 0, 193, 0, 149,
+ 141, 173, 143, 140, 130, 138, 139, 145, 147, 140,
+ 93, 134, 140, 134, 149, 139, 138, 135, 0, 135,
+ 111, 131, 113, 113, 126, 99, 91, 98, 103, 88,
+ 97, 96, 89, 89, 80, 87, 90, 85, 90, 81,
+ 0, 81, 76, 193, 80, 67, 0, 38, 17, 193,
+
+ 193, 193, 131, 136, 141, 146, 151, 156
+ } ;
+
+static yyconst flex_int16_t yy_def[109] =
+ { 0,
+ 102, 1, 103, 103, 104, 104, 105, 105, 102, 102,
+ 102, 102, 102, 13, 13, 102, 102, 13, 13, 13,
+ 13, 102, 102, 102, 106, 102, 102, 107, 102, 102,
+ 108, 102, 102, 13, 13, 13, 13, 13, 102, 13,
+ 13, 13, 13, 106, 102, 102, 107, 102, 108, 13,
+ 13, 13, 13, 13, 13, 13, 102, 13, 13, 13,
+ 13, 102, 13, 13, 13, 102, 13, 102, 13, 13,
+ 13, 102, 13, 102, 13, 13, 102, 13, 102, 102,
+ 13, 102, 13, 102, 102, 13, 102, 13, 102, 102,
+ 13, 102, 13, 102, 102, 102, 13, 102, 102, 102,
+
+ 102, 0, 102, 102, 102, 102, 102, 102
+ } ;
+
+static yyconst flex_int16_t yy_nxt[241] =
+ { 0,
+ 10, 11, 12, 11, 13, 13, 13, 13, 13, 14,
+ 13, 13, 13, 15, 16, 16, 13, 17, 13, 13,
+ 13, 13, 13, 13, 18, 13, 13, 13, 19, 13,
+ 20, 13, 21, 13, 13, 13, 13, 13, 13, 13,
+ 22, 23, 13, 13, 24, 10, 13, 12, 12, 29,
+ 29, 26, 26, 30, 30, 33, 101, 33, 27, 27,
+ 34, 34, 34, 34, 34, 35, 34, 34, 34, 34,
+ 36, 36, 34, 100, 34, 34, 34, 34, 36, 36,
+ 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
+ 36, 36, 36, 36, 36, 36, 66, 37, 34, 34,
+
+ 38, 99, 34, 39, 39, 33, 98, 33, 39, 39,
+ 53, 97, 54, 96, 95, 94, 93, 92, 91, 90,
+ 89, 88, 87, 86, 85, 84, 83, 82, 81, 80,
+ 67, 25, 25, 25, 25, 25, 28, 28, 28, 28,
+ 28, 31, 31, 31, 31, 31, 44, 79, 44, 78,
+ 44, 47, 47, 77, 76, 47, 49, 49, 49, 49,
+ 75, 74, 73, 72, 71, 70, 69, 68, 65, 64,
+ 63, 62, 61, 60, 59, 58, 57, 56, 55, 52,
+ 51, 50, 48, 46, 45, 43, 42, 41, 40, 102,
+ 32, 32, 9, 102, 102, 102, 102, 102, 102, 102,
+
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102
+ } ;
+
+static yyconst flex_int16_t yy_chk[241] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 3, 4, 5,
+ 6, 3, 4, 5, 6, 11, 99, 11, 3, 4,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 98, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 61, 15, 13, 13,
+
+ 15, 96, 13, 16, 16, 33, 95, 33, 39, 39,
+ 43, 93, 43, 92, 90, 89, 88, 87, 86, 85,
+ 84, 83, 82, 81, 80, 79, 78, 77, 76, 75,
+ 61, 103, 103, 103, 103, 103, 104, 104, 104, 104,
+ 104, 105, 105, 105, 105, 105, 106, 74, 106, 73,
+ 106, 107, 107, 72, 71, 107, 108, 108, 108, 108,
+ 70, 68, 67, 66, 65, 64, 63, 62, 60, 59,
+ 58, 57, 56, 55, 54, 53, 52, 51, 50, 42,
+ 41, 40, 29, 27, 26, 21, 20, 19, 18, 9,
+ 8, 7, 102, 102, 102, 102, 102, 102, 102, 102,
+
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
+ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int yy_flex_debug;
+int yy_flex_debug = 0;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "instrformats/instrformats.l"
+#line 2 "instrformats/instrformats.l"
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "y.tab.h"
+#include <string.h>
+#include <stdlib.h>
+
+static int commentLev = 0;
+
+#line 571 "instrformats/lex.yy.c"
+
+#define INITIAL 0
+#define COMMENT 1
+#define COMMENT2 2
+#define INCLUDE 3
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+static int yy_init_globals (void );
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy (void );
+
+int yyget_debug (void );
+
+void yyset_debug (int debug_flag );
+
+YY_EXTRA_TYPE yyget_extra (void );
+
+void yyset_extra (YY_EXTRA_TYPE user_defined );
+
+FILE *yyget_in (void );
+
+void yyset_in (FILE * in_str );
+
+FILE *yyget_out (void );
+
+void yyset_out (FILE * out_str );
+
+int yyget_leng (void );
+
+char *yyget_text (void );
+
+int yyget_lineno (void );
+
+void yyset_lineno (int line_number );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap (void );
+#else
+extern int yywrap (void );
+#endif
+#endif
+
+ static void yyunput (int c,char *buf_ptr );
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int yylex (void);
+
+#define YY_DECL int yylex (void)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 41 "instrformats/instrformats.l"
+
+#line 763 "instrformats/lex.yy.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer(yyin,YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 103 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 193 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 42 "instrformats/instrformats.l"
+{continue; }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 43 "instrformats/instrformats.l"
+{return SEMICOLON; }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 44 "instrformats/instrformats.l"
+{return LBRACKET; }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 45 "instrformats/instrformats.l"
+{return RBRACKET; }
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 46 "instrformats/instrformats.l"
+{return OPTYPES; }
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 47 "instrformats/instrformats.l"
+{return OPCODE; }
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 48 "instrformats/instrformats.l"
+{return INSTRCAT; }
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 49 "instrformats/instrformats.l"
+{return MAXOPERAND; }
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 50 "instrformats/instrformats.l"
+{return CALL_I1_LEN; }
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 51 "instrformats/instrformats.l"
+{return INSTRUCTIONS; }
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 52 "instrformats/instrformats.l"
+{continue; }
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 53 "instrformats/instrformats.l"
+{commentLev = 1; BEGIN(COMMENT); continue; }
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 54 "instrformats/instrformats.l"
+{BEGIN(COMMENT2); continue; }
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 55 "instrformats/instrformats.l"
+{BEGIN(INCLUDE); continue; }
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 56 "instrformats/instrformats.l"
+{yylval.name = strdup(yytext); return ID; }
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 57 "instrformats/instrformats.l"
+{yylval.isval.ival = atoi(yytext);
+ yylval.isval.sval = strdup(yytext);
+ return NUM; }
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 60 "instrformats/instrformats.l"
+{BEGIN(INITIAL); continue; }
+ YY_BREAK
+case 18:
+/* rule 18 can match eol */
+YY_RULE_SETUP
+#line 61 "instrformats/instrformats.l"
+{yylval.text = strdup(yytext); return STRING; }
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 63 "instrformats/instrformats.l"
+{continue; }
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 64 "instrformats/instrformats.l"
+{commentLev++; continue; }
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 65 "instrformats/instrformats.l"
+{commentLev--;
+ if (!commentLev) BEGIN(INITIAL); continue; }
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 67 "instrformats/instrformats.l"
+{BEGIN(INITIAL); continue; }
+ YY_BREAK
+case 23:
+/* rule 23 can match eol */
+YY_RULE_SETUP
+#line 68 "instrformats/instrformats.l"
+{yylval.text = strdup(yytext); return STRING2; }
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 69 "instrformats/instrformats.l"
+{return ERROR; }
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 70 "instrformats/instrformats.l"
+ECHO;
+ YY_BREAK
+#line 977 "instrformats/lex.yy.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(COMMENT):
+case YY_STATE_EOF(COMMENT2):
+case YY_STATE_EOF(INCLUDE):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_c_buf_p);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (void)
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), (size_t) num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart(yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (void)
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 103 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+{
+ register int yy_is_jam;
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 103 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 102);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ static void yyunput (int c, register char * yy_bp )
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up yytext */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register int number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart(yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyrestart (FILE * input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer(yyin,YY_BUF_SIZE );
+ }
+
+ yy_init_buffer(YY_CURRENT_BUFFER,input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+static void yy_load_buffer_state (void)
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yy_delete_buffer (YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ yyfree((void *) b->yy_ch_buf );
+
+ yyfree((void *) b );
+}
+
+#ifndef __cplusplus
+extern int isatty (int );
+#endif /* __cplusplus */
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yy_flush_buffer (YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void yyensure_buffer_stack (void)
+{
+ int num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer(b );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ *
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
+{
+
+ return yy_scan_bytes(yystr,strlen(yystr) );
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) yyalloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the current line number.
+ *
+ */
+int yyget_lineno (void)
+{
+
+ return yylineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *yyget_in (void)
+{
+ return yyin;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *yyget_out (void)
+{
+ return yyout;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int yyget_leng (void)
+{
+ return yyleng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *yyget_text (void)
+{
+ return yytext;
+}
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void yyset_lineno (int line_number )
+{
+
+ yylineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see yy_switch_to_buffer
+ */
+void yyset_in (FILE * in_str )
+{
+ yyin = in_str ;
+}
+
+void yyset_out (FILE * out_str )
+{
+ yyout = out_str ;
+}
+
+int yyget_debug (void)
+{
+ return yy_flex_debug;
+}
+
+void yyset_debug (int bdebug )
+{
+ yy_flex_debug = bdebug ;
+}
+
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from yylex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * yylex_init()
+ */
+ return 0;
+}
+
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int yylex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ yypop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ yyfree((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * yylex() is called, initialization will occur. */
+ yy_init_globals( );
+
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *yyalloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *yyrealloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void yyfree (void * ptr )
+{
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 70 "instrformats/instrformats.l"
diff --git a/src/runtime/c/teyjus/tables_gen/instrformats/y.tab.h b/src/runtime/c/teyjus/tables_gen/instrformats/y.tab.h
new file mode 100644
index 000000000..cff620e11
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/instrformats/y.tab.h
@@ -0,0 +1,104 @@
+
+/* A Bison parser, made by GNU Bison 2.4.1. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ OPTYPES = 258,
+ INSTRCAT = 259,
+ INSTRUCTIONS = 260,
+ OPCODE = 261,
+ MAXOPERAND = 262,
+ CALL_I1_LEN = 263,
+ SEMICOLON = 264,
+ ERROR = 265,
+ LBRACKET = 266,
+ RBRACKET = 267,
+ ID = 268,
+ NUM = 269,
+ STRING = 270,
+ STRING2 = 271
+ };
+#endif
+/* Tokens. */
+#define OPTYPES 258
+#define INSTRCAT 259
+#define INSTRUCTIONS 260
+#define OPCODE 261
+#define MAXOPERAND 262
+#define CALL_I1_LEN 263
+#define SEMICOLON 264
+#define ERROR 265
+#define LBRACKET 266
+#define RBRACKET 267
+#define ID 268
+#define NUM 269
+#define STRING 270
+#define STRING2 271
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+{
+
+/* Line 1676 of yacc.c */
+#line 38 "instrformats/instrformats.y"
+
+ char* name;
+ char* text;
+ struct
+ {
+ int ival;
+ char* sval;
+ } isval;
+
+
+
+/* Line 1676 of yacc.c */
+#line 96 "instrformats/y.tab.h"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+extern YYSTYPE yylval;
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/ccode.c b/src/runtime/c/teyjus/tables_gen/pervasives/ccode.c
new file mode 100644
index 000000000..dbdb047e5
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/ccode.c
@@ -0,0 +1,1024 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/***************************************************************************/
+/* ocamlcode.c. */
+/* This file defines auxiliary functions in making pervasives.h and */
+/* pervasives.c. */
+/* Since space and time efficiency is not an important concern in the */
+/* system source code generation phase, the code here is structured in the */
+/* way for the convenience of making changes on pervasive.mli{ml}. */
+/***************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ccode.h"
+#include "types.h"
+#include "../util/util.h" //to be modified
+
+/**************************************************************************/
+/* Functions for making various language constructs */
+/**************************************************************************/
+/* // <comments> */
+char* C_mkOneLineComments(char* comments)
+{
+ size_t length = strlen(comments) + 5;
+ char* commentsText = UTIL_mallocStr(length);
+
+ strcpy(commentsText, "// ");
+ strcat(commentsText, comments);
+
+ return commentsText;
+}
+
+/* <varName> = <varValue> */
+char* C_mkAssign(char* varName, char* varValue)
+{
+ size_t length = strlen(varName) + strlen(varValue) + 5;
+ char* assign = UTIL_mallocStr(length);
+
+ strcpy(assign, varName);
+ strcat(assign, " = ");
+ strcat(assign, varValue);
+
+ return assign;
+}
+
+/* #define <macroName> <macroValue> */
+char* C_mkDefine(char* macroName, char* macroValue)
+{
+ size_t length = strlen(macroName) + strlen(macroValue) + 10;
+ char* def = UTIL_mallocStr(length);
+
+ strcpy(def, "#define ");
+ strcat(def, macroName);
+ strcat(def, " ");
+ strcat(def, macroValue);
+
+ return def;
+}
+
+/* enum <typeName>\n {\n <body> } */
+char* C_mkEnum(char* typeName, char* body)
+{
+ size_t length = strlen(typeName) + strlen(body) + 15;
+ char* enumText = UTIL_mallocStr(length);
+
+ strcpy(enumText, "enum ");
+ strcat(enumText, typeName);
+ strcat(enumText, "\n{\n");
+ strcat(enumText, body);
+ strcat(enumText, "}");
+
+ return enumText;
+}
+
+/* typedef <typeStr> <typeName>; \n\n */
+char* C_mkTypeDef(char* typeStr, char* typeName)
+{
+ size_t length = strlen(typeStr) + strlen(typeName) + 15;
+ char* typeDefText = UTIL_mallocStr(length);
+
+ strcpy(typeDefText, "typedef ");
+ strcat(typeDefText, typeStr);
+ strcat(typeDefText, " ");
+ strcat(typeDefText, typeName);
+ strcat(typeDefText, ";\n\n");
+
+ return typeDefText;
+}
+
+/********************************************************************/
+/* Names */
+/********************************************************************/
+#define C_INDENT " "
+
+#define C_PREFIX "PERV_"
+#define C_SUFFIX "_INDEX"
+
+#define C_NUMKINDS "PERV_KIND_NUM"
+#define C_NUMTYSKELS "PERV_TY_SKEL_NUM"
+#define C_NUMCONSTS "PERV_CONST_NUM"
+
+#define C_TY_KINDIND "PERV_KindIndexType"
+#define C_TY_CONSTIND "PERV_ConstIndexType"
+
+
+/* PERV_<name>_INDEX */
+char* C_mkIndexName(char* name)
+{
+ char* nameUC = UTIL_upperCase(name);
+ size_t length = strlen(nameUC) + strlen(C_PREFIX) + strlen(C_SUFFIX);
+ char* indexName = UTIL_mallocStr(length);
+
+ strcpy(indexName, C_PREFIX);
+ strcat(indexName, nameUC); free(nameUC);
+ strcat(indexName, C_SUFFIX);
+
+ return indexName;
+}
+
+/* PERV_<name> */
+char* C_mkIndexName2(char* name)
+{
+ char* nameUC = UTIL_upperCase(name);
+ size_t length = strlen(nameUC) + strlen(C_PREFIX);
+ char* indexName = UTIL_mallocStr(length);
+
+ strcpy(indexName, C_PREFIX);
+ strcat(indexName, nameUC); free(nameUC);
+
+ return indexName;
+}
+
+/*
+ //comments \n
+ PERV_<name>_INDEX = <indexNum>
+*/
+char* C_mkIndex(char* name, char* indexNum, char* comments)
+{
+ char* commentText = (comments) ? C_mkOneLineComments(comments) : NULL;
+ char* varName = C_mkIndexName(name);
+ char* assign = C_mkAssign(varName, indexNum);
+ size_t length = ((commentText) ? strlen(commentText) + strlen(C_INDENT): 0)
+ + strlen(assign) + strlen(C_INDENT) + 5;
+ char* index = UTIL_mallocStr(length);
+
+ free(varName);
+ strcpy(index, C_INDENT);
+ if (commentText) {
+ strcat(index, commentText); strcat(index, "\n");
+ strcat(index, C_INDENT); free(commentText);
+ }
+ strcat(index, assign); free(assign);
+
+ return index;
+}
+
+/*
+ PERV_<name> = <indexNum>
+*/
+char* C_mkIndex2(char* name, char* indexNum)
+{
+ char* varName = C_mkIndexName2(name);
+ char* assign = C_mkAssign(varName, indexNum);
+ char* index = UTIL_mallocStr(strlen(assign) + strlen(C_INDENT));
+
+ free(varName);
+ strcpy(index, C_INDENT);
+ strcat(index, assign); free(assign);
+
+ return index;
+}
+
+/* // empty */
+char* C_mkEmptyComments()
+{
+ size_t length = strlen(C_INDENT) + 10;
+ char* text = UTIL_mallocStr(length);
+
+ strcpy(text, C_INDENT);
+ strcat(text, "// empty\n");
+
+ return text;
+}
+
+/********************************************************************/
+/* Kind relevant components */
+/********************************************************************/
+/***************************************************************/
+/* pervasives.h */
+/***************************************************************/
+#define C_NUMKINDS_COMMENTS "//total number of pervasive kinds\n"
+
+/*
+ //total number of pervasive kinds \n"
+ #define PERV_KIND_NUM <num> \n
+*/
+char* C_mkNumKinds(char* num)
+{
+ char* def = C_mkDefine(C_NUMKINDS, num);
+ size_t length = strlen(def) + strlen(C_NUMKINDS_COMMENTS) + 5;
+ char* numKinds = UTIL_mallocStr(length);
+
+ strcpy(numKinds, C_NUMKINDS_COMMENTS);
+ strcat(numKinds, def); free(def);
+ strcat(numKinds, "\n\n");
+
+ return numKinds;
+}
+
+#define C_KINDINDEX_COMMENTS \
+"//indices for predefined sorts and type constructors\n"
+/*
+ //indices for predefined sorts and type constructors\n"
+ typedef enum PERV_KindIndexType \n
+ { <body> } PERV_KindIndexType; \n
+*/
+char* C_mkKindIndexType(char* body)
+{
+ char* enumText = C_mkEnum(C_TY_KINDIND, body);
+ char* typeDefText = C_mkTypeDef(enumText, C_TY_KINDIND);
+ size_t length = strlen(typeDefText) + strlen(C_KINDINDEX_COMMENTS);
+ char* kindIndexType = UTIL_mallocStr(length);
+
+ strcpy(kindIndexType, C_KINDINDEX_COMMENTS);
+ strcat(kindIndexType, typeDefText);
+ free(enumText); free(typeDefText);
+
+ return kindIndexType;
+}
+
+//comments
+#define C_KIND_COMMENTS \
+"/****************************************************************************/\n/* PERVASIVE KIND */ \n/****************************************************************************/ \n"
+//PERV_KindData
+#define C_KINDDATA_TYPE_DEF \
+"//pervasive kind data type \ntypedef struct \n{ \n char *name; \n TwoBytes arity; \n} PERV_KindData; \n\n"
+
+//PERV_kindDataTab
+#define C_KINDDATATAB_DEC \
+"//pervasive kind data table (array) \nextern PERV_KindData PERV_kindDataTab[PERV_KIND_NUM]; \n\n"
+
+//PERV_genKindData
+#define C_GETKINDDATA_DEC \
+"//pervasive kind data access function \nPERV_KindData PERV_getKindData(int index); \n\n"
+
+//PERV_copyKindDataTab
+#define C_COPYKINDDATATAB_DEC \
+"//pervasive kind table copy function (used in module space initialization) \n//this functiion relies on the assumption that the pervasive kind data \n//has the same structure as that of the run-time kind symbol table entries. \nvoid PERV_copyKindDataTab(PERV_KindData* dst); \n\n"
+char* C_mkKindH(char* kindIndexType, char* numKinds)
+{
+ size_t length = strlen(C_KIND_COMMENTS) + strlen(kindIndexType) +
+ strlen(numKinds) + strlen(C_KINDDATA_TYPE_DEF) +
+ strlen(C_KINDDATATAB_DEC) + strlen(C_GETKINDDATA_DEC) +
+ strlen(C_COPYKINDDATATAB_DEC);
+ char* kindH = UTIL_mallocStr(length);
+
+ strcpy(kindH, C_KIND_COMMENTS);
+ strcat(kindH, kindIndexType);
+ strcat(kindH, numKinds);
+ strcat(kindH, C_KINDDATA_TYPE_DEF);
+ strcat(kindH, C_KINDDATATAB_DEC);
+ strcat(kindH, C_GETKINDDATA_DEC);
+ strcat(kindH, C_COPYKINDDATATAB_DEC);
+
+ return kindH;
+}
+
+/***************************************************************/
+/* pervasives.c */
+/***************************************************************/
+/*
+ //comments \n
+ {"<name>", <arity>}
+*/
+char* C_mkKindTabEntry(char* name, char* arity, char* comments)
+{
+ char* commentText = (comments) ? C_mkOneLineComments(comments) : NULL;
+ size_t length = ((commentText) ? strlen(commentText) + strlen(C_INDENT): 0)
+ + strlen(name) + strlen(arity) + strlen(C_INDENT)*2 + 10;
+ char* entry = UTIL_mallocStr(length);
+
+ strcpy(entry, C_INDENT);
+ if (commentText) {
+ strcat(entry, commentText); strcat(entry, "\n");
+ strcat(entry, C_INDENT); free(commentText);
+ }
+ strcat(entry, "{\"");
+ strcat(entry, name);
+ strcat(entry, "\",");
+ strcat(entry, C_INDENT);
+ strcat(entry, arity);
+ strcat(entry, "}");
+
+ return entry;
+}
+
+#define C_KIND_TAB_BEG \
+"//pervasive kind data table (array) \nPERV_KindData PERV_kindDataTab[PERV_KIND_NUM] = { \n //name, arity \n"
+#define C_KIND_TAB_END "};\n\n"
+
+/*
+ //pervasive kind data table (array)
+ PERV_KindData PERV_kindDataTab[PERV_KIND_NUM] = { \n body \n};\n
+*/
+char* C_mkKindTab(char* body)
+{
+ size_t length = strlen(C_KIND_TAB_BEG) + strlen(C_KIND_TAB_END) + strlen(body);
+ char* kindTab = UTIL_mallocStr(length);
+
+ strcpy(kindTab, C_KIND_TAB_BEG);
+ strcat(kindTab, body);
+ strcat(kindTab, C_KIND_TAB_END);
+
+ return kindTab;
+}
+
+//PERV_getKindData
+#define C_GETKINDDATA_DEF \
+"PERV_KindData PERV_getKindData(int index) \n{ \n return PERV_kindDataTab[index]; \n} \n\n"
+//PERV_copyKindDataTab
+#define C_COPYKINDDATATAB_DEF \
+"void PERV_copyKindDataTab(PERV_KindData* dst) \n{ \n //this way of copy relies on the assumption that the pervasive kind data \n //has the same structure as that of the run-time kind symbol table entries.\n memcpy((void*)dst, (void*)PERV_kindDataTab, \n sizeof(PERV_KindData) * PERV_KIND_NUM); \n} \n\n"
+
+char* C_mkKindC(char* kindTab)
+{
+ size_t length = strlen(C_KIND_COMMENTS) + strlen(kindTab) +
+ strlen(C_GETKINDDATA_DEF) + strlen(C_COPYKINDDATATAB_DEF);
+ char* kindC = UTIL_mallocStr(length);
+
+ strcpy(kindC, C_KIND_COMMENTS);
+ strcat(kindC, kindTab);
+ strcat(kindC, C_GETKINDDATA_DEF);
+ strcat(kindC, C_COPYKINDDATATAB_DEF);
+
+ return kindC;
+}
+
+
+/*********************************************************************/
+/* Type Skeleton relevant components */
+/*********************************************************************/
+#define C_NUMTYSKELS_COMMENTS \
+"//total number of type skeletons needed for pervasive constants\n"
+
+
+/*
+ //total number of type skeletons needed for pervasive constants\n
+ #define PERV_TY_SKEL_NUM <num> \n
+*/
+char* C_mkNumTySkels(char* num)
+{
+ char* def = C_mkDefine(C_NUMTYSKELS, num);
+ size_t length = strlen(def) + strlen(C_NUMTYSKELS_COMMENTS) + 5;
+ char* numTySkels = UTIL_mallocStr(length);
+
+ strcpy(numTySkels, C_NUMTYSKELS_COMMENTS);
+ strcat(numTySkels, def); free(def);
+ strcat(numTySkels, "\n\n");
+
+ return numTySkels;
+}
+
+//comments
+#define C_TYSKEL_COMMENTS \
+"/***************************************************************************/\n/* TYPE SKELETIONS FOR PERVASIVE CONSTANTS */ \n/****************************************************************************/\n\n"
+//PERV_TySkelData
+#define C_TYSKELDATA_TYPE_DEF \
+"//pervasive type skel data type \ntypedef DF_TypePtr PERV_TySkelData; \n\n"
+
+//PERV_TySkelTab
+#define C_TYSKELTAB_DEC \
+"//pervasive type skel table (array) \nextern PERV_TySkelData PERV_tySkelTab[PERV_TY_SKEL_NUM]; \n\n"
+
+//PERV_tySkelTabInit
+#define C_TYSKELTABINIT_DEC \
+"//pervasive type skeletons and type skeleton table initialization \n//Note that type skeltons have to be dynamically allocated, and so does the \n//info recorded in each entry of the pervasive type skeleton table \nvoid PERV_tySkelTabInit(); \n\n"
+
+//PERV_copyTySkelTab
+#define C_COPYTYSKELTAB_DEC \
+"//pervasive tyskel table copy function \nvoid PERV_copyTySkelTab(PERV_TySkelData* dst); \n\n"
+
+char* C_mkTySkelsH(char* numTySkels)
+{
+ size_t length = strlen(C_TYSKEL_COMMENTS) + strlen(numTySkels) +
+ strlen(C_TYSKELDATA_TYPE_DEF) + strlen(C_TYSKELTAB_DEC) +
+ strlen(C_TYSKELTABINIT_DEC) + strlen(C_COPYTYSKELTAB_DEC);
+ char* tySkelsH = UTIL_mallocStr(length);
+
+ strcpy(tySkelsH, C_TYSKEL_COMMENTS);
+ strcat(tySkelsH, numTySkels);
+ strcat(tySkelsH, C_TYSKELDATA_TYPE_DEF);
+ strcat(tySkelsH, C_TYSKELTAB_DEC);
+ strcat(tySkelsH, C_TYSKELTABINIT_DEC);
+ strcat(tySkelsH, C_COPYTYSKELTAB_DEC);
+
+ return tySkelsH;
+}
+
+/************************************************************************/
+/* pervasives.c */
+/************************************************************************/
+//manipulating each type skeleton
+#define MKSKVARTYPE_BEG " DF_mkSkelVarType(tySkelBase, "
+#define MKSORTTYPE_BEG " DF_mkSortType(tySkelBase, "
+#define MKATOMTYPE_END ");\n"
+#define MKARROWTYPE_BEG \
+" DF_mkArrowType(tySkelBase, (DF_TypePtr)(tySkelBase + "
+#define MKSTRTYPE_BEG \
+" DF_mkStrType(tySkelBase, (DF_TypePtr)(tySkelBase + "
+#define MKSTRFUNCTYPE_BEG " DF_mkStrFuncType(tySkelBase, "
+#define MKCOMPTYPE_END " * DF_TY_ATOMIC_SIZE));\n"
+#define TYSKELBASE_INC " tySkelBase += DF_TY_ATOMIC_SIZE;\n"
+
+static char* C_genTySkelSort(char* name)
+{
+ char* kindName = C_mkIndexName(name);
+ char* mytext = NULL;
+ mytext = UTIL_mallocStr(strlen(MKSORTTYPE_BEG) + strlen(MKATOMTYPE_END) +
+ strlen(kindName) + strlen(TYSKELBASE_INC));
+
+ strcpy(mytext, MKSORTTYPE_BEG);
+ strcat(mytext, kindName); free(kindName);
+ strcat(mytext, MKATOMTYPE_END);
+ strcat(mytext, TYSKELBASE_INC);
+ return mytext;
+}
+
+static char* C_genTySkelSkVar(char* index)
+{
+ char* mytext = NULL;
+ mytext = UTIL_mallocStr(strlen(MKSKVARTYPE_BEG) + strlen(MKATOMTYPE_END) +
+ strlen(index) + strlen(TYSKELBASE_INC));
+
+ strcpy(mytext, MKSKVARTYPE_BEG);
+ strcat(mytext, index);
+ strcat(mytext, MKATOMTYPE_END);
+ strcat(mytext, TYSKELBASE_INC);
+ return mytext;
+}
+
+static char* C_genTySkelFunc(char* name, char* arity)
+{
+ char* kindName = C_mkIndexName(name);
+ char* mytext = NULL;
+ mytext = UTIL_mallocStr(strlen(MKSTRFUNCTYPE_BEG) + strlen(kindName) +
+ strlen(arity) + strlen(MKATOMTYPE_END) +
+ strlen(TYSKELBASE_INC) + 5);
+
+ strcpy(mytext, MKSTRFUNCTYPE_BEG);
+ strcat(mytext, kindName); free(kindName);
+ strcat(mytext, ", ");
+ strcat(mytext, arity);
+ strcat(mytext, MKATOMTYPE_END);
+ strcat(mytext, TYSKELBASE_INC);
+ return mytext;
+}
+
+static char* C_genTySkelArrow(int argPosNum)
+{
+ char* argPos = UTIL_itoa(argPosNum);
+ char* mytext = NULL;
+ mytext = UTIL_mallocStr(strlen(MKARROWTYPE_BEG) + strlen(argPos) +
+ strlen(MKCOMPTYPE_END) + strlen(TYSKELBASE_INC));
+
+ strcpy(mytext, MKARROWTYPE_BEG);
+ strcat(mytext, argPos); free(argPos);
+ strcat(mytext, MKCOMPTYPE_END);
+ strcat(mytext, TYSKELBASE_INC);
+ return mytext;
+}
+
+static char* C_genTySkelStr(int argPosNum)
+{
+ char* argPos = UTIL_itoa(argPosNum);
+ char* mytext = NULL;
+ mytext = UTIL_mallocStr(strlen(MKSTRTYPE_BEG) + strlen(argPos) +
+ strlen(MKCOMPTYPE_END) + strlen(TYSKELBASE_INC));
+
+ strcpy(mytext, MKSTRTYPE_BEG);
+ strcat(mytext, argPos); free(argPos);
+ strcat(mytext, MKCOMPTYPE_END);
+ strcat(mytext, TYSKELBASE_INC);
+ return mytext;
+}
+
+//data structure used for breath-first traversal of type skels
+typedef struct Types
+{
+ int length;
+ TypeList types;
+} Types;
+
+int C_totalSpace = 0;
+
+static char* C_genOneTySkel(Types types)
+{
+ TypeList typeList = types.types;
+ int length = types.length;
+ char* mytext = NULL;
+
+ if (length) {
+ Type myType = typeList -> oneType;
+ TypeList remaining = typeList -> next;
+ char *mytext1 = NULL, *mytext2 = NULL;
+ free(typeList);
+ switch (myType -> tag){
+ case SORT:
+ {
+ mytext1 = C_genTySkelSort(myType->data.sort);
+ C_totalSpace++;
+ types.types = remaining;
+ types.length = length-1;
+ mytext2 = C_genOneTySkel(types);
+ break;
+ }
+ case SKVAR:
+ {
+ mytext1 = C_genTySkelSkVar(myType->data.skvar);
+ C_totalSpace++;
+ types.types = remaining;
+ types.length = length-1;
+ mytext2 = C_genOneTySkel(types);
+ break;
+ }
+ case FUNC:
+ {
+ mytext1 = C_genTySkelFunc(myType->data.func.name,
+ myType->data.func.arity);
+ C_totalSpace++;
+ types.types = remaining;
+ types.length = length -1;
+ mytext2 = C_genOneTySkel(types);
+ break;
+ }
+ case ARROW:
+ {
+ Type lop = myType->data.arrow.lop;
+ Type rop = myType->data.arrow.rop;
+ mytext1 = C_genTySkelArrow(length);
+ C_totalSpace++;
+ remaining = addItemToEnd(remaining, lop);
+ types.types = addItemToEnd(remaining, rop);
+ types.length = length+1;
+ mytext2 = C_genOneTySkel(types);
+ break;
+ }
+ case STR:
+ {
+ Type func = myType->data.str.functor;
+ TypeList args = myType->data.str.args;
+ int arity = myType -> data.str.arity;
+ mytext1 = C_genTySkelStr(length);
+ C_totalSpace++;
+ remaining = addItemToEnd(remaining, func);
+ types.types = append(remaining, args);
+ types.length = length + arity;
+ mytext2 = C_genOneTySkel(types);
+ break;
+ }
+ }
+ freeType(myType);
+ mytext = UTIL_mallocStr(strlen(mytext1) + strlen(mytext2));
+ strcpy(mytext, mytext1); free(mytext1);
+ strcat(mytext, mytext2); free(mytext2);
+ } else {
+ mytext = strdup("");
+ }
+ return mytext;
+}
+
+#define C_TYSKELS_PRE \
+"PERV_tySkelTab[tySkelInd] = (PERV_TySkelData)tySkelBase;\n tySkelInd++;\n"
+
+char* C_genTySkel(Type tyskel, char* comments)
+{
+ char* commentText = (comments) ? C_mkOneLineComments(comments) : NULL;
+ Types tyskels;
+ char* tyskelText1;
+ char* tyskelText2;
+ size_t length;
+
+ tyskels.length = 1;
+ tyskels.types = addItem(tyskel, NULL);
+ tyskelText1 = C_genOneTySkel(tyskels);
+
+ length = ((commentText) ? strlen(commentText) + strlen(C_INDENT): 0)
+ + strlen(tyskelText1) + strlen(C_TYSKELS_PRE) + strlen(C_INDENT) + 5;
+ tyskelText2 = UTIL_mallocStr(length);
+
+ strcpy(tyskelText2, C_INDENT);
+ if (commentText) {
+ strcat(tyskelText2, commentText); free(commentText);
+ strcat(tyskelText2, "\n");
+ }
+ strcat(tyskelText2, C_INDENT);
+ strcat(tyskelText2, C_TYSKELS_PRE);
+ strcat(tyskelText2, tyskelText1); free(tyskelText1);
+ strcat(tyskelText2, "\n");
+
+ return tyskelText2;
+}
+
+#define TYSKELTABINIT_BEG \
+"//pervasive type skeletons and type skeleton table initialization \n//The type skeletons are created in the memory of the system through malloc, \n//and addresses are entered into the pervasive type skeleton table. \nvoid PERV_tySkelTabInit() \n{ \n int tySkelInd = 0; //ts tab index\n"
+#define TYSKELTABINIT_END "}\n\n"
+
+#define TYSPACE_BEG " MemPtr tySkelBase = (MemPtr)EM_malloc(WORD_SIZE * "
+#define TYSPACE_END " ); //ts area\n\n"
+
+char* C_mkTySkelTabInit(char* body, int space)
+{
+ char* spaceText = UTIL_itoa(space * 2);
+ char* tabInit = UTIL_mallocStr(strlen(TYSKELTABINIT_BEG) +
+ strlen(TYSPACE_BEG) + strlen(spaceText) +
+ strlen(TYSPACE_END) + strlen(body) +
+ strlen(TYSKELTABINIT_END));
+ strcpy(tabInit, TYSKELTABINIT_BEG);
+ strcat(tabInit, TYSPACE_BEG);
+ strcat(tabInit, spaceText); free(spaceText);
+ strcat(tabInit, TYSPACE_END);
+ strcat(tabInit, body);
+ strcat(tabInit, TYSKELTABINIT_END);
+
+ return tabInit;
+}
+
+
+//PERV_tySkelTab
+#define TYSKELTAB_DEF \
+"//pervasive type skeleton table (array) \nPERV_TySkelData PERV_tySkelTab[PERV_TY_SKEL_NUM]; \n\n"
+
+//PERV_copyTySkelTab
+#define COPYTYSKELTAB_DEF \
+"void PERV_copyTySkelTab(PERV_TySkelData* dst) \n{ \n memcpy((void*)dst, (void*)PERV_tySkelTab, \n sizeof(PERV_TySkelData) * PERV_KIND_NUM); \n}\n\n"
+char* C_mkTySkelsC(char* tySkelTab)
+{
+ char* text = UTIL_mallocStr(strlen(C_TYSKEL_COMMENTS) +
+ strlen(TYSKELTAB_DEF) +
+ strlen(tySkelTab) +
+ strlen(COPYTYSKELTAB_DEF));
+ strcpy(text, C_TYSKEL_COMMENTS);
+ strcat(text, TYSKELTAB_DEF);
+ strcat(text, tySkelTab);
+ strcat(text, COPYTYSKELTAB_DEF);
+
+ return text;
+}
+
+/*********************************************************************/
+/* Constant relevant components */
+/*********************************************************************/
+#define C_NUMCONSTS_COMMENTS \
+"//total number pervasive constants\n"
+
+/*
+ //total number pervasive constants\n
+ #define PERV_CONST_NUM <num> \n
+*/
+char* C_mkNumConsts(char* num)
+{
+ char* def = C_mkDefine(C_NUMCONSTS, num);
+ size_t length = strlen(def) + strlen(C_NUMCONSTS_COMMENTS) + 5;
+ char* numConsts = UTIL_mallocStr(length);
+
+ strcpy(numConsts, C_NUMCONSTS_COMMENTS);
+ strcat(numConsts, def); free(def);
+ strcat(numConsts, "\n\n");
+
+ return numConsts;
+}
+
+#define C_CONSTINDEX_COMMENTS \
+"//indices for predefined constants\n"
+
+char* C_mkConstIndexType(char* body)
+{
+ char* enumText = C_mkEnum(C_TY_CONSTIND, body);
+ char* typeDefText = C_mkTypeDef(enumText, C_TY_CONSTIND);
+ size_t length = strlen(typeDefText) + strlen(C_CONSTINDEX_COMMENTS);
+ char* constIndexType = UTIL_mallocStr(length);
+
+ strcpy(constIndexType, C_CONSTINDEX_COMMENTS);
+ strcat(constIndexType, typeDefText);
+ free(enumText); free(typeDefText);
+
+ return constIndexType;
+}
+
+//comments
+#define C_CONST_COMMENTS \
+"/***************************************************************************/ \n/* PERVASIVE CONSTANTS */ \n/***************************************************************************/\n\n"
+
+//PERV_ConstData
+#define C_CONSTDATA_TYPE \
+"//pervasive const data type \ntypedef struct \n{ \n char *name; \n TwoBytes typeEnvSize; \n TwoBytes tskTabIndex; //index to the type skeleton table \n TwoBytes neededness; //neededness (predicate constant) \n TwoBytes univCount; \n int precedence; \n int fixity; \n} PERV_ConstData; \n\n"
+
+//PERV_ConstDataTab
+#define C_CONSTDATA_TAB_DEC \
+"//pervasive const data table (array) \nextern PERV_ConstData PERV_constDataTab[PERV_CONST_NUM]; \n\n"
+
+//PERV_getConstData
+#define C_GETCONSTDATA_DEC \
+"//pervasive const data access function \nPERV_ConstData PERV_getConstData(int index); \n\n"
+
+//PERV_copyConstDataTab
+#define C_COPYCONSTDATATAB_DEC \
+"//pervasive const table copy function (used in module space initialization) \n//this functiion relies on the assumption that the pervasive kind data \n//has the same structure as that of the run-time kind symbol table entries. \nvoid PERV_copyConstDataTab(PERV_ConstData* dst); \n\n"
+
+//PERV_isLogicSymb PERV_isPredSymb
+#define C_ISLS_ISPS_DEC \
+"//functions used by the simulator for interpreted goals \nBoolean PERV_isLogicSymb(int index); \nBoolean PERV_isPredSymb(int index); \n\n"
+
+
+//PERV_logicSymb
+#define C_LOGICSYMB_DEC "PERV_LogicSymbTypes PERV_logicSymb(int index); \n\n"
+
+//PERV_predBuiltin
+#define C_PREDBUILTIN_DEC "int PERV_predBuiltin(int index); \n\n"
+
+char* C_mkConstH(char* constIndexType, char* numConsts, char* property)
+{
+ size_t length = strlen(C_CONST_COMMENTS) + strlen(constIndexType) +
+ strlen(numConsts) + strlen(C_CONSTDATA_TYPE) +
+ strlen(C_CONSTDATA_TAB_DEC) + strlen(C_GETCONSTDATA_DEC) +
+ strlen(C_COPYCONSTDATATAB_DEC) + strlen(property) +
+ strlen(C_ISLS_ISPS_DEC) + strlen(C_LOGICSYMB_DEC) +
+ strlen(C_PREDBUILTIN_DEC);
+ char* constH = UTIL_mallocStr(length);
+
+ strcpy(constH, C_CONST_COMMENTS);
+ strcat(constH, constIndexType);
+ strcat(constH, numConsts);
+ strcat(constH, C_CONSTDATA_TYPE);
+ strcat(constH, C_CONSTDATA_TAB_DEC);
+ strcat(constH, C_GETCONSTDATA_DEC);
+ strcat(constH, C_COPYCONSTDATATAB_DEC);
+ strcat(constH, property);
+ strcat(constH, C_ISLS_ISPS_DEC);
+ strcat(constH, C_LOGICSYMB_DEC);
+ strcat(constH, C_PREDBUILTIN_DEC);
+
+ return constH;
+}
+
+/***************************************************************/
+/* pervasives.c */
+/***************************************************************/
+//traslate precedence info into a string
+static char* C_mkPrec(OP_Prec prec)
+{
+ if (OP_precIsMax(prec)) return strdup("256");
+ else return UTIL_itoa(prec.data.prec);
+}
+//translate fixity info into a string
+static char* C_mkFixity(OP_Fixity fixity)
+{
+ switch (fixity){
+ case OP_INFIX : return strdup("OP_INFIX");
+ case OP_INFIXL : return strdup("OP_INFIXL");
+ case OP_INFIXR : return strdup("OP_INFIXR");
+ case OP_PREFIX : return strdup("OP_PREFIX");
+ case OP_PREFIXR : return strdup("OP_PREFIXR");
+ case OP_POSTFIX : return strdup("OP_POSTFIX");
+ case OP_POSTFIXL : return strdup("OP_POSTFIXL");
+ case OP_NONE : return strdup("OP_NONE");
+ default : return strdup("OP_NONE");
+ }
+}
+
+
+// { name, tesize, tst, (need), UC, prec, fixity }
+char* C_mkConstTabEntry(char* name, char* tesize, OP_Prec prec,
+ OP_Fixity fixity, char* tyskelInd, char* neededness,
+ char* comments)
+{
+ char* commentText = (comments) ? C_mkOneLineComments(comments) : NULL;
+ char* precText = C_mkPrec(prec);
+ char* fixityText = C_mkFixity(fixity);
+ size_t length = ((commentText) ? strlen(commentText) + strlen(C_INDENT): 0)
+ + strlen(name) + strlen(tesize) + strlen(tyskelInd)
+ + strlen(neededness) + strlen(precText) + strlen(fixityText)
+ + strlen(C_INDENT)*7 + 15;
+ char* entry = UTIL_mallocStr(length);
+
+ strcpy(entry, C_INDENT);
+ if (commentText) {
+ strcat(entry, commentText); strcat(entry, "\n");
+ strcat(entry, C_INDENT); free(commentText);
+ }
+ strcat(entry, "{\"");
+ strcat(entry, name);
+ strcat(entry, "\",");
+ strcat(entry, C_INDENT);
+ strcat(entry, tesize);
+ strcat(entry, ",");
+ strcat(entry, C_INDENT);
+ strcat(entry, tyskelInd);
+ strcat(entry, ",");
+ strcat(entry, C_INDENT);
+ strcat(entry, neededness);
+ strcat(entry, ",");
+ strcat(entry, C_INDENT);
+ strcat(entry, "0,");
+ strcat(entry, C_INDENT);
+ strcat(entry, precText); free(precText);
+ strcat(entry, ",");
+ strcat(entry, C_INDENT);
+ strcat(entry, fixityText); free(fixityText);
+ strcat(entry, "}");
+
+ return entry;
+}
+
+
+#define C_CONST_TAB_BEG \
+"//pervasive constant data table (array) \nPERV_ConstData PERV_constDataTab[PERV_CONST_NUM] = { \n //name, tesize, tst, neededness, UC, prec, fixity \n"
+#define C_CONST_TAB_END "};\n\n"
+
+/*
+ //pervasive const data table (array)
+ PERV_ConstData PERV_constDataTab[PERV_CONST_NUM] = { \n body \n};\n
+*/
+char* C_mkConstTab(char* body)
+{
+ size_t length = strlen(C_CONST_TAB_BEG) + strlen(C_CONST_TAB_END) +
+ strlen(body);
+ char* constTab = UTIL_mallocStr(length);
+
+ strcpy(constTab, C_CONST_TAB_BEG);
+ strcat(constTab, body);
+ strcat(constTab, C_CONST_TAB_END);
+
+ return constTab;
+}
+
+//PERV_getConstData
+#define C_GETCONSTDATA_DEF \
+"PERV_ConstData PERV_getConstData(int index) \n{ \n return PERV_constDataTab[index]; \n} \n\n"
+
+//PERV_copyConstDataTab
+#define C_COPYCONSTDATATAB_DEF \
+"void PERV_copyConstDataTab(PERV_ConstData* dst) \n{ \n //this way of copy relies on the assumption that the pervasive kind data \n //has the same structure as that of the run-time kind symbol table entries.\n memcpy((void*)dst, (void*)PERV_constDataTab, \n sizeof(PERV_ConstData) * PERV_CONST_NUM); \n} \n\n"
+
+//PERV_isLogicSymb
+#define C_ISLOGICSYMB_DEF \
+"Boolean PERV_isLogicSymb(int index) \n{ \n return ((index >= PERV_LSSTART) && (index <= PERV_LSEND)); \n}\n\n"
+
+//PERV_isPredSymb
+#define C_ISPREDSYMB_DEF \
+"Boolean PERV_isPredSymb(int index) \n{ \n return ((index >= PERV_PREDSTART) && (index <= PERV_PREDEND)); \n}\n\n"
+
+//PERV_logicSymb
+#define C_LOGICSYMB_DEF \
+"PERV_LogicSymbTypes PERV_logicSymb(int index) \n{ \n return ((PERV_LogicSymbTypes)(index - PERV_LSSTART)); \n}\n\n"
+
+//PERV_predBuiltin
+#define C_PREDBUILTIN_DEF \
+"int PERV_predBuiltin(int index) \n{ \n return (index - PERV_PREDSTART); \n}\n\n"
+
+char* C_mkConstC(char* constTab)
+{
+ size_t length = strlen(C_CONST_COMMENTS) + strlen(constTab) +
+ strlen(C_GETCONSTDATA_DEF) + strlen(C_COPYCONSTDATATAB_DEF) +
+ strlen(C_ISLOGICSYMB_DEF) + strlen(C_ISPREDSYMB_DEF) +
+ strlen(C_LOGICSYMB_DEF) + strlen(C_PREDBUILTIN_DEF);
+ char* constC = UTIL_mallocStr(length);
+
+ strcpy(constC, C_CONST_COMMENTS);
+ strcat(constC, constTab);
+ strcat(constC, C_GETCONSTDATA_DEF);
+ strcat(constC, C_COPYCONSTDATATAB_DEF);
+ strcat(constC, C_ISLOGICSYMB_DEF);
+ strcat(constC, C_ISPREDSYMB_DEF);
+ strcat(constC, C_LOGICSYMB_DEF);
+ strcat(constC, C_PREDBUILTIN_DEF);
+
+ return constC;
+}
+
+#define LOGICSYMBTYPE_DEC_BEG \
+"typedef enum PERV_LogicSymbTypes \n{\n"
+#define LOGICSYMBTYPE_DEC_END "} PERV_LogicSymbTypes;\n\n"
+
+char* C_mkLSTypeDec(char* body)
+{
+ size_t length = strlen(LOGICSYMBTYPE_DEC_BEG) + strlen(LOGICSYMBTYPE_DEC_END)
+ + strlen(body);
+ char* text = UTIL_mallocStr(length);
+
+ strcpy(text, LOGICSYMBTYPE_DEC_BEG);
+ strcat(text, body);
+ strcat(text, LOGICSYMBTYPE_DEC_END);
+
+ return text;
+}
+
+//PERV_LSSTART
+#define LSSTART_BEG "#define PERV_LSSTART "
+#define LSSTART_END " //begin of interpretable symbols\n"
+#define LSEND_BEG "#define PERV_LSEND "
+#define LSEND_END " //end of interpretable symbols\n"
+char* C_mkLSRange(char* start, char* end)
+{
+ char* range;
+ char* startInd = C_mkIndexName(start);
+ char* endInd = C_mkIndexName(end);
+ size_t length = strlen(startInd) + strlen(LSSTART_BEG) + strlen(LSSTART_END) +
+ strlen(endInd) + strlen(LSEND_BEG) + strlen(LSEND_END) + 5;
+
+ range = UTIL_mallocStr(length);
+ strcpy(range, LSSTART_BEG);
+ strcat(range, " ");
+ strcat(range, startInd); free(startInd);
+ strcat(range, LSSTART_END);
+ strcat(range, LSEND_BEG);
+ strcat(range, " ");
+ strcat(range, endInd); free(endInd);
+ strcat(range, LSEND_END);
+ strcat(range, "\n");
+
+ return range;
+}
+
+//PERV_PREDSTART
+#define PREDSTART_BEG "#define PERV_PREDSTART "
+#define PREDSTART_END " //begin of predicate symbols\n"
+#define PREDEND_BEG "#define PERV_PREDEND "
+#define PREDEND_END " //end of predicate symbols\n"
+
+char* C_mkPredRange(char* start, char* end)
+{
+ char* range;
+ char* startInd = C_mkIndexName(start);
+ char* endInd = C_mkIndexName(end);
+ size_t length = strlen(startInd) + strlen(PREDSTART_BEG) +
+ strlen(PREDSTART_END) + strlen(endInd) + strlen(PREDEND_BEG) +
+ strlen(PREDEND_END) + 5;
+
+ range = UTIL_mallocStr(length);
+ strcpy(range, PREDSTART_BEG);
+ strcat(range, " ");
+ strcat(range, startInd); free(startInd);
+ strcat(range, PREDSTART_END);
+ strcat(range, PREDEND_BEG);
+ strcat(range, " ");
+ strcat(range, endInd); free(endInd);
+ strcat(range, PREDEND_END);
+ strcat(range, "\n");
+
+ return range;
+}
+
+
+/*********************************************************************/
+/* fixed part of pervasives.h{c} */
+/*********************************************************************/
+#define C_COMMENTS_BEG_H \
+"/****************************************************************************/\n/* File pervasives.h. */ \n/****************************************************************************/\n\n"
+
+
+#define C_COMPDEF_BEG_H "#ifndef PERVASIVES_H\n#define PERVASIVES_H\n\n"
+#define C_COMPDEF_END_H "#endif //PERVASIVES_H\n"
+
+#define C_INCLUDE_H \
+"#include \"../simulator/mctypes.h\" //to be changed \n#include \"../simulator/dataformats.h\" //to be changed \n\n"
+
+char* C_mkFixedBegH()
+{
+ char* text = UTIL_mallocStr(strlen(C_COMMENTS_BEG_H) +
+ strlen(C_COMPDEF_BEG_H) +
+ strlen(C_INCLUDE_H));
+ strcpy(text, C_COMMENTS_BEG_H);
+ strcat(text, C_COMPDEF_BEG_H);
+ strcat(text, C_INCLUDE_H);
+ return text;
+}
+
+char* C_mkFixedEndH()
+{
+ char* text = strdup(C_COMPDEF_END_H);
+ return text;
+}
+
+#define C_COMMENTS_BEG_C \
+"/***************************************************************************/ \n/* File pervasives.c. */ \n/***************************************************************************/\n\n"
+
+#define C_COMPDEF_BEG_C "#ifndef PERVASIVES_C\n#define PERVASIVES_C\n\n"
+#define C_COMPDEF_END_C "#endif //PERVASIVES_C\n"
+
+#define C_INCLUDE_C \
+"#include <string.h> \n#include \"pervasives.h\" \n#include \"../system/error.h\" //to be changed \n#include \"../system/operators.h\" //to be changed \n\n"
+
+char* C_mkFixedBegC()
+{
+ char* text = UTIL_mallocStr(strlen(C_COMMENTS_BEG_C) +
+ strlen(C_COMPDEF_BEG_C) +
+ strlen(C_INCLUDE_C));
+ strcpy(text, C_COMMENTS_BEG_C);
+ strcat(text, C_COMPDEF_BEG_C);
+ strcat(text, C_INCLUDE_C);
+ return text;
+}
+
+char* C_mkFixedEndC()
+{
+ char* text = strdup(C_COMPDEF_END_C);
+ return text;
+}
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/ccode.h b/src/runtime/c/teyjus/tables_gen/pervasives/ccode.h
new file mode 100644
index 000000000..7d5a781bb
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/ccode.h
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+#include "types.h"
+#include "op.h"
+
+/*******************************************************************/
+/* commen structures */
+/*******************************************************************/
+/* // <comments> */
+char* C_mkOneLineComments(char* comments);
+/* // empty */
+char* C_mkEmptyComments();
+/*
+ //comments \n
+ PERV_<name>_INDEX = <indexNum>
+*/
+char* C_mkIndex(char* name, char* indexNum, char* comments);
+/*
+ PERV_<name> = <indexNum>
+*/
+char* C_mkIndex2(char* name, char* indexNum);
+
+/******************************************************************/
+/* kind relevant components */
+/******************************************************************/
+char* C_mkNumKinds(char* num);
+char* C_mkKindIndexType(char* body);
+char* C_mkKindH(char* indexType, char* kindNum);
+
+char* C_mkKindTabEntry(char* name, char* arity, char* comments);
+char* C_mkKindTab(char* body);
+char* C_mkKindC(char* kindTab);
+
+/******************************************************************/
+/* type skeleton relevant components */
+/******************************************************************/
+char* C_mkNumTySkels(char* num);
+char* C_mkTySkelsH(char* numTySkels);
+
+extern int C_totalSpace;
+char* C_genTySkel(Type tyskel, char* comments);
+char* C_mkTySkelTabInit(char* body, int space);
+char* C_mkTySkelsC(char* tySkelTab);
+
+/******************************************************************/
+/* constant relevant components */
+/******************************************************************/
+char* C_mkNumConsts(char* num);
+char* C_mkConstIndexType(char* body);
+char* C_mkConstH(char* constIndexType, char* numConsts, char* property);
+
+char* C_mkConstTabEntry(char* name, char* tesize, OP_Prec prec,
+ OP_Fixity fixity, char* tyskelInd, char* neededness,
+ char* comments);
+char* C_mkConstTab(char* body);
+char* C_mkConstC(char* constTab);
+
+
+char* C_mkLSTypeDec(char* body);
+char* C_mkLSRange(char* start, char* end);
+char* C_mkPredRange(char* start, char* end);
+
+char* C_mkFixedBegH();
+char* C_mkFixedEndH();
+char* C_mkFixedBegC();
+char* C_mkFixedEndC();
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.c b/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.c
new file mode 100644
index 000000000..261d4dfab
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.c
@@ -0,0 +1,1434 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/***************************************************************************/
+/* ocamlcode.c. */
+/* This file defines auxiliary functions in making pervasive.mli and */
+/* pervasive.ml. */
+/* Since space and time efficiency is not an important concern in the */
+/* system source code generation phase, the code here is structured in the */
+/* way for the convenience of making changes on pervasive.mli{ml}. */
+/***************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ocamlcode.h"
+
+/***************************************************************************/
+/* Functions for making various language constructs */
+/***************************************************************************/
+/* Make a string of form <first>.<second> */
+static char* OC_mkDotStr(char* first, char* second)
+{
+ size_t length = strlen(first) + strlen(second) + 1;
+ char* ptr = UTIL_mallocStr(length+1);
+
+ strcpy(ptr, first);
+ strcat(ptr, ".");
+ strcat(ptr, second);
+
+ return ptr;
+}
+
+/*
+ (Some <info>)
+*/
+char* OC_mkSome(char* info)
+{
+ size_t length = strlen(info) + 10;
+ char* rtptr = UTIL_mallocStr(length + 1);
+
+ strcpy(rtptr, "(Some ");
+ strcat(rtptr, info);
+ strcat(rtptr, ")");
+
+ return rtptr;
+}
+
+/*
+ (ref <info>)
+*/
+char* OC_mkRef(char* info)
+{
+ size_t length = strlen(info) + 10;
+ char* rtptr = UTIL_mallocStr(length + 1);
+
+ strcpy(rtptr, "(ref ");
+ strcat(rtptr, info);
+ strcat(rtptr, ")");
+
+ return rtptr;
+}
+
+
+/* Make a variable definition:
+ let <varName> = <defs>
+*/
+static char* OC_mkVarDef(char* varName, char* defs)
+{
+ size_t length = strlen(varName) + strlen(defs) + 10;
+ char* vardef = UTIL_mallocStr(length + 1);
+
+ strcpy(vardef, "let ");
+ strcat(vardef, varName);
+ strcat(vardef, " = ");
+ strcat(vardef, defs);
+
+ return vardef;
+}
+
+/* Make a variable declaration:
+ val <varName> : <varType>"\n"
+*/
+static char* OC_mkVarDec(char* varName, char* varType)
+{
+ size_t length = strlen(varName) + strlen(varType) + 10;
+ char* vardec = UTIL_mallocStr(length + 1);
+
+ strcpy(vardec, "val ");
+ strcat(vardec, varName);
+ strcat(vardec, " : ");
+ strcat(vardec, varType);
+ strcat(vardec, "\n");
+
+ return vardec;
+}
+
+/* Make arrow type:
+ <type1> -> <type2>
+*/
+static char* OC_mkArrowType(char* ty1, char* ty2)
+{
+ size_t length = strlen(ty1) + strlen(ty2) + 5;
+ char* arrowType = UTIL_mallocStr(length);
+
+ strcpy(arrowType, ty1);
+ strcat(arrowType, " -> ");
+ strcat(arrowType, ty2);
+ return arrowType;
+}
+
+
+/**************************************************************************/
+/* Names from other modules */
+/**************************************************************************/
+/********************************************************/
+/* Fixities */
+/********************************************************/
+#define INFIX "Absyn.Infix"
+#define INFIXL "Absyn.Infixl"
+#define INFIXR "Absyn.Infixr"
+#define PREFIX "Absyn.Prefix"
+#define PREFIXR "Absyn.Prefixr"
+#define POSTFIX "Absyn.Postfix"
+#define POSTFIXL "Absyn.Postfixl"
+#define NOFIXITY "Absyn.NoFixity"
+
+#define MAXPREC "maxPrec + 1"
+
+/********************************************************/
+/* module names */
+/********************************************************/
+#define ABSYN "Absyn"
+#define SYMBOL "Symbol"
+#define ERRORMSG "Errormsg"
+#define TABLE "Table"
+
+/********************************************************/
+/* types */
+/********************************************************/
+//absyn
+#define TY_KIND "akind"
+#define TY_CONST "aconstant"
+#define TY_TERM "aterm"
+#define TY_TYABBREV "atypeabbrev"
+//table
+#define TY_SYMTAB "SymbolTable.t"
+
+/********************************************************/
+/* value constructors */
+/********************************************************/
+//absyn
+#define VCTR_KIND "Kind"
+#define VCTR_KINDTYPE "PervasiveKind"
+#define VCTR_CONSTANT "Constant"
+#define VCTR_PERVCONST "PervasiveConstant"
+#define VCTR_TYSKEL "Skeleton"
+#define VCTR_APPTYPE "ApplicationType"
+#define VCTR_ARROWTYPE "ArrowType"
+#define VCTR_SKELVARTYPE "SkeletonVarType"
+#define VCTR_BUILTIN "Builtin"
+
+//errormsg
+#define VCTR_NULLPOS "none"
+
+//symbol
+#define VCTR_SYMBOL "symbol"
+#define VCTR_SYMBOL_ALIAS "symbolAlias"
+
+//table
+#define VCTR_EMPTYTAB "SymbolTable.empty"
+
+/********************************************************/
+/* functions */
+/********************************************************/
+//table
+#define FUNC_ADD "add"
+//absyn
+#define FUNC_MAKETYSETVAR "makeTypeSetVariable"
+
+/***************************************************************************/
+/* Local names */
+/***************************************************************************/
+#define BUILDPERVKIND "buildPervasiveKinds"
+#define BUILDPERVCONST "buildPervasiveConstants"
+
+#define PERVKIND "pervasiveKinds"
+#define PERVCONST "pervasiveConstants"
+#define PERVTYABBR "pervasiveTypeAbbrevs"
+
+#define KVAR_PREFIX "k"
+#define CVAR_POSTFIX "Constant"
+#define TSKVAR_PREFIX "tyskel"
+#define TAB "t"
+
+#define IS "is"
+#define SETVARIR "tysetvarIR"
+#define SETVARIRS "tysetvarIRS"
+#define OVERLOADTYSKEL1 "overloadTySkel1"
+#define OVERLOADTYSKEL2 "overloadTySkel2"
+#define OVERLOADTYSKEL3 "overloadTySkel3"
+
+/***************************************************************************/
+/* Functions for making program components */
+/***************************************************************************/
+/*
+ (Symbol.symbol "<name>")
+*/
+static char* OC_mkSymbol(char* name)
+{
+ char* symbolCtr = OC_mkDotStr(SYMBOL, VCTR_SYMBOL);
+ size_t length = strlen(symbolCtr) + strlen(name) + 10;
+ char* rtptr= UTIL_mallocStr(length + 1);
+
+ strcpy(rtptr, "(");
+ strcat(rtptr, symbolCtr); free(symbolCtr);
+ strcat(rtptr, " \"");
+ strcat(rtptr, name);
+ strcat(rtptr, "\")");
+ return rtptr;
+}
+
+/*
+ (Symbol.symbolAlias "<name>" "<printName>")
+*/
+static char* OC_mkSymbolAlias(char *name, char *printName)
+{
+ char* symbolCtr = OC_mkDotStr(SYMBOL, VCTR_SYMBOL_ALIAS);
+ size_t length = strlen(symbolCtr) + strlen(name) + strlen(printName) + 10;
+ char* rtptr= UTIL_mallocStr(length + 1);
+
+ strcpy(rtptr, "(");
+ strcat(rtptr, symbolCtr); free(symbolCtr);
+ strcat(rtptr, " \"");
+ strcat(rtptr, name);
+ strcat(rtptr, "\" \"");
+ strcat(rtptr, printName);
+ strcat(rtptr, "\")");
+ return rtptr;
+}
+
+/* let t = Table.add (Symbol.symbol "<name>") <varName> t in\n
+ */
+char* OC_mkTabEntry(char* name, char* varName)
+{
+ char* entry;
+ char* tableAdd = OC_mkDotStr(TABLE, FUNC_ADD);
+ char* symbol = OC_mkSymbol(name);
+ size_t length = strlen(tableAdd) + strlen(symbol) + strlen(varName) +
+ strlen(TAB) + 15;
+ char* def = UTIL_mallocStr(length + 1);
+
+ strcpy(def, tableAdd); free(tableAdd);
+ strcat(def, " ");
+ strcat(def, symbol); free(symbol);
+ strcat(def, " ");
+ strcat(def, varName);
+ strcat(def, " ");
+ strcat(def, TAB);
+ strcat(def, " in\n ");
+
+ entry = OC_mkVarDef(TAB, def); free(def);
+ return entry;
+}
+
+/* let t = Table.SymbolTable.empty in \n*/
+static char* OC_mkTabInit()
+{
+ char* init;
+ char* emptyTab = OC_mkDotStr(TABLE, VCTR_EMPTYTAB);
+ size_t length = strlen(emptyTab) + 10;
+ char* def = UTIL_mallocStr(length + 1);
+
+ strcpy(def, emptyTab); free(emptyTab);
+ strcat(def, " in\n ");
+
+ init = OC_mkVarDef(TAB, def); free(def);
+
+ return init;
+}
+
+/* let <funcName> = function () ->\n
+ let t = Table.SymbolTable.empty in <entries> t\n\n */
+static char* OC_mkBuildTabFunc(char* funcName, char* entries)
+{
+ char* func;
+ char* inits = OC_mkTabInit();
+ size_t length = strlen(entries) + strlen(TAB) + strlen(inits) + 30;
+ char* def = UTIL_mallocStr(length + 1);
+
+ strcpy(def, "function () ->\n ");
+ strcat(def, inits); free(inits);
+ strcat(def, entries);
+ strcat(def, TAB);
+ strcat(def, "\n\n");
+
+ func = OC_mkVarDef(funcName, def); free(def);
+
+ return func;
+}
+
+/* let <tabName> = <buildFunc> ()\n\n */
+static char* OC_mkTab(char* tabName, char* buildFuncName)
+{
+ char* tab;
+ size_t length = strlen(buildFuncName) + 10;
+ char* def = UTIL_mallocStr(length + 1);
+
+ strcpy(def, buildFuncName);
+ strcat(def, " ()\n\n");
+
+ tab = OC_mkVarDef(tabName, def); free(def);
+
+ return tab;
+}
+
+/* val <tabName> = Absyn.<typeName> Table.SymbolTable.t\n */
+static char* OC_mkTabDec(char* tabName, char* typeName)
+{
+ char* dec;
+ char* symbolTab = OC_mkDotStr(TABLE, TY_SYMTAB);
+ char* myType = OC_mkDotStr(ABSYN, typeName);
+ size_t length = strlen(symbolTab) + strlen(myType) + 5;
+ char* typedec = UTIL_mallocStr(length + 1);
+
+ strcpy(typedec, myType); free(myType);
+ strcat(typedec, " ");
+ strcat(typedec, symbolTab); free(symbolTab);
+ strcat(typedec, "\n");
+
+ dec = OC_mkVarDec(tabName, typedec); free(typedec);
+
+ return dec;
+}
+
+/****************************************************************************/
+/* functions for making pervasive kind relevant components */
+/****************************************************************************/
+/* k<name> */
+char* OC_mkKVarName(char* name)
+{
+ return UTIL_appendStr(KVAR_PREFIX, name);
+}
+
+/* is<name> */
+char* OC_mkIsKindFuncName(char* name)
+{
+ return UTIL_appendStr(IS, name);
+}
+
+/* val <kindVarName> : Absyn.akind \n*/
+char* OC_mkKindVarDec(char* kindVarName)
+{
+ char* kindType = OC_mkDotStr(ABSYN, TY_KIND);
+ char* dec = OC_mkVarDec(kindVarName, kindType);
+ free(kindType);
+ return dec;
+}
+
+/* val <funcName> : Absyn.akind -> bool */
+char* OC_mkIsKindFuncDec(char* funcName)
+{
+ char* kindType = OC_mkDotStr(ABSYN, TY_KIND);
+ char* arrowType = OC_mkArrowType(kindType, "bool");
+ char* dec = OC_mkVarDec(funcName, arrowType);
+ free(kindType); free(arrowType);
+ return dec;
+}
+
+/* let <funcName> tm = tm == <kindVarName> */
+char* OC_mkIsKindFuncDef(char* funcName, char* kindVarName)
+{
+ char* funchead = UTIL_mallocStr(strlen(funcName) + 3);
+ char* defbody = UTIL_mallocStr(strlen(kindVarName) + 10);
+ char* def;
+
+ strcpy(funchead, funcName);
+ strcat(funchead, " tm");
+
+ strcpy(defbody, "(tm == ");
+ strcat(defbody, kindVarName);
+ strcat(defbody, ")");
+
+ def = OC_mkVarDef(funchead, defbody); free(funchead); free(defbody);
+ return def;
+}
+
+/*Kind variable definition:
+ let <varName> = Absyn.PervasiveKind(Symbol.symbol "<kindName>",
+ (Some <arity>), ref offset, Errormsg.none)
+*/
+char* OC_mkKindVar(char* varName, char* kindName, char* arity, char* offset)
+{
+ char* kindvar;
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_KIND);
+ char* symbol = OC_mkSymbol(kindName);
+ char* nargs = OC_mkSome(arity);
+ char* index = OC_mkRef(offset);
+ char* ktype = OC_mkDotStr(ABSYN, VCTR_KINDTYPE);
+ char* pos = OC_mkDotStr(ERRORMSG, VCTR_NULLPOS);
+ size_t length = strlen(ctr) + strlen(symbol) + strlen(nargs) +
+ strlen(index) + strlen(ktype) + strlen(pos) + 10;
+
+ char* def = UTIL_mallocStr(length + 1);
+
+ strcpy(def, ctr); free(ctr);
+ strcat(def, "(");
+ strcat(def, symbol); free(symbol);
+ strcat(def, ", ");
+ strcat(def, nargs); free(nargs);
+ strcat(def, ", ");
+ strcat(def, index); free(index);
+ strcat(def, ", ");
+ strcat(def, ktype); free(ktype);
+ strcat(def, ", ");
+ strcat(def, pos); free(pos);
+ strcat(def, ")");
+
+ kindvar = OC_mkVarDef(varName, def); free(def);
+ return kindvar;
+}
+
+/* let buildPervasiveKinds =
+ function () ->\n <inits> <entries>\n <tabName>\n\n */
+char* OC_mkBuildKTabFunc(char* entries)
+{
+ return OC_mkBuildTabFunc(BUILDPERVKIND, entries);
+}
+
+/****************************************************************************/
+/* functions for making pervasive type skeleton components */
+/****************************************************************************/
+/* Absyn.SkeletonVarType(ref <ind>)
+ */
+static char* genTySkelVar(char* ind)
+{
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_SKELVARTYPE);
+ char* ref = OC_mkRef(ind);
+ size_t length = strlen(ctr) + strlen(ref) + 5;
+ char* skelVar = UTIL_mallocStr(length + 1);
+
+ strcpy(skelVar, ctr); free(ctr);
+ strcat(skelVar, "(");
+ strcat(skelVar, ref); free(ref);
+ strcat(skelVar, ")");
+
+ return skelVar;
+}
+
+/* Absyn.ArrowType(<type1>, <type2>)
+ */
+static char* genTySkelArrow(char* type1, char* type2)
+{
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_ARROWTYPE);
+ size_t length = strlen(ctr) + strlen(type1) + strlen(type2) + 5;
+ char* arrowtype = UTIL_mallocStr(length + 1);
+
+ strcpy(arrowtype, ctr); free(ctr);
+ strcat(arrowtype, "(");
+ strcat(arrowtype, type1);
+ strcat(arrowtype, ", ");
+ strcat(arrowtype, type2);
+ strcat(arrowtype, ")");
+
+ return arrowtype;
+}
+
+/* Absyn.AppType(k<sortName>, <args>)
+ */
+static char* genTySkelApp(char* sortName, char* args)
+{
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_APPTYPE);
+ char* sortVar = OC_mkKVarName(sortName);
+ size_t length = strlen(ctr) + strlen(sortVar) + strlen(args) + 5;
+ char* apptype = UTIL_mallocStr(length + 1);
+
+ strcpy(apptype, ctr); free(ctr);
+ strcat(apptype, "(");
+ strcat(apptype, sortVar); free(sortVar);
+ strcat(apptype, ", ");
+ strcat(apptype, args);
+ strcat(apptype, ")");
+
+ return apptype;
+}
+
+/* Absyn.AppType(k<sortName>, [])
+ */
+static char* genTySkelSort(char* sortName)
+{
+ return genTySkelApp(sortName, "[]");
+}
+
+//forward declaration
+char* OC_genTySkel(Type args);
+
+static char* OC_genTySkelArgs(TypeList args)
+{
+ size_t length;
+ char* mytext1 = NULL;
+ char* mytext = NULL;
+ char* oneTypeText = NULL;
+ Type oneType = args -> oneType;
+
+ args = args -> next;
+ mytext1 = OC_genTySkel(oneType);
+
+ while (args) {
+ oneType = args -> oneType;
+ args = args -> next;
+ oneTypeText = OC_genTySkel(oneType);
+
+ length = strlen(mytext1) + strlen(oneTypeText) + 5;
+ mytext = UTIL_mallocStr(length + 1);
+ strcpy(mytext, mytext1); free(mytext1);
+ strcat(mytext, " :: ");
+ strcat(mytext, oneTypeText); free(oneTypeText);
+ mytext1 = mytext;
+ }
+ length = strlen(mytext1) + 10;
+ mytext = UTIL_mallocStr(length + 1);
+ strcpy(mytext, "(");
+ strcat(mytext, mytext1); free(mytext1);
+ strcat(mytext, " :: [])");
+
+ return mytext;
+}
+
+char* OC_genTySkel(Type tyskel)
+{
+ char* mytext1;
+ char* mytext2;
+ char* mytext3;
+
+ switch(tyskel -> tag) {
+ case SORT:
+ {
+ mytext1 = genTySkelSort(tyskel -> data.sort);
+ return mytext1;
+ }
+ case SKVAR:
+ {
+ mytext1 = genTySkelVar(tyskel -> data.skvar);
+ return mytext1;
+ }
+ case STR:
+ {
+ mytext1 = OC_genTySkelArgs(tyskel -> data.str.args);
+ mytext2 = genTySkelApp((tyskel -> data.str.functor)->data.func.name,
+ mytext1);
+ free(mytext1);
+ return mytext2;
+ }
+ case ARROW:
+ {
+ mytext1 = OC_genTySkel(tyskel -> data.arrow.lop);
+ mytext2 = OC_genTySkel(tyskel -> data.arrow.rop);
+ mytext3 = genTySkelArrow(mytext1, mytext2);
+ free(mytext1); free(mytext2);
+ return mytext3;
+ }
+ default:
+ return strdup("");
+ }
+}
+
+/* tyskel<number> */
+char* OC_mkTySkelVarName(char* number)
+{
+ return UTIL_appendStr(TSKVAR_PREFIX, number);
+}
+
+/* Type Skeleton variable definition:
+ let <varName> = Some(Absyn.Skeleton(<tySkel>, ref None, ref false))
+*/
+char* OC_mkTYSkelVar(char* varName, char* tySkel)
+{
+ char* tyskelvar;
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_TYSKEL);
+ char* index = OC_mkRef("None");
+ char* adjust = OC_mkRef("false");
+ size_t length = strlen(ctr) + strlen(index) + strlen(adjust) +
+ strlen(tySkel) + 15;
+ char* def = UTIL_mallocStr(length + 1);
+ char* somedef;
+
+ strcpy(def, "(");
+ strcat(def, ctr); free(ctr);
+ strcat(def, "(");
+ strcat(def, tySkel);
+ strcat(def, ", ");
+ strcat(def, index); free(index);
+ strcat(def, ", ");
+ strcat(def, adjust); free(adjust);
+ strcat(def, "))");
+
+ somedef = OC_mkSome(def); free(def);
+ tyskelvar = OC_mkVarDef(varName, somedef); free(somedef);
+
+ return tyskelvar;
+}
+
+
+static char* OC_mkTypeSetVar(char* defaultty, char* arglist, char* tyName)
+{
+ char* setVar;
+ char* func = OC_mkDotStr(ABSYN, FUNC_MAKETYSETVAR);
+ char* def = UTIL_mallocStr(strlen(func) + strlen(arglist) + strlen(defaultty) + 2);
+ strcpy(def, func); free(func);
+ strcat(def, " ");
+ strcat(def, defaultty);
+ strcat(def, " ");
+ strcat(def, arglist);
+
+ setVar = OC_mkVarDef(tyName, def); free(def);
+ return setVar;
+}
+
+/*********************************************/
+/* generate tyskels for overloaded constants */
+/*********************************************/
+static char* OC_mkTySkelRef(char* tySkel)
+{
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_TYSKEL);
+ char* index = OC_mkRef("None");
+ char* adjust = OC_mkRef("false");
+ size_t length = strlen(ctr) + strlen(index) + strlen(adjust) +
+ strlen(tySkel) + 15;
+ char* def = UTIL_mallocStr(length + 1);
+ char* somedef;
+ char* ref;
+
+ strcpy(def, "(");
+ strcat(def, ctr); free(ctr);
+ strcat(def, "(");
+ strcat(def, tySkel);
+ strcat(def, ", ");
+ strcat(def, index); free(index);
+ strcat(def, ", ");
+ strcat(def, adjust); free(adjust);
+ strcat(def, "))");
+
+ somedef = OC_mkSome(def); free(def);
+ ref = OC_mkRef(somedef); free(somedef);
+ return ref;
+}
+
+char* OC_mkFixedTySkels(char* tySkels)
+{
+ char *text;
+ char* setvarIntReal =
+ OC_mkTypeSetVar("(Absyn.ApplicationType(kint,[]))",
+ "(Absyn.ApplicationType(kint,[]) :: Absyn.ApplicationType(kreal,[]) :: [])", SETVARIR);
+ char* setvarIntRealStr =
+ OC_mkTypeSetVar("(Absyn.ApplicationType(kint,[]))",
+ "(Absyn.ApplicationType(kint,[]) :: Absyn.ApplicationType(kreal,[]) :: Absyn.ApplicationType(kstring, []) :: [])", SETVARIRS);
+ char *tyskelBody, *tyskelBody2;
+ char *tyskel, *tyskelText;
+
+ text = UTIL_appendStr(tySkels, setvarIntReal); free(setvarIntReal);
+ tySkels = UTIL_appendStr(text, "\n"); free(text);
+
+ tyskelBody = genTySkelArrow(SETVARIR, SETVARIR);
+ tyskelText = OC_mkTySkelRef(tyskelBody);
+ tyskel = OC_mkVarDef(OVERLOADTYSKEL1, tyskelText); free(tyskelText);
+ text = UTIL_appendStr(tySkels, tyskel); free(tyskel);
+ tySkels = UTIL_appendStr(text, "\n"); free(text);
+
+ tyskelBody2 = genTySkelArrow(SETVARIR, tyskelBody); free(tyskelBody);
+ tyskelText = OC_mkTySkelRef(tyskelBody2); free(tyskelBody2);
+ tyskel = OC_mkVarDef(OVERLOADTYSKEL2, tyskelText); free(tyskelText);
+ text = UTIL_appendStr(tySkels, tyskel); free(tyskel);
+ tySkels = UTIL_appendStr(text, "\n\n"); free(text);
+
+ text = UTIL_appendStr(tySkels, setvarIntRealStr); free(setvarIntRealStr);
+ tySkels = UTIL_appendStr(text, "\n"); free(text);
+
+ tyskelBody = genTySkelArrow(SETVARIRS, "Absyn.ApplicationType(kbool, [])");
+ tyskelBody2 = genTySkelArrow(SETVARIRS, tyskelBody); free(tyskelBody);
+ tyskelText = OC_mkTySkelRef(tyskelBody2); free(tyskelBody2);
+ tyskel = OC_mkVarDef(OVERLOADTYSKEL3, tyskelText); free(tyskelText);
+ text = UTIL_appendStr(tySkels, tyskel); free(tyskel);
+ tySkels = UTIL_appendStr(text, "\n\n"); free(text);
+
+ return tySkels;
+}
+
+/****************************************************************************/
+/* functions for making pervasive constants components */
+/****************************************************************************/
+/* <name>Constant */
+char* OC_mkCVarName(char* name)
+{
+ return UTIL_appendStr(name, CVAR_POSTFIX);
+}
+/* is<name>Constant */
+char* OC_mkIsConstFuncName(char* name)
+{
+ return UTIL_appendStr(IS, name);
+}
+
+/* val <constVarName> : Absyn.aconstant \n*/
+char* OC_mkConstVarDec(char* constVarName)
+{
+ char* constType = OC_mkDotStr(ABSYN, TY_CONST);
+ char* dec = OC_mkVarDec(constVarName, constType);
+ free(constType);
+ return dec;
+}
+
+/* val <funcName> : Absyn.aconstant -> bool */
+char* OC_mkIsConstFuncDec(char* funcName)
+{
+ char* constType = OC_mkDotStr(ABSYN, TY_CONST);
+ char* arrowType = OC_mkArrowType(constType, "bool");
+ char* dec = OC_mkVarDec(funcName, arrowType);
+ free(constType); free(arrowType);
+ return dec;
+}
+
+
+/* let <funcName> tm = tm == <constVarName> */
+char* OC_mkIsConstFuncDef(char* funcName, char* constVarName)
+{
+ char* funchead = UTIL_mallocStr(strlen(funcName) + 3);
+ char* defbody = UTIL_mallocStr(strlen(constVarName) + 10);
+ char* def;
+
+ strcpy(funchead, funcName);
+ strcat(funchead, " tm");
+
+ strcpy(defbody, "(tm == ");
+ strcat(defbody, constVarName);
+ strcat(defbody, ")");
+
+ def = OC_mkVarDef(funchead, defbody); free(funchead); free(defbody);
+ return def;
+}
+
+/* (ref fixity) */
+static char* OC_mkFixity(OP_Fixity fixity)
+{
+ switch (fixity){
+ case OP_INFIX : return OC_mkRef(strdup(INFIX));
+ case OP_INFIXL : return OC_mkRef(strdup(INFIXL));
+ case OP_INFIXR : return OC_mkRef(strdup(INFIXR));
+ case OP_PREFIX : return OC_mkRef(strdup(PREFIX));
+ case OP_PREFIXR : return OC_mkRef(strdup(PREFIXR));
+ case OP_POSTFIX : return OC_mkRef(strdup(POSTFIX));
+ case OP_POSTFIXL : return OC_mkRef(strdup(POSTFIXL));
+ case OP_NONE : return OC_mkRef(strdup(NOFIXITY));
+ default : return OC_mkRef(strdup(NOFIXITY));
+ }
+}
+
+/* (ref prec) */
+static char* OC_mkPrec(OP_Prec prec)
+{
+ char* precNum;
+ char* precText;
+ if (OP_precIsMax(prec)) {
+ char* temp = OC_mkDotStr(ABSYN, MAXPREC);
+ precNum = UTIL_mallocStr(strlen(temp) + 2);
+ strcpy(precNum, "(");
+ strcat(precNum, temp);
+ strcat(precNum, ")");
+ } else precNum = UTIL_itoa(prec.data.prec);
+ precText = OC_mkRef(precNum); free(precNum);
+ return precText;
+}
+
+/* (ref true/false ) */
+static char* OC_mkRefBool(UTIL_Bool value)
+{
+ if (value) return OC_mkRef("true");
+ else return OC_mkRef("false");
+}
+
+static char* OC_mkRefInt(int value)
+{
+ char* valueText = UTIL_itoa(value);
+ char* text = OC_mkRef(valueText);
+ free(valueText);
+ return text;
+}
+
+static char* OC_mkCodeInfo(OP_Code codeInfo)
+{
+ char* code;
+ char* ref;
+ if (OP_codeInfoIsNone(codeInfo)) {
+ code = strdup("None");
+ } else {
+ char* codeInd = UTIL_itoa(codeInfo);
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_BUILTIN);
+ char* codeText = UTIL_mallocStr(strlen(codeInd) + strlen(ctr) + 10);
+ strcpy(codeText, "(");
+ strcat(codeText, ctr); free(ctr);
+ strcat(codeText, "(");
+ strcat(codeText, codeInd); free(codeInd);
+ strcat(codeText, "))");
+ code = OC_mkSome(codeText); free(codeText);
+ }
+ ref = OC_mkRef(code); free(code);
+ return ref;
+}
+
+static char* OC_mkConstCat(UTIL_Bool redef)
+{
+ char* ctr = OC_mkDotStr(ABSYN,VCTR_PERVCONST);
+ char* boolValue;
+ char* cat;
+ char* ref;
+
+ if (redef) boolValue = strdup("true");
+ else boolValue = strdup("false");
+
+ cat = UTIL_mallocStr(strlen(ctr) + strlen(boolValue) + 10);
+ strcpy(cat, "(");
+ strcat(cat, ctr); free(ctr);
+ strcat(cat, "(");
+ strcat(cat, boolValue); free(boolValue);
+ strcat(cat, "))");
+
+ ref = OC_mkRef(cat); free(cat);
+ return ref;
+}
+
+static char* OC_mkSkelNeededness(int tyenvsize)
+{
+ char* length = UTIL_itoa(tyenvsize);
+ char* some;
+ char* ref;
+ char* init = UTIL_mallocStr(strlen(length) + 20);
+ strcpy(init, "(Array.make ");
+ strcat(init, length); free(length);
+ strcat(init, " true)");
+
+ some = OC_mkSome(init); free(init);
+ ref = OC_mkRef(some); free(some);
+ return ref;
+}
+
+static char* OC_mkNeededness(int neededness, int tyenvsize)
+{
+ char* length = UTIL_itoa(tyenvsize);
+ char* init;
+ char* some;
+ char* ref;
+
+ if (neededness == tyenvsize) {
+ init = UTIL_mallocStr(strlen(length) + 20);
+ strcpy(init, "(Array.make ");
+ strcat(init, length); free(length);
+ strcat(init, " true)");
+ } else {
+ char* num = UTIL_itoa(neededness);
+ init = UTIL_mallocStr(strlen(length) + strlen(num) + 60);
+ strcpy(init, "(Array.init ");
+ strcat(init, length); free(length);
+ strcat(init, " (fun x -> if x >= ");
+ strcat(init, num); free(num);
+ strcat(init, " then false else true))");
+ }
+ some = OC_mkSome(init); free(init);
+ ref = OC_mkRef(some); free(some);
+ return ref;
+}
+
+
+static char* OC_mkConstVarText(char* constName, char* fixity, char* prec,
+ char* typrev, char* tyskel, char* tyenvsize,
+ char* skelneededness, char* neededness, char* codeinfo,
+ char* constcat, char* varname, char* offset,
+ char* printName)
+{
+ char* constVar;
+ char* ctr = OC_mkDotStr(ABSYN, VCTR_CONSTANT);
+ char* symbol = OC_mkSymbolAlias(constName, printName);
+ char* refFalse = OC_mkRef("false");
+ char* refTrue = OC_mkRef("true");
+ char* index = OC_mkRef(offset);
+ char* pos = OC_mkDotStr(ERRORMSG, VCTR_NULLPOS);
+
+ size_t length = strlen(ctr) + strlen(symbol) + strlen(fixity) +
+ strlen(prec) + strlen(typrev) + strlen(tyskel) + strlen(tyenvsize) +
+ strlen(skelneededness) + strlen(neededness) + strlen(codeinfo) +
+ strlen(constcat) + strlen(index) + strlen(pos) + strlen(refFalse) * 6 + 35;
+ char* def = UTIL_mallocStr(length);
+
+ strcpy(def, ctr); free(ctr);
+ strcat(def, "(");
+ strcat(def, symbol); free(symbol);
+ strcat(def, ", ");
+ strcat(def, fixity);
+ strcat(def, ", ");
+ strcat(def, prec);
+ strcat(def, ", ");
+ strcat(def, refFalse);
+ strcat(def, ", ");
+ strcat(def, refFalse);
+ strcat(def, ", ");
+ strcat(def, refTrue); free(refTrue); /* no defs */
+ strcat(def, ", ");
+ strcat(def, refFalse);
+ strcat(def, ", ");
+ strcat(def, typrev);
+ strcat(def, ", ");
+ strcat(def, refFalse); free(refFalse);
+ strcat(def, ", ");
+ strcat(def, tyskel);
+ strcat(def, ", ");
+ strcat(def, tyenvsize);
+ strcat(def, ", ");
+ strcat(def, skelneededness);
+ strcat(def, ", ");
+ strcat(def, neededness);
+ strcat(def, ", ");
+ strcat(def, codeinfo);
+ strcat(def, ", ");
+ strcat(def, constcat);
+ strcat(def, ", ");
+ strcat(def, index); free(index);
+ strcat(def, ", ");
+ strcat(def, pos); free(pos);
+ strcat(def, ")");
+
+ constVar = OC_mkVarDef(varname, def); free(def);
+ return constVar;
+}
+
+/* Constant variable definition :
+ let <varName> = Absyn.Constant(Symbol.symbolAlias "<constName>" "<printName>",
+ ref <fixity>, ref <prec>, ref false, ref false, ref false, ref false,
+ ref false, ref <typrev>, ref false, ref <tySkel>,
+ ref <tyenvsize>, ref (Some <skelneededness>),
+ ref (Some <neededness>), ref <codeInfo>,
+ ref <constantCat>, ref 0, Errormsg.none)
+*/
+char* OC_mkConstVar(char* constName, OP_Fixity fixity, OP_Prec prec,
+ UTIL_Bool typrev, char* tySkel, int tyenvsize,
+ int neededness, OP_Code codeInfo, UTIL_Bool reDef,
+ char* varName, char* offset, char* printName)
+{
+ char* constVar;
+ char* fixityText = OC_mkFixity(fixity);
+ char* precText = OC_mkPrec(prec);
+ char* typrevText = OC_mkRefBool(typrev);
+ char* tySkelText = OC_mkRef(tySkel);
+ char* tyenvsizeText = OC_mkRefInt(tyenvsize);
+ char* skelneedednessText = OC_mkSkelNeededness(tyenvsize);
+ char* needednessText = OC_mkNeededness(neededness, tyenvsize);
+ char* codeInfoText = OC_mkCodeInfo(codeInfo);
+ char* constCatText = OC_mkConstCat(reDef);
+
+ constVar = OC_mkConstVarText(constName, fixityText, precText,
+ typrevText, tySkelText, tyenvsizeText,
+ skelneedednessText, needednessText, codeInfoText,
+ constCatText, varName, offset, printName);
+
+ free(fixityText); free(precText); free(typrevText); free(tySkelText);
+ free(tyenvsizeText); free(skelneedednessText); free(needednessText);
+ free(codeInfoText); free(constCatText);
+
+ return constVar;
+}
+
+#define GENERICAPPLY "genericApplyConstant"
+#define OVERLOADUMINUS "overloadUMinusConstant"
+#define OVERLOADABS "overloadAbsConstant"
+#define OVERLOADPLUS "overloadPlusConstant"
+#define OVERLOADMINUS "overloadMinusConstant"
+#define OVERLOADTIME "overloadTimeConstant"
+#define OVERLOADLT "overloadLTConstant"
+#define OVERLOADGT "overloadGTConstant"
+#define OVERLOADLE "overloadLEConstant"
+#define OVERLOADGE "overloadGEConstant"
+
+static char* OC_mkOverLoadConstVar(char* name, char* fixity, char* prec,
+ char* tyskel, char* varName)
+{
+ char* constVar;
+ constVar = OC_mkConstVarText(name, fixity, prec, "ref true", tyskel,
+ "ref 0", "ref(Some(Array.make 0 true))", "ref None", "ref None",
+ "ref(Absyn.PervasiveConstant(false))",
+ varName, "0", name);
+ return constVar;
+}
+
+/* generate fixed constants */
+char* OC_mkGenericConstVar(char* varList)
+{
+ char* text;
+ char* constVar;
+
+ constVar = OC_mkConstVarText(" apply", "ref Absyn.Infixl",
+ "ref (Absyn.maxPrec + 2)", "ref false",
+ "ref(Some(Absyn.Skeleton(Absyn.ErrorType, ref None, ref false)))",
+ "ref 0", "ref(Some(Array.make 0 true))", "ref None", "ref None",
+ "ref(Absyn.PervasiveConstant(false))", GENERICAPPLY, "0",
+ " apply");
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar("~", "ref Absyn.Prefix",
+ "ref (Absyn.maxPrec + 1)", OVERLOADTYSKEL1,
+ OVERLOADUMINUS);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+
+ constVar = OC_mkConstVarText("abs", "ref Absyn.NoFixity",
+ "ref 0", "ref true",
+ OVERLOADTYSKEL1,
+ "ref 0", "ref(Some(Array.make 0 true))",
+ "ref None", "ref None",
+ "ref(Absyn.PervasiveConstant(true))",
+ OVERLOADABS, "0", "abs");
+
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+
+ constVar = OC_mkOverLoadConstVar("+", "ref Absyn.Infixl", "ref 150",
+ OVERLOADTYSKEL2, OVERLOADPLUS);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar("-", "ref Absyn.Infixl", "ref 150",
+ OVERLOADTYSKEL2, OVERLOADMINUS);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar("*", "ref Absyn.Infixl", "ref 160",
+ OVERLOADTYSKEL2, OVERLOADTIME);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar("<", "ref Absyn.Infix", "ref 130",
+ OVERLOADTYSKEL3, OVERLOADLT);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar(">", "ref Absyn.Infix", "ref 130",
+ OVERLOADTYSKEL3, OVERLOADGT);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar("<", "ref Absyn.Infix", "ref 130",
+ OVERLOADTYSKEL3, OVERLOADLE);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+
+ constVar = OC_mkOverLoadConstVar(">=", "ref Absyn.Infix", "ref 130",
+ OVERLOADTYSKEL3, OVERLOADGE);
+ text = UTIL_appendStr(varList, constVar); free(constVar);
+ varList = UTIL_appendStr(text, "\n\n"); free(text);
+ return varList;
+}
+
+/* generate fixed constants decs */
+char* OC_mkGenericConstVarDec(char* decList)
+{
+ char* text;
+ char* dec;
+
+ dec = OC_mkConstVarDec(GENERICAPPLY);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADUMINUS);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+
+ dec = OC_mkConstVarDec(OVERLOADABS);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+
+ dec = OC_mkConstVarDec(OVERLOADPLUS);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADMINUS);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADTIME);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADLT);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADGT);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADLE);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ dec = OC_mkConstVarDec(OVERLOADGE);
+ text = UTIL_appendStr(decList, dec); free(decList); free(dec);
+ decList = text;
+
+ return decList;
+}
+
+
+/* generate fixed constants entry in buildConstant function */
+char* OC_mkGenericConstTabEntry(char* entries)
+{
+ char* text;
+ char* tabEntry;
+
+ tabEntry = OC_mkTabEntry("~", OVERLOADUMINUS);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+
+ tabEntry = OC_mkTabEntry("abs", OVERLOADABS);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+
+ tabEntry = OC_mkTabEntry("+", OVERLOADPLUS);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry("-", OVERLOADMINUS);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry("*", OVERLOADTIME);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry("<", OVERLOADLT);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry(">", OVERLOADGT);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry("<=", OVERLOADLE);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ tabEntry = OC_mkTabEntry(">=", OVERLOADGE);
+ text = UTIL_appendStr(entries, tabEntry);
+ free(tabEntry); free(entries);
+ entries = text;
+
+ return entries;
+}
+
+/* let buildPervasiveKinds =
+ function () ->\n <inits> <entries>\n <tabName>\n\n */
+char* OC_mkBuildCTabFunc(char* entries)
+{
+ return OC_mkBuildTabFunc(BUILDPERVCONST, entries);
+}
+
+/* make generaic const is function decs */
+char* OC_mkGenericConstFuncDecs(char* funcDefs)
+{
+ char* funcName;
+ char* def;
+ char* text;
+
+ funcName = OC_mkIsConstFuncName(GENERICAPPLY);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADUMINUS);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+
+ funcName = OC_mkIsConstFuncName(OVERLOADABS);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+
+ funcName = OC_mkIsConstFuncName(OVERLOADPLUS);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADMINUS);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADTIME);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADLT);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADGT);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADLE);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ funcName = OC_mkIsConstFuncName(OVERLOADGE);
+ def = OC_mkIsConstFuncDec(funcName); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = text;
+
+ return funcDefs;
+}
+
+
+/* make generaic const is function defs */
+char* OC_mkGenericConstFuncDefs(char* funcDefs)
+{
+ char* funcName;
+ char* def;
+ char* text;
+
+ funcName = OC_mkIsConstFuncName(GENERICAPPLY);
+ def = OC_mkIsConstFuncDef(funcName, GENERICAPPLY); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+
+ funcName = OC_mkIsConstFuncName(OVERLOADUMINUS);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADUMINUS); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+
+ funcName = OC_mkIsConstFuncName(OVERLOADABS);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADABS); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+
+ funcName = OC_mkIsConstFuncName(OVERLOADPLUS);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADPLUS); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADMINUS);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADMINUS); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADTIME);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADTIME); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADLT);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADLT); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADGT);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADGT); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADLE);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADLE); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ funcName = OC_mkIsConstFuncName(OVERLOADGE);
+ def = OC_mkIsConstFuncDef(funcName, OVERLOADGE); free(funcName);
+ text = UTIL_appendStr(funcDefs, def); free(def); free(funcDefs);
+ funcDefs = UTIL_appendStr(text, "\n\n"); free(text);
+
+ return funcDefs;
+}
+
+char* OC_mkCompare(char* name)
+{
+ char* text = UTIL_mallocStr(strlen(name) + 15);
+ strcpy(text, "(const == ");
+ strcat(text, name);
+ strcat(text, ")");
+ return text;
+}
+
+
+char* OC_mkOr(char* operandl, char* operandr)
+{
+ char* text = UTIL_mallocStr(strlen(operandl) + strlen(operandr) + 5);
+ strcpy(text, operandl);
+ strcat(text, " || ");
+ strcat(text, operandr);
+
+ return text;
+}
+
+
+#define PERV_REGCLOB_DEF_BEG "let regClobberingPerv const = \n if ("
+#define PERV_REGCLOB_DEF_END ") then true else false \n\n"
+char* OC_mkRegClobFunc(char* body)
+{
+ char* text = UTIL_mallocStr(strlen(PERV_REGCLOB_DEF_BEG) + strlen(body) +
+ strlen(PERV_REGCLOB_DEF_END));
+ strcpy(text, PERV_REGCLOB_DEF_BEG);
+ strcat(text, body);
+ strcat(text, PERV_REGCLOB_DEF_END);
+
+ return text;
+}
+
+#define PERV_BCK_DEF_BEG "let backtrackablePerv const = \n if ("
+#define PERV_BCK_DEF_END ") then true else false \n\n"
+char* OC_mkBackTrackFunc(char* body)
+{
+ char* text = UTIL_mallocStr(strlen(PERV_BCK_DEF_BEG) + strlen(body) +
+ strlen(PERV_BCK_DEF_END));
+ strcpy(text, PERV_BCK_DEF_BEG);
+ strcat(text, body);
+ strcat(text, PERV_BCK_DEF_END);
+
+ return text;
+}
+
+
+
+/*****************************************************************************/
+/* functions for making the fixed part of pervasive.mli */
+/*****************************************************************************/
+#define TERM_DECS \
+"val implicationTerm : Absyn.aterm\nval andTerm : Absyn.aterm\n"
+
+#define PERV_FUNC_DECS \
+"val isPerv : Absyn.aconstant -> bool \nval regClobberingPerv : Absyn.aconstant -> bool \nval backtrackablePerv : Absyn.aconstant -> bool\n"
+
+/*
+ val pervasiveKinds : Absyn.akind Table.SymbolTable.t
+ val pervasiveConstants : Absyn.aconstant Table.SymbolTable.t
+ val pervasiveTypeAbbrevs : Absyn.atypeabbrev Table.SymbolTable.t
+*/
+char* OC_mkFixedMLI()
+{
+ char* kindDec = OC_mkTabDec(PERVKIND, TY_KIND);
+ char* constDec = OC_mkTabDec(PERVCONST, TY_CONST);
+ char* tyabbrDec = OC_mkTabDec(PERVTYABBR, TY_TYABBREV);
+ size_t length = strlen(kindDec) + strlen(constDec) + strlen(tyabbrDec) +
+ strlen(TERM_DECS) + strlen(PERV_FUNC_DECS) + 10;
+ char* decs = UTIL_mallocStr(length + 1);
+
+ strcpy(decs, kindDec); free(kindDec);
+ strcat(decs, constDec); free(constDec);
+ strcat(decs, tyabbrDec); free(tyabbrDec);
+ strcat(decs, "\n");
+ strcat(decs, TERM_DECS);
+ strcat(decs, "\n");
+ strcat(decs, PERV_FUNC_DECS);
+ strcat(decs, "\n");
+
+ return decs;
+}
+
+/*****************************************************************************/
+/* functions for making the fixed part of pervasive.ml */
+/*****************************************************************************/
+#define TERM_DEFS \
+"let andTerm = Absyn.ConstantTerm(andConstant, [], false, Errormsg.none) \nlet implicationTerm = Absyn.ConstantTerm(implConstant, [], false, Errormsg.none)\n"
+
+#define PERV_ISPERV_DEF \
+"let isPerv const = \n let constCat = Absyn.getConstantType(const) in \n match constCat with \n Absyn.PervasiveConstant(_) -> true \n | _ -> false \n"
+
+/*
+ let pervasiveKinds = buildPervasiveKinds ()
+ let pervasiveConstants = buildPervasiveConstants ()
+ let pervasiveTypeAbbrevs = Table.SymbolTable.empty
+*/
+char* OC_mkFixedML()
+{
+ char* kindDef = OC_mkTab(PERVKIND, BUILDPERVKIND);
+ char* constDef = OC_mkTab(PERVCONST, BUILDPERVCONST);
+ char* emptyTab = OC_mkDotStr(TABLE, VCTR_EMPTYTAB);
+ char* tyabbrDef = OC_mkVarDef(PERVTYABBR, emptyTab);
+ size_t length = strlen(kindDef) + strlen(constDef) + strlen(tyabbrDef) +
+ strlen(TERM_DEFS) + strlen(PERV_ISPERV_DEF) + 10;
+ char* defs = UTIL_mallocStr(length + 1);
+
+ free(emptyTab);
+ strcpy(defs, kindDef); free(kindDef);
+ strcat(defs, constDef); free(constDef);
+ strcat(defs, tyabbrDef); free(tyabbrDef);
+ strcat(defs, "\n\n");
+ strcat(defs, TERM_DEFS);
+ strcat(defs, "\n");
+ strcat(defs, PERV_ISPERV_DEF);
+ strcat(defs, "\n");
+
+ return defs;
+}
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.h b/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.h
new file mode 100644
index 000000000..8b2ba062b
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/ocamlcode.h
@@ -0,0 +1,152 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/***************************************************************************/
+/* ocamlcode.h{c}. */
+/* These files contain usful macros and auxiliary functions for generating */
+/* the pervasive.mli and pervasive.ml. */
+/* The parts of the ocaml files that are independent to the pervasives.in */
+/* also reside here. */
+/* The length macros for string macros defined here may be larger than the */
+/* extra lengthes of corresponding strings. This is ok because space and */
+/* time efficiency are not of concern in generating system files. */
+/***************************************************************************/
+#include "types.h"
+#include "op.h"
+#include "../util/util.h"
+
+/***************************************************************************/
+/* Functions for making program components */
+/***************************************************************************/
+/* let t = Table.add (Symbol.symbol "<name>") <varName> t in\n
+*/
+char* OC_mkTabEntry(char* name, char* varName);
+
+
+/****************************************************************************/
+/* functions for making pervasive kind relevant components */
+/****************************************************************************/
+/* k<name> */
+char* OC_mkKVarName(char* name);
+/* is<name> */
+char* OC_mkIsKindFuncName(char* name);
+/* val <kindVarName> : Absyn.akind \n*/
+char* OC_mkKindVarDec(char* kindVarName);
+/* val <funcName> : Absyn.akind -> bool */
+char* OC_mkIsKindFuncDec(char* funcName);
+/* let <funcName> tm = tm == <kindVarName> */
+char* OC_mkIsKindFuncDef(char* funcName, char* kindVarName);
+
+
+/* let <varName> = Absyn.PervasiveKind(Symbol.symbol "<kindName>",
+ (Some <arity>), ref offset, Errormsg.none)
+*/
+char* OC_mkKindVar(char* varName, char* kindName, char* arity, char* offset);
+
+/* let buildPervasiveKinds =
+ function () ->\n <inits> <entries>\n <tabName>\n\n */
+char* OC_mkBuildKTabFunc(char* entries);
+
+/****************************************************************************/
+/* functions for making pervasive type skeleton components */
+/****************************************************************************/
+/* generating code for type skeleton */
+char* OC_genTySkel(Type tyskel);
+
+/* tyskel<number> */
+char* OC_mkTySkelVarName(char* number);
+
+/* Type Skeleton variable definition:
+ let <varName> = Some(Absyn.Skeleton(<tySkel>, ref None, ref false))
+*/
+char* OC_mkTYSkelVar(char* varName, char* tySkel);
+
+/* generate tyskels for overloaded constants */
+char* OC_mkFixedTySkels(char* tySkels);
+
+
+/****************************************************************************/
+/* functions for making pervasive constants components */
+/****************************************************************************/
+/* <name>Constant */
+char* OC_mkCVarName(char* name);
+/* is<name> */
+char* OC_mkIsConstFuncName(char* name);
+
+/* val <constVarName> : Absyn.aconstant \n*/
+char* OC_mkConstVarDec(char* constVarName);
+
+/* Constant variable definition :
+ let <varName> = Absyn.Constant(Symbol.symbolAlias "<constName>" "<printName>",
+ ref <fixity>,
+ ref <prec>, ref false, ref false, ref false, ref false,
+ ref false, ref <typrev>, ref false, ref <tySkel>,
+ ref <tyenvsize>, ref (Some <neededness>), ref <codeInfo>,
+ ref <constantCat>, ref offset, Errormsg.none)
+*/
+char* OC_mkConstVar(char* constName, OP_Fixity fixity, OP_Prec prec,
+ UTIL_Bool typrev, char* tySkel, int tyenvsize,
+ int neededness, OP_Code codeInfo, UTIL_Bool reDef,
+ char* varName, char* offset, char* printName);
+
+/* val <funcName> : Absyn.aconstant -> bool */
+char* OC_mkIsConstFuncDec(char* funcName);
+
+/* let <funcName> tm = tm == <constVarName> */
+char* OC_mkIsConstFuncDef(char* funcName, char* constVarName);
+
+/* generate fixed constants */
+char* OC_mkGenericConstVar(char* varList);
+/* generate fixed constants decs */
+char* OC_mkGenericConstVarDec(char* decList);
+
+/* generate fixed constants entry in buildConstant function */
+char* OC_mkGenericConstTabEntry(char* entries);
+/* let buildPervasiveKinds =
+ function () ->\n <inits> <entries>\n <tabName>\n\n */
+char* OC_mkBuildCTabFunc(char* entries);
+
+/* make generaic const is function decs */
+char* OC_mkGenericConstFuncDecs(char* funcDefs);
+/* make generaic const is function defs */
+char* OC_mkGenericConstFuncDefs(char* funcDefs);
+
+
+char* OC_mkCompare(char* name);
+char* OC_mkOr(char* operandl, char* operandr);
+
+char* OC_mkRegClobFunc(char* body);
+char* OC_mkBackTrackFunc(char* body);
+
+/*****************************************************************************/
+/* functions for making the fixed part of pervasive.mli */
+/*****************************************************************************/
+/*
+ val pervasiveKinds : Absyn.akind Table.SymbolTable.t
+ val pervasiveConstants : Absyn.aconstant Table.SymbolTable.t
+ val pervasiveTypeAbbrevs : Absyn.atypeabbrev Table.SymbolTable.t
+*/
+char* OC_mkFixedMLI();
+
+/*****************************************************************************/
+/* functions for making the fixed part of pervasive.ml */
+/*****************************************************************************/
+/*
+ let pervasiveKinds = buildPervasiveKinds ()
+ let pervasiveConstants = buildPervasiveConstants ()
+ let pervasiveTypeAbbrevs = Table.SymbolTable.empty
+*/
+char* OC_mkFixedML();
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/op.c b/src/runtime/c/teyjus/tables_gen/pervasives/op.c
new file mode 100644
index 000000000..583063e49
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/op.c
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+#include <stdlib.h>
+#include <string.h>
+#include "../util/util.h"
+#include "op.h"
+
+OP_Prec OP_mkPrecMin1()
+{
+ OP_Prec prec;
+ prec.cat = OP_PREC;
+ prec.data.prec = -1;
+
+ return prec;
+}
+
+OP_Prec OP_mkPrecMin2()
+{
+ OP_Prec prec;
+ prec.cat = OP_PREC;
+ prec.data.prec = -2;
+
+ return prec;
+}
+
+OP_Prec OP_mkPrec(int precedence)
+{
+ OP_Prec prec;
+ prec.cat = OP_PREC;
+ prec.data.prec = precedence ;
+
+ return prec;
+}
+
+OP_Prec OP_mkPrecMax()
+{
+ OP_Prec prec;
+ prec.cat = OP_PREC_NAME;
+ prec.data.name = strdup("MAX");
+ return prec;
+}
+
+int OP_precIsMax(OP_Prec prec)
+{
+ if ((prec.cat == OP_PREC_NAME) && (strcmp(prec.data.name, "MAX") == 0))
+ return 1;
+ return 0;
+}
+
+
+OP_Code OP_mkCodeInfoNone()
+{
+ return -1;
+}
+
+OP_Code OP_mkCodeInfo(int ind)
+{
+ return ind;
+}
+
+int OP_codeInfoIsNone(OP_Code code)
+{
+ return (code < 0);
+}
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/op.h b/src/runtime/c/teyjus/tables_gen/pervasives/op.h
new file mode 100644
index 000000000..37456c897
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/op.h
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+#ifndef OP_H
+#define OP_H
+
+//fixity type
+typedef enum {
+ OP_INFIX, OP_INFIXL, OP_INFIXR, OP_PREFIX, OP_PREFIXR, OP_POSTFIX,
+ OP_POSTFIXL, OP_NONE
+} OP_Fixity;
+
+typedef enum {
+ OP_PREC, OP_PREC_NAME
+} OP_PrecTypeCat;
+
+//precedence type
+typedef struct
+{
+ OP_PrecTypeCat cat;
+ union
+ {
+ int prec;
+ char* name;
+ } data;
+} OP_Prec;
+
+OP_Prec OP_mkPrecMin1();
+OP_Prec OP_mkPrecMin2();
+OP_Prec OP_mkPrec(int prec);
+OP_Prec OP_mkPrecMax();
+
+int OP_precIsMax(OP_Prec prec);
+
+
+//code info type
+typedef int OP_Code;
+
+OP_Code OP_mkCodeInfoNone();
+OP_Code OP_mkCodeInfo(int ind);
+
+int OP_codeInfoIsNone(OP_Code code);
+
+#endif
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.in b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.in
new file mode 100644
index 000000000..2a332da91
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.in
@@ -0,0 +1,404 @@
+/% input file for pervasives files generation %/
+
+/% section I: pervasive kinds %/
+ /% number of pervasive kinds %/
+ KIND 7
+ /% kind data table %/
+ /% index name index_name arity %/
+ /* int */
+ 0 int int 0 ;;
+ /* real */
+ 1 real real 0 ;;
+ /* bool */
+ 2 o bool 0 ;;
+ /* string */
+ 3 string string 0 ;;
+ /* list type constructor */
+ 4 list list 1 ;;
+ /* in_stream */
+ 5 in_stream instream 0 ;;
+ /* out_stream */
+ 6 out_stream outstream 0
+
+/% section II: pervasive constants and their type skeletons %/
+ /% section II.I : type skeletion and constant declarations %/
+
+ /% number of pervasive constants %/
+ CONST 94
+ /% number of type skeletons %/
+ TYPE SKEL 42
+
+ /% type skeleton and constant data table %/
+ /% type skeleton format:
+ [comments]
+ TYPE index type %/
+ /% constant format:
+ index name indname tesize neededness typerv redef prec fixity codeinfo
+ %/
+
+ /* A */
+ TYPE 0 #0
+ /* for unnamed universal constants (Note: tesize should be 0)*/
+ 85 <constant> univ 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* (list A) */
+ TYPE 1 (@ list 1 [#0])
+ /* nil */
+ 89 nil nil 0 1 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+
+ /* A->(list A)->(list A) */
+ TYPE 2 #0 -> (@ list 1 [#0]) -> (@ list 1 [#0])
+ /* cons */
+ 93 :: cons 0 1 0 TRUE FALSE 140 INFIXR NOCODE
+ ;;
+
+ /* int */
+ TYPE 3 int
+ /* integer constant */
+ 90 <int_constant> intc 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* real */
+ TYPE 4 real
+ /* real constant */
+ 91 <real_constant> realc 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* string */
+ TYPE 5 string
+ /* string constant */
+ 92 <str_constant> strc 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* o (type of proposition)*/
+ TYPE 6 bool
+ /* true proposition */
+ 4 true true 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ /* cut predicate */
+ 5 ! cut 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ /* fail predicate */
+ 6 fail fail 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ /* halt the system */
+ 9 halt halt 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ /* return to top level */
+ 10 stop stop 0 0 0 TRUE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* int -> int */
+ TYPE 7 int -> int
+ /* unary minus on integers */
+ 56 %i~ intuminus 0 0 0 TRUE FALSE MAX PREFIX NOCODE -
+ /* modulus */
+ 61 mod mod 0 0 0 TRUE TRUE 160 INFIXL NOCODE
+ /* integer abs */
+ 63 %iabs iabs 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE abs
+ ;;
+
+ /* int -> int -> int */
+ TYPE 8 int -> int -> int
+ /* addition on integers */
+ 57 %i+ intplus 0 0 0 TRUE FALSE 150 INFIXL NOCODE +
+ /* subtraction on integers */
+ 58 %i- intminus 0 0 0 TRUE FALSE 150 INFIXL NOCODE -
+ /* mutiplication on integers */
+ 59 %i* intmult 0 0 0 TRUE FALSE 160 INFIXL NOCODE *
+ /* integer division */
+ 60 div intdiv 0 0 0 TRUE FALSE 160 INFIXL NOCODE
+ ;;
+
+ /* int -> int -> o */
+ TYPE 9 int -> int -> bool
+ /* less than on integers */
+ 19 %i< intlss 0 0 0 TRUE FALSE 130 INFIX 4 <
+ /* greater than on integers */
+ 20 %i> intgrt 0 0 0 TRUE FALSE 130 INFIX 5 >
+ /* less than or eq on integers */
+ 21 %i<= intleq 0 0 0 TRUE FALSE 130 INFIX 6 <=
+ /* greater than or eq on integers*/
+ 22 %i>= intgeq 0 0 0 TRUE FALSE 130 INFIX 7 >=
+ /* time predicate */
+ 51 time time 0 0 0 TRUE TRUE 0 NOFIXITY 36
+ ;;
+
+ /* int -> real */
+ TYPE 10 int -> real
+ /* coercion to real */
+ 62 int_to_real itor 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* real -> int */
+ TYPE 11 real -> int
+ /* floor function */
+ 74 floor floor 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* ceiling function */
+ 75 ceil ceil 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* truncation */
+ 76 truncate trunc 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* real -> real */
+ TYPE 12 real -> real
+ /* unary minus on real */
+ 64 %r~ realuminus 0 0 0 TRUE FALSE MAX PREFIX NOCODE -
+ /* square root */
+ 69 sqrt sqrt 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* sine */
+ 70 sin sin 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* cosine */
+ 71 cos cos 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* arc tan */
+ 72 arctan arctan 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* natural log */
+ 73 ln log 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* real abs */
+ 77 %rabs rabs 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE rabs
+ ;;
+
+ /* real -> string */
+ TYPE 13 real -> string
+ /* real to string */
+ 84 real_to_string rtos 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* real -> real -> real */
+ TYPE 14 real -> real -> real
+ /* addition on reals */
+ 65 %r+ realplus 0 0 0 TRUE FALSE 150 INFIXL NOCODE +
+ /* subtraction on reals */
+ 66 %r- realminus 0 0 0 TRUE FALSE 150 INFIXL NOCODE -
+ /* multiplication on reals */
+ 67 %r* realmult 0 0 0 TRUE FALSE 160 INFIXL NOCODE *
+ /* division */
+ 68 / realdiv 0 0 0 TRUE FALSE 160 INFIXL NOCODE
+ ;;
+
+ /* real -> real -> o */
+ TYPE 15 real -> real -> bool
+ /* less than in reals */
+ 23 %r< reallss 0 0 0 TRUE FALSE 130 INFIX 8 <
+ /* greater than on reals */
+ 24 %r> realgrt 0 0 0 TRUE FALSE 130 INFIX 9 >
+ /* less than or eq on reals */
+ 25 %r<= realleq 0 0 0 TRUE FALSE 130 INFIX 10 <=
+ /* greater than or eq on reals */
+ 26 %r>= realgeq 0 0 0 TRUE FALSE 130 INFIX 11 >=
+ ;;
+
+ /* string -> int */
+ TYPE 16 string -> int
+ /* string length */
+ 79 size slen 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* ord function */
+ 81 string_to_int stoi 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* int -> string */
+ TYPE 17 int -> string
+ /* chr function */
+ 80 chr itochr 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* int to string */
+ 83 int_to_string itostr 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* string -> string -> string */
+ TYPE 18 string -> string -> string
+ /* string concatination */
+ 78 ^ scat 0 0 0 TRUE TRUE 150 INFIXL NOCODE
+ ;;
+
+ /* string -> string -> o */
+ TYPE 19 string -> string -> bool
+ /* less than on strings */
+ 27 %s< strlss 0 0 0 TRUE TRUE 130 INFIX 12 <
+ /* greater than on strings */
+ 28 %s> strgrt 0 0 0 TRUE TRUE 130 INFIX 13 >
+ /* less than or eq on strings */
+ 29 %s<= strleq 0 0 0 TRUE TRUE 130 INFIX 14 <=
+ /* greater than or eq on strings */
+ 30 %s>= strgeq 0 0 0 TRUE TRUE 130 INFIX 15 >=
+ /* getenv predicate; needed? */
+ 49 getenv getenv 0 0 0 TRUE TRUE 0 NOFIXITY 34
+ ;;
+
+ /* string -> int -> int -> string */
+ TYPE 20 string -> int -> int -> string
+ /* substring */
+ 82 substring substr 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* o -> o -> o */
+ TYPE 21 bool -> bool -> bool
+ /* logical and */
+ 0 , and 0 0 0 TRUE FALSE 110 INFIXL NOCODE
+ /* logical or */
+ 1 ; or 0 0 0 TRUE FALSE 100 INFIXL NOCODE
+ /* another logical and */
+ 8 & ampand 0 0 0 TRUE FALSE 120 INFIXR NOCODE
+ /* Prolog if; needed? */
+ 11 :- colondash 0 0 0 TRUE FALSE 0 INFIXL NOCODE
+ /* implication; needed? */
+ 12 => impl 0 0 0 TRUE FALSE 130 INFIXR NOCODE
+ ;;
+
+ /* (A -> o) -> o */
+ TYPE 22 (#0 -> bool) -> bool
+ /* existential quantifier */
+ 2 sigma some 1 1 1 FALSE FALSE 0 NOFIXITY NOCODE
+ /* universal quantifier */
+ 3 pi all 1 1 1 FALSE FALSE 0 NOFIXITY NOCODE
+ ;;
+
+ /* A -> A -> o */
+ TYPE 23 #0 -> #0 -> bool
+ /* is */
+ 16 is is 1 1 1 FALSE FALSE 130 INFIX 1
+ /* equality (unify) predicate */
+ 18 = eq 1 1 1 FALSE FALSE 130 INFIX 3
+ ;;
+
+ /* in_stream */
+ TYPE 24 instream
+ /* std_in */
+ 86 std_in stdin 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* out_stream */
+ TYPE 25 outstream
+ /* std_out */
+ 87 std_out stdout 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ /* std_err */
+ 88 std_err stderr 0 0 0 TRUE TRUE 0 NOFIXITY NOCODE
+ ;;
+
+ /* string -> in_stream -> o */
+ TYPE 26 string -> instream -> bool
+ /* open_in */
+ 31 open_in openin 0 0 0 TRUE TRUE 0 NOFIXITY 16
+ /* open_string */
+ 36 open_string openstr 0 0 0 TRUE TRUE 0 NOFIXITY 21
+ ;;
+
+ /* string -> out_stream -> o */
+ TYPE 27 string -> outstream -> bool
+ /* open_out */
+ 32 open_out openout 0 0 0 TRUE TRUE 0 NOFIXITY 17
+ /* open_append */
+ 33 open_append openapp 0 0 0 TRUE TRUE 0 NOFIXITY 18
+ ;;
+
+ /* in_stream -> o */
+ TYPE 28 instream -> bool
+ /* close_in */
+ 34 close_in closein 0 0 0 TRUE TRUE 0 NOFIXITY 19
+ /* eof */
+ 41 eof eof 0 0 0 TRUE TRUE 0 NOFIXITY 26
+ ;;
+
+ /* out_stream -> o */
+ TYPE 29 outstream -> bool
+ /* close_out */
+ 35 close_out closeout 0 0 0 TRUE TRUE 0 NOFIXITY 20
+ /* flush */
+ 42 flush flush 0 0 0 TRUE TRUE 0 NOFIXITY 27
+ ;;
+
+ /* A -> string -> o */
+ TYPE 30 #0 -> string -> bool
+ /* term_to_string */
+ 46 term_to_string termtostr 1 1 0 FALSE TRUE 0 NOFIXITY 31
+ ;;
+
+ /* string -> A -> o */
+ TYPE 31 string -> #0 -> bool
+ /* string_to_term */
+ 47 string_to_term strtoterm 1 1 1 FALSE TRUE 0 NOFIXITY 32
+ ;;
+
+ /* out_stream -> string -> o */
+ TYPE 32 outstream -> string -> bool
+ /* output */
+ 38 output output 0 0 0 TRUE TRUE 0 NOFIXITY 23
+ ;;
+
+ /* in_stream -> int -> string -> o */
+ TYPE 33 instream -> int -> string -> bool
+ /* input */
+ 37 input input 0 0 0 TRUE TRUE 0 NOFIXITY 22
+ ;;
+
+ /* in_stream -> string -> o */
+ TYPE 34 instream -> string -> bool
+ /* input_line */
+ 39 input_line inputline 0 0 0 TRUE TRUE 0 NOFIXITY 24
+ /* lookahead */
+ 40 lookahead lookahead 0 0 0 TRUE TRUE 0 NOFIXITY 25
+ ;;
+
+ /* string -> o */
+ TYPE 35 string -> bool
+ /* print */
+ 43 print print 0 0 0 TRUE TRUE 0 NOFIXITY 28
+ ;;
+
+ /* A -> o */
+ TYPE 36 #0 -> bool
+ /* read */
+ 44 read read 1 1 1 FALSE TRUE 0 NOFIXITY 29
+ ;;
+
+ /* out_stream -> A -> o */
+ TYPE 37 outstream -> #0 -> bool
+ /* printterm */
+ 45 printterm printterm 1 1 0 FALSE TRUE 0 NOFIXITY 30
+ ;;
+
+ /* in_stream -> A -> o */
+ TYPE 38 instream -> #0 -> bool
+ /* readterm */
+ 48 readterm readterm 1 1 1 FALSE TRUE 0 NOFIXITY 33
+ ;;
+
+ /* o -> o */
+ TYPE 39 bool -> bool
+ /* solve; used by code generator */
+ 15 solve solve 0 0 0 TRUE FALSE 0 NOFIXITY 0
+ /* not */
+ 17 not not 0 0 0 TRUE FALSE 0 NOFIXITY 2
+ ;;
+
+ /* string -> int -> in_stream -> out_stream -> o */
+ TYPE 40 string -> int -> instream -> outstream -> bool
+ /* open_socket predicate */
+ 50 open_socket opensocket 0 0 0 FALSE TRUE 0 NOFIXITY 35
+ ;;
+
+ /* string -> int -> o */
+ TYPE 41 string -> int -> bool
+ /* system predicate */
+ 52 system system 0 0 0 FALSE TRUE 0 NOFIXITY 37
+
+ /% pervasive constant classification %/
+ LOGIC SYMBOL 11
+ LS_START and LS_END stop
+ /% logic symbol types %/
+ 0 and
+ 1 or
+ 2 some
+ 3 all
+ 4 l_true
+ 5 cut
+ 6 fail
+ 7 eq
+ 8 ampand
+ 9 halt
+ 10 stop
+
+ PRED SYMBOL 37
+ PRED_START solve PRED_END system
+
+ REGCL solve not getenv strtoterm readterm read is lookahead input inputline
+
+ BACKTRACK eq
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.l b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.l
new file mode 100644
index 000000000..e046a63c0
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.l
@@ -0,0 +1,96 @@
+%{
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "../util/util.h"
+#include "op.h"
+#include "types.h"
+#include "y.tab.h"
+#include <stdlib.h>
+#include <string.h>
+
+static int commentLev = 0;
+%}
+
+LETTER [A-Za-z]
+DIGIT [0-9]
+SYMBOL "_"|"+"|"-"|"*"|"/"|"!"|"~"|"@"|"$"|"%"|"^"|"&"|"*"|"<"|">"|"="|"'"|";"|":"|","
+
+ID ({LETTER}|{SYMBOL})({LETTER}|{DIGIT}|{SYMBOL})*
+NUM {DIGIT}+
+WSPACE [ \t]+
+STRING [^*/]+
+
+%x COMMENT C_COMMENT
+
+/* Some versions of lex require an explicit positions argument */
+%p 10000
+
+%%
+<INITIAL,COMMENT>"\n" {continue; }
+<INITIAL>"KIND" {return KIND; }
+<INITIAL>"CONST" {return CONST; }
+<INITIAL>"TYPE SKEL" {return TYSKEL; }
+<INITIAL>"TYPE" {return TYPE; }
+<INITIAL>"->" {return TYARROW; }
+<INITIAL>"@" {return TYAPP; }
+<INITIAL>"[" {return LBRACKET; }
+<INITIAL>"]" {return RBRACKET; }
+<INITIAL>"(" {return LPAREN; }
+<INITIAL>")" {return RPAREN; }
+<INITIAL>"t," {return COMMA; }
+<INITIAL>"#" {return POUND; }
+<INITIAL>";;" {return SEMICOLON; }
+<INITIAL>"INFIX" {return INFIX; }
+<INITIAL>"INFIXL" {return INFIXL; }
+<INITIAL>"INFIXR" {return INFIXR; }
+<INITIAL>"PREFIX" {return PREFIX; }
+<INITIAL>"PREFIXR" {return PREFIXR; }
+<INITIAL>"POSTFIX" {return POSTFIX; }
+<INITIAL>"POSTFIXL" {return POSTFIXL; }
+<INITIAL>"NOFIXITY" {return NOFIXITY; }
+<INITIAL>"MIN1" {return MIN1; }
+<INITIAL>"MIN2" {return MIN2; }
+<INITIAL>"MAX" {return MAX; }
+<INITIAL>"NOCODE" {return NOCODE; }
+<INITIAL>"LOGIC SYMBOL" {return LSSYMB; }
+<INITIAL>"LS_START" {return LSSTART; }
+<INITIAL>"LS_END" {return LSEND; }
+<INITIAL>"PRED SYMBOL" {return PREDSYMB; }
+<INITIAL>"PRED_START" {return PREDSTART; }
+<INITIAL>"PRED_END" {return PREDEND; }
+<INITIAL>"REGCL" {return REGCL; }
+<INITIAL>"BACKTRACK" {return BACKTRACK; }
+<INITIAL>"TRUE" {return TRUE; }
+<INITIAL>"FALSE" {return FALSE; }
+<INITIAL>{WSPACE} {continue; }
+<INITIAL>"/%" {commentLev = 1; BEGIN(COMMENT); continue; }
+<INITIAL>"/*" {BEGIN(C_COMMENT); continue; }
+<INITIAL>{ID} {yylval.name = strdup(yytext); return ID; }
+<INITIAL>{NUM} {yylval.isval.ival = atoi(yytext);
+ yylval.isval.sval = strdup(yytext);
+ return NUM; }
+
+<C_COMMENT>"*/" {BEGIN(INITIAL); continue; }
+<C_COMMENT>{STRING} {yylval.text = strdup(yytext); return STRING; }
+
+<COMMENT>[^%/\n]+ {continue; }
+<COMMENT>"/%" {commentLev++; continue; }
+<COMMENT>"%/" {commentLev--;
+ if (!commentLev) BEGIN(INITIAL); continue; }
+
+. {return ERROR; }
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.y b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.y
new file mode 100644
index 000000000..3b55e3aad
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervasives.y
@@ -0,0 +1,351 @@
+%{
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../util/util.h"
+#include "op.h"
+#include "types.h"
+#include "pervgen-c.h"
+#include "pervgen-ocaml.h"
+//#include "ops.h"
+
+extern int yylex();
+
+int yywrap() {return 1;}
+
+void yyerror(const char* str)
+{
+ printf("Error: Unable to parse input: %s\n", str);
+}
+
+static int tySkelInd = 0;
+
+%}
+
+%union
+{
+ char* name;
+ char* text;
+ OP_Fixity fixityType;
+ OP_Prec precType;
+ OP_Code codeType;
+ UTIL_Bool boolType;
+ struct
+ {
+ int ival;
+ char* sval;
+ } isval;
+ Type tyval;
+ TypeList tylistval;
+}
+
+%token LBRACKET RBRACKET LPAREN RPAREN COMMA POUND SEMICOLON TRUE
+ FALSE
+ TYARROW TYAPP
+ INFIX INFIXL INFIXR PREFIX PREFIXR POSTFIX POSTFIXL NOFIXITY
+ MIN1 MIN2 MAX
+ NOCODE
+ LSSYMB LSSTART LSEND PREDSYMB PREDSTART PREDEND REGCL
+ BACKTRACK
+ KIND CONST EMPTY TYSKEL TYPE EMPTYTYPE ERROR
+
+%token <name> ID
+%token <isval> NUM
+%token <text> STRING
+
+
+%start pervasives
+%type <text> comments
+%type <tyval> arrow_tyskel app_tyskel atomic_tyskel
+%type <tylistval> tyskel_list
+%type <isval> ty_index tesize neededness
+%type <name> const_name const_ind_name
+%type <fixityType> fixity
+%type <precType> prec
+%type <codeType> code_info
+%type <boolType> redef typrev
+%%
+
+pervasives : kind const_tyskel
+ ;
+
+kind : kind_header kind_decls
+ { cgenKindH(); cgenKindC(); ocamlGenKinds(); }
+ ;
+
+kind_header : KIND NUM
+ { cgenKindInit($2.ival); cgenNumKinds($2.sval);
+ ocamlGenNumKinds($2.sval);
+ }
+ ;
+
+kind_decls : kind_decl SEMICOLON kind_decls
+ | kind_decl
+ ;
+
+kind_decl : NUM ID ID NUM
+ { cgenKindIndex($1.ival, $3, $1.sval, NULL);
+ cgenKindData($1.ival, $2, $4.sval, NULL);
+ ocamlGenKind($2, $3, $4.sval, $1.sval); }
+ | comments NUM ID ID NUM
+ { cgenKindIndex($2.ival, $4, $2.sval, $1);
+ cgenKindData($2.ival, $3, $5.sval, $1);
+ ocamlGenKind($3, $4, $5.sval, $2.sval); }
+ ;
+
+comments : STRING { $$ = $1;};
+ ;
+
+const_tyskel : const_tyskel_header const_tyskel_decls const_property
+ { cgenTySkelsH(); cgenTySkelsC(); cgenConstProperty();
+ cgenConstH(); cgenConstC();
+ ocamlGenConsts();
+ }
+ ;
+
+
+const_tyskel_header : CONST NUM TYSKEL NUM
+ { cgenNumTySkels($4.sval); cgenTySkelInit($4.ival);
+ cgenNumConsts($2.sval); cgenConstInit($2.ival);
+ ocamlGenNumConsts($2.sval);
+ }
+ ;
+
+const_tyskel_decls : const_tyskel_decl SEMICOLON const_tyskel_decls
+ | const_tyskel_decl
+ ;
+
+const_tyskel_decl : tyskel_decl const_decls
+ ;
+
+tyskel_decl : TYPE NUM arrow_tyskel
+ {tySkelInd = $2.ival;
+ ocamlGenTySkel($2.sval, $3);
+ cgenTySkelTab($2.ival, $3, NULL);
+ }
+ | comments TYPE NUM arrow_tyskel
+ {tySkelInd = $3.ival;
+ ocamlGenTySkel($3.sval, $4);
+ cgenTySkelTab($3.ival, $4, $1);
+ }
+ ;
+
+
+arrow_tyskel : app_tyskel TYARROW arrow_tyskel
+ { $$ = mkArrowType($1, $3); }
+ | app_tyskel
+ { $$ = $1; }
+ ;
+
+app_tyskel : LPAREN TYAPP ID NUM LBRACKET tyskel_list
+ RBRACKET RPAREN
+ {$$ = mkStrType(mkStrFuncType($3,$4.sval), $4.ival, $6);}
+ | atomic_tyskel
+ {$$ = $1; }
+ ;
+
+atomic_tyskel : ID
+ { $$ = mkSortType($1); }
+ | ty_index
+ { $$ = mkSkVarType($1.sval); }
+ | LPAREN arrow_tyskel RPAREN
+ { $$ = $2; }
+ ;
+
+tyskel_list : arrow_tyskel COMMA tyskel_list
+ { $$ = addItem($1, $3); }
+ | arrow_tyskel
+ { $$ = addItem($1, NULL); }
+
+ty_index : POUND NUM {$$ = $2;}
+ ;
+
+const_decls : const_decl const_decls
+ | const_decl
+ ;
+
+const_decl : NUM const_name const_ind_name tesize tesize neededness
+ typrev redef prec fixity code_info
+ { cgenConstIndex($1.ival, $3, $1.sval, NULL);
+ cgenConstData($1.ival, $2, $4.sval, $9, $10, tySkelInd,
+ $5.sval, NULL);
+ ocamlGenConst($1.sval, $2, $3, $10, $9, $7, $8,
+ $4.ival, tySkelInd, $6.ival, $11,
+ $1.sval, $2);
+ }
+ | NUM const_name const_ind_name tesize tesize neededness
+ typrev redef prec fixity code_info const_name
+ { cgenConstIndex($1.ival, $3, $1.sval, NULL);
+ cgenConstData($1.ival, $12, $4.sval, $9, $10, tySkelInd,
+ $5.sval, NULL);
+ ocamlGenConst($1.sval, $2, $3, $10, $9, $7, $8,
+ $4.ival, tySkelInd, $6.ival, $11,
+ $1.sval, $12);
+ }
+ | comments NUM const_name const_ind_name tesize tesize
+ neededness typrev redef prec fixity code_info
+ { cgenConstIndex($2.ival, $4, $2.sval, $1);
+ cgenConstData($2.ival, $3, $5.sval, $10, $11,
+ tySkelInd, $7.sval, $1);
+ ocamlGenConst($2.sval, $3, $4, $11, $10, $8, $9,
+ $5.ival, tySkelInd, $7.ival, $12,
+ $2.sval, $3);
+ }
+ | comments NUM const_name const_ind_name tesize tesize
+ neededness typrev redef prec fixity code_info const_name
+ { cgenConstIndex($2.ival, $4, $2.sval, $1);
+ cgenConstData($2.ival, $13, $5.sval, $10, $11,
+ tySkelInd, $7.sval, $1);
+ ocamlGenConst($2.sval, $3, $4, $11, $10, $8, $9,
+ $5.ival, tySkelInd, $7.ival, $12,
+ $2.sval, $13);
+ }
+ ;
+
+const_name : ID {$$ = $1;}
+ ;
+const_ind_name : ID {$$ = $1;}
+ ;
+
+tesize : NUM {$$ = $1;}
+ ;
+neededness : NUM {$$ = $1;}
+ ;
+
+typrev : TRUE {$$ = UTIL_TRUE;}
+ | FALSE {$$ = UTIL_FALSE;}
+ ;
+
+redef : TRUE {$$ = UTIL_TRUE;}
+ | FALSE {$$ = UTIL_FALSE;}
+ ;
+
+fixity : INFIX {$$ = OP_INFIX;}
+ | INFIXL {$$ = OP_INFIXL;}
+ | INFIXR {$$ = OP_INFIXR;}
+ | PREFIX {$$ = OP_PREFIX;}
+ | PREFIXR {$$ = OP_PREFIXR;}
+ | POSTFIX {$$ = OP_POSTFIX;}
+ | POSTFIXL {$$ = OP_POSTFIXL;}
+ | NOFIXITY {$$ = OP_NONE;}
+ ;
+
+prec : MIN1 {$$ = OP_mkPrecMin1();}
+ | MIN2 {$$ = OP_mkPrecMin2();}
+ | NUM {$$ = OP_mkPrec($1.ival);}
+ | MAX {$$ = OP_mkPrecMax();}
+ ;
+
+code_info : NOCODE {$$ = OP_mkCodeInfoNone();}
+ | NUM {$$ = OP_mkCodeInfo($1.ival);}
+ ;
+
+const_property : logic_symbol pred_symbol regclobber backtrackable
+ ;
+
+logic_symbol : ls_header ls_range ls_types
+ ;
+
+ls_header : LSSYMB NUM { cgenLogicSymbolInit($2.ival); }
+ ;
+
+ls_range : LSSTART const_ind_name LSEND const_ind_name
+ { cgenLSRange($2, $4);}
+ ;
+
+ls_types : ls_type ls_types
+ | ls_type
+ ;
+
+ls_type : NUM ID {cgenLogicSymbType($1.ival, $2, $1.sval);}
+ ;
+
+pred_symbol : pred_header pred_range
+ ;
+
+pred_header : PREDSYMB NUM
+ {if ($2.ival == 0) {
+ fprintf(stderr,
+ "The number of predicate symbols cannot be 0\n");
+ exit(1);
+ }
+ }
+ ;
+
+pred_range : PREDSTART const_ind_name PREDEND const_ind_name
+ { cgenPREDRange($2, $4); }
+ ;
+
+regclobber : REGCL const_list { ocamlGenRC(); }
+ ;
+
+backtrackable : BACKTRACK const_list { ocamlGenBC(); }
+ ;
+
+const_list : ID const_list { ocamlCollectConsts($1, 0); }
+ | ID { ocamlCollectConsts($1, 1); }
+ ;
+
+%%
+
+extern FILE* yyin;
+
+int main(argc, argv)
+ int argc;
+ char * argv[];
+{
+ int ret = 0;
+ char * root = NULL;
+ if(argc == 1)
+ {
+ //printf("No input file specified; using 'Pervasives.in'.\n");
+ yyin = UTIL_fopenR("pervasives.in");
+ }
+ else
+ {
+ yyin = UTIL_fopenR(argv[1]);
+ }
+
+ if(argc > 2)
+ {
+ root = argv[2];
+ }
+ else
+ {
+ //printf("Teyjus source root directory not specified; using '../../'.\n");
+ root = "../../";
+ }
+
+ //printf("Generating pervasive files...\n");
+
+ ret = yyparse();
+ UTIL_fclose(yyin);
+
+ if(ret != 0)
+ {
+ printf("Generation failed.\n");
+ return -1;
+ }
+ spitCPervasivesH(root);
+ spitCPervasivesC(root);
+ //spitOCPervasiveMLI(root);
+ //spitOCPervasiveML(root);
+ //printf("Done.\n");
+ return 0;
+}
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.c b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.c
new file mode 100644
index 000000000..c3a4327ad
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.c
@@ -0,0 +1,454 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/*****************************************************************************/
+/* File pervgen-c.c. This files contains function definitions for generating */
+/* files pervasives.h and pervasives.c. */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pervgen-c.h"
+#include "ccode.h"
+#include "../util/util.h"
+
+//dynamic string array type
+typedef struct StringArray
+{
+ char **array;
+ int length;
+} StringArray;
+
+//array initialization
+static void arrayInit(char **array, int size)
+{
+ int i ;
+ for (i =0; i < size; i++) array[i] = NULL;
+}
+
+//collect string in a StringArray into a single array
+static char* collectStringArray(StringArray arr, char* emptyText)
+{
+ char *myText = NULL;
+ char *myText2 = NULL;
+ int i;
+ int length = 0;
+
+ for (i = 0; i < arr.length; i++) {
+ char* text = arr.array[i];
+ if (text == NULL) text = emptyText;
+
+ if (myText) {
+ myText2 = UTIL_mallocStr(strlen(text) + strlen(myText));
+ strcpy(myText2, myText);
+ strcat(myText2, text);
+ free(myText);
+ } else {
+ myText2 = UTIL_mallocStr(strlen(text));
+ strcpy(myText2, text);
+ }
+ if (arr.array[i]) free(arr.array[i]);
+ myText = myText2;
+ }
+ free(arr.array);
+
+ return myText;
+}
+
+/****************************************************************************/
+/* kind relevant components */
+/****************************************************************************/
+/***********************************************************************/
+/* pervasives.h */
+/***********************************************************************/
+//number of pervasive kinds
+static char* numKinds = NULL;
+
+void cgenNumKinds(char* num)
+{
+ numKinds = C_mkNumKinds(num);
+}
+
+//pervasive kind indices declaration
+static StringArray kindIndices; //kind indices declaration
+
+void cgenKindIndex(int index, char* name, char* indexT, char* comments)
+{
+ char* kindIndex;
+ char* kindIndexText;
+
+ if (index >= kindIndices.length) {
+ fprintf(stderr, "kind index exceed total number of kinds\n");
+ exit(1);
+ }
+ kindIndex = C_mkIndex(name, indexT, comments);
+ kindIndexText = UTIL_mallocStr(strlen(kindIndex) + 2);
+ strcpy(kindIndexText, kindIndex); free(kindIndex);
+ if (index != (kindIndices.length - 1)) strcat(kindIndexText, ",");
+ strcat(kindIndexText, "\n");
+
+ kindIndices.array[index] = kindIndexText;
+}
+
+//pervasive kind relevant information in pervasives.h
+static char* kindH;
+void cgenKindH()
+{
+ char* emptyText = C_mkEmptyComments();
+
+ char* kindIndexBody = collectStringArray(kindIndices, emptyText);
+ char* kindIndexTypeDef = C_mkKindIndexType(kindIndexBody);
+
+ kindH = C_mkKindH(kindIndexTypeDef, numKinds);
+ free(kindIndexBody); free(kindIndexTypeDef); free(numKinds);
+ free(emptyText);
+}
+
+/***********************************************************************/
+/* pervasives.c */
+/***********************************************************************/
+//pervasive kind table entries
+static StringArray kindData;
+void cgenKindData(int index, char* name, char* arity, char* comments)
+{
+ char* oneKindData;
+ char* kindDataText;
+
+ if (index >= kindData.length) {
+ fprintf(stderr, "kind index exceed total number of kinds\n");
+ exit(1);
+ }
+ oneKindData = C_mkKindTabEntry(name, arity, comments);
+ kindDataText = UTIL_mallocStr(strlen(oneKindData) + 2);
+ strcpy(kindDataText, oneKindData); free(oneKindData);
+ if (index != kindData.length - 1) strcat(kindDataText, ",");
+ strcat(kindDataText, "\n");
+
+ kindData.array[index] = kindDataText;
+}
+
+#define EMPTY_TEXT_KIND_TAB " //nothing \n {NULL, 0},\n"
+
+//pervasive kind relevant information in pervasives.c
+static char* kindC;
+void cgenKindC()
+{
+ char* kindTabBody = collectStringArray(kindData, EMPTY_TEXT_KIND_TAB);
+ char* kindTab = C_mkKindTab(kindTabBody);
+
+ kindC = C_mkKindC(kindTab);
+ free(kindTabBody); free(kindTab);
+}
+
+//kind indices info and kind table info initiation
+void cgenKindInit(int length)
+{
+ kindIndices.length = length;
+ kindIndices.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(kindIndices.array, length);
+ kindData.length = length;
+ kindData.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(kindData.array, length);
+}
+
+/****************************************************************************/
+/* type skeleton relevant components */
+/****************************************************************************/
+/***********************************************************************/
+/* pervasives.h */
+/***********************************************************************/
+//number of type skeletons for pervasive constants
+static char* numTySkels = NULL;
+void cgenNumTySkels(char* num)
+{
+ numTySkels = C_mkNumTySkels(num);
+}
+
+//type skeleton relevant information in pervasives.h
+static char* tySkelsH;
+void cgenTySkelsH()
+{
+ tySkelsH = C_mkTySkelsH(numTySkels);
+ free(numTySkels);
+}
+
+/***********************************************************************/
+/* pervasives.c */
+/***********************************************************************/
+//type skeleton creation code
+static StringArray tySkels;
+void cgenTySkelTab(int index, Type tyskel, char* comments)
+{
+ if (index >= tySkels.length){
+ fprintf(stderr,
+ "type skeleton index exceed total number of type skeletons\n");
+ exit(1);
+ }
+ tySkels.array[index] = C_genTySkel(tyskel, comments);
+}
+
+//generate types skeleton initialization code
+static char* cgenTySkelTabInit()
+{
+ char* body = collectStringArray(tySkels, "");
+ char* text = C_mkTySkelTabInit(body, C_totalSpace);
+
+ free(body);
+ return text;
+}
+
+//type skeleton info initiation
+void cgenTySkelInit(int length)
+{
+ if (length == 0) {
+ fprintf(stderr, "The number of type skeletons cannot be 0\n");
+ exit(1);
+ }
+ tySkels.length = length;
+ tySkels.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(tySkels.array, length);
+}
+
+//type skeleton relevant information in pervasives.c
+static char* tySkelsC;
+void cgenTySkelsC()
+{
+ char* tySkelTab = cgenTySkelTabInit();
+ tySkelsC = C_mkTySkelsC(tySkelTab); free(tySkelTab);
+}
+
+/****************************************************************************/
+/* constant relevant components */
+/****************************************************************************/
+/***********************************************************************/
+/* pervasives.h */
+/***********************************************************************/
+//number of pervasive constants
+static char* numConsts = NULL;
+void cgenNumConsts(char* num)
+{
+ numConsts = C_mkNumConsts(num);
+}
+
+//pervasive constant indices declaration
+static StringArray constIndices;
+
+void cgenConstIndex(int index, char* name, char* indexT, char* comments)
+{
+ char* constIndex;
+ char* constIndexText;
+
+ if (index >= constIndices.length) {
+ fprintf(stderr, "constant index exceed total number of constants\n");
+ exit(1);
+ }
+ constIndex = C_mkIndex(name, indexT, comments);
+ constIndexText = UTIL_mallocStr(strlen(constIndex) + 2);
+ strcpy(constIndexText, constIndex);
+ if (index != (constIndices.length - 1)) strcat(constIndexText, ",");
+ strcat(constIndexText, "\n");
+
+ constIndices.array[index] = constIndexText;
+}
+
+/***********************************************************************/
+/* constant property functions */
+/***********************************************************************/
+static StringArray logicSymbTypes;
+//initiale logic symb types
+void cgenLogicSymbolInit(int length)
+{
+ logicSymbTypes.length = length;
+ logicSymbTypes.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(logicSymbTypes.array, length);
+}
+
+//generate logic symbol types
+void cgenLogicSymbType(int index, char* name, char* indexT)
+{
+ char* constIndex;
+ char* constIndexText;
+
+ if (index >= logicSymbTypes.length) {
+ fprintf(stderr, "logic symbol type index exceed the total number of logic symbols\n");
+ exit(1);
+ }
+ constIndex = C_mkIndex2(name, indexT);
+ constIndexText = UTIL_mallocStr(strlen(constIndex) + 2);
+ strcpy(constIndexText, constIndex);
+ if (index != (constIndices.length - 1)) strcat(constIndexText, ",");
+ strcat(constIndexText, "\n");
+
+ logicSymbTypes.array[index] = constIndexText;
+}
+
+static char* lsRange = NULL;
+//generate logic symbol start/end position
+void cgenLSRange(char* start, char* end)
+{
+ lsRange = C_mkLSRange(start, end);
+}
+
+
+static char* predRange = NULL;
+//generate predicate symbol start/end position
+void cgenPREDRange(char* start, char* end)
+{
+ predRange = C_mkPredRange(start, end);
+}
+
+
+static char* constProperty = NULL;
+void cgenConstProperty()
+{
+ char* emptyText = C_mkEmptyComments();
+ char* logicSymbTypeBody = collectStringArray(logicSymbTypes, emptyText);
+ char* logicSymbTypeDec = C_mkLSTypeDec(logicSymbTypeBody);
+
+ constProperty = UTIL_mallocStr(strlen(logicSymbTypeDec) + strlen(lsRange)
+ + strlen(predRange));
+ strcpy(constProperty, lsRange);
+ strcat(constProperty, predRange);
+ strcat(constProperty , logicSymbTypeDec);
+
+ free(emptyText); free(logicSymbTypeBody); free(logicSymbTypeDec);
+ free(lsRange); free(predRange);
+}
+
+
+//pervasive kind relevant information in pervasives.h
+static char* constH;
+void cgenConstH()
+{
+ char* emptyText = C_mkEmptyComments();
+ char* constIndexBody = collectStringArray(constIndices, emptyText);
+ char* constIndexTypeDef = C_mkConstIndexType(constIndexBody);
+
+ constH = C_mkConstH(constIndexTypeDef, numConsts, constProperty);
+ free(constIndexBody); free(constIndexTypeDef);
+ free(emptyText); free(constProperty);
+}
+
+/***********************************************************************/
+/* pervasives.c */
+/***********************************************************************/
+//pervasive const table entries
+static StringArray constData;
+void cgenConstData(int index, char* name, char* tesize, OP_Prec prec,
+ OP_Fixity fixity, int tySkelInd, char* neededness,
+ char* comments)
+{
+ char* oneConstData;
+ char* constDataText;
+ char* tySkelIndText = UTIL_itoa(tySkelInd);
+
+ if (index >= constData.length) {
+ fprintf(stderr, "const index exceed total number of consts\n");
+ exit(1);
+ }
+ oneConstData = C_mkConstTabEntry(name, tesize, prec, fixity, tySkelIndText,
+ neededness, comments);
+ free(tySkelIndText);
+ constDataText = UTIL_mallocStr(strlen(oneConstData) + 2);
+ strcpy(constDataText, oneConstData); free(oneConstData);
+ if (index != constData.length - 1) strcat(constDataText, ",");
+ strcat(constDataText, "\n");
+
+ constData.array[index] = constDataText;
+}
+
+#define EMPTY_TEXT_CONST_TAB \
+" //nothing\n {NULL, 0, 0, 0, 0, OP_NONE },\n"
+
+//pervasive const relevant information in pervasives.c
+static char* constC;
+void cgenConstC()
+{
+ char* constTabBody = collectStringArray(constData, EMPTY_TEXT_CONST_TAB);
+ char* constTab = C_mkConstTab(constTabBody);
+
+ constC = C_mkConstC(constTab);
+ free(constTabBody); free(constTab);
+}
+
+
+//const indices info and const table info initiation
+void cgenConstInit(int length)
+{
+ constIndices.length = length;
+ constIndices.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(constIndices.array, length);
+ constData.length = length;
+ constData.array = (char**)UTIL_malloc(sizeof(char*)*length);
+ arrayInit(constData.array, length);
+}
+
+
+/****************************************************************************/
+/* Writing files */
+/****************************************************************************/
+static char* pervBegH;
+static char* pervEndH;
+static void cgenFixedH()
+{
+ pervBegH = C_mkFixedBegH();
+ pervEndH = C_mkFixedEndH();
+}
+
+static char* pervBegC;
+static char* pervEndC;
+static void cgenFixedC()
+{
+ pervBegC = C_mkFixedBegC();
+ pervEndC = C_mkFixedEndC();
+}
+
+/* dump peravsives.h */
+void spitCPervasivesH(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "tables/pervasives.h");
+
+ outFile = UTIL_fopenW(filename);
+ cgenFixedH();
+ fprintf(outFile, "%s\n", pervBegH); free(pervBegH);
+ fprintf(outFile, "%s\n", kindH); free(kindH);
+ fprintf(outFile, "%s\n", tySkelsH); free(tySkelsH);
+ fprintf(outFile, "%s\n", constH); free(constH);
+ fprintf(outFile, "%s\n", pervEndH); free(pervEndH);
+ UTIL_fclose(outFile);
+ free(filename);
+}
+
+/* dump pervasives.c */
+void spitCPervasivesC(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "tables/pervasives.c");
+ outFile = UTIL_fopenW(filename);
+ cgenFixedC();
+ fprintf(outFile, "%s\n", pervBegC); free(pervBegC);
+ fprintf(outFile, "%s\n", kindC); free(kindC);
+ fprintf(outFile, "%s\n", tySkelsC); free(tySkelsC);
+ fprintf(outFile, "%s\n", constC); free(constC);
+ fprintf(outFile, "%s\n", pervEndC); free(pervEndC);
+ UTIL_fclose(outFile);
+ free(filename);
+}
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.h b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.h
new file mode 100644
index 000000000..294d1e6bf
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-c.h
@@ -0,0 +1,95 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/*****************************************************************************/
+/* File pervgen-c.h. This files contains function definitions for generating */
+/* files pervasives.h and pervasives.c. */
+/*****************************************************************************/
+#include "types.h"
+#include "op.h"
+
+/****************************************************************************/
+/* kind relevant components */
+/****************************************************************************/
+//kind indices info and kind table info initiation
+void cgenKindInit(int size);
+
+//number of pervasive kinds
+void cgenNumKinds(char* num);
+//pervasive kind indices declaration
+void cgenKindIndex(int index, char* name, char* indexT, char* comments);
+//pervasive kind relevant information in pervasives.h
+void cgenKindH();
+
+//pervasive kind table entries
+void cgenKindData(int index, char* name, char* arity, char* comments);
+//pervasive kind relevant information in pervasives.c
+void cgenKindC();
+
+/****************************************************************************/
+/* type skeleton relevant components */
+/****************************************************************************/
+//number of type skeletons for pervasive constants
+void cgenNumTySkels(char* num);
+//type skeleton relevant information in pervasives.h
+void cgenTySkelsH();
+
+//type skeleton creation code
+void cgenTySkelTab(int index, Type tyskel, char* comments);
+//type skeleton info initiation
+void cgenTySkelInit(int length);
+//type skeleton relevant information in pervasives.c
+void cgenTySkelsC();
+
+
+/****************************************************************************/
+/* constant relevant components */
+/****************************************************************************/
+//const indices info and const table info initiation
+void cgenConstInit(int length);
+
+//number of pervasive constants
+void cgenNumConsts(char* num);
+//pervasive constant indices declaration
+void cgenConstIndex(int index, char* name, char* indexT, char* comments);
+//pervasive constant relevant information in pervasives.h
+void cgenConstH();
+
+
+//pervasive constant table entries
+void cgenConstData(int index, char* name, char* tesize, OP_Prec prec,
+ OP_Fixity fixity, int tySkelInd, char* neededness,
+ char* comments);
+//pervasive const relevant information in pervasives.c
+void cgenConstC();
+
+//initiale logic symb types
+void cgenLogicSymbolInit(int length);
+//generate logic symbol types
+void cgenLogicSymbType(int index, char* name, char* indexText);
+//generate logic symbol start/end position
+void cgenLSRange(char* start, char* end);
+//generate predicate symbol start/end position
+void cgenPREDRange(char* start, char* end);
+void cgenConstProperty();
+
+/****************************************************************************/
+/* Writing files */
+/****************************************************************************/
+/* dump files pervasives.h */
+void spitCPervasivesH(char * root);
+/* dump files pervasives.c */
+void spitCPervasivesC(char * root);
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.c b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.c
new file mode 100644
index 000000000..5bd932ffb
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.c
@@ -0,0 +1,350 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/*****************************************************************************/
+/* File pervgen-ocaml.c. This files contains function definitions for */
+/* generating files pervasive.mli and pervasive.ml. */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pervgen-ocaml.h"
+#include "ocamlcode.h"
+
+
+static char* addLine(char* str, char* addOn)
+{
+ size_t length = (str ? strlen(str) : 0) + strlen(addOn) + 2;
+ char* newStr = UTIL_mallocStr(length);
+
+ if (str) {
+ strcpy(newStr, str);
+ strcat(newStr, addOn);
+ } else strcpy(newStr, addOn);
+ strcat(newStr, "\n\n");
+ return newStr;
+}
+
+static char* addStr(char* str, char* addOn)
+{
+ size_t length = (str ? strlen(str) : 0) + strlen(addOn);
+ char* newStr = UTIL_mallocStr(length);
+
+ if (str) {
+ strcpy(newStr, str);
+ strcat(newStr, addOn);
+ } else strcpy(newStr, addOn);
+ return newStr;
+}
+
+/**************************************************************************/
+/* generating pervasive kind relevant part */
+/**************************************************************************/
+static char* numKindsML = NULL;
+static char* numKindsMLI = NULL;
+
+void ocamlGenNumKinds(char* number)
+{
+ numKindsMLI = strdup("val numberPervasiveKinds : int");
+ numKindsML = addStr("let numberPervasiveKinds = ", number);
+}
+
+static char* kindVarList = NULL; //kind variable definitions
+static char* buildPervKindBody = NULL; //buildPervKind function defs
+static char* kindVarDecs = NULL; //kind vars in signature
+static char* isKindFuncDecs = NULL; //is kind function decs
+static char* isKindFuncDefs = NULL; //is kind function defs
+void ocamlGenKind(char* kindName, char* kVarName, char* arity, char* offset)
+{
+ char* kindVarName = OC_mkKVarName(kVarName);
+ char* funcName = OC_mkIsKindFuncName(kindVarName);
+ char* kindVar = OC_mkKindVar(kindVarName, kindName, arity, offset);
+ char* kindTabEntry = OC_mkTabEntry(kindName, kindVarName);
+ char* kindVarDec = OC_mkKindVarDec(kindVarName);
+ char* funcDec = OC_mkIsKindFuncDec(funcName);
+ char* funcDef = OC_mkIsKindFuncDef(funcName, kindVarName);
+ char *myKindVarList, *myBuildPervKindBody, *myKindVarDecs,
+ *myisKindFuncDecs, *myisKindFuncDefs;
+
+ free(kindVarName);
+
+ myKindVarList = addLine(kindVarList, kindVar);
+ free(kindVarList); free(kindVar);
+ kindVarList = myKindVarList;
+
+ myBuildPervKindBody = addStr(buildPervKindBody, kindTabEntry);
+ free(buildPervKindBody); free(kindTabEntry);
+ buildPervKindBody = myBuildPervKindBody;
+
+ myKindVarDecs = addStr(kindVarDecs, kindVarDec);
+ free(kindVarDecs); free(kindVarDec);
+ kindVarDecs = myKindVarDecs;
+
+ myisKindFuncDecs = addStr(isKindFuncDecs, funcDec);
+ free(isKindFuncDecs); free(funcDec);
+ isKindFuncDecs = myisKindFuncDecs;
+
+ myisKindFuncDefs = addLine(isKindFuncDefs, funcDef);
+ free(isKindFuncDefs); free(funcDef);
+ isKindFuncDefs = myisKindFuncDefs;
+}
+
+static char* kindML = NULL; //kind relevant code in pervasive.ml
+static char* kindMLI = NULL; //kind relevant code in pervasive.mli
+
+void ocamlGenKinds()
+{
+ char* buildTabFunc = OC_mkBuildKTabFunc(buildPervKindBody);
+ size_t length = strlen(kindVarList) + strlen(buildTabFunc) +
+ strlen(isKindFuncDefs) + strlen(numKindsML) + 4;
+
+ kindML = UTIL_mallocStr(length);
+ strcpy(kindML, kindVarList);
+ strcat(kindML, "\n");
+ strcat(kindML, numKindsML);
+ strcat(kindML, "\n\n");
+ strcat(kindML, buildTabFunc);
+ strcat(kindML, "\n");
+ strcat(kindML, isKindFuncDefs);
+
+ free(buildPervKindBody); free(buildTabFunc); free(kindVarList);
+ free(isKindFuncDefs); free(numKindsML);
+
+ length = strlen(kindVarDecs) + strlen(isKindFuncDecs) +
+ strlen(numKindsMLI) + 4;
+ kindMLI = UTIL_mallocStr(length);
+ strcpy(kindMLI, kindVarDecs);
+ strcat(kindMLI, "\n\n");
+ strcat(kindMLI, numKindsMLI);
+ strcat(kindMLI, "\n\n");
+ strcat(kindMLI, isKindFuncDecs);
+ free(kindVarDecs); free(isKindFuncDecs); free(numKindsMLI);
+}
+
+/**************************************************************************/
+/* generating pervasive type skeleton relevant part */
+/**************************************************************************/
+static char* tySkelVarList = NULL; //type skel vars
+
+void ocamlGenTySkel(char* ind, Type tySkel)
+{
+ char* varName = OC_mkTySkelVarName(ind);
+ char* tySkelText = OC_genTySkel(tySkel);
+ char* tySkelVarDef = OC_mkTYSkelVar(varName, tySkelText);
+ size_t length = (tySkelVarList ? strlen(tySkelVarList) : 0) +
+ strlen(tySkelVarDef) + 1;
+ char* mytySkelVarList = UTIL_mallocStr(length + 1);
+
+ free(varName); free(tySkelText);
+
+ mytySkelVarList = addLine(tySkelVarList, tySkelVarDef);
+ free(tySkelVarList); free(tySkelVarDef);
+ tySkelVarList = mytySkelVarList;
+}
+
+/**************************************************************************/
+/* generating pervasive constants relevant part */
+/**************************************************************************/
+static char* numConstsML = NULL;
+static char* numConstsMLI = NULL;
+
+void ocamlGenNumConsts(char* number)
+{
+ numConstsMLI = strdup("val numberPervasiveConstants : int");
+ numConstsML = addStr("let numberPervasiveConstants = ", number);
+}
+
+static char* constVarList = NULL; //constant vars
+static char* buildPervConstBody = NULL; //buildPervConst function defs
+static char* constVarDecs = NULL; //constant vars in signature
+static char* isConstFuncDecs = NULL; //is constant function decs
+static char* isConstFuncDefs = NULL; //is constant function defs
+
+void ocamlGenConst(char* ind, char* name, char* cVarName, OP_Fixity fixity,
+ OP_Prec prec, UTIL_Bool tyPrev, UTIL_Bool redef, int tesize,
+ int tyskelInd, int neededness, OP_Code codeInfo,
+ char* offset, char *printName)
+{
+ char* constVarName = OC_mkCVarName(cVarName);
+ char* funcName = OC_mkIsConstFuncName(constVarName);
+ char* tyskelText = UTIL_itoa(tyskelInd);
+ char* tyskelName = OC_mkTySkelVarName(tyskelText);
+
+ char* constVar = OC_mkConstVar(name, fixity, prec, tyPrev, tyskelName,
+ tesize, neededness, codeInfo, redef,
+ constVarName, offset, printName);
+ char* constTabEntry = OC_mkTabEntry(name, constVarName);
+ char* constVarDec = OC_mkConstVarDec(constVarName);
+ char* funcDec = OC_mkIsConstFuncDec(funcName);
+ char* funcDef = OC_mkIsConstFuncDef(funcName, constVarName);
+
+ char *myConstVarList, *myBuildPervConstBody, *myConstVarDecs,
+ *myisConstFuncDecs, *myisConstFuncDefs;
+
+ free(constVarName); free(funcName); free(tyskelName); free(tyskelText);
+
+ myConstVarList = addLine(constVarList, constVar);
+ free(constVarList); free(constVar);
+ constVarList = myConstVarList;
+
+ myBuildPervConstBody = addStr(buildPervConstBody, constTabEntry);
+ free(buildPervConstBody); free(constTabEntry);
+ buildPervConstBody = myBuildPervConstBody;
+
+ myConstVarDecs = addStr(constVarDecs, constVarDec);
+ free(constVarDecs); free(constVarDec);
+ constVarDecs = myConstVarDecs;
+
+ myisConstFuncDecs = addStr(isConstFuncDecs, funcDec);
+ free(isConstFuncDecs); free(funcDec);
+ isConstFuncDecs = myisConstFuncDecs;
+
+ myisConstFuncDefs = addLine(isConstFuncDefs, funcDef);
+ free(isConstFuncDefs); free(funcDef);
+ isConstFuncDefs = myisConstFuncDefs;
+}
+
+static char* constMLI = NULL; //const relevant code in pervasive.mli
+static char* constML = NULL; //const relevant code in pervasive.ml
+
+void ocamlGenConsts()
+{
+ char* tyskels = OC_mkFixedTySkels(tySkelVarList);
+ char* varDefs = OC_mkGenericConstVar(constVarList);
+ char* varDecs = OC_mkGenericConstVarDec(constVarDecs);
+ char* buildFuncBody = OC_mkGenericConstTabEntry(buildPervConstBody);
+ char* buildTabFunc = OC_mkBuildCTabFunc(buildFuncBody);
+ char* funcDefs = OC_mkGenericConstFuncDefs(isConstFuncDefs);
+ char* funcDecs = OC_mkGenericConstFuncDecs(isConstFuncDecs);
+
+
+ size_t length = strlen(varDefs) + strlen(buildTabFunc) + strlen(funcDefs)
+ + strlen(numConstsML) + 4;
+
+ tySkelVarList = tyskels;
+
+ constML = UTIL_mallocStr(length);
+ strcpy(constML, varDefs); free(varDefs);
+ strcat(constML, "\n");
+ strcat(constML, numConstsML); free(numConstsML);
+ strcat(constML, "\n\n");
+ strcat(constML, buildTabFunc); free(buildTabFunc); free(buildFuncBody);
+ strcat(constML, "\n");
+ strcat(constML, funcDefs); free(funcDefs);
+
+ length = strlen(varDecs) + strlen(funcDecs) + strlen(numConstsMLI) + 4;
+ constMLI = UTIL_mallocStr(length);
+
+ strcpy(constMLI, varDecs); free(varDecs);
+ strcat(constMLI, "\n\n");
+ strcat(constMLI, numConstsMLI); free(numConstsMLI);
+ strcat(constMLI, "\n\n");
+ strcat(constMLI, funcDecs); free(funcDecs);
+}
+
+static char* constProperty = NULL;
+void ocamlCollectConsts(char* name, int last)
+{
+ char* constName = OC_mkCVarName(name);
+ char* cond = OC_mkCompare(constName);
+ char* body;
+
+ free(constName);
+ if (last) body = cond;
+ else {
+ if (constProperty) {
+ body = OC_mkOr(cond, constProperty);
+ free(constProperty);
+ free(cond);
+ } else body = cond;
+ }
+ constProperty = body;
+}
+
+static char* regClob = NULL;
+void ocamlGenRC()
+{
+ regClob = OC_mkRegClobFunc(constProperty);
+ free(constProperty);
+ constProperty = NULL;
+}
+
+static char* backTrack = NULL;
+void ocamlGenBC()
+{
+ backTrack = OC_mkBackTrackFunc(constProperty);
+ free(constProperty);
+ constProperty = NULL;
+}
+
+/**************************************************************************/
+/* generating fixed part of pervasive.ml and pervasive.mli */
+/**************************************************************************/
+static char* fixedML = NULL; //fixed part of pervasive.ml
+static char* fixedMLI = NULL; //fixed part of pervasive.mli
+
+static void ocamlGenFixedML()
+{
+ fixedML = OC_mkFixedML();
+}
+static void ocamlGenFixedMLI()
+{
+ fixedMLI = OC_mkFixedMLI();
+}
+
+/***************************************************************************/
+/* Dump code into pervasive.ml and pervasive.mli */
+/***************************************************************************/
+/* dump peravsive.ml */
+void spitOCPervasiveML(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "compiler/pervasive.ml");
+ outFile = UTIL_fopenW(filename);
+
+ ocamlGenFixedML();
+ fprintf(outFile, "%s\n\n", kindML); free(kindML);
+ fprintf(outFile, "%s\n\n", tySkelVarList); free(tySkelVarList);
+ fprintf(outFile, "%s\n\n", constML); free(constML);
+ fprintf(outFile, "%s\n\n", fixedML); free(fixedML);
+ fprintf(outFile, "%s\n\n", regClob); free(regClob);
+ fprintf(outFile, "%s\n\n", backTrack); free(backTrack);
+
+
+ UTIL_fclose(outFile);
+ free(filename);
+}
+
+/* dump peravsive.mli */
+void spitOCPervasiveMLI(char * root)
+{
+ FILE* outFile;
+ char * filename = malloc(strlen(root) + 32);
+ strcpy(filename, root);
+ strcat(filename, "compiler/pervasive.mli");
+ outFile = UTIL_fopenW(filename);
+
+ ocamlGenFixedMLI();
+ fprintf(outFile, "%s\n\n", kindMLI); free(kindMLI);
+ fprintf(outFile, "%s\n\n", constMLI); free(constMLI);
+ fprintf(outFile, "%s\n\n", fixedMLI); free(fixedMLI);
+ UTIL_fclose(outFile);
+ free(filename);
+}
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.h b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.h
new file mode 100644
index 000000000..4acc4d6cb
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/pervgen-ocaml.h
@@ -0,0 +1,60 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/*****************************************************************************/
+/* File pervgen-ocaml.c. This files contains function definitions for */
+/* generating files pervasive.mli and pervasive.ml. */
+/*****************************************************************************/
+#include "op.h"
+#include "types.h"
+#include "../util/util.h"
+
+/**************************************************************************/
+/* generating pervasive kind relevant part */
+/**************************************************************************/
+void ocamlGenNumKinds(char* number);
+void ocamlGenKind(char* kindName, char* kVarName, char* arity, char* offset);
+void ocamlGenKinds();
+
+/**************************************************************************/
+/* generating pervasive type skeleton relevant part */
+/**************************************************************************/
+void ocamlGenTySkel(char* ind, Type tySkel);
+
+/**************************************************************************/
+/* generating pervasive constants relevant part */
+/**************************************************************************/
+void ocamlGenNumConsts(char* number);
+void ocamlGenConst(char* ind, char* name, char* cVarName, OP_Fixity fixity,
+ OP_Prec prec, UTIL_Bool tyPrev, UTIL_Bool redef, int tesize,
+ int tyskelInd, int neededness, OP_Code codeInfo,
+ char* offset, char* printName);
+
+void ocamlGenConsts();
+
+void ocamlCollectConsts(char* name, int last);
+
+void ocamlGenRC();
+void ocamlGenBC();
+/***************************************************************************/
+/* Dump code into pervasive.ml and pervasive.mli */
+/***************************************************************************/
+/* dump peravsive.ml */
+void spitOCPervasiveML(char * root);
+/* dump peravsive.mli */
+void spitOCPervasiveMLI(char * root);
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/types.c b/src/runtime/c/teyjus/tables_gen/pervasives/types.c
new file mode 100644
index 000000000..9418992c1
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/types.c
@@ -0,0 +1,114 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/****************************************************************************/
+/* File types.c. This file contains "abstract syntax" representation of */
+/* type skeletons that is used for parsing those in pervasives.in. */
+/****************************************************************************/
+#include <stdlib.h>
+#include "types.h"
+#include "../util/util.h"
+
+Type mkSortType(char* name)
+{
+ Type rtPtr = (Type)UTIL_malloc(sizeof(Type_));
+ rtPtr -> tag = SORT;
+ rtPtr -> data.sort = name;
+ return rtPtr;
+}
+
+Type mkSkVarType(char* index)
+{
+ Type rtPtr = (Type)UTIL_malloc(sizeof(Type_));
+ rtPtr -> tag = SKVAR;
+ rtPtr -> data.skvar = index;
+ return rtPtr;
+}
+
+Type mkStrFuncType(char* name, char* arity)
+{
+ Type rtPtr = (Type)UTIL_malloc(sizeof(Type_));
+ rtPtr -> tag = FUNC;
+ rtPtr -> data.func.name = name;
+ rtPtr -> data.func.arity = arity;
+ return rtPtr;
+}
+
+
+Type mkStrType(Type func, int arity, TypeList args)
+{
+ Type rtPtr = (Type)UTIL_malloc(sizeof(Type_));
+ rtPtr -> tag = STR;
+ rtPtr -> data.str.functor = func;
+ rtPtr -> data.str.arity = arity;
+ rtPtr -> data.str.args = args;
+ return rtPtr;
+}
+
+Type mkArrowType(Type lop, Type rop)
+{
+ Type rtPtr = (Type)UTIL_malloc(sizeof(Type_));
+ rtPtr -> tag = ARROW;
+ rtPtr -> data.arrow.lop = lop;
+ rtPtr -> data.arrow.rop = rop;
+ return rtPtr;
+
+}
+
+void freeType(Type ty)
+{
+ if (ty -> tag == SORT) free(ty->data.sort);
+ else if (ty -> tag == SKVAR) free(ty->data.skvar);
+ else if (ty -> tag == FUNC) {
+ free(ty->data.func.name);
+ free(ty->data.func.arity);
+ }
+ free(ty);
+}
+
+
+TypeList addItem(Type data, TypeList typeList)
+{
+ TypeList new = (TypeList)UTIL_malloc(sizeof(TypeList_));
+ new -> oneType = data;
+ if (typeList) new -> next = typeList;
+ else new -> next = NULL;
+ typeList = new;
+ return typeList;
+}
+
+TypeList addItemToEnd(TypeList typeList, Type data)
+{
+ TypeList new = (TypeList)UTIL_malloc(sizeof(TypeList_));
+ new -> oneType = data;
+ new -> next = NULL;
+ if (typeList) {
+ TypeList temp = typeList;
+ while (temp -> next) temp = temp -> next;
+ temp -> next = new;
+ } else typeList = new;
+ return typeList;
+}
+
+TypeList append(TypeList typeList1, TypeList typeList2)
+{
+ if (typeList1) {
+ TypeList temp = typeList1;
+ while (temp -> next) temp = temp -> next;
+ temp -> next = typeList2;
+ } else typeList1 = typeList2;
+ return typeList1;
+}
diff --git a/src/runtime/c/teyjus/tables_gen/pervasives/types.h b/src/runtime/c/teyjus/tables_gen/pervasives/types.h
new file mode 100644
index 000000000..4aae0fc56
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/pervasives/types.h
@@ -0,0 +1,92 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+/****************************************************************************/
+/* File types.h. This file contains "abstract syntax" representation of */
+/* type skeletons that is used for parsing those in pervasives.in. */
+/****************************************************************************/
+#ifndef TYPES_H
+#define TYPES_H
+
+typedef struct Type_ *Type;
+typedef struct TypeList_ *TypeList;
+
+//type arrow information
+typedef struct ArrowInfo
+{
+ Type lop;
+ Type rop;
+} ArrowInfo;
+
+//structure functor information
+typedef struct FuncInfo
+{
+ char *name;
+ char *arity;
+} FuncInfo;
+
+//type structure information
+typedef struct StrInfo
+{
+ Type functor;
+ int arity;
+ TypeList args;
+} StrInfo;
+
+//type skeleton category
+typedef enum {
+ SORT, SKVAR, ARROW, STR, FUNC
+} TypeCats;
+
+//type representation
+typedef struct Type_
+{
+ TypeCats tag;
+ union
+ {
+ char* sort;
+ char* skvar;
+ FuncInfo func;
+ ArrowInfo arrow;
+ StrInfo str;
+ } data;
+} Type_;
+
+//type list representation
+typedef struct TypeList_
+{
+ Type oneType;
+ TypeList next;
+} TypeList_;
+
+
+Type mkSortType(char* name);
+Type mkSkVarType(char* index);
+Type mkStrFuncType(char* name, char* arity);
+Type mkStrType(Type name, int arity, TypeList args);
+Type mkArrowType(Type lop, Type rop);
+void freeType(Type ty);
+
+
+TypeList addItem(Type data, TypeList typeList);
+TypeList addItemToEnd(TypeList typeList, Type data);
+TypeList append(TypeList typeList1, TypeList typeList2);
+
+#endif //TYPES_H
+
+
+
+
diff --git a/src/runtime/c/teyjus/tables_gen/util/util.c b/src/runtime/c/teyjus/tables_gen/util/util.c
new file mode 100644
index 000000000..502bfa68f
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/util/util.c
@@ -0,0 +1,135 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "util.h"
+
+
+/**************************************************************************/
+/* Space allocation */
+/**************************************************************************/
+/* allocate space of n bytes*/
+void* UTIL_malloc(size_t n)
+{
+ void* ptr = (void*)malloc(n);
+ if (ptr) return ptr;
+ printf("Error : cannot allocate space\n");
+ exit(1);
+
+}
+
+
+/* allocate space for a string of given size */
+char* UTIL_mallocStr(size_t size)
+{
+ char* ptr = (char*)malloc(sizeof(char)*(size + 1));
+ if (ptr) return ptr;
+
+ printf("Error : cannot allocate space\n");
+ exit(1);
+}
+
+
+/**************************************************************************/
+/* string operation */
+/**************************************************************************/
+/* Append two strings */
+char* UTIL_appendStr(char* str1, char* str2)
+{
+ size_t length = strlen(str1) + strlen(str2);
+ char* ptr = UTIL_mallocStr(length + 1);
+
+ strcpy(ptr, str1);
+ strcat(ptr, str2);
+
+ return ptr;
+}
+
+
+//convert lower case letters in a string to upper case ones
+char* UTIL_upperCase(char* str)
+{
+ char *newstr, *tmp;
+ newstr = strdup(str);
+ tmp = newstr;
+ while ((*tmp) != '\0'){
+ if ((97 <= (int)*tmp) && ((int)*tmp <= 122))
+ *tmp = (char)((int)*tmp - 32);
+ tmp++;
+ }
+ return newstr;
+}
+
+//convert to lower cases
+char* UTIL_lowerCase(char* str)
+{
+ char *newstr, *tmp;
+ newstr = strdup(str);
+ tmp = newstr;
+ while ((*tmp) != '\0'){
+ if ((65 <= (int)*tmp) && ((int)*tmp) <= 90)
+ *tmp = (char)((int)*tmp + 32);
+ tmp++;
+ }
+ return newstr;
+}
+
+//covert an non-negtive integer to string
+char* UTIL_itoa(int num)
+{
+ char *str = UTIL_mallocStr(33);
+ sprintf(str, "%d", num);
+ return str;
+}
+
+
+/**************************************************************************/
+/* file operation */
+/**************************************************************************/
+
+/* open file in read mode */
+FILE* UTIL_fopenR(char* filename)
+{
+ FILE* filePtr = fopen(filename, "r");
+ if (filePtr) return filePtr;
+
+ printf("Error : cannot open input file %s\n", filename);
+ exit(1);
+}
+
+
+/* open file in write mode */
+FILE* UTIL_fopenW(char* filename)
+{
+ FILE* filePtr = fopen(filename, "w");
+ if (filePtr) return filePtr;
+
+ printf("Error : cannot open output file %s\n", filename);
+ exit(1);
+}
+
+/* close file */
+void UTIL_fclose(FILE* file)
+{
+ fclose(file);
+}
+
diff --git a/src/runtime/c/teyjus/tables_gen/util/util.h b/src/runtime/c/teyjus/tables_gen/util/util.h
new file mode 100644
index 000000000..4cc6a8a11
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/util/util.h
@@ -0,0 +1,71 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/**************************************************************************/
+/* util.h{c}. */
+/* Auxiliary functions needed for generating source files. */
+/**************************************************************************/
+#ifndef UTIL_H
+#define UTIL_H
+#include <stdio.h>
+
+
+/**************************************************************************/
+/* Space allocation */
+/**************************************************************************/
+/* allocate space */
+void* UTIL_malloc(size_t size);
+
+/* allocate space for a string of given size */
+char* UTIL_mallocStr(size_t size);
+
+/**************************************************************************/
+/* string operation */
+/**************************************************************************/
+/* append two strings */
+char* UTIL_appendStr(char* str1, char* str2);
+/* capitalizing */
+char* UTIL_upperCase(char* str);
+/* to lower cases */
+char* UTIL_lowerCase(char* str);
+/* covert a non-negative integer to string */
+char* UTIL_itoa(int num);
+
+/**************************************************************************/
+/* file operation */
+/**************************************************************************/
+/* open file in read mode */
+FILE* UTIL_fopenR(char* filename);
+
+/* open file in write mode */
+FILE* UTIL_fopenW(char* filename);
+
+/* close file */
+void UTIL_fclose(FILE* file);
+
+
+/* bool type */
+typedef enum {
+ UTIL_FALSE, UTIL_TRUE
+} UTIL_Bool;
+
+#endif
+
+