annotate python/c3/codegenerator.py @ 269:5f8c04a8d26b

Towards better modularity
author Windel Bouwman
date Sun, 18 Aug 2013 17:43:18 +0200
parents 5ec7580976d9
children e64bae57cda8
rev   line source
255
7416c923a02a Added more logging
Windel Bouwman
parents: 252
diff changeset
1 import logging
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
2 import ir
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 151
diff changeset
3 from . import astnodes
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
4 from .scope import boolType, intType
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 217
diff changeset
5 from ppci import CompilerError
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
6 from .typecheck import theType
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
7
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
8
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
9 class CodeGenerator(ir.Builder):
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents: 259
diff changeset
10 """ Generates intermediate code from a package """
255
7416c923a02a Added more logging
Windel Bouwman
parents: 252
diff changeset
11 def __init__(self):
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents: 259
diff changeset
12 self.logger = logging.getLogger('c3cgen')
444b9df2ed99 try to split up code generation
Windel Bouwman
parents: 259
diff changeset
13
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
14 def gencode(self, pkg):
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
15 self.prepare()
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
16 assert type(pkg) is astnodes.Package
255
7416c923a02a Added more logging
Windel Bouwman
parents: 252
diff changeset
17 self.logger.info('Generating ir-code for {}'.format(pkg.name))
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
18 self.varMap = {} # Maps variables to storage locations.
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
19 self.funcMap = {}
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
20 self.m = ir.Module(pkg.name)
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
21 self.genModule(pkg)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
22 return self.m
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 169
diff changeset
23
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
24 # inner helpers:
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
25 def genModule(self, pkg):
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
26 # Take care of forward declarations:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
27 for s in pkg.innerScope.Functions:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
28 f = self.newFunction(s.name)
175
a51b3c956386 Added function call in expressions
Windel Bouwman
parents: 174
diff changeset
29 self.funcMap[s] = f
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
30 for s in pkg.innerScope:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
31 if type(s) is astnodes.Variable:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
32 #v = self.builder.newTmp(s.name)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
33 self.varMap[s] = self.newTemp()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
34 pass
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
35 elif type(s) is astnodes.Function:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
36 self.genFunction(s)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
37 else:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
38 raise NotImplementedError(str(s))
174
3eb06f5fb987 Added memory alloc for locals
Windel Bouwman
parents: 172
diff changeset
39
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
40 def genFunction(self, fn):
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
41 # TODO: handle arguments
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
42 f = self.funcMap[fn]
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
43 # TODO reserve room for stack, this can be done at later point?
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
44 self.setFunction(f)
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
45 l2 = self.newBlock()
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
46 self.emit(ir.Jump(l2))
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
47 self.setBlock(l2)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
48 # generate room for locals:
174
3eb06f5fb987 Added memory alloc for locals
Windel Bouwman
parents: 172
diff changeset
49
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
50 for sym in fn.innerScope:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
51 # TODO: handle parameters different
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
52 v = self.newTemp()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
53 # TODO: make this ssa here??
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
54 self.varMap[sym] = v
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
55
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
56 self.genCode(fn.body)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
57 # TODO handle return?
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
58 self.emit(ir.Jump(f.epiloog))
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
59 #self.emit(ir.Return(ir.Const(0)))
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
60 self.setFunction(None)
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
61
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
62 def genCode(self, code):
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
63 assert isinstance(code, astnodes.Statement)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
64 self.setLoc(code.loc)
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
65 if type(code) is astnodes.CompoundStatement:
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
66 for s in code.statements:
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
67 self.genCode(s)
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
68 elif type(code) is astnodes.Assignment:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
69 rval = self.genExprCode(code.rval)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
70 lval = self.genExprCode(code.lval)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
71 self.emit(ir.Move(lval, rval))
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
72 elif type(code) is astnodes.ExpressionStatement:
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
73 self.genExprCode(code.ex)
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
74 elif type(code) is astnodes.IfStatement:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
75 bbtrue = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
76 bbfalse = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
77 te = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
78 self.genCondCode(code.condition, bbtrue, bbfalse)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
79 self.setBlock(bbtrue)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
80 self.genCode(code.truestatement)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
81 self.emit(ir.Jump(te))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
82 self.setBlock(bbfalse)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
83 if code.falsestatement:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
84 self.genCode(code.falsestatement)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
85 self.emit(ir.Jump(te))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
86 self.setBlock(te)
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
87 elif type(code) is astnodes.ReturnStatement:
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
88 if code.expr:
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
89 re = self.genExprCode(code.expr)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
90 self.emit(ir.Return(re))
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
91 else:
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
92 self.builder.addIns(ir.Return())
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
93 elif type(code) is astnodes.WhileStatement:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
94 bbdo = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
95 bbtest = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
96 te = self.newBlock()
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
97 self.emit(ir.Jump(bbtest))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
98 self.setBlock(bbtest)
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
99 self.genCondCode(code.condition, bbdo, te)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
100 self.setBlock(bbdo)
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
101 self.genCode(code.statement)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
102 self.emit(ir.Jump(bbtest))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
103 self.setBlock(te)
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
104 else:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
105 raise NotImplementedError('Unknown stmt {}'.format(code))
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
106
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
107 def genCondCode(self, expr, bbtrue, bbfalse):
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
108 # Implement sequential logical operators
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
109 assert expr.typ == boolType
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
110 if type(expr) is astnodes.Binop:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
111 if expr.op == 'or':
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
112 l2 = self.newBlock()
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
113 self.genCondCode(expr.a, bbtrue, l2)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
114 self.setBlock(l2)
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
115 self.genCondCode(expr.b, bbtrue, bbfalse)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
116 elif expr.op == 'and':
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
117 l2 = self.newBlock()
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
118 self.genCondCode(expr.a, l2, bbfalse)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
119 self.setBlock(l2)
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
120 self.genCondCode(expr.b, bbtrue, bbfalse)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
121 elif expr.op in ['==', '>', '<']:
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
122 ta = self.genExprCode(expr.a)
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
123 tb = self.genExprCode(expr.b)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
124 self.emit(ir.CJump(ta, expr.op, tb, bbtrue, bbfalse))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
125 else:
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
126 raise NotImplementedError('Unknown condition {}'.format(expr))
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
127 elif type(expr) is astnodes.Literal:
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
128 if expr.val:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
129 self.emit(ir.Jump(bbtrue))
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
130 else:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
131 self.emit(ir.Jump(bbfalse))
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
132 else:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
133 raise NotImplementedError('Unknown cond {}'.format(expr))
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
134
217
8b2e5f3cd579 Removed some stale python source files
Windel Bouwman
parents: 205
diff changeset
135 def genExprCode(self, expr):
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
136 assert isinstance(expr, astnodes.Expression)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
137 if type(expr) is astnodes.Binop and expr.op in ir.Binop.ops:
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
138 ra = self.genExprCode(expr.a)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
139 rb = self.genExprCode(expr.b)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
140 return ir.Binop(ra, expr.op, rb)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
141 elif type(expr) is astnodes.Unop and expr.op == '&':
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
142 ra = self.genExprCode(expr.a)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
143 # TODO: Make this work?
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
144 return ra
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
145 elif type(expr) is astnodes.VariableUse:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
146 return self.varMap[expr.target]
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
147 elif type(expr) is astnodes.Deref:
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
148 # dereference pointer type:
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
149 addr = self.genExprCode(expr.ptr)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
150 return ir.Mem(addr)
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 225
diff changeset
151 elif type(expr) is astnodes.FieldRef:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
152 b = self.genExprCode(expr.base)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
153 #b = b.e
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
154 bt = theType(expr.base.typ)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
155 offset = ir.Const(bt.fieldOffset(expr.field))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
156 return ir.Mem(ir.Binop(b, '+', offset))
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
157 elif type(expr) is astnodes.Literal:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
158 return ir.Const(expr.val)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
159 elif type(expr) is astnodes.TypeCast:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
160 # TODO: improve this mess:
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
161 ar = self.genExprCode(expr.a)
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
162 tt = theType(expr.to_type)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
163 if isinstance(tt, astnodes.PointerType):
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
164 if expr.a.typ is intType:
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
165 return ar
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
166 elif isinstance(expr.a.typ, astnodes.PointerType):
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
167 return ar
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
168 else:
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
169 raise Exception()
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
170 else:
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents: 232
diff changeset
171 raise NotImplementedError("not implemented")
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
172 elif type(expr) is astnodes.FunctionCall:
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
173 args = [self.genExprCode(e) for e in expr.args]
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 255
diff changeset
174 fn = self.funcMap[expr.proc]
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
175 return ir.Call(fn, args)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
176 else:
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 255
diff changeset
177 raise NotImplementedError('Unknown expr {}'.format(expr))
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 156
diff changeset
178