Skip to content

Commit

Permalink
-std=c89
Browse files Browse the repository at this point in the history
  • Loading branch information
sheisc committed Feb 10, 2023
1 parent fec5aa2 commit 10658ca
Show file tree
Hide file tree
Showing 66 changed files with 1,320 additions and 1,130 deletions.
2 changes: 1 addition & 1 deletion ucc/driver/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
char *CPPProg[] =
{
"/usr/bin/gcc", "-m32", "-U__GNUC__", "-D_POSIX_SOURCE", "-D__STRICT_ANSI__",
"/usr/bin/gcc", "-m32", "-std=c89", "-U__GNUC__", "-D_POSIX_SOURCE", "-D__STRICT_ANSI__",
"-Dunix", "-Di386", "-Dlinux", "-D__unix__", "-D__i386__", "-D__linux__",
"-D__signed__=signed", "-D_UCC", "-I" UCCDIR "include", "$1", "-E", "$2", "-o", "$3", 0
};
Expand Down
16 changes: 8 additions & 8 deletions ucc/driver/ucc.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ char** BuildCommand(char *cmd[], List flags, List infiles, List outfiles)
int i, j;
List lists[3];
List p;
// $1
/* $1 */
lists[0] = flags;
// $2
/* $2 */
lists[1] = infiles;
// $3
/* $3 */
lists[2] = outfiles;
for (i = j = 0; cmd[i] != NULL; i++)
{
Expand Down Expand Up @@ -222,7 +222,7 @@ static int GetFileType(char *filename)
static void AddFile(char *filename)
{
int type = GetFileType(filename);
// 4 R_OK ,2 W_OK ,1 X_OK
/* 4 R_OK ,2 W_OK ,1 X_OK */
if (access(filename, 4) != 0)
{
fprintf(stderr, "No such file: %s\n", filename);
Expand Down Expand Up @@ -378,13 +378,13 @@ int InvokeProgram(int oftype)

for (p = Option.aflags, Option.aflags = NULL; p != NULL; p = p->next)
{
// see "-Wa," strlen("-Wa,") is 4 ,ParseCmdLine()
/* see "-Wa," strlen("-Wa,") is 4 ,ParseCmdLine() */
Option.aflags = ListCombine(Option.aflags, ParseOption(p->str + 4));
}
for (p = Option.pfiles; p != NULL; p = p->next)
{
if(Option.out && Option.oftype == ASM_FILE){
//PRINT_DEBUG_INFO(("Option.out = %s\n",Option.out));
/* PRINT_DEBUG_INFO(("Option.out = %s\n",Option.out)); */
ofname = Option.out;
}else{
ofname = FileName(p->str, DEF_ASM_EXT);
Expand Down Expand Up @@ -428,7 +428,7 @@ int InvokeProgram(int oftype)
}
for (p = Option.lflags, Option.lflags = NULL; p != NULL; p = p->next)
{
// see "-Wl," strlen("-Wl,") is 4 ,ParseCmdLine()
/* see "-Wl," strlen("-Wl,") is 4 ,ParseCmdLine() */
Option.lflags = ListCombine(Option.lflags, ParseOption(p->str + 4));
}

Expand All @@ -451,7 +451,7 @@ static int ParseCmdLine(int argc, char *argv[])

for (i = 0; i < argc; ++i)
{
//PRINT_DEBUG_INFO(("%s",argv[i]));
/* PRINT_DEBUG_INFO(("%s",argv[i])); */
if (strcmp(argv[i], "--dump-ast") == 0 ||
strcmp(argv[i], "--dump-IR") == 0)
{
Expand Down
28 changes: 14 additions & 14 deletions ucc/driver/ucc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ typedef struct list

struct option
{
List pflags; // flags for preprocessor
List cflags; // flags for compiler
List aflags; // flags for assembler
List lflags; // flags for linker
List cfiles; //.c
List pfiles; //.i
List afiles; //.s
List ofiles; //.obj
List lfiles; //.a .lib
List linput; //input for linker
List pflags; /* flags for preprocessor */
List cflags; /* flags for compiler */
List aflags; /* flags for assembler */
List lflags; /* flags for linker */
List cfiles; /* .c */
List pfiles; /* .i */
List afiles; /* .s */
List ofiles; /* .obj */
List lfiles; /* .a .lib */
List linput; /* input for linker */
int verbose;
int oftype; //output file type
int oftype; /* output file type */
char *out;
};

Expand All @@ -38,9 +38,9 @@ void SetupToolChain(void);
int InvokeProgram(int oftype);

extern char* ExtNames[];
extern List PPFiles; //*.i
extern List ASMFiles; //*.s
extern List OBJFiles; //*.obj
extern List PPFiles; /* *.i */
extern List ASMFiles; /* *.s */
extern List OBJFiles; /* *.obj */
extern struct option Option;


Expand Down
2 changes: 1 addition & 1 deletion ucc/driver/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void SetupToolChain(void)
#if 1
LDProg[8] = "libcmt.lib";
#endif
#if 0 // commented
#if 0
return;
#endif
ok:
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/enum/empty.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ enum Color{

int main(){

//printf("%d %d\n",RED,GREEN);
/* printf("%d %d\n",RED,GREEN); */
return 0;
}
2 changes: 1 addition & 1 deletion ucc/examples/fpu/fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ double PI;
int main(){
int i,method;

// system("clear");
/* system("clear"); */
PI=atan(1)*4;
printf("Please input the size of x:\n");
scanf("%d",&size_x);
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/implicite/implicite.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ a = 3.0;


int main(){
//b = 3.0; // --------------- error
/* b = 3.0; --------------- error */
int c = 30;
printf("%d \n",sizeof(a));
return 0;
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/link/1.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <math.h>
//float fabsf(float);
/* float fabsf(float); */
REAL_T add(REAL_T a , REAL_T b){
return a+b;
}
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/link/2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <math.h>
//int abc = 200;
/* int abc = 200; */
int abc;
int abc = 300;

Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/qualifier/qualify.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main(){
#if 0
#include <stdio.h>
/**
//
int IsIncompleteRecord(Type ty){
ty = Unqual(ty);
return ( IsRecordType(ty) && !((RecordType) ty)->complete);
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/sc/decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
static AstNodePtr DirectDeclarator(void);
static AstNodePtr PostfixDeclarator(void);
static AstNodePtr Declarator(void);
////////////////////////////////////////////////////////////////

/**
direct-declarator:
ID
Expand Down
10 changes: 5 additions & 5 deletions ucc/examples/sc/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int snprintf(char *str, size_t size, const char *format, ...);
#define ADD_RIGHT_ASSOCIATE
#define MUL_RIGHT_ASSOCIATE

/////////////////////////////////////////////////////////////////////

static int NewTemp(void){
static int tmpNo;
return tmpNo++;
Expand All @@ -29,7 +29,7 @@ AstNodePtr CreateAstNode(TokenKind tk,Value * pVal,
AstNodePtr left,AstNodePtr right){

AstNodePtr pNode = (AstNodePtr) malloc(sizeof(struct astNode));
// memset(pNode,0,sizeof(*pNode));
/* memset(pNode,0,sizeof(*pNode)); */
pNode->op = tk;
pNode->value = *pVal;
pNode->kids[0] = left;
Expand All @@ -38,15 +38,15 @@ AstNodePtr CreateAstNode(TokenKind tk,Value * pVal,
}


//

void Expect(TokenKind tk){
if(curToken.kind == tk){
NEXT_TOKEN;
}else{
Error("%s expected.\n",GetTokenName(tk));
}
}
//


static AstNodePtr PrimaryExpression(void){
AstNodePtr expr = NULL;
Expand All @@ -65,7 +65,7 @@ static AstNodePtr PrimaryExpression(void){
}


// id - id - id -....
/* id - id - id -.... */
static AstNodePtr MultiplicativeExpression(void){
#ifndef MUL_RIGHT_ASSOCIATE
AstNodePtr left;
Expand Down
14 changes: 7 additions & 7 deletions ucc/examples/sc/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static char * tokenNames[] = {
};
Token curToken;

////////////////////////////////////////////////////////////////////////

static TokenKind GetKeywordKind(char * id){
int i = 0;
for(i = 0; i < sizeof(keywords)/sizeof(keywords[0]); i++){
Expand All @@ -42,7 +42,7 @@ static int IsWhiteSpace(char ch){
static char defaultNextChar(void){
return EOF_CH;
}
//

static TokenKind GetTokenKindOfChar(char ch){
int i = 0;
for(i = 0; i < sizeof(tokenNames)/sizeof(tokenNames[0]); i++){
Expand All @@ -55,27 +55,27 @@ static TokenKind GetTokenKindOfChar(char ch){
const char * GetTokenName(TokenKind tk){
return tokenNames[tk];
}
//

Token GetToken(void){
Token token;
int len = 0;
memset(&token,0,sizeof(token));
// skip white space
/* skip white space */
while(IsWhiteSpace(curChar)){
curChar = NextChar();
}
TryAgain:
if(curChar == EOF_CH){
token.kind = TK_EOF;
}else if(isalpha(curChar)){//id or keyword
}else if(isalpha(curChar)){/* id or keyword */
len = 0;
do{
token.value.name[len] = curChar;
curChar = NextChar();
len++;
}while(isalnum(curChar) && len < MAX_ID_LEN);
token.kind = GetKeywordKind(token.value.name);
}else if(isdigit(curChar)){//number
}else if(isdigit(curChar)){/* number */
int numVal = 0;
token.kind = TK_NUM;
do{
Expand All @@ -85,7 +85,7 @@ Token GetToken(void){
token.value.numVal = numVal;
}else{
token.kind = GetTokenKindOfChar(curChar);
if(token.kind != TK_NA){// '+','-','*','/',...
if(token.kind != TK_NA){/* '+','-','*','/',... */
token.value.name[0] = curChar;
curChar = NextChar();
}else{
Expand Down
8 changes: 4 additions & 4 deletions ucc/examples/sc/lex.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#ifndef LEX_H
#define LEX_H
//

#define MAX_ID_LEN 15




//

typedef union{
char name[MAX_ID_LEN+1];
int numVal;

}Value;

//

typedef enum {
#define TOKEN(kind,name) kind,
#include "tokens.txt"
#undef TOKEN
}TokenKind;
//

typedef struct{
TokenKind kind;
Value value;
Expand Down
16 changes: 8 additions & 8 deletions ucc/examples/sc/stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ static AstStmtNodePtr WhileStatement(void);

static int isPrefixOfStatement(TokenKind tk);
static int NewLabel(void);
/////////////////////////////////////////////////////////////////////

static TokenKind prefixOfStmt[] = {
TK_ID,TK_IF,TK_WHILE,TK_LBRACE,TK_INT
};

///////////////////////////////////////////////////////////////////////////////

static int NewLabel(void){
static int labelNo;
return labelNo++;
Expand Down Expand Up @@ -57,7 +57,7 @@ static int isPrefixOfStatement(TokenKind tk){
}
static AstStmtNodePtr ExpressionStatement(void){
if(curToken.kind == TK_ID){
// id = expression;
/* id = expression; */
AstStmtNodePtr assign = CreateStmtNode(TK_ASSIGN);
assign->kids[0] = CreateAstNode(TK_ID,&curToken.value,NULL,NULL);
NEXT_TOKEN;
Expand All @@ -70,7 +70,7 @@ static AstStmtNodePtr ExpressionStatement(void){
Expect(TK_SEMICOLON);
return assign;
}else if(IS_PREFIX_OF_DECL(curToken.kind)){
// declaration ;
/* declaration ; */
AstStmtNodePtr decl = CreateStmtNode(TK_DECLARATION);
decl->expr = Declaration();
Expect(TK_SEMICOLON);
Expand Down Expand Up @@ -112,7 +112,7 @@ static AstStmtNodePtr IfStatement(void){
if(curToken.kind == TK_ELSE){
NEXT_TOKEN;
ifStmt->elseStmt = Statement();
// label for the statement after if-statment
/* label for the statement after if-statment */
ifStmt->kids[1] = CreateLabelNode();
}

Expand All @@ -136,11 +136,11 @@ static AstStmtNodePtr WhileStatement(void){
whileStmt->expr = Expression();
Expect(TK_RPAREN);
whileStmt->thenStmt = Statement();
// lable for the statement after while
/* lable for the statement after while */
whileStmt->kids[1] = CreateLabelNode();
return whileStmt;
}
// comStmt->next ----> list of statements
/* comStmt->next ----> list of statements */
AstStmtNodePtr CompoundStatement(void){
AstStmtNodePtr comStmt;
AstStmtNodePtr * pStmt;
Expand Down Expand Up @@ -218,7 +218,7 @@ void VisitStatementNode(AstStmtNodePtr stmt){
}
}
break;
case TK_DECLARATION: //declaration
case TK_DECLARATION: /* declaration */
VisitDeclarationNode(stmt->expr);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/sc/stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef struct astStmtNode{
TokenKind op;
Value value;
struct astNode * kids[2];
/////////////////////////////
/* ... */
struct astNode * expr;
struct astStmtNode * thenStmt;
struct astStmtNode * elseStmt;
Expand Down
2 changes: 1 addition & 1 deletion ucc/examples/struct/FirstFieldType.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(){
tk.value = 2;
tk.kind = 2;

//switch(tk.value){ // -----------Bug, tk.value is mistaken as struct type.
/* switch(tk.value){ -----------Bug, tk.value is mistaken as struct type. */
switch(tk.kind){
case 1:
printf("%s %d : case 1\n",__FILE__,__LINE__);
Expand Down
Loading

0 comments on commit 10658ca

Please sign in to comment.