Transcript PPTX

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:
http://cs.wisc.edu/~cs536-1/
What is a compiler?
class D : public C
{
public:
int foo(std::string & s);
}
int D::foo(std::string & s)
{
return s.length();
}
Source code
(e.g. C++)
Compiler
10110101010101110000110
10101001010101010111010
10010110101010010010011
10001010101010101010111
01010101011010101010111
00001101010100101010101
01110101001011010101001
00100111000101010101010
10101110101010101101010
10101110000110101010010
10101010111010100101101
01010010010011100010101
Target code
(e.g. machine code)
What is a compiler?
class D : public C
{
public:
int foo(std::string & s);
};
int D::foo(std::string & s)
{
return s.length();
}
Source code
(e.g. C++)
struct D
{
struct C;
};
Compiler
Int D__foo(std__string * s)
{
return
std__string_length(s);
}
Target code
(e.g. C)
class D : public C
{
public:
int foo(std::string & s);
}
int D::foo(std::string & s)
{
return s.length();
}
Compiler
10110101010101110000110
10101001010101010111010
10010110101010010010011
10001010101010101010111
01010101011010101010111
00001101010100101010101
01110101001011010101001
00100111000101010101010
10101110101010101101010
10101110000110101010010
10101010111010100101101
01010010010011100010101
class D : public C
{
public:
int foo(std::string & s);
}
int D::foo(std::string & s)
{
return s.length();
}
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
Compiler
10110101010101110000110
10101001010101010111010
10010110101010010010011
10001010101010101010111
01010101011010101010111
00001101010100101010101
01110101001011010101001
00100111000101010101010
10101110101010101101010
10101110000110101010010
10101010111010100101101
01010010010011100010101
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();
}
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
Compiler
Runtime
10110101010101110000110
10101001010101010111010
10010110101010010010011
10001010101010101010111
01010101011010101010111
00001101010100101010101
01110101001011010101001
00100111000101010101010
10101110101010101101010
10101110000110101010010
10101010111010100101101
01010010010011100010101
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();
}
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
Various input
streams; files,
network, command
line args, system
calls
Interpreter
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
Virtual
Machine
Various output
methods: files,
standard output,
files,
class D : public C
{
public:
int f(
std::string&s);
}
push 5
push
add
push z
multi
call bar
Various input
streams; files,
network, command
line args, system
calls
Compiler
push 5
push
add
push z
multi
call bar
Control
Bytecode
Interpreter
JIT Compiler
Various output
methods: files,
standard output,
files,
class D : public C
{
public:
int foo(std::string & s);
}
1011010101010111000011010101
0010101010101110101001011010
1010010010011100010101010101
0101011101010101011010101010
1110000110101010010101010101
1101010010110101010010010011
1000101010101010101011101010
1010110101010101110000110101
0100101010101011101010010110
101010010010011100010101
Runtime
Compiler
int D::foo(std::string & s)
{
return s.length();
}
class D : public C
{
public:
int f(
std::string&s);
}
class D : public
C
{
public:
int f(
Compiler
push 5
push
add
push z
multi
call bar
std::string&s);
}
Various input
streams; files,
network,
command line
args, system
calls
Interpreter
Various output
methods: files,
standard
output, files,
push 5
push
add
push z
multi
call bar
Various input
streams; files,
network, command
line args, system
calls
Control
Bytecode
Interpreter
JIT
Compiler
Various output
methods: files,
standard output,
files,
class D : public C
{
public:
int foo(std::string & s);
}
1011010101010111000011010101
0010101010101110101001011010
1010010010011100010101010101
0101011101010101011010101010
1110000110101010010101010101
1101010010110101010010010011
1000101010101010101011101010
1010110101010101110000110101
0100101010101011101010010110
101010010010011100010101
Runtime
Compiler
int D::foo(std::string & s)
{
return s.length();
}
class D : public C
{
public:
int f(
std::string&s);
}
class D : public
C
{
public:
int f(
Compiler
push 5
push
add
push z
multi
call bar
std::string&s);
}
Various input
streams; files,
network,
command line
args, system
calls
Interpreter
Various output
methods: files,
standard
output, files,
push 5
push
add
push z
multi
call bar
Various input
streams; files,
network, command
line args, system
calls
Control
Bytecode
Interpreter
JIT
Compiler
Various output
methods: files,
standard output,
files,