summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--colm/analysis.cc2
-rw-r--r--colm/bytecode.c132
-rw-r--r--colm/bytecode.h15
-rw-r--r--colm/closure.cc2
-rw-r--r--colm/dotgen.cc2
-rw-r--r--colm/fsmcodegen.cc17
-rw-r--r--colm/fsmexec.cc2
-rw-r--r--colm/global.h (renamed from colm/colm.h)0
-rw-r--r--colm/lmparse.kl2
-rw-r--r--colm/lmscan.h2
-rw-r--r--colm/lmscan.rl2
-rw-r--r--colm/main.cc2
-rw-r--r--colm/parsedata.cc2
-rw-r--r--colm/parsedata.h2
-rw-r--r--colm/parsetree.h2
-rw-r--r--colm/pdabuild.cc2
-rw-r--r--colm/pdacodegen.cc2
-rw-r--r--colm/pdagraph.cc2
-rw-r--r--colm/pdarun.h3
-rw-r--r--colm/redbuild.cc2
-rw-r--r--colm/redfsm.h3
21 files changed, 106 insertions, 94 deletions
diff --git a/colm/analysis.cc b/colm/analysis.cc
index 14035ec0..5be09c05 100644
--- a/colm/analysis.cc
+++ b/colm/analysis.cc
@@ -26,7 +26,7 @@
#include <limits.h>
#include <sstream>
-#include "colm.h"
+#include "program.h"
#include "lmparse.h"
#include "parsedata.h"
#include "parsetree.h"
diff --git a/colm/bytecode.c b/colm/bytecode.c
index 9ba82374..a28533f0 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -467,6 +467,19 @@ Tree *constructArgv( Program *prg, int argc, char **argv )
* Execution environment
*/
+void initColm( long debugRealm )
+{
+ /* Always on because because logging is controlled with ifdefs in\n" the
+ * runtime lib. */
+ colm_log_bytecode = 1;
+ colm_log_parse = 1;
+ colm_log_match = 1;
+ colm_log_compile = 1;
+ colm_log_conds = 1;
+ colmActiveRealm = 0xffffffff;
+ initInputFuncs();
+}
+
void initProgram( Program *prg, int argc, char **argv, int ctxDepParsing,
RuntimeData *rtd )
{
@@ -523,8 +536,67 @@ void clearGlobal( Program *prg, Tree **sp )
treeFree( prg, prg->global );
}
-void clearProgram( Program *prg, Tree **vm_stack, Tree **sp )
+void allocGlobal( Program *prg )
+{
+ /* Alloc the global. */
+ Tree *tree = treeAllocate( prg );
+ tree->child = allocAttrs( prg, prg->rtd->globalSize );
+ tree->refs = 1;
+ prg->global = tree;
+}
+
+Tree **stackAlloc()
+{
+ //return new Tree*[VM_STACK_SIZE];
+
+ return (Tree**)mmap( 0, sizeof(Tree*)*VM_STACK_SIZE,
+ PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 );
+}
+
+void runProgram( Program *prg )
+{
+ assert( sizeof(Int) <= sizeof(Tree) );
+ assert( sizeof(Str) <= sizeof(Tree) );
+ assert( sizeof(Pointer) <= sizeof(Tree) );
+ assert( sizeof(Map) <= sizeof(MapEl) );
+ assert( sizeof(List) <= sizeof(MapEl) );
+ assert( sizeof(Stream) <= sizeof(MapEl) );
+ assert( sizeof(Accum) <= sizeof(MapEl) );
+
+ /* Allocate the global variable. */
+ allocGlobal( prg );
+
+ /*
+ * Allocate the VM stack.
+ */
+
+ prg->vm_stack = stackAlloc();
+ prg->vm_root = &prg->vm_stack[VM_STACK_SIZE];
+
+ /*
+ * Execute
+ */
+
+ if ( prg->rtd->rootCodeLen > 0 ) {
+ RtCodeVect rcodeCollect;
+ Execution execution;
+ initRtCodeVect( &rcodeCollect );
+ initExecution( &execution, prg, &rcodeCollect, 0, 0, prg->rtd->rootCode, 0, 0, 0, 0 );
+ forwardExecution( &execution, prg->vm_root );
+
+ debug( REALM_BYTECODE, "freeing the root reverse code" );
+
+ /* The root code should all be commit code and reverse code
+ * should be empty. */
+ assert( rcodeCollect.tabLen == 0 );
+ }
+}
+
+void clearProgram( Program *prg )
{
+ Tree **vm_stack = prg->vm_stack;
+ Tree **sp = prg->vm_root;
+
#ifdef COLM_LOG_BYTECODE
if ( colm_log_bytecode ) {
cerr << "clearing the prg" << endl;
@@ -601,64 +673,6 @@ void clearProgram( Program *prg, Tree **vm_stack, Tree **sp )
}
}
-void allocGlobal( Program *prg )
-{
- /* Alloc the global. */
- Tree *tree = treeAllocate( prg );
- tree->child = allocAttrs( prg, prg->rtd->globalSize );
- tree->refs = 1;
- prg->global = tree;
-}
-
-Tree **stackAlloc()
-{
- //return new Tree*[VM_STACK_SIZE];
-
- return (Tree**)mmap( 0, sizeof(Tree*)*VM_STACK_SIZE,
- PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 );
-}
-
-void runProgram( Program *prg )
-{
- assert( sizeof(Int) <= sizeof(Tree) );
- assert( sizeof(Str) <= sizeof(Tree) );
- assert( sizeof(Pointer) <= sizeof(Tree) );
- assert( sizeof(Map) <= sizeof(MapEl) );
- assert( sizeof(List) <= sizeof(MapEl) );
- assert( sizeof(Stream) <= sizeof(MapEl) );
- assert( sizeof(Accum) <= sizeof(MapEl) );
-
- /* Allocate the global variable. */
- allocGlobal( prg );
-
- /*
- * Allocate the VM stack.
- */
-
- Tree **vm_stack = stackAlloc();
- Tree **root = &vm_stack[VM_STACK_SIZE];
-
- /*
- * Execute
- */
-
- if ( prg->rtd->rootCodeLen > 0 ) {
- RtCodeVect rcodeCollect;
- Execution execution;
- initRtCodeVect( &rcodeCollect );
- initExecution( &execution, prg, &rcodeCollect, 0, 0, prg->rtd->rootCode, 0, 0, 0, 0 );
- forwardExecution( &execution, root );
-
- debug( REALM_BYTECODE, "freeing the root reverse code" );
-
- /* The root code should all be commit code and reverse code
- * should be empty. */
- assert( rcodeCollect.tabLen == 0 );
- }
-
- /* Clear */
- clearProgram( prg, vm_stack, root );
-}
void initExecution( Execution *exec, Program *prg, RtCodeVect *rcodeCollect,
PdaRun *pdaRun, FsmRun *fsmRun, Code *code, Tree *lhs,
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 6ba2ba55..2154f09d 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _BYTECODE2_H
-#define _BYTECODE2_H
+#ifndef _BYTECODE_H
+#define _BYTECODE_H
#include "pdarun.h"
#include "tree.h"
@@ -472,16 +472,17 @@ Tree *getParsedRoot( PdaRun *pdaRun, int stop );
Tree *prepParseTree( Program *prg, Tree **sp, Tree *tree );
void splitRef( Tree ***sp, Program *prg, Ref *fromRef );
-void initProgram( Program *program, int argc, char **argv,
- int ctxDepParsing, RuntimeData *rtd );
-void clearProgram( Program *prg, Tree **vm_stack, Tree **sp );
-void runProgram( Program *prg );
void allocGlobal( Program *prg );
-
void executeCode( Execution *exec, Tree **sp, Code *instr );
void rcodeDownref( Program *prg, Tree **sp, Code *instr );
Tree **stackAlloc();
+void initColm( long debugRealm );
+void initProgram( Program *program, int argc, char **argv,
+ int ctxDepParsing, RuntimeData *rtd );
+void runProgram( Program *prg );
+void clearProgram( Program *prg );
+
#ifdef __cplusplus
}
#endif
diff --git a/colm/closure.cc b/colm/closure.cc
index 47901e32..fb5a9d90 100644
--- a/colm/closure.cc
+++ b/colm/closure.cc
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "colm.h"
+#include "global.h"
#include "parsedata.h"
#include "vector.h"
diff --git a/colm/dotgen.cc b/colm/dotgen.cc
index e738cfb7..7ac8951a 100644
--- a/colm/dotgen.cc
+++ b/colm/dotgen.cc
@@ -20,7 +20,7 @@
*/
-#include "colm.h"
+#include "global.h"
#include "parsedata.h"
using namespace std;
diff --git a/colm/fsmcodegen.cc b/colm/fsmcodegen.cc
index f09b312c..d59c7a5e 100644
--- a/colm/fsmcodegen.cc
+++ b/colm/fsmcodegen.cc
@@ -1072,23 +1072,18 @@ void FsmCodeGen::writeCode()
"void initStaticFuncs() {}\n"
"void initPatternFuncs() {}\n"
"void initReplFuncs() {}\n"
- "void initInputFuncs();\n";
+ "void initInputFuncs();\n"
+ "\n"
+ "\n";
out <<
"int main( int argc, char **argv )\n"
"{\n"
- " /* Always on because because logging is controlled with ifdefs in\n"
- " * the runtime lib. */\n"
- " colm_log_bytecode = 1;\n"
- " colm_log_parse = 1;\n"
- " colm_log_match = 1;\n"
- " colm_log_compile = 1;\n"
- " colm_log_conds = 1;\n"
- " colmActiveRealm = 0xffffffff;\n"
- " initInputFuncs();\n"
+ " initColm( 0 );\n"
" Program program;\n"
- " initProgram( &program, argc, argv, true, &main_runtimeData );\n"
+ " initProgram( &program, argc, argv, 1, &main_runtimeData );\n"
" runProgram( &program );\n"
+ " clearProgram( &program );\n"
" return 0;\n"
"}\n"
"\n";
diff --git a/colm/fsmexec.cc b/colm/fsmexec.cc
index 80e0cdc0..d761ce21 100644
--- a/colm/fsmexec.cc
+++ b/colm/fsmexec.cc
@@ -29,7 +29,7 @@
#include "parsedata.h"
#include "parsetree.h"
#include "pdarun.h"
-#include "colm.h"
+#include "global.h"
void execAction( FsmRun *fsmRun, GenAction *genAction )
{
diff --git a/colm/colm.h b/colm/global.h
index 69aa5740..69aa5740 100644
--- a/colm/colm.h
+++ b/colm/global.h
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index 6fd52606..3d077a8b 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -24,7 +24,7 @@
#include "config.h"
#include "lmparse.h"
-#include "colm.h"
+#include "global.h"
#include "input.h"
#include "fsmrun.h"
diff --git a/colm/lmscan.h b/colm/lmscan.h
index 1049bcca..4e349301 100644
--- a/colm/lmscan.h
+++ b/colm/lmscan.h
@@ -26,7 +26,7 @@
#include <fstream>
#include <string.h>
-#include "colm.h"
+#include "global.h"
#include "lmparse.h"
#include "parsedata.h"
#include "avltree.h"
diff --git a/colm/lmscan.rl b/colm/lmscan.rl
index ef6ac44d..7ae4f116 100644
--- a/colm/lmscan.rl
+++ b/colm/lmscan.rl
@@ -23,7 +23,7 @@
#include <fstream>
#include <string.h>
-#include "colm.h"
+#include "global.h"
#include "lmscan.h"
#include "lmparse.h"
#include "parsedata.h"
diff --git a/colm/main.cc b/colm/main.cc
index 639f938d..072e9925 100644
--- a/colm/main.cc
+++ b/colm/main.cc
@@ -30,7 +30,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "colm.h"
+#include "program.h"
#include "debug.h"
#include "lmscan.h"
#include "pcheck.h"
diff --git a/colm/parsedata.cc b/colm/parsedata.cc
index 3e9d2bd6..359b5496 100644
--- a/colm/parsedata.cc
+++ b/colm/parsedata.cc
@@ -26,7 +26,7 @@
#include <limits.h>
#include <sstream>
-#include "colm.h"
+#include "global.h"
#include "lmparse.h"
#include "parsedata.h"
#include "parsetree.h"
diff --git a/colm/parsedata.h b/colm/parsedata.h
index ce06789d..1a307bba 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -25,7 +25,7 @@
#include <iostream>
#include <limits.h>
#include "bstset.h"
-#include "colm.h"
+#include "global.h"
#include "avlmap.h"
#include "avlset.h"
#include "bstmap.h"
diff --git a/colm/parsetree.h b/colm/parsetree.h
index 9a1f716f..60d9ff39 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -24,7 +24,7 @@
#include <iostream>
#include <string.h>
-#include "colm.h"
+#include "global.h"
#include "avlmap.h"
#include "bstmap.h"
#include "bstset.h"
diff --git a/colm/pdabuild.cc b/colm/pdabuild.cc
index 8021ed1c..2c1426bc 100644
--- a/colm/pdabuild.cc
+++ b/colm/pdabuild.cc
@@ -25,7 +25,7 @@
#include <stdlib.h>
/* Parsing. */
-#include "colm.h"
+#include "global.h"
#include "parsedata.h"
#include "pdacodegen.h"
#include "pdarun.h"
diff --git a/colm/pdacodegen.cc b/colm/pdacodegen.cc
index 9b235304..00213687 100644
--- a/colm/pdacodegen.cc
+++ b/colm/pdacodegen.cc
@@ -23,7 +23,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
-#include "colm.h"
+#include "global.h"
#include "parsedata.h"
#include "avlmap.h"
#include "avlbasic.h"
diff --git a/colm/pdagraph.cc b/colm/pdagraph.cc
index fbea60d1..9ccf11d5 100644
--- a/colm/pdagraph.cc
+++ b/colm/pdagraph.cc
@@ -23,7 +23,7 @@
#include <iostream>
#include <string.h>
#include <assert.h>
-#include "colm.h"
+#include "global.h"
#include "pdagraph.h"
#include "mergesort.h"
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 9ff5c93a..c701a20c 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -466,6 +466,9 @@ typedef struct _Program
Stream *stderrVal;
RunBuf *allocRunBuf;
+
+ Tree **vm_stack;
+ Tree **vm_root;
} Program;
typedef struct _TreeIter
diff --git a/colm/redbuild.cc b/colm/redbuild.cc
index 70124ed8..fcf02cb6 100644
--- a/colm/redbuild.cc
+++ b/colm/redbuild.cc
@@ -20,7 +20,7 @@
*/
-#include "colm.h"
+#include "global.h"
#include "redbuild.h"
#include "fsmgraph.h"
#include "redfsm.h"
diff --git a/colm/redfsm.h b/colm/redfsm.h
index 36ee925b..9c08f481 100644
--- a/colm/redfsm.h
+++ b/colm/redfsm.h
@@ -38,8 +38,7 @@
#include "sbstmap.h"
#include "sbstset.h"
#include "sbsttable.h"
-#include "colm.h"
-#include "fsmrun.h"
+#include "global.h"
#include "fsmrun.h"
#define TRANS_ERR_TRANS 0