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
Not Charles Fischer
Class home page:
What is a compiler? class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler Source code (e.g. C++) Target code (e.g. machine code)
class D : public C { public: int foo(std::string & s); }; int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); }; int D::foo(std::string & s) { return s.length(); } Compiler struct D { struct C; }; Int D__foo(std__string * s) { return std__string_length(s); } struct D { struct C; }; Int D__foo(std__string * s) { return std__string_length(s); } Source code (e.g. C++) Target code (e.g. C) What is a compiler?
class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler
class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler Source code (e.g. C++) Target code (e.g. machine code)
class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 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 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 Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo
class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler 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 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 Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo Runtime
class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(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 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 Output to stdout: M foo.txt ? bar.c Network traffic: Communication wi/ repo
class D : public C { public: int f( std::string&s); } class D : public C { public: int f( std::string&s); } Compiler class D : public C { public: int f( std::string&s); } class D : public C { public: int f( std::string&s); } 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); } 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 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); } 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 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); } 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 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); } 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 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); } class D : public C { public: int f( std::string&s); } Interpreter Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler Runtime
class D : public C { public: int f( std::string&s); } 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 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 class D : public C { public: int f( std::string&s); } class D : public C { public: int f( std::string&s); } Various input streams; files, network, command line args, system calls Various output methods: files, standard output, files, class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } class D : public C { public: int foo(std::string & s); } int D::foo(std::string & s) { return s.length(); } Compiler JIT Compiler Interpreter Compiler Runtime