annotate doc/internals.txt @ 363:d96c30e60ddf

Added pass2 and various supporting logic including symbol lookups
author lost@starbug
date Tue, 06 Apr 2010 21:03:19 -0600
parents e7885b3ee266
children 6a98cc90c14f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
1 LWASM Internals
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
2 ===============
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
3
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
4 LWASM is a table-driven assembler that notionally uses two passes. However,
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
5 it implements its assembly in several passes as follows.
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
6
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
7 Pass 1
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
8 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
9
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
10 This pass reads the entire source code and parses each line into an internal
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
11 representation. Macros, file inclusions, and conditional assembly
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
12 instructions are resolved at this point as well. Instructions with known
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
13 sizes will have their sizes resolved at this point.
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
14
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
15 Pass 2
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
16 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
17
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
18 Check all exported symbols for validity and set them as imports if the
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
19 assembler state says so. Also resolve all symbol references in all
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
20 expressions to be direct references either to the symbol table or
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
21 to the import list.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
22
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
23 Pass 3
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
24 ------
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
25
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
26 This pass resolves all instruction sizes that can be resolved without
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
27 setting addresses for instructions. This process is repeated until no
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
28 further instructions sizes are resolved.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
29
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
30 Pass 4
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
31 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
32
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
33 This pass assigns addresses to all symbols where values are known. It does
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
34 the same for instructions. Then a repeat of similar algorithms as in the
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
35 previous pass is used to resolve as many operands as possible.
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
36
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
37 This pass is repeated multiple times until no further instructions or
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
38 symbols are resolved.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
39
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
40 Pass 5
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
41 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
42
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
43 Finalization of all instruction sizes by forcing them to the maximum
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
44 addressing mode. Then all remaining instruction addresses and symbol values
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
45 are resolved.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
46
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
47 Pass 6
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
48 ------
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
49
338
e7885b3ee266 Updated internals docs
lost
parents: 333
diff changeset
50 This pass does actual code generation. This is the notional second pass. All
e7885b3ee266 Updated internals docs
lost
parents: 333
diff changeset
51 other passes are the notional first pass.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
52
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
53
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
54 Expression Evaluation
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
55 =====================
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
56
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
57 Each expression carries a certainty flag. Any expression in which any term
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
58 is flagged as uncertain is, itself, uncertain. There are a few specific
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
59 cases where such uncertainty can cancel out. For instance, X-X where X is
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
60 uncertain is guaranteed to be 0 and so there is no uncertainty.
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
61