1
00:00:02,280 --> 00:00:12,020
In this video we're going to begin our
discussion of run time systems. Now, at

2
00:00:12,020 --> 00:00:18,119
this point we have actually covered the
entire front end of the compiler which

3
00:00:18,119 --> 00:00:23,987
consists of the three phases, lexical
analysis, parsing and semantic analysis

4
00:00:23,987 --> 00:00:29,932
And these three passes or these three
phases together, their job is to really

5
00:00:29,932 --> 00:00:38,291
enforce the language semantics or the
language definition. So, we know. After

6
00:00:38,291 --> 00:00:42,789
these three phases are done that if no
errors have been generated by anyone of

7
00:00:42,789 --> 00:00:47,173
those phases then the program is actually
a valid program in the programming

8
00:00:47,173 --> 00:00:51,955
language that we're compiling And at this
point the compiler is going to be able to

9
00:00:51,955 --> 00:00:56,738
produce codes to produce a translation of
the program that you can actually execute.

10
00:00:56,738 --> 00:01:01,375
And I should say that of course. Enforcing
the language after the [inaudible] one

11
00:01:01,375 --> 00:01:05,971
purpose of the front-end. The front-end
also builds the data structures that are

12
00:01:05,971 --> 00:01:10,682
needed to do co-generation as we seen but
there is a real. Once we get through the

13
00:01:10,682 --> 00:01:15,450
front-end we no longer looking for errors
in the program. We're no longer trying to

14
00:01:15,450 --> 00:01:20,103
figure out whether it's a valid program.
Now we're really down to the point where

15
00:01:20,103 --> 00:01:25,195
we're going to generate code And that is a
job at the back end. So cogeneration is

16
00:01:25,195 --> 00:01:30,457
certainly part of it. The other big part
of the back end is program optimization so

17
00:01:30,457 --> 00:01:35,277
doing transformations to improve the
program. But before we can talk about

18
00:01:35,277 --> 00:01:40,859
either one of those things, we need to
talk about Runtime organization And why is

19
00:01:40,859 --> 00:01:45,532
that, well because we need to understand
what it is we're trying to generate before

20
00:01:45,532 --> 00:01:49,811
we can talk about how we generated and
have that makes sense. So first, we're

21
00:01:49,811 --> 00:01:54,652
gonna talk about what the, the translator
program looks like and how it's organized

22
00:01:54,652 --> 00:01:59,269
and then we'll talk about algorithms and
code generation algorithms were actually

23
00:01:59,269 --> 00:02:03,773
producing those things. And this is a
well-understood area or at least some very

24
00:02:03,773 --> 00:02:08,446
standard techniques that are widely used
and those are the ones we wanted to cover

25
00:02:08,446 --> 00:02:15,323
and, and encourage you to use in your
project. The main thing we're going to

26
00:02:15,323 --> 00:02:20,334
cover in this sequence of videos is the
management of Runtime resources and in

27
00:02:20,334 --> 00:02:25,663
particular I'm going to be stressing the
correspondence and the distinction between

28
00:02:25,663 --> 00:02:30,484
static and dynamic structures. So static
structures are things that exist to

29
00:02:30,484 --> 00:02:35,622
compile time and dynamic structures, those
are the things that exist or happen at

30
00:02:35,622 --> 00:02:40,868
Runtime And, this is probably the most
important distinction for you to try to

31
00:02:40,868 --> 00:02:45,606
understand if you really want to
understand how a compiler works. What

32
00:02:45,606 --> 00:02:50,279
happens to the compile time and what
happens at run time. Having a clear

33
00:02:50,279 --> 00:02:55,601
separation in your mind between what is
done by the compiler and what is deferred

34
00:02:55,601 --> 00:03:00,599
to when the target program or the
generated program actually runs that is

35
00:03:00,599 --> 00:03:05,820
key to really understanding how compilers
work. And we'll also be talking about

36
00:03:05,820 --> 00:03:11,179
storage organization. So how memory is
used to store the data structures of the

37
00:03:11,179 --> 00:03:17,555
executing program. So let's begin at the
beginning. So initially there is the

38
00:03:17,555 --> 00:03:22,638
operating system and the operating system
is the only thing that is running on the

39
00:03:22,638 --> 00:03:27,660
machine and when a program is invoke. When
the user says he wants to run a program,

