180 likes | 390 Views
CS 536. Intro to Programming Languages and Compliers Spring 2009 Evan Driscoll. “. Introduction to the theory and practice of compiler design. Comparison of features of several programming languages and their implications for implementation techniques. Several programming projects required.
E N D
CS 536 Intro to Programming Languages and Compliers Spring 2009 Evan Driscoll
“ Introduction to the theory and practice of compiler design. Comparison of features of several programming languages and their implications for implementation techniques. Several programming projects required. ”
CS 536 Intro to Programming Languages and Compliers Spring 2009 Evan Driscoll
CS 536 Introduction to Compiler Construction Spring 2009 Evan Driscoll
What is a compiler? class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101 Source code (e.g. C++) Target code (e.g. machine code)
What is a compiler? class D : public C { public: intfoo(std::string & s); }; int D::foo(std::string & s) { return s.length(); } Compiler struct D { struct C; }; IntD__foo(std__string * s) { return std__string_length(s); } Source code (e.g. C++) Target code (e.g. C)
class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101
class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101 Command line args: ‘svn’, ‘stat’, ‘-u’ Results of system calls: readdir . -> foo.txt, bar.c stat foo.txt stat bar.c stat .svn/foo.txt stat .svn/bar.txt Results of network traffic: Communication w/ repo Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo
class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101 Command line args: ‘svn’, ‘stat’, ‘-u’ Results of system calls: readdir . -> foo.txt, bar.c stat foo.txt stat bar.c stat .svn/foo.txt stat .svn/bar.txt Results of network traffic: Communication w/ repo Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo Runtime
class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Interpreter Command line args: ‘svn’, ‘stat’, ‘-u’ Results of system calls: readdir . -> foo.txt, bar.c stat foo.txt stat bar.c stat .svn/foo.txt stat .svn/bar.txt Results of network traffic: Communication w/ repo Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo
class D : public C { public: int f( std::string&s); } Compiler push 5 push add push z multi call bar push 5 push add push z multi call bar Interpreter Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files,
class D : public C { public: int f( std::string&s); } Compiler push 5 push add push z multi call bar push 5 push add push z multi call bar Virtual Machine Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files,
class D : public C { public: int f( std::string&s); } Compiler push 5 push add push z multi call bar push 5 push add push z multi call bar Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, Control Bytecode Interpreter JIT Compiler
class D : public C { public: int f( std::string&s); } Compiler push 5 push add push z multi call bar push 5 push add push z multi call bar Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101 Runtime Interpreter Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler class D : public C { public: int f( std::string&s); } Control Bytecode Interpreter JIT Compiler
class D : public C { public: int f( std::string&s); } Runtime class D : public C { public: int f( std::string&s); } push 5 push add push z multi call bar push 5 push add push z multi call bar Various input streams; files, network, command line args, system calls Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, Various output methods: files, standard output, files, class D : public C { public: intfoo(std::string & s); } int D::foo(std::string & s) { return s.length(); } 101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101010101010101110101010101101010101011100001101010100101010101011101010010110101010010010011100010101 Compiler Interpreter Compiler Control Bytecode Interpreter JIT Compiler