From 167c27c92703b165412d705a7aa876bb40de6f54 Mon Sep 17 00:00:00 2001
From: Andrea Shepard <andrea@special-circumstanc.es>
Date: Thu, 14 Nov 2019 01:22:06 +0000
Subject: [PATCH] Pass around const HParser * in LLVM; the reasons are silly
 but the change is easy

---
 src/internal.h        |  4 +++-
 src/parsers/bits.c    |  2 +-
 src/parsers/ch.c      |  2 +-
 src/parsers/charset.c |  2 +-
 src/parsers/end.c     |  2 +-
 src/parsers/epsilon.c |  2 +-
 src/parsers/nothing.c |  2 +-
 src/parsers/token.c   | 12 ++++++------
 8 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index 23e0b7cd..7eaee5f8 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -505,7 +505,9 @@ struct HParserVtable_ {
   bool (*compile_to_rvm)(HRVMProg *prog, void* env); // FIXME: forgot what the bool return value was supposed to mean.
   void (*desugar)(HAllocator *mm__, HCFStack *stk__, void *env);
 #ifdef HAMMER_LLVM_BACKEND
-  bool (*llvm)(HLLVMParserCompileContext *ctxt, HParser *p, LLVMValueRef *result);
+  bool (*llvm)(HLLVMParserCompileContext *ctxt,
+               const HParser *p,
+               LLVMValueRef *result);
 #endif
   bool higher; // false if primitive
 };
diff --git a/src/parsers/bits.c b/src/parsers/bits.c
index 6fe71e79..ae01a7f1 100644
--- a/src/parsers/bits.c
+++ b/src/parsers/bits.c
@@ -27,7 +27,7 @@ static HParseResult* parse_bits(void* env, HParseState *state) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool bits_llvm(HLLVMParserCompileContext *ctxt,
-                      HParser *p,
+                      const HParser *p,
                       LLVMValueRef *res) {
   /* Emit LLVM IR to parse ((struct bits_env *)(p->env))->length bits */
 
diff --git a/src/parsers/ch.c b/src/parsers/ch.c
index 0ae2b713..858887d2 100644
--- a/src/parsers/ch.c
+++ b/src/parsers/ch.c
@@ -51,7 +51,7 @@ static bool ch_ctrvm(HRVMProg *prog, void* env) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool ch_llvm(HLLVMParserCompileContext *ctxt,
-                    HParser *p,
+                    const HParser *p,
                     LLVMValueRef *res) {
   /* Build a new LLVM function to parse a character */
 
diff --git a/src/parsers/charset.c b/src/parsers/charset.c
index 49dd5601..1333c3a4 100644
--- a/src/parsers/charset.c
+++ b/src/parsers/charset.c
@@ -80,7 +80,7 @@ static bool cs_ctrvm(HRVMProg *prog, void *env) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool cs_llvm(HLLVMParserCompileContext *ctxt,
-                    HParser *p,
+                    const HParser *p,
                     LLVMValueRef *res) {
   /*
    * LLVM to build a function to parse a charset; the args are a stream and an
diff --git a/src/parsers/end.c b/src/parsers/end.c
index e8e1896f..f2f655e0 100644
--- a/src/parsers/end.c
+++ b/src/parsers/end.c
@@ -29,7 +29,7 @@ static bool end_ctrvm(HRVMProg *prog, void *env) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool end_llvm(HLLVMParserCompileContext *ctxt, 
-                     HParser *p,
+                     const HParser *p,
                      LLVMValueRef *res) {
   /* Allocator */
   HAllocator *mm__ = NULL;
diff --git a/src/parsers/epsilon.c b/src/parsers/epsilon.c
index 26d97cc5..537b1c66 100644
--- a/src/parsers/epsilon.c
+++ b/src/parsers/epsilon.c
@@ -22,7 +22,7 @@ static bool epsilon_ctrvm(HRVMProg *prog, void* env) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool epsilon_llvm(HLLVMParserCompileContext *ctxt,
-                         HParser *p,
+                         const HParser *p,
                          LLVMValueRef *res) {
   /* Allocator */
   HAllocator *mm__ = NULL;
diff --git a/src/parsers/nothing.c b/src/parsers/nothing.c
index fa5faf55..3ec425df 100644
--- a/src/parsers/nothing.c
+++ b/src/parsers/nothing.c
@@ -28,7 +28,7 @@ static bool nothing_ctrvm(HRVMProg *prog, void* env) {
 #ifdef HAMMER_LLVM_BACKEND
 
 static bool nothing_llvm(HLLVMParserCompileContext *ctxt,
-                         HParser *p,
+                         const HParser *p,
                          LLVMValueRef *res) {
   /* Allocator */
   HAllocator *mm__;
diff --git a/src/parsers/token.c b/src/parsers/token.c
index 66012540..3c2c6a88 100644
--- a/src/parsers/token.c
+++ b/src/parsers/token.c
@@ -82,8 +82,8 @@ static bool token_ctrvm(HRVMProg *prog, void *env) {
 
 static bool token_llvm_with_global(
     HLLVMParserCompileContext *ctxt,
-    HParser *p,
-    HToken *t,
+    const HParser *p,
+    const HToken *t,
     LLVMValueRef *res) {
   /* Allocator*/
   HAllocator *mm__ = NULL;
@@ -400,8 +400,8 @@ static bool token_llvm_with_global(
 
 static bool token_llvm_with_sequential_comparisons(
     HLLVMParserCompileContext *ctxt,
-    HParser *p,
-    HToken *t,
+    const HParser *p,
+    const HToken *t,
     LLVMValueRef *res) {
   /* Allocator */
   HAllocator *mm__;
@@ -567,9 +567,9 @@ static bool token_llvm_with_sequential_comparisons(
 #define TOKEN_LENGTH_USE_GLOBAL_CUTOFF 4
 
 static bool token_llvm(HLLVMParserCompileContext *ctxt,
-                       HParser *p,
+                       const HParser *p,
                        LLVMValueRef *res) {
-  HToken *t;
+  const HToken *t;
 
   if (!res) return false;
   if (!p) return false;
-- 
GitLab