update
[tinycc.git] / tcc-doc.texi
blobd5ddb409a47a0e6147a8effb0c9130e0ec2913b9
1 \input texinfo @c -*- texinfo -*-
3 @settitle Tiny C Compiler Reference Documentation
4 @titlepage
5 @sp 7
6 @center @titlefont{Tiny C Compiler Reference Documentation}
7 @sp 3
8 @end titlepage
10 @chapter Introduction
12 TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
13 compilers, it is meant to be self-suffisant: you do not need an
14 external assembler or linker because TCC does that for you.
16 TCC compiles so @emph{fast} that even for big projects @code{Makefile}s may
17 not be necessary. 
19 TCC not only supports ANSI C, but also most of the new ISO C99
20 standard and many GNUC extensions.
22 TCC can also be used to make @emph{C scripts}, i.e. pieces of C source
23 that you run as a Perl or Python script. Compilation is so fast that
24 your script will be as fast as if it was an executable.
26 TCC can also automatically generate memory and bound checks
27 (@xref{bounds}) while allowing all C pointers operations. TCC can do
28 these checks even if non patched libraries are used.
30 With @code{libtcc}, you can use TCC as a backend for dynamic code
31 generation (@xref{libtcc}).
33 @node invoke
34 @chapter Command line invocation
36 @section Quick start
38 @example
39 usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]
40            [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]
41            [--] infile1 [infile2... --] [infile_args...]
42 @end example
44 TCC options are a very much like gcc. The main difference is that TCC
45 can also execute directly the resulting program and give it runtime
46 arguments.
48 Here are some examples to understand the logic:
50 @table @code
51 @item tcc a.c
52 Compile a.c and execute it directly
54 @item tcc a.c arg1
55 Compile a.c and execute it directly. arg1 is given as first argument to
56 the @code{main()} of a.c.
58 @item tcc -- a.c b.c -- arg1
59 Compile a.c and b.c, link them together and execute them. arg1 is given
60 as first argument to the @code{main()} of the resulting program. Because
61 multiple C files are specified, @code{--} are necessary to clearly separate the
62 program arguments from the TCC options.
64 @item tcc -o myprog a.c b.c
65 Compile a.c and b.c, link them and generate the executable myprog.
67 @item tcc -o myprog a.o b.o
68 link a.o and b.o together and generate the executable myprog.
70 @item tcc -c a.c
71 Compile a.c and generate object file a.o
73 @item tcc -r -o ab.o a.c b.c
74 Compile a.c and b.c, link them together and generate the object file ab.o.
76 @end table
78 Scripting:
80 TCC can be invoked from @emph{scripts}, just as shell scripts. You just
81 need to add @code{#!/usr/local/bin/tcc} at the start of your C source:
83 @example
84 #!/usr/local/bin/tcc
85 #include <stdio.h>
87 int main() 
89     printf("Hello World\n");
90     return 0;
92 @end example
94 @section Option summary
96 General Options:
98 @table @samp
99 @item -c
100 Generate an object file (@samp{-o} option must also be given).
102 @item -o outfile
103 Put object file, executable, or dll into output file @file{outfile}.
105 @item -Bdir
106 Set the path where the tcc internal libraries can be found (default is
107 @file{PREFIX/lib/tcc}).
109 @item -bench
110 Output compilation statistics.
111 @end table
113 Preprocessor options:
115 @table @samp
116 @item -Idir
117 Specify an additionnal include path. Include paths are searched in the
118 order they are specified.
120 System include paths are always searched after. The default system
121 include paths are: @file{/usr/local/include}, @file{/usr/include}
122 and @file{PREFIX/lib/tcc/include}. (@code{PREFIX} is usually
123 @file{/usr} or @file{/usr/local}).
125 @item -Dsym[=val]
126 Define preprocessor symbol 'sym' to
127 val. If val is not present, its value is '1'. Function-like macros can
128 also be defined: @code{'-DF(a)=a+1'}
130 @item -Usym
131 Undefine preprocessor symbol 'sym'.
132 @end table
134 Linker options:
136 @table @samp
137 @item -Ldir
138 Specify an additionnal static library path for the @samp{-l} option. The
139 default library paths are @file{/usr/local/lib}, @file{/usr/lib} and @file{/lib}.
141 @item -lxxx
142 Link your program with dynamic library libxxx.so or static library
143 libxxx.a. The library is searched in the paths specified by the
144 @samp{-L} option.
146 @item -shared
147 Generate a shared library instead of an executable (@samp{-o} option
148 must also be given).
150 @item -static
151 Generate a statically linked executable (default is a shared linked
152 executable) (@samp{-o} option must also be given).
154 @item -r
155 Generate an object file combining all input files (@samp{-o} option must
156 also be given).
158 @end table
160 Debugger options:
162 @table @samp
163 @item -g
164 Generate run time debug information so that you get clear run time
165 error messages: @code{ test.c:68: in function 'test5()': dereferencing
166 invalid pointer} instead of the laconic @code{Segmentation
167 fault}.
169 @item -b
170 Generate additionnal support code to check
171 memory allocations and array/pointer bounds. @samp{-g} is implied. Note
172 that the generated code is slower and bigger in this case.
174 @item -bt N
175 Display N callers in stack traces. This is useful with @samp{-g} or
176 @samp{-b}.
178 @end table
180 Note: GCC options @samp{-Ox}, @samp{-Wx}, @samp{-fx} and @samp{-mx} are
181 ignored.
183 @chapter C language support
185 @section ANSI C
187 TCC implements all the ANSI C standard, including structure bit fields
188 and floating point numbers (@code{long double}, @code{double}, and
189 @code{float} fully supported).
191 @section ISOC99 extensions
193 TCC implements many features of the new C standard: ISO C99. Currently
194 missing items are: complex and imaginary numbers and variable length
195 arrays.
197 Currently implemented ISOC99 features:
199 @itemize
201 @item 64 bit @code{'long long'} types are fully supported.
203 @item The boolean type @code{'_Bool'} is supported.
205 @item @code{'__func__'} is a string variable containing the current
206 function name.
208 @item Variadic macros: @code{__VA_ARGS__} can be used for
209    function-like macros:
210 @example
211     #define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__)
212 @end example
213 @code{dprintf} can then be used with a variable number of parameters.
215 @item Declarations can appear anywhere in a block (as in C++).
217 @item Array and struct/union elements can be initialized in any order by
218   using designators:
219 @example
220     struct { int x, y; } st[10] = { [0].x = 1, [0].y = 2 };
222     int tab[10] = { 1, 2, [5] = 5, [9] = 9};
223 @end example
224     
225 @item Compound initializers are supported:
226 @example
227     int *p = (int []){ 1, 2, 3 };
228 @end example
229 to initialize a pointer pointing to an initialized array. The same
230 works for structures and strings.
232 @item Hexadecimal floating point constants are supported:
233 @example
234           double d = 0x1234p10;
235 @end example
236 is the same as writing 
237 @example
238           double d = 4771840.0;
239 @end example
241 @item @code{'inline'} keyword is ignored.
243 @item @code{'restrict'} keyword is ignored.
244 @end itemize
246 @section GNU C extensions
248 TCC implements some GNU C extensions:
250 @itemize
252 @item array designators can be used without '=': 
253 @example
254     int a[10] = { [0] 1, [5] 2, 3, 4 };
255 @end example
257 @item Structure field designators can be a label: 
258 @example
259     struct { int x, y; } st = { x: 1, y: 1};
260 @end example
261 instead of
262 @example
263     struct { int x, y; } st = { .x = 1, .y = 1};
264 @end example
266 @item @code{'\e'} is ASCII character 27.
268 @item case ranges : ranges can be used in @code{case}s:
269 @example
270     switch(a) {
271     case 1 ... 9:
272           printf("range 1 to 9\n");
273           break;
274     default:
275           printf("unexpected\n");
276           break;
277     }
278 @end example
280 @item The keyword @code{__attribute__} is handled to specify variable or
281 function attributes. The following attributes are supported:
282   @itemize
283   @item @code{aligned(n)}: align data to n bytes (must be a power of two).
285   @item @code{section(name)}: generate function or data in assembly
286   section name (name is a string containing the section name) instead
287   of the default section.
289   @item @code{unused}: specify that the variable or the function is unused.
291   @item @code{cdecl}: use standard C calling convention.
293   @item @code{stdcall}: use Pascal-like calling convention.
295   @end itemize
297 Here are some examples:
298 @example
299     int a __attribute__ ((aligned(8), section(".mysection")));
300 @end example
302 align variable @code{'a'} to 8 bytes and put it in section @code{.mysection}.
304 @example
305     int my_add(int a, int b) __attribute__ ((section(".mycodesection"))) 
306     {
307         return a + b;
308     }
309 @end example
311 generate function @code{'my_add'} in section @code{.mycodesection}.
313 @item GNU style variadic macros:
314 @example
315     #define dprintf(fmt, args...) printf(fmt, ## args)
317     dprintf("no arg\n");
318     dprintf("one arg %d\n", 1);
319 @end example
321 @item @code{__FUNCTION__} is interpreted as C99 @code{__func__} 
322 (so it has not exactly the same semantics as string literal GNUC
323 where it is a string literal).
325 @item The @code{__alignof__} keyword can be used as @code{sizeof} 
326 to get the alignment of a type or an expression.
328 @item The @code{typeof(x)} returns the type of @code{x}. 
329 @code{x} is an expression or a type.
331 @item Computed gotos: @code{&&label} returns a pointer of type 
332 @code{void *} on the goto label @code{label}. @code{goto *expr} can be
333 used to jump on the pointer resulting from @code{expr}.
335 @end itemize
337 @section TinyCC extensions
339 @itemize
341 @item @code{__TINYC__} is a predefined macro to @code{'1'} to
342 indicate that you use TCC.
344 @item @code{'#!'} at the start of a line is ignored to allow scripting.
346 @item Binary digits can be entered (@code{'0b101'} instead of
347 @code{'5'}).
349 @item @code{__BOUNDS_CHECKING_ON} is defined if bound checking is activated.
351 @end itemize
353 @chapter TinyCC Linker
355 @section ELF file generation
357 TCC can directly output relocatable ELF files (object files),
358 executable ELF files and dynamic ELF libraries without relying on an
359 external linker.
361 Dynamic ELF libraries can be output but the C compiler does not generate
362 position independant code (PIC) code. It means that the dynamic librairy
363 code generated by TCC cannot be factorized among processes yet.
365 TCC linker cannot currently suppress unused object code. But TCC
366 will soon integrate a novel feature not found in GNU tools: unused code
367 will be suppressed at the function or variable level, provided you only
368 use TCC to compile your files.
370 @section ELF file loader
372 TCC can load ELF object files, archives (.a files) and dynamic
373 libraries (.so).
375 @section GNU Linker Scripts
377 Because on many Linux systems some dynamic libraries (such as
378 @file{/usr/lib/libc.so}) are in fact GNU ld link scripts (horrible!),
379 TCC linker also support a subset of GNU ld scripts.
381 The @code{GROUP} and @code{FILE} commands are supported.
383 Example from @file{/usr/lib/libc.so}:
384 @example
385 /* GNU ld script
386    Use the shared library, but some functions are only in
387    the static library, so try that secondarily.  */
388 GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )
389 @end example
391 @node bounds
392 @chapter TinyCC Memory and Bound checks
394 This feature is activated with the @code{'-b'} (@xref{invoke}).
396 Note that pointer size is @emph{unchanged} and that code generated
397 with bound checks is @emph{fully compatible} with unchecked
398 code. When a pointer comes from unchecked code, it is assumed to be
399 valid. Even very obscure C code with casts should work correctly.
401 To have more information about the ideas behind this method, check at 
402 @url{http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html}.
404 Here are some examples of catched errors:
406 @table @asis
408 @item Invalid range with standard string function:
409 @example
411     char tab[10];
412     memset(tab, 0, 11);
414 @end example
416 @item Bound error in global or local arrays:
417 @example
419     int tab[10];
420     for(i=0;i<11;i++) {
421         sum += tab[i];
422     }
424 @end example
426 @item Bound error in allocated data:
427 @example
429     int *tab;
430     tab = malloc(20 * sizeof(int));
431     for(i=0;i<21;i++) {
432         sum += tab4[i];
433     }
434     free(tab);
436 @end example
438 @item Access to a freed region:
439 @example
441     int *tab;
442     tab = malloc(20 * sizeof(int));
443     free(tab);
444     for(i=0;i<20;i++) {
445         sum += tab4[i];
446     }
448 @end example
450 @item Freeing an already freed region:
451 @example
453     int *tab;
454     tab = malloc(20 * sizeof(int));
455     free(tab);
456     free(tab);
458 @end example
460 @end table
462 @node libtcc
463 @chapter The @code{libtcc} library
465 The @code{libtcc} library enables you to use TCC as a backend for
466 dynamic code generation. 
468 Read the @file{libtcc.h} to have an overview of the API. Read
469 @file{libtcc_test.c} to have a very simple example.
471 The idea consists in giving a C string containing the program you want
472 to compile directly to @code{libtcc}. Then the @code{main()} function of
473 the compiled string can be launched.
475 @chapter Developper's guide
477 This chapter gives some hints to understand how TCC works. You can skip
478 it if you do not intend to modify the TCC code.
480 @section File reading
482 The @code{BufferedFile} structure contains the context needed to read a
483 file, including the current line number. @code{tcc_open()} opens a new
484 file and @code{tcc_close()} closes it. @code{inp()} returns the next
485 character.
487 @section Lexer
489 @code{next()} reads the next token in the current
490 file. @code{next_nomacro()} reads the next token without macro
491 expansion.
493 @code{tok} contains the current token (see @code{TOK_xxx})
494 constants. Identifiers and keywords are also keywords. @code{tokc}
495 contains additionnal infos about the token (for example a constant value
496 if number or string token).
498 @section Parser
500 The parser is hardcoded (yacc is not necessary). It does only one pass,
501 except:
503 @itemize
505 @item For initialized arrays with unknown size, a first pass 
506 is done to count the number of elements.
508 @item For architectures where arguments are evaluated in 
509 reverse order, a first pass is done to reverse the argument order.
511 @end itemize
513 @section Types
515 The types are stored in a single 'int' variable. It was choosen in the
516 first stages of development when tcc was much simpler. Now, it may not
517 be the best solution.
519 @example
520 #define VT_INT        0  /* integer type */
521 #define VT_BYTE       1  /* signed byte type */
522 #define VT_SHORT      2  /* short type */
523 #define VT_VOID       3  /* void type */
524 #define VT_PTR        4  /* pointer */
525 #define VT_ENUM       5  /* enum definition */
526 #define VT_FUNC       6  /* function type */
527 #define VT_STRUCT     7  /* struct/union definition */
528 #define VT_FLOAT      8  /* IEEE float */
529 #define VT_DOUBLE     9  /* IEEE double */
530 #define VT_LDOUBLE   10  /* IEEE long double */
531 #define VT_BOOL      11  /* ISOC99 boolean type */
532 #define VT_LLONG     12  /* 64 bit integer */
533 #define VT_LONG      13  /* long integer (NEVER USED as type, only
534                             during parsing) */
535 #define VT_BTYPE      0x000f /* mask for basic type */
536 #define VT_UNSIGNED   0x0010  /* unsigned type */
537 #define VT_ARRAY      0x0020  /* array type (also has VT_PTR) */
538 #define VT_BITFIELD   0x0040  /* bitfield modifier */
540 #define VT_STRUCT_SHIFT 16   /* structure/enum name shift (16 bits left) */
541 @end example
543 When a reference to another type is needed (for pointers, functions and
544 structures), the @code{32 - VT_STRUCT_SHIFT} high order bits are used to
545 store an identifier reference.
547 The @code{VT_UNSIGNED} flag can be set for chars, shorts, ints and long
548 longs.
550 Arrays are considered as pointers @code{VT_PTR} with the flag
551 @code{VT_ARRAY} set.
553 The @code{VT_BITFIELD} flag can be set for chars, shorts, ints and long
554 longs. If it is set, then the bitfield position is stored from bits
555 VT_STRUCT_SHIFT to VT_STRUCT_SHIFT + 5 and the bit field size is stored
556 from bits VT_STRUCT_SHIFT + 6 to VT_STRUCT_SHIFT + 11.
558 @code{VT_LONG} is never used except during parsing.
560 During parsing, the storage of an object is also stored in the type
561 integer:
563 @example
564 #define VT_EXTERN  0x00000080  /* extern definition */
565 #define VT_STATIC  0x00000100  /* static variable */
566 #define VT_TYPEDEF 0x00000200  /* typedef definition */
567 @end example
569 @section Symbols
571 All symbols are stored in hashed symbol stacks. Each symbol stack
572 contains @code{Sym} structures.
574 @code{Sym.v} contains the symbol name (remember
575 an idenfier is also a token, so a string is never necessary to store
576 it). @code{Sym.t} gives the type of the symbol. @code{Sym.r} is usually
577 the register in which the corresponding variable is stored. @code{Sym.c} is
578 usually a constant associated to the symbol.
580 Four main symbol stacks are defined:
582 @table @code
584 @item define_stack
585 for the macros (@code{#define}s).
587 @item global_stack
588 for the global variables, functions and types.
590 @item local_stack
591 for the local variables, functions and types.
593 @item label_stack
594 for the local labels (for @code{goto}).
596 @end table
598 @code{sym_push()} is used to add a new symbol in the local symbol
599 stack. If no local symbol stack is active, it is added in the global
600 symbol stack.
602 @code{sym_pop(st,b)} pops symbols from the symbol stack @var{st} until
603 the symbol @var{b} is on the top of stack. If @var{b} is NULL, the stack
604 is emptied.
606 @code{sym_find(v)} return the symbol associated to the identifier
607 @var{v}. The local stack is searched first from top to bottom, then the
608 global stack.
610 @section Sections
612 The generated code and datas are written in sections. The structure
613 @code{Section} contains all the necessary information for a given
614 section. @code{new_section()} creates a new section. ELF file semantics
615 is assumed for each section.
617 The following sections are predefined:
619 @table @code
621 @item text_section
622 is the section containing the generated code. @var{ind} contains the
623 current position in the code section.
625 @item data_section
626 contains initialized data
628 @item bss_section
629 contains uninitialized data
631 @item bounds_section
632 @itemx lbounds_section
633 are used when bound checking is activated
635 @item stab_section
636 @itemx stabstr_section
637 are used when debugging is actived to store debug information
639 @item symtab_section
640 @itemx strtab_section
641 contain the exported symbols (currently only used for debugging).
643 @end table
645 @section Code generation
647 @subsection Introduction
649 The TCC code generator directly generates linked binary code in one
650 pass. It is rather unusual these days (see gcc for example which
651 generates text assembly), but it allows to be very fast and surprisingly
652 not so complicated.
654 The TCC code generator is register based. Optimization is only done at
655 the expression level. No intermediate representation of expression is
656 kept except the current values stored in the @emph{value stack}.
658 On x86, three temporary registers are used. When more registers are
659 needed, one register is flushed in a new local variable.
661 @subsection The value stack
663 When an expression is parsed, its value is pushed on the value stack
664 (@var{vstack}). The top of the value stack is @var{vtop}. Each value
665 stack entry is the structure @code{SValue}.
667 @code{SValue.t} is the type. @code{SValue.r} indicates how the value is
668 currently stored in the generated code. It is usually a CPU register
669 index (@code{REG_xxx} constants), but additionnal values and flags are
670 defined:
672 @example
673 #define VT_CONST     0x00f0
674 #define VT_LLOCAL    0x00f1
675 #define VT_LOCAL     0x00f2
676 #define VT_CMP       0x00f3
677 #define VT_JMP       0x00f4
678 #define VT_JMPI      0x00f5
679 #define VT_LVAL      0x0100
680 #define VT_SYM       0x0200
681 #define VT_MUSTCAST  0x0400
682 #define VT_MUSTBOUND 0x0800
683 #define VT_BOUNDED   0x8000
684 #define VT_LVAL_BYTE     0x1000
685 #define VT_LVAL_SHORT    0x2000
686 #define VT_LVAL_UNSIGNED 0x4000
687 #define VT_LVAL_TYPE     (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
688 @end example
690 @table @code
692 @item VT_CONST
693 indicates that the value is a constant. It is stored in the union
694 @code{SValue.c}, depending on its type.
696 @item VT_LOCAL
697 indicates a local variable pointer at offset @code{SValue.c.i} in the
698 stack.
700 @item VT_CMP
701 indicates that the value is actually stored in the CPU flags (i.e. the
702 value is the consequence of a test). The value is either 0 or 1. The
703 actual CPU flags used is indicated in @code{SValue.c.i}. 
705 If any code is generated which destroys the CPU flags, this value MUST be
706 put in a normal register.
708 @item VT_JMP
709 @itemx VT_JMPI
710 indicates that the value is the consequence of a jmp. For VT_JMP, it is
711 1 if the jump is taken, 0 otherwise. For VT_JMPI it is inverted.
713 These values are used to compile the @code{||} and @code{&&} logical
714 operators.
716 If any code is generated, this value MUST be put in a normal
717 register. Otherwise, the generated code won't be executed if the jump is
718 taken.
720 @item VT_LVAL
721 is a flag indicating that the value is actually an lvalue (left value of
722 an assignment). It means that the value stored is actually a pointer to
723 the wanted value. 
725 Understanding the use @code{VT_LVAL} is very important if you want to
726 understand how TCC works.
728 @item VT_LVAL_BYTE
729 @itemx VT_LVAL_SHORT
730 @itemx VT_LVAL_UNSIGNED
731 if the lvalue has an integer type, then these flags give its real
732 type. The type alone is not suffisant in case of cast optimisations.
734 @item VT_LLOCAL
735 is a saved lvalue on the stack. @code{VT_LLOCAL} should be suppressed
736 ASAP because its semantics are rather complicated.
738 @item VT_MUSTCAST
739 indicates that a cast to the value type must be performed if the value
740 is used (lazy casting).
742 @item VT_SYM
743 indicates that the symbol @code{SValue.sym} must be added to the constant.
745 @item VT_MUSTBOUND
746 @itemx VT_BOUNDED
747 are only used for optional bound checking.
749 @end table
751 @subsection Manipulating the value stack
753 @code{vsetc()} and @code{vset()} pushes a new value on the value
754 stack. If the previous @code{vtop} was stored in a very unsafe place(for
755 example in the CPU flags), then some code is generated to put the
756 previous @code{vtop} in a safe storage.
758 @code{vpop()} pops @code{vtop}. In some cases, it also generates cleanup
759 code (for example if stacked floating point registers are used as on
760 x86).
762 The @code{gv(rc)} function generates code to evaluate @code{vtop} (the
763 top value of the stack) into registers. @var{rc} selects in which
764 register class the value should be put. @code{gv()} is the @emph{most
765 important function} of the code generator.
767 @code{gv2()} is the same as @code{gv()} but for the top two stack
768 entries.
770 @subsection CPU dependent code generation
772 See the @file{i386-gen.c} file to have an example.
774 @table @code
776 @item load()
777 must generate the code needed to load a stack value into a register.
779 @item store()
780 must generate the code needed to store a register into a stack value
781 lvalue.
783 @item gfunc_start()
784 @itemx gfunc_param()
785 @itemx gfunc_call()
786 should generate a function call
788 @item gfunc_prolog()
789 @itemx gfunc_epilog()
790 should generate a function prolog/epilog.
792 @item gen_opi(op)
793 must generate the binary integer operation @var{op} on the two top
794 entries of the stack which are guaranted to contain integer types.
796 The result value should be put on the stack.
798 @item gen_opf(op)
799 same as @code{gen_opi()} for floating point operations. The two top
800 entries of the stack are guaranted to contain floating point values of
801 same types.
803 @item gen_cvt_itof()
804 integer to floating point conversion.
806 @item gen_cvt_ftoi()
807 floating point to integer conversion.
809 @item gen_cvt_ftof()
810 floating point to floating point of different size conversion.
812 @item gen_bounded_ptr_add()
813 @item gen_bounded_ptr_deref()
814 are only used for bound checking.
816 @end table
818 @section Optimizations done
820 Constant propagation is done for all operations. Multiplications and
821 divisions are optimized to shifts when appropriate. Comparison
822 operators are optimized by maintaining a special cache for the
823 processor flags. &&, || and ! are optimized by maintaining a special
824 'jump target' value. No other jump optimization is currently performed
825 because it would require to store the code in a more abstract fashion.