
Detailed Overview of Memory Organization and Calling Conventions in Compiler Principles
Explore the intricate components of memory organization during procedural program execution, including code constants, stack management, and heap utilization. Dive into the nuances of calling conventions and public name mangling in the realm of compiler principles, understanding the critical role they play in function and procedure execution sequences.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Compiler principles Run-time support Jakub Yaghob
Run-time support Static language support Compiler Library interface Header files Dynamic language support Run-time program environment Storage organization Memory content before execution Constructors and destructors of global objects Libraries Calling convention
Memory organization Memory organization during procedural program execution Code Constants Code Initialized static data Static data Uninitialized static data Stack for thread 1 Stack Stack for thread n Heap Heap
Activation record Control link Activation record of the caller Access link Pointer to nonlocal data held in other activation records Saved machine status Return address to the code Registers Return value Actual parameters Control link Access link Saved machine status Local data Temporaries
Calling convention Calling convention Public name mangling Call/return sequence for functions and procedures Housekeeping responsibility Parameter passing Registers, stack Order of passed parameters Return value Registers, stacks Registers role Parameter passing, scratch, preserved
Public name mangling Real meaning mangle mandlovat rozsekat, roztrhat, rozb t, rozdrtit, t ce po kodit, potlouci, pohmo diti p en. pokazit, znetvo it, k nepozn n zm nit, p ekroutit, zkomolit Examples: long f1(int i, const char *m, struct s *p) MSVC IA-32 C __cdecl MSVC IA-32 C __fastcall MSVC IA-32 C __stdcall MSVC IA-32 C++ GCC IA-32 C GCC IA-32 C++ MSVC IA-64 C MSVC IA-64 C++ _f1 @f1@12 _f1@12 ?f1@@YAJHPBDPAUs@@@Z _f1 __Z2f1iPKcP1s f1 ?f1@@YAJHPEBDPEAUs@@@Z
Call/return sequence C Pascal Parameters, return value Caller s activation record Links, machine state Caller s responsibility Caller s responsibility Local and temporal data Parameters, return value Callee s activation record Callee s responsibility Links, machine state Callee s responsibility FP Local and temporal data
Access to semantically superior variables Pascal Nested functions Parameters NA RA Previous AR I Parameters NA RA procedure A; var I:integer; procedure B; var J:integer; procedure C; begin I+J end; begin if I>0 B else C; end; begin B end; Previous AR Link to A J Parameters NA RA Previous AR Link to A J Parameters NA RA Previous AR Link to A Link to B Variables NA
Parameter passing Call by value Actual parameter is evaluated and the value is passed Input parameters, the parameter is like a local variable C, non-VAR parameters in Pascal Call by reference The caller passes a pointer to the storage Input/output parameters & in C++, VAR parameters in Pascal Call by name Like a macro actual expression substituted at the point of use
Dynamic memory Allocation algorithms Continuous blocks of variable length Garbage collector Implicit deallocation Reference counting Markers Stop the program at some point of execution All pointers must be known including types All blocks marked as unused Go recursively through pointers and mark used blocks Unused blocks are removed Possible memory consolidation