Hello and welcome.
And in this lecture, we're going to start creating our fix up functionality.
So this functionality we will create today will basically be an abstraction that different parts of
our compiler can use that will resolve fix ups.
So what we're going to do, we're going to create a new file called Fix Up C.
Now, just in here, we're going to include compiler dot hatch and we're going to define a structure
for fix up.
We will be moving all of this stuff in the header file when we're done.
So we're just going to say init flags struct fix up system which we haven't defined yet, struct fix
up config so as to find the fix up system.
And it's just going to contain a vector essentially.
And we're just going to call the vector fix ups and this will be a vector of fix ups.
Now we're going to define fix up config.
Okay.
So just above the config, let's do struct fix up.
We're going to forward declare the fix of structure and we're going to have a type def ball fix up fix.
So this is a function pointer struct fix up.
So this function pointer will be responsible for fixing a fix up and we're going to create another one
called Fix Up End
and this one should return a void, guys.
So anyone who implements this function should return.
True, if the fix up was successful.
So we can right there fixes the fix up here.
This one signifies the fix up has been removed from memory.
The receiver now the implementer of this function
should free any memory related to the fix up.
Okay, nice.
So that's where those two functions are for.
So we're going to say fix up fix and our fix up config and we're going to call that fix fix up and I'm
going to call that end.
So anyone implementing a fix of configuration will need to specify a fix function pointer to their fix
of fix function and an and pointer to their fix of end function.
This abstraction allows complete flexibility, which is why we're running our code this way.
And we also need a void pointer called Private.
This will contain private data.
We'll talk more on that later.
So just above our fix that we're going to create an enum fix up flag resolved equals 0b1234, one,
two, three, four and knock off the last zero input of one.
So seven zeros and a one.
So if this flag is present in the fix of flags, then this fix up has been resolved.
Okay, that's perfect.
So let's start with our creation of the fix subsystem.
So we're going to create a function now struct fix up system, fix up sis new.
So this will create a new fix up system.
So we're first going to allocate allocate the fix up system and we need to implement calc as well.
So just scroll up.
So we're going to say size of struct.
Fix up system.
We're just going to put a one by there.
All right.
Nice.
So, yeah, include ad lib to get that car lock function guys as I did there OC.
So now we're going to define the fix up.
So we're going to say fix ups equals vector create and we need to include the vector as well.
Guys
include vector vector create and we're going to say size of struct fix up.
So this is a vector effect, subs not fixed, a pointers fix ups.
Finally, we're just going to return the system.
So now we're going to say struct fix up config fix up, config struct fix up and we're just going to
say return ampersand and fix up config.
So I return the configuration for a fix up.
Now we're going to say void fix up free struct, fix up, fix up and we're going to say fix up config
and fix up.
So that gives the implementer of this fix up to be able to free its data.
Right?
Because we call the actual end function pointer that's been implemented and then we're just going to
say free fix up.
So now we're going to create the function that cleans up the actual fix subsystem system.
So we're going to say void fix up system, fix ups free.
So yeah, it won't click, it won't clean up the fix up system, it will clean up all the fix ups basically
guys.
And before we can implement this, we need to implement one more function VI fix up start iteration
and that's going to set the P pointer
of the fix ups to zero.
So we're going to say in here fix up start iteration system, we're going to say struck fix up fix up
equals fix.
Up next, which you haven't yet implemented, we're going implement that now.
Okay.
So fix up next is just going to go over to vector big pointer system fix ups.
So now we're going to say, well, fix up, fix up free fix up fix up equals fix.
Up next, we're going to pass in the system.
So that's our fix ups, free function, which basically frees all the memory of all the fix ups in our
fix up system.
So now we're going to say VI, fix up system free.
This free is the actual fix subsystem.
Okay.
So that's going to call fix up system fix ups free on the system.
It's going to free the vector and it's going to free the system, provide it perfect.
So now we need a function that counts all the unresolved fix ups.
So we're going to say init it fix up system unresolved fix ups count
now we're going to go size t see if count equals zero fix up start iteration.
Struck fix up fix up equals fix.
Up next
wall fix up fix up equals fix up next system.
So this is like an iteration.
If fix up flags and some fix up flag resolved, then ignore it.
So fix up equals fix up next system and then we're going to continue.
Otherwise C++ and we're just going to return to C.
So now we're going to take create a fix up register function which will register a fix that basically.
So this will take a fix up system and it will take a fix up config.
So we're going to allocate the fix up.
We're going to copy the configuration memory into the fix up configuration
because we obviously want to copy in case this pointer gets freed or something.
Right?
Then we're going to say fix up system equals system and we're going to push it to the to the vector,
essentially.
And I know we've done an ampersand here.
Go to the ampersand because we want to store the actual.
Uh, the actual fix of memory, not a fixed pointer.
Okay, so just passing the fix up without the ampersand, and then we're going to return fix up.
So now we're going to say ball fix up, resolve struck, fix up, fix up.
So this resolves the fix up.
So we say fix up config, fix up, fix, fix up.
So if it returns true, then we're going to on the flag fix up resolved and then we're going to return.
True.
Otherwise, we're going to return false because we failed to fix it because the fix function returned
false.
Right.
So now we're going to say void pointer, fix a private.
So this returns the private data of the fix up
from the actual fix config, I should say.
Finally, we're going to create that fix ups resolve function that I discussed in the presentation.
Subsets of fix up system.
Fix up starter duration struct fix up fix up equals fix up next while fix up
fix up equals fix up next system.
So if it's resolved already,
then we're just going to continue because it's already been resolved, right?
But if it's not resolved, we're going to call fix it resolve on that fix up and then we're going to
return fix up sis unresolved fix ups count system and we're going to check this equal to zero.
So if it's equal to zero, then that means we successfully resolved all fix ups.
If one of these fixable results fails, then obviously the count will never reach zero.
So this resolve function will fail and return false, which will mean that there was an error.
We're trying to fix one of the fix ups.
Okay, let's put this in the Makefile and see if it works.
So we're just going to go build, fix up, fix support c tab gcc fix of dot c
includes oh build fix up dot old, that's g dash C.
So I'm going to scroll up and we're going to.
Put it after the sim resolver.
And there we go.
Make clean.
Make.
No such file.
So back to fix.
See, it's going to be helpers.
Vector dots.
Try that again.
See that compiles now without issue.
So the final thing to do, we're going to copy and paste all the header information we made in this
source file.
In fact, we're going to copy and paste everything
and we're going to go to compiler page.
And we're just going to paste it in the bottom here.
I just get rid of all these function bodies because we only care about the prototypes, right?
You.
Okay.
And there we go.
So we have all of our fix up functionality created.
So now in the next lecture, we'll be able to create a subsystem of this fix up for our parser.
So we'll implement these fix and end functions in our paths dot C file and we'll be able to create some
fix ups.
Thanks for watching.