/* MasC interpreter/compiler
(Master Assembly Script Container)
written by Jared Bruni
After reading Writing Compilers and Interpreters A approach using C++ by Ronald Mak
and the Dragon Book
code completly re-written but using concepts teached in this book
*/
// debug information implemntation file
#include "debug_info.h"
// get Reserved Byte code name as a string
char *getReservedCodeName(char code)
{
switch(code) {
case 99:
return "reserved code: Numeric value";
break;
case 100:
return "reserved code: String value";
break;
default:
return "Terminating Symbol";
}
return "";
}
// get Symbol code name as a string
char *getSymbolCodeName(enum var_type vcode)
{
switch(vcode) {
case tVAR_INT:
return "Integer";
case tVAR_FLOAT:
return "Floating point";
case tVAR_STR:
return "String";
case tVAR_LABEL:
return "Code Label";
case tVAR_NONE:
return "Void";
}
return "";
}
// print Debug information to html file
void printDebugInfo(char *debug_file, struct BackEnd *bend, struct Token *tokens)
{
FILE *f_ptr = fopen(debug_file, "w");
struct symNode *node_ptr = 0;
int i = 0;
if(!f_ptr) {
printf("File debug.html could not be opened for writing\n");
}
fprintf(f_ptr,"
Debug information for (%s) ", bend->obj_name);
fprintf(f_ptr, " Debug information for %s
", bend->obj_name);
fprintf(f_ptr, "
");
fprintf(f_ptr, " Intermediate Code
Byte Code | Symbols | String | Value | ");
while(tokens[i++].code != End) {
fprintf(f_ptr, "| %d | %s | %s | %f | ", tokens[i].code, tokens[i].code < getReservedLen() ? syntax_str[tokens[i].code] : getReservedCodeName(tokens[i].code),tokens[i].text != 0 ? tokens[i].text : "", (float)tokens[i].value == 0 ? 0 : (float)tokens[i].value );
}
fprintf(f_ptr, "
|---|
Symbol Table
");
fprintf(f_ptr, "| Entery ID | Variable Type | Numeric Value | String Value | ");
node_ptr = &bend->g_stable.root;
while(node_ptr != 0) {
fprintf(f_ptr, "
|---|
| %s | %s | %f | %s | ",node_ptr->str, getSymbolCodeName(node_ptr->vtype), (float)node_ptr->value, node_ptr->str_value);
node_ptr = node_ptr->next;
}
fprintf(f_ptr, "
|---|
");
fclose(f_ptr);
}
// spun 81 lines of code