Porting picoc to xv6 xv6-picoc

4.1 Porting Picoc to xv6


4.1.1 New functions added to port Picoc to xv6


Once Picoc is invoked it reads an input file through FILE structure mechanism. This function of reading original source file is done by PicocPlatformReadFile(). Similarly to generate intermediate files or final output file it makes an extensive use of functions such as fprintf(), sprintf(), fputs().As it makes use of these functions such as fopen(), fread(), fclose() we have implemented these functions in current xv6 library. As mentioned above Picoc can handle the various data types such as INT,FLOAT,CHAR * etc. So to perform arithmetic operations on data types such as float and double it needs to make use of complex exponential operations. For example, while printing float datatype to standard output it calls PrintFP() which uses two mathematical functions Pow() and exp(). Hence these two functions are also ported to current version of Xv6. Their implementations are borrowed from dietlibc.

4.1.2 Library of Picoc


Considering the general work flow of Picoc as explained in chapter 3. For providing ap- propriate environment to Picoc we have provided complementing sets of library functions whose wrappers are supported by Picoc during run time. In picoc currently we have just provided limited API that includes following functions:
1.printf
2.scanf
3.getchar
4.putchar
5.strcmp
6.strlen
along with the support to standard data types such as int,double,float,char etc. When an instance of picoc is running it shows output at different stages of interpretation like symbol table generation, tokenization and library call wrappers. The main reason to limit the library API to such small scale so that it will create a scope for students to understand the current structure and add further functionality into it.

4.2 Standard library in C


The current version of xv6 uses a static library. All of the library functions are made part of kernel. It doesn’t make use of library archives. If an application wants make use of these library routines then it has to be built by using a shell script given in Appendix B. There are two options while adding these definitions in current library. First is to implement these functions by own or second one is to use some already existing POSIX standard library. Here in this case we have used a library named dietlibc. List of functions that are ported to current library of xv6 which are borrowed from dietlibc can be found Appendix A.