40
00:03:27,660 --> 00:03:32,743
what happens while the operating system is
going to allocate space for the program

41
00:03:32,927 --> 00:03:37,581
the code for the program is going to be
loaded into that space and then the

42
00:03:37,581 --> 00:03:42,848
operating system is going to execute a job
to the entry point or the main function of

43
00:03:42,848 --> 00:03:49,125
the program and then your program will be
off and running. So, let's take a look at

44
00:03:49,125 --> 00:03:54,747
what the organization memory looks like
very roughly when the Operating System

45
00:03:54,747 --> 00:04:00,155
began execution of the compiled program.
So we're gonna draw our pictures of memory

46
00:04:00,155 --> 00:04:05,362
like this. That would be just a big block
and there will be a starting address at

47
00:04:05,362 --> 00:04:10,073
the, a lower address and a higher address
and this is all the memory that is

48
00:04:10,073 --> 00:04:15,218
allocated to your program. Now into some
portion of that space goes to code for the

49
00:04:15,218 --> 00:04:20,238
program so the actual compiled code for
the program is loaded usually at one end

50
00:04:20,238 --> 00:04:24,832
of the memory space allocated to the
program. And then there is a bunch. Of

51
00:04:24,832 --> 00:04:30,343
other space that is going to be used for
other things and we'll talk about that in

52
00:04:30,343 --> 00:04:37,031
a minute. Before going on, I want to say a
few words about this pictures of Run-time

53
00:04:37,031 --> 00:04:41,558
Organization because I'm going to be
drawing a lot of them over the next few

54
00:04:41,558 --> 00:04:46,498
videos. So, it's just traditional to have
memory drawn as a rectangle with the low

55
00:04:46,498 --> 00:04:51,496
address at the top and the high address at
the bottom. There's nothing magic about

56
00:04:51,496 --> 00:04:56,023
that, just a convention we could adjust it
easily every verse or order of the

57
00:04:56,023 --> 00:05:00,928
address, no big deal. And then we'll be
drawing lines to the limit different

58
00:05:00,928 --> 00:05:06,420
regions of this memory showing different
kinds of data and how they're stored in

59
00:05:06,420 --> 00:05:12,047
the memory allocated to the program. And
clearly these pictures are simplifications

60
00:05:12,047 --> 00:05:17,403
if this, is a virtual memory system for
example, there's no guarantee that these

61
00:05:17,403 --> 00:05:23,301
data is actually laid out contiguously but
it helps to understand you know, what the

62
00:05:23,301 --> 00:05:29,732
different kinds of data are. And what the,
a compiler needs to do with them to have

63
00:05:29,732 --> 00:05:36,362
simple pictures like this. So coming back
to our picture of run time organization,

64
00:05:36,362 --> 00:05:41,315
we have some block memory and the first
portion of that is occupied by the actual

65
00:05:41,315 --> 00:05:46,269
generated code for the program and then
there was this other space and we're what

66
00:05:46,269 --> 00:05:51,563
goes to that space? Well, what goes to
that space is the data for the program. So

67
00:05:51,563 --> 00:05:56,711
all the data is in the rest of the space
and the tricky thing about code generation

68
00:05:56,711 --> 00:06:01,063
that the compiler is responsible for
generating the code but it's also

69
00:06:01,063 --> 00:06:06,272
responsible for orchestrating the data. So
the compiler has to decide what the lay of

70
00:06:06,272 --> 00:06:11,420
the data is going to be and then generate
code that correctly manipulates that data

71
00:06:11,420 --> 00:06:16,439
so there are references of course in the
code. To the data and the code and data

72
00:06:16,439 --> 00:06:21,421
need to be designed, the code and the
layout of the data, excuse me, need to be

73
00:06:21,421 --> 00:06:26,496
designed together so that the generated
program will function correctly. Now, it

74
00:06:26,496 --> 00:06:31,547
turns out that this actually more than one
kind of data that the compiler is going to

75
00:06:31,547 --> 00:06:36,497
be interested in and what we'll be talking
about. In the next video is the different

76
00:06:36,497 --> 00:06:40,862
kinds of data and the different
distinction between the kinds of data tha

77
00:06:40,862 --> 00:06:42,260
t go in this data carrier.
