You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/11/08 00:52:13 UTC

[GitHub] [tvm] gromero commented on a diff in pull request #13313: [microTVM][CRT] Add memory size as project option

gromero commented on code in PR #13313:
URL: https://github.com/apache/tvm/pull/13313#discussion_r1016021735


##########
src/runtime/crt/host/microtvm_api_server.py:
##########
@@ -67,6 +88,29 @@ def server_info_query(self, tvm_version):
     # The build target given to make
     BUILD_TARGET = "build/main"
 
+    def _populate_makefile(
+        self,
+        makefile_template_path: pathlib.Path,
+        makefile_path: pathlib.Path,
+        memory_size: int,
+    ):
+        """Generate Makefile from template."""
+        flags = {
+            "MEMORY_SIZE_BYTES": str(memory_size),
+        }
+
+        with open(makefile_path, "w") as makefile_f:
+            with open(makefile_template_path, "r") as makefile_template_f:
+                for line in makefile_template_f:
+                    SUBST_TOKEN_RE = re.compile(r"<([A-Z_]+)>")
+                    outs = []
+                    for i, m in enumerate(re.split(SUBST_TOKEN_RE, line)):
+                        if i % 2 == 1:
+                            m = flags[m]
+                        outs.append(m)
+                    line = "".join(outs)
+                    makefile_f.write(line)

Review Comment:
   Could we make it shorter with (or something alike to):
   
   ```
   token_val = {
       "MEMORY": str(memory_size),
   }
   
   regex = re.compile(r'([A-Z_]+) := (<[A-Z_]+>)')
   with open(makefile_path, "w") as makefile_f:
       with open(makefile_template_path, "r") as makefile_template_f:
           for line in makefile_template_f:
               m = regex.match(line)
               if m:
                   var, token = m.groups()
                   line = line.replace(token, token_val[var])
                
               makefile_f.write(line)
   ```
   ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org