Mercurial > lcfOS
comparison python/ppci/assembler.py @ 345:b4882ff0ed06
Added more arm isa tests
author | Windel Bouwman |
---|---|
date | Sun, 02 Mar 2014 17:12:08 +0100 |
parents | 86b02c98a717 |
children | 3bb7dcfe5529 |
comparison
equal
deleted
inserted
replaced
344:1378c4b027a0 | 345:b4882ff0ed06 |
---|---|
5 from .target import Target, Label | 5 from .target import Target, Label |
6 from .asmnodes import ALabel, AInstruction, ABinop, AUnop, ASymbol, ANumber | 6 from .asmnodes import ALabel, AInstruction, ABinop, AUnop, ASymbol, ANumber |
7 | 7 |
8 | 8 |
9 def bit_type(value): | 9 def bit_type(value): |
10 assert value < (2**31) | 10 assert value < (2**32) |
11 assert value >= 0 | 11 assert value >= 0 |
12 t = 'val32' | 12 t = 'val32' |
13 for n in [16, 8, 5, 3]: | 13 for n in [16, 12, 8, 5, 3]: |
14 if value < (2**n): | 14 if value < (2**n): |
15 t = 'val{}'.format(n) | 15 t = 'val{}'.format(n) |
16 return t | 16 return t |
17 | 17 |
18 def tokenize(s, kws): | 18 def tokenize(s, kws): |
98 | 98 |
99 def __init__(self, kws, instruction_rules, emit): | 99 def __init__(self, kws, instruction_rules, emit): |
100 # Construct a parser given a grammar: | 100 # Construct a parser given a grammar: |
101 tokens2 = ['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', | 101 tokens2 = ['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', |
102 pyyacc.EPS, 'COMMENT', '{', '}', | 102 pyyacc.EPS, 'COMMENT', '{', '}', |
103 pyyacc.EOF, 'val32', 'val16', 'val8', 'val5', 'val3'] | 103 pyyacc.EOF, 'val32', 'val16', 'val12', 'val8', 'val5', 'val3'] |
104 tokens2.extend(kws) | 104 tokens2.extend(kws) |
105 self.kws = kws | 105 self.kws = kws |
106 g = pyyacc.Grammar(tokens2) | 106 g = pyyacc.Grammar(tokens2) |
107 self.g = g | 107 self.g = g |
108 # Global structure of assembly line: | 108 # Global structure of assembly line: |