changeset 311:ff665880a6b0

Added testcase for kernel and userspace
author Windel Bouwman
date Mon, 16 Dec 2013 12:49:24 +0100
parents e95e5572cd6d
children 2c9768114877
files kernel/make.py python/ide/ide.py python/ppci/c3/codegenerator.py python/ppci/c3/parser.py python/zcc.py test/grind.py test/testc3.py test/testzcc.py user/hello.c3 user/ipc.c3 user/lib.c3 user/makeuser.py
diffstat 12 files changed, 68 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kernel/make.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/kernel/make.py	Mon Dec 16 12:49:24 2013 +0100
@@ -2,10 +2,9 @@
 
 import sys
 import os
-sys.path.insert(0, os.path.join('..', 'python'))
 import zcc
 
-def make():
+def make_kernel():
     arglist = ['memory.c3', 'kernel.c3', 'syscall.c3', 'process.c3']
     arglist += ['schedule.c3', 'arch_arm.c3']
     arglist += ['--target', 'arm']
@@ -16,4 +15,5 @@
     zcc.main(args)
 
 if __name__ == '__main__':
-    make()
+    sys.path.insert(0, os.path.join('..', 'python'))
+    make_kernel()
--- a/python/ide/ide.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/python/ide/ide.py	Mon Dec 16 12:49:24 2013 +0100
@@ -11,7 +11,6 @@
 
 # Compiler imports:
 p = os.path.join(os.path.dirname(__file__), '..')
-# print(p)
 sys.path.insert(0, p)
 sys.path.insert(0, os.path.join(p, 'utils'))
 import ppci
--- a/python/ppci/c3/codegenerator.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/python/ppci/c3/codegenerator.py	Mon Dec 16 12:49:24 2013 +0100
@@ -180,7 +180,7 @@
                                .format(expr.a.typ, expr.b.typ), expr.loc)
                 self.emit(ir.CJump(ta, expr.op, tb, bbtrue, bbfalse))
             else:
-                raise NotImplementedError('Unknown condition {}'.format(expr))
+                raise SemanticError('non-bool: {}'.format(expr.op), expr.loc)
             expr.typ = self.boolType
         elif type(expr) is ast.Literal:
             self.genExprCode(expr)
--- a/python/ppci/c3/parser.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/python/ppci/c3/parser.py	Mon Dec 16 12:49:24 2013 +0100
@@ -386,6 +386,9 @@
         elif self.Peak == 'false':
             val = self.Consume('false')
             return Literal(False, val.loc)
+        elif self.Peak == 'STRING':
+            val = self.Consume('STRING')
+            return Literal(val.val, val.loc)
         elif self.Peak == 'ID':
             return self.parseDesignator()
         self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak))
--- a/python/zcc.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/python/zcc.py	Mon Dec 16 12:49:24 2013 +0100
@@ -10,6 +10,8 @@
 import outstream
 from utils import HexFile
 import target
+from ppci import irutils
+import io
 
 
 logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s'
@@ -67,7 +69,9 @@
         # Optimization passes, TODO
 
         if dumpir:
-            ircode.dump()
+            f = io.StringIO()
+            irutils.Writer().write(ircode, f)
+            print(f.getvalue())
 
         # Code generation:
         logging.info('Starting code generation for {}'.format(ircode))
--- a/test/grind.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/test/grind.py	Mon Dec 16 12:49:24 2013 +0100
@@ -6,12 +6,9 @@
 import sys
 import os
 
-sys.path.insert(0, os.path.join('..','python'))
-
 if __name__ == '__main__':
     suite = unittest.TestLoader().discover('.')
     def runtests():
         unittest.TextTestRunner().run(suite)
     #s = cProfile.run('runtests()',sort='cumtime')
     s = cProfile.run('runtests()',sort='tottime')
-
--- a/test/testc3.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/test/testc3.py	Mon Dec 16 12:49:24 2013 +0100
@@ -261,7 +261,7 @@
         snippet = """
         module tst;
         function void t() {
-         if (3) {
+         if (3+3) {
          }
         }
         """
--- a/test/testzcc.py	Fri Dec 13 14:10:10 2013 +0100
+++ b/test/testzcc.py	Mon Dec 16 12:49:24 2013 +0100
@@ -1,14 +1,18 @@
 import unittest
+import os
+import sys
+
 import zcc
 import outstream
 import ppci
 import io
-import os
 import target
 
 
 class ZccTestCase(unittest.TestCase):
     """ Tests the compiler driver """
+    def setUp(self):
+        os.chdir(os.path.dirname(os.path.abspath(__file__)))
 
     def do(self, filenames, imps=[]):
         basedir = os.path.join('..', 'examples', 'c3')
@@ -21,6 +25,33 @@
         args = zcc.parser.parse_args(arg_list)
         self.assertEqual(0, zcc.main(args))
 
+    def testDumpIr(self):
+        basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
+        arg_list = [basedir]
+        arg_list.append('--target')
+        arg_list.append('arm')
+        arg_list.append('--dumpir')
+        args = zcc.parser.parse_args(arg_list)
+        self.assertEqual(0, zcc.main(args))
+
+    def testKernel(self):
+        # Build kernel using zcc:
+        kerneldir = os.path.normpath(os.path.join('..', 'kernel'))
+        sys.path.insert(0, kerneldir) 
+        from make import make_kernel
+        os.chdir(kerneldir)
+        make_kernel()
+        sys.path.pop(-1)
+        
+    def testUser(self):
+        # Build userspace using zcc:
+        userdir = os.path.normpath(os.path.join('..', 'user'))
+        sys.path.insert(0, userdir) 
+        from makeuser import make_user
+        os.chdir(userdir)
+        make_user()
+        sys.path.pop(-1)
+
     def testBurn2(self):
         self.do(['burn2.c3'], ['stm32f4xx.c3'])
 
--- a/user/hello.c3	Fri Dec 13 14:10:10 2013 +0100
+++ b/user/hello.c3	Mon Dec 16 12:49:24 2013 +0100
@@ -5,8 +5,8 @@
     Demo program running in userspace.
 */
 
-func void start()
+function void start()
 {
-    lib.print("Hello space");
+    lib.print('Hello space');
 }
 
--- a/user/ipc.c3	Fri Dec 13 14:10:10 2013 +0100
+++ b/user/ipc.c3	Mon Dec 16 12:49:24 2013 +0100
@@ -1,12 +1,12 @@
 
 module ipc;
 
-func SendMessage(Msg *msg)
+function void SendMessage(Msg *msg)
 {
     kernelTrap(MSG_SEND, msg)
 }
 
-func RecvMessage(Msg msg)
+function void RecvMessage(Msg msg)
 {
     kernelTrap(MSG_RECV, msg);
 }
--- a/user/lib.c3	Fri Dec 13 14:10:10 2013 +0100
+++ b/user/lib.c3	Mon Dec 16 12:49:24 2013 +0100
@@ -5,7 +5,7 @@
 
 */
 
-func void print(string txt)
+function void print(string txt)
 {
     // TODO
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/makeuser.py	Mon Dec 16 12:49:24 2013 +0100
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import zcc
+
+def make_user():
+    arglist = ['lib.c3', 'ipc.c3', 'hello.c3']
+    arglist += ['--target', 'arm']
+    arglist += ['--dumpasm', '--dumpir']
+    arglist += ['--log', 'debug']
+
+    args = zcc.parser.parse_args(arglist)
+    zcc.main(args)
+
+if __name__ == '__main__':
+    sys.path.insert(0, os.path.join('..', 'python'))
+    make_user()