⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pass2.c

📁 类PASCAL语言的编译器,LINUX环境的,我没试过是否正确.
💻 C
📖 第 1 页 / 共 4 页
字号:
/************************************************************************ *			 FREXX PROGRAMMING LANGUAGE			      * ************************************************************************ Pass2.c Compiling functions ************************************************************************//************************************************************************ *                                                                      * * fpl.library - A shared library interpreting script langauge.         * * Copyright (C) 1992-1995 FrexxWare                                    * * Author: Daniel Stenberg                                              * *                                                                      * * This program is free software; you may redistribute for non          * * commercial purposes only. Commercial programs must have a written    * * permission from the author to use FPL. FPL is *NOT* public domain!   * * Any provided source code is only for reference and for assurance     * * that users should be able to compile FPL on any operating system     * * he/she wants to use it in!                                           * *                                                                      * * You may not change, resource, patch files or in any way reverse      * * engineer anything in the FPL package.                                * *                                                                      * * This program is distributed in the hope that it will be useful,      * * but WITHOUT ANY WARRANTY; without even the implied warranty of       * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                 * *                                                                      * * Daniel Stenberg                                                      * * Ankdammsgatan 36, 4tr                                                * * S-171 43 Solna                                                       * * Sweden                                                               * *                                                                      * * FidoNet 2:201/328    email:dast@sth.frontec.se                       * *                                                                      * ************************************************************************/#ifdef AMIGA#include <exec/types.h>#include <proto/exec.h>#include <libraries/dos.h>#include <proto/dos.h>#include <exec/libraries.h>#include <dos.h>#elif defined(UNIX)#include <sys/types.h>#include <sys/stat.h>#endif#include <stdlib.h>#include <stdio.h>#include <string.h>#include <stddef.h>#include "script.h"#include "optimize.h"#include "pass2.h"extern struct Pass1Data first_data;struct Pass2Data pass2_first_data;struct Pass2Data pass2_current_data;struct Pass2Data main_declare_link_first, function_declare_link_first, function_contain_link_first;struct Pass2Data *main_declare_link=&main_declare_link_first;struct Pass2Data *function_declare_link=&function_declare_link_first;struct Pass2Data *function_contain_link=&function_contain_link_first;struct Pass2Data *function_start;static ReturnCode HandleReference(struct Data *scr, struct Pass1Data **p1datapek, struct Pass2Data **pass2_list);static ReturnCode HandleFunctionCall(struct Data *scr, struct Pass1Data **p1datapek, struct Pass2Data **pass2_list);static ReturnCode ExamineLevel(struct Data *scr, struct Pass1Data **p1datapek, struct Pass2Data **pass2_list);long level=0;long mainlevel=0;long labelcount=0;long total_number_of_variables=0;long total_number_of_functions=0;long max_level=0;long main_label_number;#ifdef DEBUG_OUTPUTstatic void Describe(struct Data *scr, struct Pass2Data *data){  char *s[]={  "NOTHING",  "DECLARE",  "REF_LOCAL_SYMBOL",  "REF_GLOBAL_SYMBOL",  "REF_EXPORT_SYMBOL",  "POSTINC",  "POSTDEC",  "PREINC",  "PREDEC",  "CONTENTSOF",  "NUM_CONSTANT",  "STRING_CONSTANT",  "OPEN_PAREN",  "CLOSE_PAREN",  "ONCECOMPLEMENT",  "NOTOPERATOR",  "NEGATE",  "COMMA",  "NOTEQUAL",  "GREATER",  "SHIFTRIGHT",  "GREATEQ",  "LESS",  "SHIFTLEFT",  "LESSEQ",  "XOR",  "REMAIN",  "DIVISION",  "MULTIPLY",  "CONDOPEND",  "CONDOPSTART",  "MINUS",  "PLUS",  "BINARYOR",  "BINARYAND",  "LOGICOR",  "LOGICAND",  "EQUAL",  "STRING_APPEND",  "END_OF_EXPR",  "ASSIGN_LOCAL_SYMBOL",  /* [var num] [assign type] */  "ASSIGN_GLOBAL_SYMBOL",  /* [var num] [assign type] */  "ASSIGN_EXPORT_SYMBOL", /* [hash num] [assign type] [name] */  "LABEL_GOTO",	/* [number] */  "IFNOT_BRANCH",	/* if branch */  "IF_BRANCH",	/* if branch */  "CALL_LOCAL_FUNCTION",  "CALL_EXPORT_FUNCTION",  "CALL_INTERNAL_FUNCTION",  "SWITCH",  "CASE",	/* [label number] */  "BREAK_EXPR", /* Followed by an expression and several GOTO_BREAK and END_OF_EXPR */  "RETURN",  "RESIZE",  "OPEN_BRACKET",  "CLOSE_BRACKET",  "ASSIGN_ARGUMENT", /* [var number], [arg number] */  "EXPORT_FUNCTION", /* [type], [number], [offset] */  "RESET_VARIABLE", /* [number] */  "OPEN_BRACE",  "CLOSE_BRACE",  "EXIT", /* expression */  "VARIABLE_REFERENCE",  "TYPE_OF_ARGUMENTS", /* [string] */  "JUMP_OVER_ELSE",	/* jump over olse */  "MAIN_START",  "MAIN_END",  "IFNOT_BRANCH_BREAK",/* if not branch to break */  "IFNOT_BRANCH_ELSE",/* if not branch to else */  "LOCAL_FUNCTION", /* [type], [number], [offset] */  "LABEL",  "LABEL_BEGIN",	/* [number] */  "LABEL_CONTINUE",	/* [level] */  "LABEL_BREAK",	/* [level] */  "GOTO_BEGIN",	/* [number] */  "GOTO_BREAK",	/* [level] */  "LABEL_ELSE",		/* else [number]*/  "END_OF_ELSE",	/* else [number]*/  "FUNCTION_START", /* [function/var number] */  "CONTINUE", /* level */  "AMOUNT_VARIABLES",  "END_OF_FUNCTION",  "LINE_NUMBER",  };  if (scr->cmdline[LINE_VERBOSE]&VERBOSE_PASS2) {    if(data->code>sizeof(s)/sizeof(char *))      printf("UNKNOWN\n");    else {      printf("%1d %2d %-20s", data->final_size, data->level, s[data->code]);      if (data->flags&P2D_FLAG_NUM0)        printf(" [%08x]", data->num[0]);      if (data->flags&P2D_FLAG_NUM1)        printf(" [%08x]", data->num[1]);      if (data->flags&P2D_FLAG_NUM2)        printf(" [%08x]", data->num[2]);      if (data->flags&P2D_FLAG_STRING) {        printf(" [%.*s] (%d)", data->strlen[0], data->string[0], data->strlen[0]);      }      if (data->flags&P2D_FLAG_STRING2) {        printf(" [%.*s] (%d)", data->strlen[1], data->string[1], data->strlen[1]);      }      printf("\n");    }  }}#endifReturnCode Pass2PutOpen(struct Data *scr, char *file){#ifdef DEBUG_OUTPUT  if (scr->cmdline[LINE_VERBOSE]&VERBOSE_PASS2)    printf("\n-------------------------------\nPASS2 START\n-------------------------------\n");#endif  return FPL_OK;}ReturnCode Pass2PushPut(struct Data *scr, struct Pass2Data **link){  ReturnCode ret;  struct Pass2Data *new;  if (pass2_current_data.code!=PASS2_NOTHING) {    long size=sizeof(struct Pass2Data);    if (!pass2_current_data.flags)      size=offsetof(struct Pass2Data, num);  /* OBS: The structure is allocated shorter now */    GETMEM(new, size);    memcpy(new, &pass2_current_data, size);    if (*link) {      new->next=(*link)->next;      (*link)->next=new;    } else      (*link)=new;#ifdef DEBUG_OUTPUT    Describe(scr, &pass2_current_data);#endif    pass2_current_data.flags=0;    pass2_current_data.code=PASS2_NOTHING;    *link=new;  }  return FPL_OK;}ReturnCode Pass2Link(struct Data *scr, struct Pass2Data **link, struct Pass2Data *new){  ReturnCode ret;  struct Pass2Data *last=NULL;  if (*link)    last=(*link)->next;  if (new) {    if (*link) {      (*link)->next=new;      while (new->next)        new=new->next;      new->next=last;    }    *link=new;  }  return FPL_OK;}  void Pass2PutClose(struct Data *scr){  struct Pass2Data *count;  count=&pass2_first_data;#ifdef DEBUG_OUTPUT  if (scr->cmdline[LINE_VERBOSE]&VERBOSE_PASS2) {    printf("\nRESULT\n");    while (count=count->next) {      Describe(scr, count);    }  }#endif}  ReturnCode Pass2Put(struct Data *scr, Pass2 code, struct Pass1Data *pass1_reference, struct Pass2Data **pass2_list, char size){  ReturnCode ret;  if (pass1_reference) {    pass2_current_data.line=pass1_reference->line;    pass2_current_data.row=pass1_reference->row;  }  pass2_current_data.code=code;  pass2_current_data.level=level;  pass2_current_data.final_size=size;  if (pass2_current_data.code!=PASS2_NOTHING) {    CALL(Pass2PushPut(scr, pass2_list));  }  pass2_current_data.code=PASS2_NOTHING;  pass2_current_data.level=0;  pass2_current_data.line=0;  pass2_current_data.row=0;  pass2_current_data.next=NULL;  return FPL_OK;}  ReturnCode Pass2PutArg(struct Data *scr, long arg){  ReturnCode ret;  if (!(pass2_current_data.flags&P2D_FLAG_NUM0)) {    pass2_current_data.num[0]=arg;    pass2_current_data.flags|=P2D_FLAG_NUM0;  } else if (!(pass2_current_data.flags&P2D_FLAG_NUM1)) {    pass2_current_data.num[1]=arg;    pass2_current_data.flags|=P2D_FLAG_NUM1;  } else if (!(pass2_current_data.flags&P2D_FLAG_NUM2)) {    pass2_current_data.num[2]=arg;    pass2_current_data.flags|=P2D_FLAG_NUM2;  }  return FPL_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -